Search in sources :

Example 6 with SubjectAclService

use of org.obiba.mica.security.service.SubjectAclService in project mica2 by obiba.

the class DraftHarmonizedDatasetsResource method list.

/**
 * Get all {@link HarmonizationDataset}, optionally filtered by study.
 *
 * @param studyId can be null, in which case all datasets are returned
 * @return
 */
@GET
@Path("/harmonized-datasets")
@Timed
public List<Mica.DatasetDto> list(@QueryParam("study") String studyId, @QueryParam("query") String query, @QueryParam("from") @DefaultValue("0") Integer from, @QueryParam("limit") Integer limit, @QueryParam("sort") @DefaultValue("id") String sort, @QueryParam("order") @DefaultValue("asc") String order, @QueryParam("filter") @DefaultValue("ALL") String filter, @Context HttpServletResponse response) {
    long totalCount;
    EntityStateFilter entityStateFilter = EntityStateFilter.valueOf(filter);
    List<String> filteredIds = datasetService.getIdsByStateFilter(entityStateFilter);
    Searcher.IdFilter accessibleIdFilter = AccessibleIdFilterBuilder.newBuilder().aclService(subjectAclService).resources(Lists.newArrayList("/draft/harmonized-dataset")).ids(filteredIds).build();
    if (limit == null)
        limit = MAX_LIMIT;
    if (limit < 0)
        throw new IllegalArgumentException("limit cannot be negative");
    DocumentService.Documents<HarmonizationDataset> datasets = draftDatasetService.find(from, limit, sort, order, studyId, query, null, null, accessibleIdFilter);
    totalCount = datasets.getTotal();
    response.addHeader("X-Total-Count", Long.toString(totalCount));
    return datasets.getList().stream().map(dataset -> dtos.asDto(dataset, true)).collect(toList());
}
Also used : EntityStateFilter(org.obiba.mica.core.domain.EntityStateFilter) Async(org.springframework.scheduling.annotation.Async) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) Scope(org.springframework.context.annotation.Scope) Inject(javax.inject.Inject) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) QueryParam(javax.ws.rs.QueryParam) Lists(com.google.common.collect.Lists) Mica(org.obiba.mica.web.model.Mica) DefaultValue(javax.ws.rs.DefaultValue) Dtos(org.obiba.mica.web.model.Dtos) Nullable(javax.annotation.Nullable) AccessibleIdFilterBuilder(org.obiba.mica.search.AccessibleIdFilterBuilder) DraftHarmonizationDatasetService(org.obiba.mica.dataset.service.DraftHarmonizationDatasetService) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) SubjectAclService(org.obiba.mica.security.service.SubjectAclService) Searcher(org.obiba.mica.spi.search.Searcher) HttpServletResponse(javax.servlet.http.HttpServletResponse) Dataset(org.obiba.mica.dataset.domain.Dataset) ApplicationContext(org.springframework.context.ApplicationContext) HarmonizedDatasetService(org.obiba.mica.dataset.service.HarmonizedDatasetService) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) Component(org.springframework.stereotype.Component) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) DocumentService(org.obiba.mica.core.service.DocumentService) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) PUT(javax.ws.rs.PUT) UriInfo(javax.ws.rs.core.UriInfo) EntityStateFilter(org.obiba.mica.core.domain.EntityStateFilter) Searcher(org.obiba.mica.spi.search.Searcher) DocumentService(org.obiba.mica.core.service.DocumentService) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Aggregations

Lists (com.google.common.collect.Lists)6 List (java.util.List)6 Inject (javax.inject.Inject)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 SubjectAclService (org.obiba.mica.security.service.SubjectAclService)6 Timed (com.codahale.metrics.annotation.Timed)5 Collectors.toList (java.util.stream.Collectors.toList)5 Stream (java.util.stream.Stream)5 DefaultValue (javax.ws.rs.DefaultValue)5 GET (javax.ws.rs.GET)5 Path (javax.ws.rs.Path)5 PathParam (javax.ws.rs.PathParam)5 QueryParam (javax.ws.rs.QueryParam)5 Context (javax.ws.rs.core.Context)5 EntityStateFilter (org.obiba.mica.core.domain.EntityStateFilter)5 DocumentService (org.obiba.mica.core.service.DocumentService)5 AccessibleIdFilterBuilder (org.obiba.mica.search.AccessibleIdFilterBuilder)5 Searcher (org.obiba.mica.spi.search.Searcher)5 Dtos (org.obiba.mica.web.model.Dtos)5 Mica (org.obiba.mica.web.model.Mica)5