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;
}
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;
}
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());
}
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());
}
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;
}
Aggregations