use of org.openforis.idm.metamodel.FileAttributeDefinition in project collect by openforis.
the class XMLDataExportProcess method calculateRecordFileEntryName.
public static String calculateRecordFileEntryName(FileAttribute fileAttribute) {
FileAttributeDefinition fileAttributeDefinition = fileAttribute.getDefinition();
String repositoryRelativePath = RecordFileManager.getRepositoryRelativePath(fileAttributeDefinition, ZIP_DIRECTORY_SEPARATOR, false);
String relativePath = RECORD_FILE_DIRECTORY_NAME + ZIP_DIRECTORY_SEPARATOR + repositoryRelativePath;
String entryName = relativePath + ZIP_DIRECTORY_SEPARATOR + fileAttribute.getFilename();
return entryName;
}
use of org.openforis.idm.metamodel.FileAttributeDefinition in project collect by openforis.
the class RecordFileManager method moveFileIntoRepository.
/**
* Moves a file into the repository and associates the file name to the corresponding file attribute node
* Returns true if the record is modified (file name or size different from the old one).
*/
public boolean moveFileIntoRepository(CollectRecord record, int nodeId, java.io.File newFile) throws IOException {
boolean recordUpdated = false;
FileAttribute fileAttribute = (FileAttribute) record.getNodeByInternalId(nodeId);
FileAttributeDefinition defn = fileAttribute.getDefinition();
String repositoryFileName = generateUniqueRepositoryFileName(fileAttribute, newFile);
File repositoryFile = new java.io.File(getRepositoryDir(defn), repositoryFileName);
long repositoryFileSize = newFile.length();
if (!repositoryFileName.equals(fileAttribute.getFilename()) || !Long.valueOf(repositoryFileSize).equals(fileAttribute.getSize())) {
recordUpdated = true;
fileAttribute.setFilename(repositoryFileName);
fileAttribute.setSize(repositoryFileSize);
}
FileUtils.moveFile(newFile, repositoryFile);
return recordUpdated;
}
use of org.openforis.idm.metamodel.FileAttributeDefinition in project collect by openforis.
the class SessionRecordFileManager method performFilesDelete.
protected boolean performFilesDelete(CollectRecord record) {
boolean result = false;
Set<Entry<Integer, String>> entrySet = filesToDelete.entrySet();
for (Entry<Integer, String> entry : entrySet) {
int nodeId = entry.getKey();
String fileName = entry.getValue();
FileAttribute fileAttr = (FileAttribute) record.getNodeByInternalId(nodeId);
FileAttributeDefinition defn = fileAttr.getDefinition();
java.io.File repositoryFile = recordFileManager.getRepositoryFile(defn, fileName);
repositoryFile.delete();
result = true;
}
filesToDelete.clear();
return result;
}
Aggregations