Search in sources :

Example 1 with EntityStateFilter

use of org.obiba.mica.core.domain.EntityStateFilter in project mica2 by obiba.

the class StudyStatesResource method listCollectionStudyStates.

@GET
@Path("/study-states")
@Timed
public List<Mica.StudySummaryDto> listCollectionStudyStates(@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("type") String type, @QueryParam("exclude") List<String> excludes, @QueryParam("filter") @DefaultValue("ALL") String filter, @Context HttpServletResponse response) {
    Stream<? extends EntityState> result;
    long totalCount;
    EntityStateFilter entityStateFilter = EntityStateFilter.valueOf(filter);
    List<String> filteredIds = Strings.isNullOrEmpty(type) ? studyService.getIdsByStateFilter(entityStateFilter) : getStudyServiceByType(type).getIdsByStateFilter(entityStateFilter);
    Searcher.IdFilter accessibleIdFilter = AccessibleIdFilterBuilder.newBuilder().aclService(subjectAclService).resources(getPermissionResources(type)).ids(filteredIds).build();
    String ids = excludes.stream().map(s -> "id:" + s).collect(Collectors.joining(" "));
    if (!Strings.isNullOrEmpty(ids)) {
        if (Strings.isNullOrEmpty(query))
            query = String.format("NOT(%s)", ids);
        else
            query += String.format(" AND NOT(%s)", ids);
    }
    if (limit == null)
        limit = MAX_LIMIT;
    if (limit < 0)
        throw new IllegalArgumentException("limit cannot be negative");
    DocumentService.Documents<Study> studyDocuments = draftStudyService.find(from, limit, sort, order, null, query, null, null, accessibleIdFilter);
    totalCount = studyDocuments.getTotal();
    response.addHeader("X-Total-Count", Long.toString(totalCount));
    return studyDocuments.getList().stream().map(study -> dtos.asDto(study, studyService.getEntityState(study.getId()))).collect(toList());
}
Also used : EntityStateFilter(org.obiba.mica.core.domain.EntityStateFilter) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) EntityState(org.obiba.mica.core.domain.EntityState) QueryParam(javax.ws.rs.QueryParam) Mica(org.obiba.mica.web.model.Mica) DefaultValue(javax.ws.rs.DefaultValue) Dtos(org.obiba.mica.web.model.Dtos) AccessibleIdFilterBuilder(org.obiba.mica.search.AccessibleIdFilterBuilder) SubjectAclService(org.obiba.mica.security.service.SubjectAclService) Context(javax.ws.rs.core.Context) Searcher(org.obiba.mica.spi.search.Searcher) HarmonizationStudyService(org.obiba.mica.study.service.HarmonizationStudyService) BaseStudy(org.obiba.mica.study.domain.BaseStudy) HttpServletResponse(javax.servlet.http.HttpServletResponse) StudyService(org.obiba.mica.study.service.StudyService) NotNull(javax.validation.constraints.NotNull) AbstractStudyService(org.obiba.mica.study.service.AbstractStudyService) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) Timed(com.codahale.metrics.annotation.Timed) IndividualStudyService(org.obiba.mica.study.service.IndividualStudyService) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Study(org.obiba.mica.study.domain.Study) Stream(java.util.stream.Stream) DocumentService(org.obiba.mica.core.service.DocumentService) DraftStudyService(org.obiba.mica.study.service.DraftStudyService) EntityStateFilter(org.obiba.mica.core.domain.EntityStateFilter) BaseStudy(org.obiba.mica.study.domain.BaseStudy) Study(org.obiba.mica.study.domain.Study) Searcher(org.obiba.mica.spi.search.Searcher) DocumentService(org.obiba.mica.core.service.DocumentService) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 2 with EntityStateFilter

use of org.obiba.mica.core.domain.EntityStateFilter in project mica2 by obiba.

the class DraftProjectsResource method list.

@GET
@Path("/projects")
@Timed
public Mica.ProjectsDto list(@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) {
    EntityStateFilter entityStateFilter = EntityStateFilter.valueOf(filter);
    List<String> filteredIds = projectService.getIdsByStateFilter(entityStateFilter);
    Searcher.IdFilter accessibleIdFilter = AccessibleIdFilterBuilder.newBuilder().aclService(subjectAclService).resources(Lists.newArrayList("/draft/project")).ids(filteredIds).build();
    if (limit == null)
        limit = MAX_LIMIT;
    if (limit < 0)
        throw new IllegalArgumentException("limit cannot be negative");
    DocumentService.Documents<Project> projectDocuments = draftProjectService.find(from, limit, sort, order, null, query, null, null, accessibleIdFilter);
    long totalCount = projectDocuments.getTotal();
    List<Mica.ProjectDto> result = projectDocuments.getList().stream().map(n -> dtos.asDto(n, true)).collect(toList());
    Mica.ProjectsDto.Builder builder = Mica.ProjectsDto.newBuilder();
    builder.setFrom(from).setLimit(limit).setTotal(Long.valueOf(totalCount).intValue());
    builder.addAllProjects(result);
    if (subjectAclService.isPermitted("/draft/project", "ADD")) {
        builder.addActions("ADD");
    }
    return builder.build();
}
Also used : PathParam(javax.ws.rs.PathParam) Project(org.obiba.mica.project.domain.Project) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) ProjectService(org.obiba.mica.project.service.ProjectService) AbstractGitPersistable(org.obiba.mica.core.domain.AbstractGitPersistable) DraftProjectService(org.obiba.mica.project.service.DraftProjectService) Scope(org.springframework.context.annotation.Scope) Inject(javax.inject.Inject) EventBus(com.google.common.eventbus.EventBus) 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) 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) ApplicationContext(org.springframework.context.ApplicationContext) 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) PUT(javax.ws.rs.PUT) UriInfo(javax.ws.rs.core.UriInfo) EntityStateFilter(org.obiba.mica.core.domain.EntityStateFilter) IndexProjectsEvent(org.obiba.mica.project.event.IndexProjectsEvent) Searcher(org.obiba.mica.spi.search.Searcher) DocumentService(org.obiba.mica.core.service.DocumentService) EntityStateFilter(org.obiba.mica.core.domain.EntityStateFilter) Project(org.obiba.mica.project.domain.Project) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 3 with EntityStateFilter

