Search in sources :

Example 1 with Paper

use of com.odysseusinc.arachne.portal.model.Paper 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 Paper

use of com.odysseusinc.arachne.portal.model.Paper in project ArachneCentralAPI by OHDSI.

the class BasePaperServiceImpl method delete.

@PreAuthorize("hasPermission(#id, 'Paper', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).EDIT_PAPER)")
@Transactional
@Override
public void delete(Long id) throws FileNotFoundException {
    final Paper paper = Optional.of(paperRepository.getOne(id)).orElseThrow(() -> new NotExistException(Paper.class));
    Stream.concat(paper.getPapers().stream(), paper.getProtocols().stream()).forEach(file -> {
        try {
            deleteFile(id, file.getUuid(), file.getType());
        } catch (FileNotFoundException ex) {
            log.error("Paper file with uuid={} is not found", file.getUuid());
        }
    });
    if (paperRepository.deleteById(id) == 0) {
        throw new NotExistException(Paper.class);
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) Paper(com.odysseusinc.arachne.portal.model.Paper) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with Paper

use of com.odysseusinc.arachne.portal.model.Paper 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, String link, PaperFileType type, String label, IUser user) throws MalformedURLException {
    if (StringUtils.isEmpty(link)) {
        throw new IllegalArgumentException();
    }
    final Paper paper = get(paperId);
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(singletonList(MediaType.APPLICATION_OCTET_STREAM));
    HttpEntity<String> entity = new HttpEntity<>(headers);
    URL url = new URL(link);
    String fileName = FilenameUtils.getName(url.getPath());
    ResponseEntity<byte[]> response = restTemplate.exchange(link, HttpMethod.GET, entity, byte[].class);
    if (response.getStatusCode() == HttpStatus.OK) {
        String contentType = response.getHeaders().getContentType().toString();
        final AbstractPaperFile abstractPaperFile = savePaperFile(type, label, user, paper, CommonFileUtils.TYPE_LINK, fileName, link);
        return abstractPaperFile.getUuid();
    } else {
        throw new IllegalArgumentException();
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) Paper(com.odysseusinc.arachne.portal.model.Paper) URL(java.net.URL) AbstractPaperFile(com.odysseusinc.arachne.portal.model.AbstractPaperFile) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Paper

use of com.odysseusinc.arachne.portal.model.Paper in project ArachneCentralAPI by OHDSI.

the class BasePaperToPaperDTOConverter method convert.

@Override
public PD convert(P paper) {
    final PD paperDTO = createResultObject();
    paperDTO.setId(paper.getId());
    final Study study = paper.getStudy();
    final StudyMediumDTO studyDTO = conversionService.convert(study, StudyMediumDTO.class);
    paperDTO.setStudy(studyDTO);
    paperDTO.setPublishState(paper.getPublishState());
    paperDTO.setPublishedDate(paper.getPublishedDate());
    final List<PaperFileDTO> protocols = paper.getProtocols().stream().map(protocolFile -> conversionService.convert(protocolFile, PaperFileDTO.class)).collect(Collectors.toList());
    paperDTO.setProtocols(protocols);
    final List<PaperFileDTO> paperFileDTOs = paper.getPapers().stream().map(paperFile -> conversionService.convert(paperFile, PaperFileDTO.class)).collect(Collectors.toList());
    paperDTO.setPapers(paperFileDTOs);
    paperDTO.setPermissions(conversionService.convert(paper, PermissionsDTO.class));
    proceedAdditionalFields(paperDTO, paper);
    return paperDTO;
}
Also used : List(java.util.List) Component(org.springframework.stereotype.Component) PaperDTO(com.odysseusinc.arachne.portal.api.v1.dto.PaperDTO) StudyMediumDTO(com.odysseusinc.arachne.portal.api.v1.dto.StudyMediumDTO) Autowired(org.springframework.beans.factory.annotation.Autowired) BaseConversionServiceAwareConverter(com.odysseusinc.arachne.portal.api.v1.dto.converters.BaseConversionServiceAwareConverter) GenericConversionService(org.springframework.core.convert.support.GenericConversionService) PaperFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.PaperFileDTO) PermissionsDTO(com.odysseusinc.arachne.portal.api.v1.dto.PermissionsDTO) Collectors(java.util.stream.Collectors) Paper(com.odysseusinc.arachne.portal.model.Paper) Study(com.odysseusinc.arachne.portal.model.Study) Study(com.odysseusinc.arachne.portal.model.Study) PaperFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.PaperFileDTO) PermissionsDTO(com.odysseusinc.arachne.portal.api.v1.dto.PermissionsDTO) StudyMediumDTO(com.odysseusinc.arachne.portal.api.v1.dto.StudyMediumDTO)

