use of org.openforis.collect.manager.exception.RecordFileException in project collect by openforis.
the class SessionRecordFileManager method saveToTempFile.
public java.io.File saveToTempFile(InputStream is, String originalFileName, CollectRecord record, int nodeId) throws RecordFileException {
try {
prepareDeleteFile(record, nodeId);
String extension = FilenameUtils.getExtension(originalFileName);
java.io.File tempFile = java.io.File.createTempFile("collect_record_file_upload", "." + extension);
FileUtils.copyInputStreamToFile(is, tempFile);
indexTempFile(tempFile, nodeId);
return tempFile;
} catch (IOException e) {
throw new RecordFileException(e);
}
}
use of org.openforis.collect.manager.exception.RecordFileException 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);
}
}
}
}
use of org.openforis.collect.manager.exception.RecordFileException in project collect by openforis.
the class SessionRecordFileManager method moveTempFilesToRepository.
protected boolean moveTempFilesToRepository(CollectRecord record) throws RecordFileException {
try {
boolean recordChanged = false;
for (Entry<Integer, String> entry : nodeIdToTempFilePath.entrySet()) {
int nodeId = entry.getKey();
String fileName = entry.getValue();
java.io.File tempFile = new java.io.File(fileName);
boolean currentRecordChanged = recordFileManager.moveFileIntoRepository(record, nodeId, tempFile);
recordChanged = recordChanged || currentRecordChanged;
}
nodeIdToTempFilePath.clear();
return recordChanged;
} catch (IOException e) {
throw new RecordFileException(e);
}
}
Aggregations