/** * Move the files of the deliver to a new path. If old path * * @param dstPath Path to store the files. It cannot exist previously. * @return True if all files have been correctly moved to the new path of False otherwise */ public boolean moveFiles(File dstPath) { // Check that destination folder does not exist if (dstPath.getAbsoluteFile().exists()) { return false; } // Create the output path if (!dstPath.getAbsoluteFile().mkdirs()) { return false; } // Move the files for (DeliverFile f : _files) { if (!f.getAbsolutePath(_rootPath).renameTo(f.getAbsolutePath(dstPath))) { return false; } } // Remove old path _rootPath.getAbsoluteFile().delete(); // Change the root path to the new folder _rootPath = dstPath; return true; }
/** * Add a new file to the deliver * * @param file Path to the file * @return True if the file is correctly added or False otherwise. */ public boolean addFile(DeliverFile file) { if (!file.getAbsolutePath(_rootPath).exists()) { return false; } _files.add(file.clone()); return true; }
/** * Basic copy constructor * * @param deliver Deliver object with data */ public Deliver(Deliver deliver) { _deliverID = new DeliverID(deliver._deliverID); _rootPath = deliver._rootPath; for (DeliverFile file : deliver._files) { _files.add(file.clone()); } _creationDate = deliver._creationDate; _userLabClassroom = deliver._userLabClassroom; _userMainClassroom = deliver._userMainClassroom; }
/** * Checks if the deliver is correct * * @return True if the deliver is correct or False otherwise. */ public boolean correct() { if (_rootPath == null) { return false; } for (DeliverFile df : _files) { File f = df.getAbsolutePath(_rootPath); if (!f.exists() || !f.canRead()) { return false; } } return true; }
/** * Obtain the code project from this deliver * * @return Code project with the code files of the deliver * @throws ExecPelpException If some file cannot be accessed */ public CodeProject getCodeProject() throws ExecPelpException { CodeProject project = new CodeProject(_rootPath); // Add code files to the project for (DeliverFile deliverFile : _files) { if (deliverFile.getType().equals(FileType.Code)) { if (deliverFile.isMainFile()) { project.addMainFile(deliverFile.getAbsolutePath(_rootPath)); } else { project.addFile(deliverFile.getAbsolutePath(_rootPath)); } } } return project; }