Search in sources :

Example 6 with FileResource

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;
}
Also used : RevisionStatus(org.obiba.mica.core.domain.RevisionStatus) PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ConstraintException(org.obiba.mica.study.ConstraintException) Path(javax.ws.rs.Path) HashMap(java.util.HashMap) Scope(org.springframework.context.annotation.Scope) Inject(javax.inject.Inject) MediaType(javax.ws.rs.core.MediaType) AbstractGitPersistableResource(org.obiba.mica.AbstractGitPersistableResource) QueryParam(javax.ws.rs.QueryParam) PublishCascadingScope(org.obiba.mica.core.domain.PublishCascadingScope) SubjectAclResource(org.obiba.mica.security.rest.SubjectAclResource) Map(java.util.Map) Mica(org.obiba.mica.web.model.Mica) DefaultValue(javax.ws.rs.DefaultValue) StudyState(org.obiba.mica.study.domain.StudyState) Dtos(org.obiba.mica.web.model.Dtos) Nullable(javax.annotation.Nullable) DELETE(javax.ws.rs.DELETE) FileResource(org.obiba.mica.file.rest.FileResource) Attachment(org.obiba.mica.file.Attachment) FileSystemService(org.obiba.mica.file.service.FileSystemService) IOException(java.io.IOException) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) ApplicationContext(org.springframework.context.ApplicationContext) Maps(com.google.common.collect.Maps) NoSuchEntityException(org.obiba.mica.NoSuchEntityException) IndividualStudyService(org.obiba.mica.study.service.IndividualStudyService) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) Component(org.springframework.stereotype.Component) Study(org.obiba.mica.study.domain.Study) Response(javax.ws.rs.core.Response) PUT(javax.ws.rs.PUT) AbstractGitPersistableService(org.obiba.mica.core.service.AbstractGitPersistableService) Study(org.obiba.mica.study.domain.Study) FileResource(org.obiba.mica.file.rest.FileResource) Attachment(org.obiba.mica.file.Attachment) Path(javax.ws.rs.Path)

Aggregations

FileResource (org.obiba.mica.file.rest.FileResource)6 Attachment (org.obiba.mica.file.Attachment)5 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Inject (javax.inject.Inject)3 Path (javax.ws.rs.Path)3 NoSuchEntityException (org.obiba.mica.NoSuchEntityException)3 FileSystemService (org.obiba.mica.file.service.FileSystemService)3 Dtos (org.obiba.mica.web.model.Dtos)3 ApplicationContext (org.springframework.context.ApplicationContext)3 Timed (com.codahale.metrics.annotation.Timed)2 Maps (com.google.common.collect.Maps)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Nullable (javax.annotation.Nullable)2 NotNull (javax.validation.constraints.NotNull)2 DELETE (javax.ws.rs.DELETE)2 DefaultValue (javax.ws.rs.DefaultValue)2 GET (javax.ws.rs.GET)2