Search in sources :

Example 1 with FileAttribute

use of org.openforis.idm.model.FileAttribute in project collect by openforis.

the class RecordFileRestoreTask method importRecordFiles.

private void importRecordFiles(CollectRecord record) throws IOException, RecordPersistenceException {
    sessionRecordFileManager.resetTempInfo();
    recordFileManager.deleteAllFiles(record);
    List<FileAttribute> fileAttributes = record.getFileAttributes();
    for (FileAttribute fileAttribute : fileAttributes) {
        if (!fileAttribute.isEmpty()) {
            String recordFileEntryName = RecordFileBackupTask.calculateRecordFileEntryName(fileAttribute);
            InputStream is = backupFileExtractor.findEntryInputStream(recordFileEntryName);
            if (is != null) {
                sessionRecordFileManager.saveToTempFile(is, fileAttribute.getFilename(), record, fileAttribute.getInternalId());
            }
        }
    }
    if (sessionRecordFileManager.commitChanges(record)) {
        recordManager.save(record, null, null, false);
    }
}
Also used : InputStream(java.io.InputStream) FileAttribute(org.openforis.idm.model.FileAttribute)

Example 2 with FileAttribute

use of org.openforis.idm.model.FileAttribute in project collect by openforis.

the class FileAttributeMapper method setFields.

@Override
void setFields(Node<?> node, InsertSetStep<?> insert) {
    FileAttribute f = (FileAttribute) node;
    File value = f.getValue();
    if (value != null) {
        insert.set(Data.DATA.TEXT1, value.getFilename());
        insert.set(Data.DATA.NUMBER1, toNumeric(value.getSize()));
    }
}
Also used : File(org.openforis.idm.model.File) FileAttribute(org.openforis.idm.model.FileAttribute)

Example 3 with FileAttribute

use of org.openforis.idm.model.FileAttribute in project collect by openforis.

the class CollectRecord method getFileAttributes.

public List<FileAttribute> getFileAttributes() {
    final List<FileAttribute> result = new ArrayList<FileAttribute>();
    Entity rootEntity = getRootEntity();
    rootEntity.traverse(new NodeVisitor() {

        @Override
        public void visit(Node<? extends NodeDefinition> node, int pos) {
            if (node instanceof FileAttribute) {
                result.add((FileAttribute) node);
            }
        }
    });
    return result;
}
Also used : Entity(org.openforis.idm.model.Entity) ArrayList(java.util.ArrayList) FileAttribute(org.openforis.idm.model.FileAttribute) NodeVisitor(org.openforis.idm.model.NodeVisitor)

Example 4 with FileAttribute

use of org.openforis.idm.model.FileAttribute in project collect by openforis.

the class AttributeUpdateRequestProxy method toAttributeUpdateRequest.

@Override
@SuppressWarnings("unchecked")
public AttributeUpdateRequest<?> toAttributeUpdateRequest(CodeListManager codeListManager, RecordSessionManager sessionManager, CollectRecord record) {
    AttributeUpdateRequest<Value> opts = new NodeUpdateRequest.AttributeUpdateRequest<Value>();
    Attribute<?, ?> attribute = (Attribute<?, ?>) record.getNodeByInternalId(nodeId);
    opts.setAttribute((Attribute<?, Value>) attribute);
    Value parsedValue;
    if (attribute instanceof FileAttribute) {
        parsedValue = parseFileAttributeValue(sessionManager, record, nodeId, value);
    } else if (value == null) {
        parsedValue = null;
    } else {
        Entity parentEntity = attribute.getParent();
        String attributeName = attribute.getName();
        parsedValue = parseCompositeAttributeValue(codeListManager, parentEntity, attributeName, value);
    }
    opts.setValue(parsedValue);
    opts.setSymbol(symbol);
    return opts;
}
Also used : Entity(org.openforis.idm.model.Entity) AttributeUpdateRequest(org.openforis.collect.remoting.service.NodeUpdateRequest.AttributeUpdateRequest) Attribute(org.openforis.idm.model.Attribute) FileAttribute(org.openforis.idm.model.FileAttribute) Value(org.openforis.idm.model.Value) FileAttribute(org.openforis.idm.model.FileAttribute)

Example 5 with FileAttribute

use of org.openforis.idm.model.FileAttribute in project collect by openforis.

the class XMLDataExportProcess method backupRecordFiles.

private void backupRecordFiles(ZipOutputStream zipOutputStream, CollectRecord record) throws RecordFileException {
    List<FileAttribute> fileAttributes = record.getFileAttributes();
    for (FileAttribute fileAttribute : fileAttributes) {
        if (!fileAttribute.isEmpty()) {
            File file = recordFileManager.getRepositoryFile(fileAttribute);
            if (file == null) {
                String message = String.format("Missing file: %s attributeId: %d attributeName: %s", fileAttribute.getFilename(), fileAttribute.getInternalId(), fileAttribute.getName());
                throw new RecordFileException(message);
            } else {
                String entryName = calculateRecordFileEntryName(fileAttribute);
                writeFile(zipOutputStream, file, entryName);
            }
        }
    }
}
Also used : RecordFileException(org.openforis.collect.manager.exception.RecordFileException) File(java.io.File) FileAttribute(org.openforis.idm.model.FileAttribute)

Aggregations

FileAttribute (org.openforis.idm.model.FileAttribute)10 File (java.io.File)3 InputStream (java.io.InputStream)2 CollectRecord (org.openforis.collect.model.CollectRecord)2 FileAttributeDefinition (org.openforis.idm.metamodel.FileAttributeDefinition)2 Entity (org.openforis.idm.model.Entity)2 ArrayList (java.util.ArrayList)1 Entry (java.util.Map.Entry)1 RecordFileException (org.openforis.collect.manager.exception.RecordFileException)1 Step (org.openforis.collect.model.CollectRecord.Step)1 AttributeUpdateRequest (org.openforis.collect.remoting.service.NodeUpdateRequest.AttributeUpdateRequest)1 Attribute (org.openforis.idm.model.Attribute)1 File (org.openforis.idm.model.File)1 NodeVisitor (org.openforis.idm.model.NodeVisitor)1 Value (org.openforis.idm.model.Value)1