use of org.obiba.mica.core.domain.EntityStateFilter in project mica2 by obiba.

the class DraftNetworksResource method list.

@GET
@Path("/networks")
@Timed
public List<Mica.NetworkSummaryDto> 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("exclude") List<String> excludes, @QueryParam("filter") @DefaultValue("ALL") String filter, @Context HttpServletResponse response) {
    Stream<Network> result;
    long totalCount;
    EntityStateFilter entityStateFilter = EntityStateFilter.valueOf(filter);
    List<String> filteredIds = networkService.getIdsByStateFilter(entityStateFilter);
    Searcher.IdFilter accessibleIdFilter = AccessibleIdFilterBuilder.newBuilder().aclService(subjectAclService).resources(Lists.newArrayList("/draft/network")).ids(filteredIds).build();
    if (limit == null)
        limit = MAX_LIMIT;
    if (limit < 0)
        throw new IllegalArgumentException("limit cannot be negative");
    String ids = excludes.stream().map(s -> "id:" + s).collect(Collectors.joining(" "));
    if (!Strings.isNullOrEmpty(ids)) {
        if (Strings.isNullOrEmpty(query))
            query = String.format("NOT(%s)", ids);
        else
            query += String.format(" AND NOT(%s)", ids);
    }
    DocumentService.Documents<Network> networkDocuments = draftNetworkService.find(from, limit, sort, order, studyId, query, null, null, accessibleIdFilter);
    totalCount = networkDocuments.getTotal();
    response.addHeader("X-Total-Count", Long.toString(totalCount));
    return networkDocuments.getList().stream().map(network -> dtos.asSummaryDto(network, true)).collect(toList());
}
Also used : EntityStateFilter(org.obiba.mica.core.domain.EntityStateFilter) DraftNetworkService(org.obiba.mica.network.service.DraftNetworkService) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) AbstractGitPersistable(org.obiba.mica.core.domain.AbstractGitPersistable) IndexNetworksEvent(org.obiba.mica.network.event.IndexNetworksEvent) Scope(org.springframework.context.annotation.Scope) Inject(javax.inject.Inject) EventBus(com.google.common.eventbus.EventBus) Strings(com.google.common.base.Strings) 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) Network(org.obiba.mica.network.domain.Network) Dtos(org.obiba.mica.web.model.Dtos) Nullable(javax.annotation.Nullable) AccessibleIdFilterBuilder(org.obiba.mica.search.AccessibleIdFilterBuilder) 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) Collectors(java.util.stream.Collectors) ApplicationContext(org.springframework.context.ApplicationContext) 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) PUT(javax.ws.rs.PUT) UriInfo(javax.ws.rs.core.UriInfo) EntityStateFilter(org.obiba.mica.core.domain.EntityStateFilter) NetworkService(org.obiba.mica.network.service.NetworkService) Network(org.obiba.mica.network.domain.Network) Searcher(org.obiba.mica.spi.search.Searcher) DocumentService(org.obiba.mica.core.service.DocumentService) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 4 with EntityStateFilter

use of org.obiba.mica.core.domain.EntityStateFilter in project mica2 by obiba.

the class DraftCollectedDatasetsResource method list.

/**
 * Get all {@link org.obiba.mica.dataset.domain.StudyDataset}, optionally filtered by study.
 *
 * @param studyId can be null, in which case all datasets are returned
 * @return
 */
@GET
@Path("/collected-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/collected-dataset")).ids(filteredIds).build();
    if (limit == null)
        limit = MAX_LIMIT;
    if (limit < 0)
        throw new IllegalArgumentException("limit cannot be negative");
    DocumentService.Documents<StudyDataset> datasets = draftCollectedDatasetService.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) DraftCollectedDatasetService(org.obiba.mica.dataset.service.DraftCollectedDatasetService) 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) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) Dtos(org.obiba.mica.web.model.Dtos) Nullable(javax.annotation.Nullable) AccessibleIdFilterBuilder(org.obiba.mica.search.AccessibleIdFilterBuilder) 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) CollectedDatasetService(org.obiba.mica.dataset.service.CollectedDatasetService) Dataset(org.obiba.mica.dataset.domain.Dataset) ApplicationContext(org.springframework.context.ApplicationContext) 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) 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) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) DocumentService(org.obiba.mica.core.service.DocumentService) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 5 with EntityStateFilter

use of org.obiba.mica.core.domain.EntityStateFilter 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

Timed (com.codahale.metrics.annotation.Timed)5 Lists (com.google.common.collect.Lists)5 List (java.util.List)5 Collectors.toList (java.util.stream.Collectors.toList)5 Stream (java.util.stream.Stream)5 Inject (javax.inject.Inject)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)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 SubjectAclService (org.obiba.mica.security.service.SubjectAclService)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