use of com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobFileType 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.AntivirusJobFileType in project ArachneCentralAPI by OHDSI.
the class AntivirusServiceImpl method processRequest.
@EventListener
@Async(value = "antivirusScanExecutor")
public void processRequest(AntivirusJobEvent event) {
final AntivirusJob antivirusJob = event.getAntivirusJob();
final AntivirusJobFileType fileType = antivirusJob.getAntivirusJobFileType();
final Long fileId = antivirusJob.getFileId();
logger.debug(PROCESSING_SCAN_REQUEST, fileId, fileType);
String description = null;
AntivirusStatus status;
try {
final ScanResult scan = retryTemplate.execute((RetryCallback<ScanResult, Exception>) retryContext -> {
logger.debug(PROCESSING_SCAN_ATTEMPT, fileId, fileType);
return scan(antivirusJob.getContent());
});
if (scan instanceof ScanResult.OK) {
status = AntivirusStatus.OK;
} else {
status = AntivirusStatus.INFECTED;
description = scan.toString();
}
} catch (Exception e) {
logger.error("Error scanning file: {}", e.getMessage());
if (e instanceof ClamavException) {
final Throwable cause = e.getCause();
description = cause.getMessage();
} else {
description = e.getMessage();
}
status = AntivirusStatus.NOT_SCANNED;
}
logger.debug(PROCESSING_SCAN_RESULT, fileId, fileType, status);
publishResponse(fileType, fileId, status, description);
}
Aggregations