Search in sources :

Example 1 with AntivirusJobFileType

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();
}
Also used : AntivirusJob(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob) AntivirusJobFileType(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobFileType) Paper(com.odysseusinc.arachne.portal.model.Paper) AntivirusJobEvent(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobEvent) AbstractPaperFile(com.odysseusinc.arachne.portal.model.AbstractPaperFile) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with AntivirusJobFileType

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);
}
Also used : Async(org.springframework.scheduling.annotation.Async) LoggerFactory(org.slf4j.LoggerFactory) AntivirusJobResponse(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobResponse) Autowired(org.springframework.beans.factory.annotation.Autowired) ScanResult(xyz.capybara.clamav.commands.scan.result.ScanResult) AntivirusStatus(com.odysseusinc.arachne.portal.model.AntivirusStatus) AntivirusJobStudyFileResponseEvent(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobStudyFileResponseEvent) Value(org.springframework.beans.factory.annotation.Value) AntivirusJobEvent(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobEvent) Service(org.springframework.stereotype.Service) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) ClamavException(xyz.capybara.clamav.ClamavException) AntivirusJobPaperProtocolFileResponseEvent(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobPaperProtocolFileResponseEvent) Logger(org.slf4j.Logger) AntivirusJobFileType(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobFileType) AntivirusJobAnalysisFileResponseEvent(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobAnalysisFileResponseEvent) EventListener(org.springframework.context.event.EventListener) IOException(java.io.IOException) AntivirusJobPaperPaperFileResponseEvent(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobPaperPaperFileResponseEvent) AntivirusJobResponseEventBase(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobResponseEventBase) ClamavClient(xyz.capybara.clamav.ClamavClient) AntivirusJob(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob) RetryCallback(org.springframework.retry.RetryCallback) RetryTemplate(org.springframework.retry.support.RetryTemplate) InputStream(java.io.InputStream) AntivirusJob(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob) ScanResult(xyz.capybara.clamav.commands.scan.result.ScanResult) AntivirusJobFileType(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobFileType) AntivirusStatus(com.odysseusinc.arachne.portal.model.AntivirusStatus) ClamavException(xyz.capybara.clamav.ClamavException) IOException(java.io.IOException) ClamavException(xyz.capybara.clamav.ClamavException) Async(org.springframework.scheduling.annotation.Async) EventListener(org.springframework.context.event.EventListener)

Aggregations

AntivirusJob (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob)2 AntivirusJobEvent (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobEvent)2 AntivirusJobFileType (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobFileType)2 AbstractPaperFile (com.odysseusinc.arachne.portal.model.AbstractPaperFile)1 AntivirusStatus (com.odysseusinc.arachne.portal.model.AntivirusStatus)1 Paper (com.odysseusinc.arachne.portal.model.Paper)1 AntivirusJobAnalysisFileResponseEvent (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobAnalysisFileResponseEvent)1 AntivirusJobPaperPaperFileResponseEvent (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobPaperPaperFileResponseEvent)1 AntivirusJobPaperProtocolFileResponseEvent (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobPaperProtocolFileResponseEvent)1 AntivirusJobResponse (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobResponse)1 AntivirusJobResponseEventBase (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobResponseEventBase)1 AntivirusJobStudyFileResponseEvent (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobStudyFileResponseEvent)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Qualifier (org.springframework.beans.factory.annotation.Qualifier)1 Value (org.springframework.beans.factory.annotation.Value)1 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)1