use of org.obiba.mica.file.rest.FileResource in project mica2 by obiba.
the class DraftIndividualStudyResource method file.
@Path("/file/{fileId}")
public FileResource file(@PathParam("fileId") String fileId, @QueryParam("key") String key) {
checkPermission("/draft/individual-study", "VIEW", key);
FileResource fileResource = applicationContext.getBean(FileResource.class);
Study study = individualStudyService.findDraft(id);
if (study.hasLogo() && study.getLogo().getId().equals(fileId)) {
fileResource.setAttachment(study.getLogo());
} else {
List<Attachment> attachments = fileSystemService.findAttachments(String.format("^/individual-study/%s", study.getId()), false).stream().filter(a -> a.getId().equals(fileId)).collect(Collectors.toList());
if (attachments.isEmpty())
throw NoSuchEntityException.withId(Attachment.class, fileId);
fileResource.setAttachment(attachments.get(0));
}
return fileResource;
}
Aggregations