Search in sources :

Example 11 with Dataset

use of org.obiba.mica.dataset.domain.Dataset in project mica2 by obiba.

the class DatasetCacheResolver method resolveCaches.

@Override
public synchronized Collection<? extends Cache> resolveCaches(CacheOperationInvocationContext<?> cacheOperationInvocationContext) {
    Collection<Cache> res = Lists.newArrayList();
    Optional<Object> dataset = Arrays.stream(cacheOperationInvocationContext.getArgs()).filter(o -> o instanceof Dataset).findFirst();
    if (dataset.isPresent()) {
        String cacheName = "dataset-" + ((Dataset) dataset.get()).getId();
        Cache datasetCache = springCacheManager.getCache(cacheName);
        if (datasetCache == null) {
            CacheConfiguration conf = cacheManager.getEhcache("dataset-variables").getCacheConfiguration().clone();
            conf.setName(cacheName);
            cacheManager.addCache(new net.sf.ehcache.Cache(conf));
            net.sf.ehcache.Cache cache = cacheManager.getCache(cacheName);
            cacheManager.replaceCacheWithDecoratedCache(cache, InstrumentedEhcache.instrument(metricRegistry, cache));
            datasetCache = new EhCacheCache(cacheManager.getEhcache(cacheName));
        }
        res.add(datasetCache);
    }
    return res;
}
Also used : Arrays(java.util.Arrays) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) MetricRegistry(com.codahale.metrics.MetricRegistry) InstrumentedEhcache(com.codahale.metrics.ehcache.InstrumentedEhcache) Cache(org.springframework.cache.Cache) CacheOperationInvocationContext(org.springframework.cache.interceptor.CacheOperationInvocationContext) Collection(java.util.Collection) Dataset(org.obiba.mica.dataset.domain.Dataset) CacheResolver(org.springframework.cache.interceptor.CacheResolver) Inject(javax.inject.Inject) Component(org.springframework.stereotype.Component) Lists(com.google.common.collect.Lists) CacheManager(org.springframework.cache.CacheManager) EhCacheCache(org.springframework.cache.ehcache.EhCacheCache) Optional(java.util.Optional) Dataset(org.obiba.mica.dataset.domain.Dataset) EhCacheCache(org.springframework.cache.ehcache.EhCacheCache) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Cache(org.springframework.cache.Cache) EhCacheCache(org.springframework.cache.ehcache.EhCacheCache)

Example 12 with Dataset

use of org.obiba.mica.dataset.domain.Dataset in project mica2 by obiba.

the class DatasetDtos method asDtoBuilder.

