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);
}
}
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()));
}
}
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;
}
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;
}
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);
}
}
}
}
Aggregations