private File retrieveMetadataFile(File thesisFolder) {
return new File(this.sourceFolder.getPath() + File.separator + META + File.separator + new File(thesisFolder.getParent()).getName() + File.separator + thesisFolder.getName() + ".xml");
}
private void populateRepositoryFromThesis(File thesisFolderFile) throws ObjectLockedException, ObjectExistsException, FileNotFoundException {
Folder thesisFolder = new FolderImpl();
thesisFolder.setName(thesisFolderFile.getName());
thesisFolder.setDatestamp(new GregorianCalendar());
File metadataFile = this.retrieveMetadataFile(thesisFolderFile);
ThesisMetadata thesisMetadata = ThesisMetadata.createInstanceFromFile(metadataFile);
DatabaseUtil dbUtil = DatabaseUtil.getSingleton();
try {
//FIXME Do not hardcode
dbUtil.beginTransaction(new CredentialsWrapper(username, password));
Collection folderCollection = this.createOrGetThesisCollection(thesisMetadata);
if (folderCollection.getFolders() == null) {
folderCollection.setFolders( new ArrayList() );
}
folderCollection.getFolders().add(thesisFolder);
thesisFolder.setParentCollection(folderCollection);
if (thesisFolder.getReadUsers() == null) {
thesisFolder.setReadUsers(new ArrayList());
}
thesisFolder.getReadUsers().add(new UserImpl("anonymous", ""));
FolderDao.createInstance().save(thesisFolder);
this.addMetadateInFolder(thesisMetadata, thesisFolder);
this.addFilesInFolder(thesisFolderFile, thesisFolder);