use of org.openforis.idm.model.FileAttribute in project collect by openforis.
the class XMLDataImportProcess method importRecordFiles.
private void importRecordFiles(CollectRecord record) throws IOException, RecordPersistenceException {
sessionRecordFileManager.resetTempInfo();
List<FileAttribute> fileAttributes = record.getFileAttributes();
String sessionId = "admindataimport";
for (FileAttribute fileAttribute : fileAttributes) {
String recordFileEntryName = XMLDataExportProcess.calculateRecordFileEntryName(fileAttribute);
InputStream is = backupFileExtractor.findEntryInputStream(recordFileEntryName);
if (is != null) {
sessionRecordFileManager.saveToTempFile(is, fileAttribute.getFilename(), record, fileAttribute.getInternalId());
}
}
if (sessionRecordFileManager.commitChanges(record)) {
if (record.getStep() == Step.ANALYSIS) {
record.setStep(Step.CLEANSING);
recordManager.save(record, sessionId);
record.setStep(Step.ANALYSIS);
}
recordManager.save(record, sessionId);
}
}
use of org.openforis.idm.model.FileAttribute in project collect by openforis.
the class RecordFileBackupTask method backup.
private void backup(CollectRecordSummary summary) throws RecordFileException, IOException {
Integer id = summary.getId();
CollectRecord record = recordManager.load(survey, id, summary.getStep(), false);
List<FileAttribute> fileAttributes = record.getFileAttributes();
for (FileAttribute fileAttribute : fileAttributes) {
if (StringUtils.isNotBlank(fileAttribute.getFilename())) {
File file = recordFileManager.getRepositoryFile(fileAttribute);
if (file != null && file.exists()) {
String entryName = calculateRecordFileEntryName(fileAttribute);
writeFile(file, entryName);
} else {
addSkippedFileError(summary, fileAttribute.getPath(), recordFileManager.getRepositoryFileAbsolutePath(fileAttribute));
log.error(String.format("Record file not found for record %s (%d) attribute %s (%d)", StringUtils.join(record.getRootEntityKeyValues(), ','), record.getId(), fileAttribute.getPath(), fileAttribute.getInternalId()));
// throw new RecordFileException(message);
}
}
}
}
use of org.openforis.idm.model.FileAttribute in project collect by openforis.
the class SpecifiedValidator method evaluate.
@Override
public ValidationResultFlag evaluate(Attribute<?, ?> attribute) {
CollectRecord record = (CollectRecord) attribute.getRecord();
Step step = record.getStep();
if (Step.ENTRY == step) {
if (attribute.isRelevant() && attribute.isEmpty() && !(attribute instanceof FileAttribute)) {
if (isReasonBlankAlwaysSpecified(attribute)) {
if (attribute.isRequired()) {
return WARNING;
} else {
return OK;
}
} else {
return ERROR;
}
} else {
return OK;
}
}
return OK;
}
use of org.openforis.idm.model.FileAttribute 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.model.FileAttribute 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