use of com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisServiceImpl method writeContentAndCheckForViruses.
private void writeContentAndCheckForViruses(final AnalysisFile analysisFile, final IUser updatedBy, final String content) throws IOException {
try {
final Analysis analysis = analysisFile.getAnalysis();
Path analysisFolder = analysisHelper.getAnalysisFolder(analysis);
if (Files.notExists(analysisFolder)) {
Files.createDirectories(analysisFolder);
}
Path targetPath = analysisFolder.resolve(analysisFile.getUuid());
byte[] bytes = content.getBytes(StandardCharsets.UTF_8);
try (final InputStream stream = new ByteArrayInputStream(bytes)) {
Files.copy(stream, targetPath, REPLACE_EXISTING);
}
analysisFile.setUpdated(new Date());
analysisFile.setEntryPoint(analysisFile.getEntryPoint());
analysisFile.setUpdatedBy(updatedBy);
analysisFile.setContentType(CommonFileUtils.getContentType(analysisFile.getName(), targetPath.toString()));
analysisFile.incrementVersion();
analysisFile.setAntivirusStatus(AntivirusStatus.SCANNING);
analysisFile.setAntivirusDescription(null);
eventPublisher.publishEvent(new AntivirusJobEvent(this, new AntivirusJob(analysisFile.getId(), analysisFile.getName(), 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);
}
}
use of com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob 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 (InputStream content = antivirusJob.getContent()) {
clamavClientAvailabilityCheck();
final ScanResult scan = retryTemplate.execute((RetryCallback<ScanResult, Exception>) retryContext -> {
logger.debug(PROCESSING_SCAN_ATTEMPT, fileId, fileType);
return scan(content);
});
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