@NotNull
Mica.DatasetDto.Builder asDtoBuilder(@NotNull HarmonizationDataset dataset, boolean asDraft, boolean studySummary) {
    Mica.DatasetDto.Builder builder = asBuilder(dataset);
    builder.setVariableType(DatasetVariable.Type.Dataschema.name());
    Mica.HarmonizedDatasetDto.Builder hbuilder = Mica.HarmonizedDatasetDto.newBuilder();
    if (dataset.hasHarmonizationTable() && !Strings.isNullOrEmpty(dataset.getHarmonizationTable().getStudyId()) && isStudyTablePermitted(asDraft, "harmonization", dataset.getHarmonizationTable().getStudyId())) {
        hbuilder.setHarmonizationTable(createHarmonizationLinkDtoFromHarmonizationTable(dataset.getHarmonizationTable(), asDraft));
    }
    if (!dataset.getStudyTables().isEmpty()) {
        dataset.getStudyTables().stream().filter(studyTable -> isStudyTablePermitted(asDraft, "individual", studyTable.getStudyId())).forEach(studyTable -> hbuilder.addStudyTables(asDto(studyTable, studySummary)));
    }
    if (!dataset.getHarmonizationTables().isEmpty()) {
        dataset.getHarmonizationTables().stream().filter(studyTable -> isStudyTablePermitted(asDraft, "harmonization", studyTable.getStudyId())).forEach(harmonizationTable -> hbuilder.addHarmonizationTables(asDto(harmonizationTable, studySummary)));
    }
    builder.setExtension(Mica.HarmonizedDatasetDto.type, hbuilder.build());
    Mica.PermissionsDto permissionsDto = permissionsDtos.asDto(dataset);
    if (asDraft) {
        HarmonizationDatasetState state = harmonizationDatasetStateRepository.findOne(dataset.getId());
        if (state != null) {
            builder.setPublished(state.isPublished());
            builder.setExtension(Mica.EntityStateDto.datasetState, entityStateDtos.asDto(state).setPermissions(permissionsDto).build());
        }
    }
    builder.setPermissions(permissionsDto);
    return builder;
}
Also used : Search(org.obiba.opal.web.model.Search) MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) Inject(javax.inject.Inject) Term(org.obiba.opal.core.domain.taxonomy.Term) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) Map(java.util.Map) JSONUtils(org.obiba.mica.JSONUtils) HarmonizationDatasetState(org.obiba.mica.dataset.domain.HarmonizationDatasetState) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) Nullable(javax.annotation.Nullable) SubjectAclService(org.obiba.mica.security.service.SubjectAclService) Math(org.obiba.opal.web.model.Math) Collection(java.util.Collection) DatasetCategory(org.obiba.mica.dataset.domain.DatasetCategory) DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) NotNull(javax.validation.constraints.NotNull) Dataset(org.obiba.mica.dataset.domain.Dataset) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) PublishedStudyService(org.obiba.mica.study.service.PublishedStudyService) List(java.util.List) Component(org.springframework.stereotype.Component) HarmonizationDatasetStateRepository(org.obiba.mica.dataset.HarmonizationDatasetStateRepository) StudyDatasetState(org.obiba.mica.dataset.domain.StudyDatasetState) BooleanType(org.obiba.magma.type.BooleanType) org.obiba.mica.core.domain(org.obiba.mica.core.domain) StudyDatasetStateRepository(org.obiba.mica.dataset.StudyDatasetStateRepository) MicaConfigService(org.obiba.mica.micaConfig.service.MicaConfigService) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) Optional(java.util.Optional) Vocabulary(org.obiba.opal.core.domain.taxonomy.Vocabulary) Collections(java.util.Collections) Assert(org.springframework.util.Assert) HarmonizationDatasetState(org.obiba.mica.dataset.domain.HarmonizationDatasetState) NotNull(javax.validation.constraints.NotNull)

Example 13 with Dataset

use of org.obiba.mica.dataset.domain.Dataset 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 14 with Dataset

use of org.obiba.mica.dataset.domain.Dataset 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)

Example 15 with Dataset

use of org.obiba.mica.dataset.domain.Dataset in project mica2 by obiba.

the class PublishedDatasetResource method alternativeStudyDataset.

private StudyDataset alternativeStudyDataset(String id, String project, String table) {
    Dataset dataset = getDataset(id);
    if (!(dataset instanceof StudyDataset))
        throw NoSuchDatasetException.withId(id);
    StudyDataset asStudyDataset = (StudyDataset) dataset;
    asStudyDataset.getStudyTable().setProject(project);
    asStudyDataset.getStudyTable().setTable(table);
    return asStudyDataset;
}
Also used : Dataset(org.obiba.mica.dataset.domain.Dataset) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset)

Aggregations

Dataset (org.obiba.mica.dataset.domain.Dataset)18 StudyDataset (org.obiba.mica.dataset.domain.StudyDataset)13 HarmonizationDataset (org.obiba.mica.dataset.domain.HarmonizationDataset)8 Lists (com.google.common.collect.Lists)7 Inject (javax.inject.Inject)7 Component (org.springframework.stereotype.Component)6 Timed (com.codahale.metrics.annotation.Timed)5 DatasetVariable (org.obiba.mica.dataset.domain.DatasetVariable)5 Collectors (java.util.stream.Collectors)4 Collectors.toList (java.util.stream.Collectors.toList)4 Stream (java.util.stream.Stream)4 NotNull (javax.validation.constraints.NotNull)4 POST (javax.ws.rs.POST)4 Path (javax.ws.rs.Path)4 Async (org.springframework.scheduling.annotation.Async)4 Strings (com.google.common.base.Strings)3 java.util (java.util)3 List (java.util.List)3 Nullable (javax.annotation.Nullable)3 NoSuchDatasetException (org.obiba.mica.dataset.NoSuchDatasetException)3