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();
}
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);
}
}
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();
}
}
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;
}
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;
}
Aggregations