Search in sources :

Example 1 with RecordFileException

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);
    }
}
Also used : RecordFileException(org.openforis.collect.manager.exception.RecordFileException) IOException(java.io.IOException)

Example 2 with RecordFileException

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

Example 3 with RecordFileException

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);
    }
}
Also used : RecordFileException(org.openforis.collect.manager.exception.RecordFileException) IOException(java.io.IOException)

Aggregations

RecordFileException (org.openforis.collect.manager.exception.RecordFileException)3 IOException (java.io.IOException)2 File (java.io.File)1 FileAttribute (org.openforis.idm.model.FileAttribute)1