Search in sources :

Example 6 with FileAttributeDefinition

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;
}
Also used : FileAttributeDefinition(org.openforis.idm.metamodel.FileAttributeDefinition)

Example 7 with FileAttributeDefinition

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;
}
Also used : FileAttributeDefinition(org.openforis.idm.metamodel.FileAttributeDefinition) File(java.io.File) FileAttribute(org.openforis.idm.model.FileAttribute)

Example 8 with FileAttributeDefinition

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;
}
Also used : Entry(java.util.Map.Entry) FileAttributeDefinition(org.openforis.idm.metamodel.FileAttributeDefinition) FileAttribute(org.openforis.idm.model.FileAttribute)

Aggregations

FileAttributeDefinition (org.openforis.idm.metamodel.FileAttributeDefinition)8 File (java.io.File)2 FileAttribute (org.openforis.idm.model.FileAttribute)2 ArrayList (java.util.ArrayList)1 Entry (java.util.Map.Entry)1 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)1 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)1 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)1 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)1 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)1 RangeAttributeDefinition (org.openforis.idm.metamodel.RangeAttributeDefinition)1 TaxonAttributeDefinition (org.openforis.idm.metamodel.TaxonAttributeDefinition)1 TextAttributeDefinition (org.openforis.idm.metamodel.TextAttributeDefinition)1 TimeAttributeDefinition (org.openforis.idm.metamodel.TimeAttributeDefinition)1