use of com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob 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.service.impl.antivirus.events.AntivirusJob in project ArachneCentralAPI by OHDSI.
the class BasePaperServiceImpl method saveFile.
@PreAuthorize("hasPermission(#paperId, 'Paper', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).LIMITED_EDIT_PAPER)")
@Transactional(rollbackFor = Exception.class)
@Override
public String saveFile(Long paperId, MultipartFile file, PaperFileType fileType, String label, IUser user) throws IOException {
if (file == null) {
throw new IllegalArgumentException("File must not be null");
}
final Paper paper = get(paperId);
final String realName = file.getOriginalFilename();
final String contentType = CommonFileUtils.getContentType(realName, file);
AbstractPaperFile paperFile = savePaperFile(fileType, label, user, paper, contentType, realName, null);
fileService.saveFile(file, paperFile);
AntivirusJobFileType antivirusJobFileType;
switch(fileType) {
case PAPER:
antivirusJobFileType = AntivirusJobFileType.PAPER_PAPER_FILE;
break;
case PROTOCOL:
antivirusJobFileType = AntivirusJobFileType.PAPER_PROTOCOL_FILE;
break;
default:
throw new IllegalArgumentException();
}
eventPublisher.publishEvent(new AntivirusJobEvent(this, new AntivirusJob(paperFile.getId(), paperFile.getRealName(), fileService.getFileInputStream(paperFile), antivirusJobFileType)));
return paperFile.getUuid();
}
use of com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob in project ArachneCentralAPI by OHDSI.
the class AnalysisFilesSavingServiceImpl method saveFile.
@Override
@PreAuthorize("hasPermission(#analysis, " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).UPLOAD_ANALYSIS_FILES)")
public AnalysisFile saveFile(MultipartFile multipartFile, IUser user, A analysis, String label, Boolean isExecutable, DataReference dataReference) throws AlreadyExistException {
ensureLabelIsUnique(analysis.getId(), label);
String originalFilename = multipartFile.getOriginalFilename();
String fileNameLowerCase = UUID.randomUUID().toString();
try {
Path analysisPath = analysisHelper.getAnalysisPath(analysis);
Path targetPath = Paths.get(analysisPath.toString(), fileNameLowerCase);
Files.copy(multipartFile.getInputStream(), targetPath, REPLACE_EXISTING);
final String contentType = CommonFileUtils.getContentType(originalFilename, targetPath.toString());
AnalysisFile analysisFile = buildNewAnalysisFileEntry(user, analysis, label, isExecutable, originalFilename, fileNameLowerCase, contentType);
analysisFile.setDataReference(dataReference);
AnalysisFile saved = analysisFileRepository.save(analysisFile);
analysis.getFiles().add(saved);
preprocessorService.preprocessFile(analysis, analysisFile);
eventPublisher.publishEvent(new AntivirusJobEvent(this, new AntivirusJob(saved.getId(), saved.getName(), 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();
log.error(message, ex);
throw new ArachneSystemRuntimeException(message);
}
}
use of com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob in project ArachneCentralAPI by OHDSI.
the class BaseStudyServiceImpl method saveFile.
@Override
@PreAuthorize("hasPermission(#studyId, 'Study', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).UPLOAD_FILES)")
public String saveFile(MultipartFile multipartFile, Long studyId, String label, IUser user) throws IOException {
Study study = studyRepository.getOne(studyId);
String fileNameLowerCase = UUID.randomUUID().toString();
try {
StudyFile studyFile = new StudyFile();
studyFile.setUuid(fileNameLowerCase);
studyFile.setStudy(study);
studyFile.setLabel(label);
studyFile.setRealName(multipartFile.getOriginalFilename());
Date created = new Date();
studyFile.setCreated(created);
studyFile.setUpdated(created);
studyFile.setAuthor(user);
// Save study after uuid and Study were set
fileService.saveFile(multipartFile, studyFile);
// Detect file content type (requires file to exist)
String contentType = CommonFileUtils.getContentType(multipartFile.getOriginalFilename(), fileService.getStudyFilePath(studyFile).toAbsolutePath().toString());
studyFile.setContentType(contentType);
// Save entity
studyFileRepository.save(studyFile);
eventPublisher.publishEvent(new AntivirusJobEvent(this, new AntivirusJob(studyFile.getId(), studyFile.getRealName(), fileService.getFileInputStream(studyFile), AntivirusJobFileType.STUDY_FILE)));
return fileNameLowerCase;
} catch (IOException | RuntimeException ex) {
String message = "error save file to disk, filename=" + fileNameLowerCase + " ex=" + ex.toString();
LOGGER.debug(message, ex);
throw new IOException(message);
}
}
use of com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisServiceImpl method writeToFile.
@Override
@PreAuthorize("hasPermission(#analysisFile, " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).DELETE_ANALYSIS_FILES)")
public void writeToFile(AnalysisFile analysisFile, FileDTO fileContentDTO, IUser updatedBy) throws IOException {
Analysis analysis = analysisFile.getAnalysis();
throwAccessDeniedExceptionIfLocked(analysis);
Study study = analysis.getStudy();
try {
Path analysisFolder = analysisHelper.getAnalysisFolder(analysis);
if (Files.notExists(analysisFolder)) {
Files.createDirectories(analysisFolder);
}
Path targetPath = analysisFolder.resolve(analysisFile.getUuid());
byte[] content = fileContentDTO.getContent().getBytes(StandardCharsets.UTF_8);
try (final InputStream stream = new ByteArrayInputStream(content)) {
Files.copy(stream, targetPath, REPLACE_EXISTING);
}
analysisFile.setUpdated(new Date());
analysisFile.setEntryPoint(analysisFile.getEntryPoint());
analysisFile.setUpdatedBy(updatedBy);
analysisFile.setContentType(CommonFileUtils.getContentType(analysisFile.getRealName(), targetPath.toString()));
analysisFile.incrementVersion();
analysisFile.setAntivirusStatus(AntivirusStatus.SCANNING);
analysisFile.setAntivirusDescription(null);
final AnalysisFile saved = analysisFileRepository.save(analysisFile);
eventPublisher.publishEvent(new AntivirusJobEvent(this, new AntivirusJob(saved.getId(), saved.getRealName(), new FileInputStream(targetPath.toString()), AntivirusJobFileType.ANALYSIS_FILE)));
} catch (IOException | RuntimeException ex) {
String message = "error save file to disk, filename=" + analysisFile.getUuid() + " ex=" + ex.toString();
LOGGER.error(message, ex);
throw new IOException(message);
}
}
Aggregations