use of com.odysseusinc.arachne.portal.model.AnalysisFile in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisServiceImpl method saveFile.
@Override
public AnalysisFile saveFile(MultipartFile multipartFile, IUser user, A analysis, String label, Boolean isExecutable, DataReference dataReference) throws IOException {
String originalFilename = multipartFile.getOriginalFilename();
String fileNameLowerCase = UUID.randomUUID().toString();
try {
Path analysisPath = getAnalysisPath(analysis);
Path targetPath = Paths.get(analysisPath.toString(), fileNameLowerCase);
Files.copy(multipartFile.getInputStream(), targetPath, REPLACE_EXISTING);
AnalysisFile analysisFile = new AnalysisFile();
analysisFile.setDataReference(dataReference);
analysisFile.setUuid(fileNameLowerCase);
analysisFile.setAnalysis(analysis);
analysisFile.setContentType(CommonFileUtils.getContentType(originalFilename, targetPath.toString()));
analysisFile.setLabel(label);
analysisFile.setAuthor(user);
analysisFile.setUpdatedBy(user);
analysisFile.setExecutable(false);
analysisFile.setRealName(originalFilename);
Date created = new Date();
analysisFile.setCreated(created);
analysisFile.setUpdated(created);
analysisFile.setVersion(1);
beforeSaveAnalysisFile(analysisFile);
AnalysisFile saved = analysisFileRepository.save(analysisFile);
analysis.getFiles().add(saved);
afterSaveAnalysisFile(saved);
if (Boolean.TRUE.equals(isExecutable)) {
setIsExecutable(saved.getUuid());
}
preprocessorService.preprocessFile(analysis, analysisFile);
eventPublisher.publishEvent(new AntivirusJobEvent(this, new AntivirusJob(saved.getId(), saved.getRealName(), new FileInputStream(targetPath.toString()), AntivirusJobFileType.ANALYSIS_FILE)));
return saved;
} catch (IOException | RuntimeException ex) {
String message = "error save file to disk, filename=" + fileNameLowerCase + " ex=" + ex.toString();
LOGGER.error(message, ex);
throw new IOException(message);
}
}
use of com.odysseusinc.arachne.portal.model.AnalysisFile in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisServiceImpl method updateFile.
@Override
public void updateFile(String uuid, MultipartFile file, Long analysisId, Boolean isExecutable) throws IOException {
A analysis = analysisRepository.findOne(analysisId);
throwAccessDeniedExceptionIfLocked(analysis);
Study study = analysis.getStudy();
try {
AnalysisFile analysisFile = analysisFileRepository.findByUuid(uuid);
if (file != null) {
analysisFile.setRealName(file.getOriginalFilename());
Path analysisFolder = analysisHelper.getAnalysisFolder(analysis);
if (Files.notExists(analysisFolder)) {
Files.createDirectories(analysisFolder);
}
Path targetPath = analysisFolder.resolve(uuid);
Files.copy(file.getInputStream(), targetPath, REPLACE_EXISTING);
String contentType = CommonFileUtils.getContentType(file.getOriginalFilename(), targetPath.toString());
analysisFile.setContentType(contentType);
}
Date updated = new Date();
analysisFile.setUpdated(updated);
analysisFile.incrementVersion();
analysisFile.setExecutable(isExecutable != null && isExecutable);
analysisFileRepository.save(analysisFile);
} catch (IOException | RuntimeException ex) {
String message = "error save file to disk, filename=" + uuid + " ex=" + ex.toString();
LOGGER.error(message, ex);
throw new IOException(message);
}
}
use of com.odysseusinc.arachne.portal.model.AnalysisFile in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisServiceImpl method getAnalysisAllFiles.
@Override
public void getAnalysisAllFiles(Long analysisId, String archiveName, OutputStream os) throws IOException {
Analysis analysis = analysisRepository.findOne(analysisId);
Path storeFilesPath = analysisHelper.getAnalysisFolder(analysis);
try (ZipOutputStream zos = new ZipOutputStream(os)) {
for (AnalysisFile analysisFile : analysis.getFiles()) {
String realName = analysisFile.getRealName();
Path file = storeFilesPath.resolve(analysisFile.getUuid());
ZipUtil.addZipEntry(zos, realName, file);
}
}
}
use of com.odysseusinc.arachne.portal.model.AnalysisFile in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisServiceImpl method processAntivirusResponse.
@EventListener
@Transactional
@Override
public void processAntivirusResponse(AntivirusJobAnalysisFileResponseEvent event) {
final AntivirusJobResponse antivirusJobResponse = event.getAntivirusJobResponse();
final AnalysisFile analysisFile = analysisFileRepository.findOne(antivirusJobResponse.getFileId());
if (analysisFile != null) {
analysisFile.setAntivirusStatus(antivirusJobResponse.getStatus());
analysisFile.setAntivirusDescription(antivirusJobResponse.getDescription());
analysisFileRepository.save(analysisFile);
}
}
use of com.odysseusinc.arachne.portal.model.AnalysisFile in project ArachneCentralAPI by OHDSI.
the class AnalysisPreprocessorService method preprocessFile.
public void preprocessFile(Analysis analysis, AnalysisFile file) {
Path analysisFolder = analysisHelper.getAnalysisFolder(analysis);
File target = analysisFolder.resolve(file.getRealName()).toFile();
getPreprocessorRegistry().getPreprocessor(file.getContentType()).preprocess(analysis, target);
}
Aggregations