Search in sources :

Example 1 with FileResource

use of org.obiba.mica.file.rest.FileResource in project mica2 by obiba.

the class PublishedNetworkResource method study.

@Path("/file/{fileId}")
public FileResource study(@PathParam("id") String id, @PathParam("fileId") String fileId) {
    checkAccess(id);
    FileResource fileResource = applicationContext.getBean(FileResource.class);
    Network network = getNetwork(id);
    if (network.getLogo() == null)
        throw NoSuchEntityException.withId(Attachment.class, fileId);
    fileResource.setAttachment(network.getLogo());
    return fileResource;
}
Also used : Network(org.obiba.mica.network.domain.Network) FileResource(org.obiba.mica.file.rest.FileResource) Attachment(org.obiba.mica.file.Attachment) Path(javax.ws.rs.Path)

Example 2 with FileResource

use of org.obiba.mica.file.rest.FileResource in project mica2 by obiba.

the class DraftHarmonizationStudyResource method file.

@Path("/file/{fileId}")
public FileResource file(@PathParam("fileId") String fileId, @QueryParam("key") String key) {
    checkPermission("/draft/harmonization-study", "VIEW", key);
    FileResource fileResource = applicationContext.getBean(FileResource.class);
    HarmonizationStudy study = studyService.findDraft(id);
    if (study.hasLogo() && study.getLogo().getId().equals(fileId)) {
        fileResource.setAttachment(study.getLogo());
    } else {
        List<Attachment> attachments = fileSystemService.findAttachments(String.format("^/harmonization-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) Lists(com.google.common.collect.Lists) 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) HarmonizationStudyState(org.obiba.mica.study.domain.HarmonizationStudyState) 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) HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) HarmonizationStudyService(org.obiba.mica.study.service.HarmonizationStudyService) 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) HarmonizedDatasetService(org.obiba.mica.dataset.service.HarmonizedDatasetService) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) Component(org.springframework.stereotype.Component) Response(javax.ws.rs.core.Response) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) PUT(javax.ws.rs.PUT) AbstractGitPersistableService(org.obiba.mica.core.service.AbstractGitPersistableService) HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) FileResource(org.obiba.mica.file.rest.FileResource) Attachment(org.obiba.mica.file.Attachment) Path(javax.ws.rs.Path)

Example 3 with FileResource

use of org.obiba.mica.file.rest.FileResource in project mica2 by obiba.

the class DraftNetworkResource method file.

@Path("/file/{fileId}")
public FileResource file(@PathParam("fileId") String fileId, @QueryParam("key") String key) {
    checkPermission("/draft/network", "VIEW", key);
    FileResource fileResource = applicationContext.getBean(FileResource.class);
    Network network = networkService.findById(id);
    if (network.getLogo() == null)
        throw NoSuchEntityException.withId(Attachment.class, fileId);
    fileResource.setAttachment(network.getLogo());
    return fileResource;
}
Also used : Network(org.obiba.mica.network.domain.Network) FileResource(org.obiba.mica.file.rest.FileResource) Attachment(org.obiba.mica.file.Attachment)

Example 4 with FileResource

use of org.obiba.mica.file.rest.FileResource in project mica2 by obiba.

the class DraftProjectResource method file.

@Path("/file/{fileId}")
public FileResource file(@PathParam("fileId") String fileId, @QueryParam("key") String key) {
    checkPermission("/draft/project", "VIEW", key);
    FileResource fileResource = applicationContext.getBean(FileResource.class);
    projectService.findById(id);
    return fileResource;
}
Also used : FileResource(org.obiba.mica.file.rest.FileResource)

Example 5 with FileResource

use of org.obiba.mica.file.rest.FileResource in project mica2 by obiba.

the class AbstractPublishedStudyResource method getStudyFileResource.

protected FileResource getStudyFileResource(String id, String fileId) {
    checkAccess(id);
    FileResource fileResource = applicationContext.getBean(FileResource.class);
    BaseStudy study = getStudy(id);
    if (study.hasLogo() && study.getLogo().getId().equals(fileId)) {
        fileResource.setAttachment(study.getLogo());
    } else {
        List<Attachment> attachments = fileSystemService.findAttachments(String.format("^/%s/%s", getStudyPath(id), id), true).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 : FileResource(org.obiba.mica.file.rest.FileResource) Attachment(org.obiba.mica.file.Attachment) SubjectAclService(org.obiba.mica.security.service.SubjectAclService) Logger(org.slf4j.Logger) BaseStudy(org.obiba.mica.study.domain.BaseStudy) LoggerFactory(org.slf4j.LoggerFactory) FileSystemService(org.obiba.mica.file.service.FileSystemService) StudyService(org.obiba.mica.study.service.StudyService) Collectors(java.util.stream.Collectors) ApplicationContext(org.springframework.context.ApplicationContext) NoSuchEntityException(org.obiba.mica.NoSuchEntityException) NoSuchStudyException(org.obiba.mica.study.NoSuchStudyException) PublishedStudyService(org.obiba.mica.study.service.PublishedStudyService) Inject(javax.inject.Inject) List(java.util.List) ModelAwareTranslator(org.obiba.mica.core.ModelAwareTranslator) Dtos(org.obiba.mica.web.model.Dtos) FileResource(org.obiba.mica.file.rest.FileResource) Attachment(org.obiba.mica.file.Attachment) BaseStudy(org.obiba.mica.study.domain.BaseStudy)

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