use of com.odysseusinc.arachne.portal.model.AbstractPaperFile in project ArachneCentralAPI by OHDSI.
the class BasePaperController method getFile.
@ApiOperation("Get file of the Paper")
@RequestMapping(value = "/{id}/files/{fileUuid}", method = GET)
public FileDTO getFile(@PathVariable("id") Long id, @PathVariable("fileUuid") String uuid, @RequestParam("type") PaperFileType type, @RequestParam(defaultValue = "true") Boolean withContent) throws PermissionDeniedException, IOException {
final AbstractPaperFile paperFile = paperService.getFile(id, uuid, type);
FileDTO fileDto = conversionService.convert(paperFile, PaperFileDTO.class);
if (withContent) {
fileDto = FileDtoContentHandler.getInstance(fileDto, fileService.getPathToFile(paperFile).toFile()).withPdfConverter(toPdfConverter::convert).handle();
}
return fileDto;
}
use of com.odysseusinc.arachne.portal.model.AbstractPaperFile 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.AbstractPaperFile in project ArachneCentralAPI by OHDSI.
the class BasePaperServiceImpl method deleteFile.
@PreAuthorize("hasPermission(#paperId, 'Paper', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).LIMITED_EDIT_PAPER)")
// @Transactional not usable for this method.
@Override
public void deleteFile(Long paperId, String fileUuid, PaperFileType fileType) throws FileNotFoundException {
AbstractPaperFile paperFile;
switch(fileType) {
case PAPER:
{
paperFile = paperPaperFileRepository.findByPaperIdAndUuid(paperId, fileUuid).orElseThrow(() -> new NotExistException(AbstractPaperFile.class));
paperPaperFileRepository.delete(paperFile.getId());
break;
}
case PROTOCOL:
{
paperFile = paperProtocolFileRepository.findByPaperIdAndUuid(paperId, fileUuid).orElseThrow(() -> new NotExistException(AbstractPaperFile.class));
paperProtocolFileRepository.delete(paperFile.getId());
break;
}
default:
{
throw new IllegalArgumentException("Illegal filetype: " + fileType);
}
}
fileService.delete(paperFile);
}
use of com.odysseusinc.arachne.portal.model.AbstractPaperFile in project ArachneCentralAPI by OHDSI.
the class BasePaperServiceImpl method updateFile.
@PreAuthorize("hasPermission(#paperId, 'Paper', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).EDIT_PAPER)")
@Override
public void updateFile(Long paperId, String uuid, MultipartFile multipartFile, PaperFileType fileType, IUser user) throws IOException {
final AbstractPaperFile paperFile = getAbstractPaperFile(paperId, uuid, fileType);
fileService.updateFile(multipartFile, paperFile);
}
use of com.odysseusinc.arachne.portal.model.AbstractPaperFile 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();
}
}
Aggregations