Example 5 with Paper

use of com.odysseusinc.arachne.portal.model.Paper in project ArachneCentralAPI by OHDSI.

the class InvitationableToInvitationDTOConverter method convert.

@Override
public InvitationDTO convert(Invitationable source) {
    final InvitationDTO invitationDTO = new InvitationDTO();
    final List<ActionDTO> actionList = Arrays.asList(new ActionDTO("Accept", "accept", "success"), new ActionDTO("Decline", "decline", "cancel"));
    invitationDTO.setActionList(actionList);
    invitationDTO.setType(source.getInvitationType());
    invitationDTO.setId(source.getId());
    invitationDTO.setActionType(source.getActionType());
    invitationDTO.setDate(source.getCreated());
    invitationDTO.setUser(conversionService.convert(source.getAuthor(), ShortUserDTO.class));
    final Object entity = source.getEntity();
    String title = "";
    Long id = null;
    if (entity instanceof Study) {
        final Study study = (Study) entity;
        title = study.getTitle();
        id = study.getId();
    } else if (entity instanceof Paper) {
        final Paper paper = (Paper) entity;
        title = paper.getStudy().getDescription();
        id = paper.getId();
    } else if (entity instanceof Analysis) {
        final Analysis analysis = (Analysis) entity;
        title = analysis.getTitle();
        id = analysis.getId();
    }
    final InvitationEntityDTO studyShortDTO = getInvitationEntityDTO(title, id);
    invitationDTO.setEntity(studyShortDTO);
    return invitationDTO;
}
Also used : Study(com.odysseusinc.arachne.portal.model.Study) ShortUserDTO(com.odysseusinc.arachne.portal.api.v1.dto.ShortUserDTO) Analysis(com.odysseusinc.arachne.portal.model.Analysis) InvitationDTO(com.odysseusinc.arachne.portal.api.v1.dto.InvitationDTO) Paper(com.odysseusinc.arachne.portal.model.Paper) ActionDTO(com.odysseusinc.arachne.portal.api.v1.dto.ActionDTO) InvitationEntityDTO(com.odysseusinc.arachne.portal.api.v1.dto.InvitationEntityDTO)

Aggregations

Paper (com.odysseusinc.arachne.portal.model.Paper)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 Transactional (org.springframework.transaction.annotation.Transactional)3 AbstractPaperFile (com.odysseusinc.arachne.portal.model.AbstractPaperFile)2 Study (com.odysseusinc.arachne.portal.model.Study)2 ActionDTO (com.odysseusinc.arachne.portal.api.v1.dto.ActionDTO)1 InvitationDTO (com.odysseusinc.arachne.portal.api.v1.dto.InvitationDTO)1 InvitationEntityDTO (com.odysseusinc.arachne.portal.api.v1.dto.InvitationEntityDTO)1 PaperDTO (com.odysseusinc.arachne.portal.api.v1.dto.PaperDTO)1 PaperFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.PaperFileDTO)1 PermissionsDTO (com.odysseusinc.arachne.portal.api.v1.dto.PermissionsDTO)1 ShortUserDTO (com.odysseusinc.arachne.portal.api.v1.dto.ShortUserDTO)1 StudyMediumDTO (com.odysseusinc.arachne.portal.api.v1.dto.StudyMediumDTO)1 BaseConversionServiceAwareConverter (com.odysseusinc.arachne.portal.api.v1.dto.converters.BaseConversionServiceAwareConverter)1 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)1 Analysis (com.odysseusinc.arachne.portal.model.Analysis)1 AntivirusJob (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob)1 AntivirusJobEvent (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobEvent)1 AntivirusJobFileType (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobFileType)1 FileNotFoundException (java.io.FileNotFoundException)1