use of org.obiba.mica.dataset.domain.Dataset in project mica2 by obiba.
the class VariableSetService method createOpalViews.
/**
* Get a list of opal view dto for backup restore purposes
*
* @param variables The source variables set
* @return a list of opal views grouped by project and entity type
*/
private List<Magma.ViewDto> createOpalViews(List<DatasetVariable> variables, MicaConfig.OpalViewsGrouping opalViewsGrouping) {
List<Magma.ViewDto> views = new ArrayList<>();
List<Dataset> datasets = publishedDatasetService.findByIds(variables.stream().map(DatasetVariable::getDatasetId).distinct().collect(Collectors.toList()));
Map<String, List<String>> opalTableFullNameMap = datasets.stream().collect(Collectors.toMap(Dataset::getId, this::toOpalTableFullName));
switch(opalViewsGrouping) {
case PROJECT_TABLE:
Map<String, List<DatasetVariable>> variablesGroupedByProjectTable = Maps.newHashMap();
variables.forEach(variable -> {
List<String> projectTables = opalTableFullNameMap.get(variable.getDatasetId());
projectTables.forEach(projectTable -> {
if (!variablesGroupedByProjectTable.containsKey(projectTable))
variablesGroupedByProjectTable.put(projectTable, Lists.newArrayList());
variablesGroupedByProjectTable.get(projectTable).add(variable);
});
});
for (Entry<String, List<DatasetVariable>> entry : variablesGroupedByProjectTable.entrySet()) {
views.add(createViewDto(entry.getValue(), entry.getKey()));
}
break;
case PROJECT_ENTITY_TYPE:
Map<String, List<DatasetVariable>> variablesGroupedByProjectEntityType = Maps.newHashMap();
variables.forEach(variable -> {
List<String> projectTables = opalTableFullNameMap.get(variable.getDatasetId());
projectTables.forEach(projectTable -> {
String projectEntityType = projectTable.split("\\.")[0] + "." + variable.getEntityType();
if (!variablesGroupedByProjectEntityType.containsKey(projectEntityType))
variablesGroupedByProjectEntityType.put(projectEntityType, Lists.newArrayList());
Optional<DatasetVariable> varOpt = variablesGroupedByProjectEntityType.get(projectEntityType).stream().filter(var -> var.getName().equals(variable.getName())).findFirst();
if (!varOpt.isPresent())
variablesGroupedByProjectEntityType.get(projectEntityType).add(variable);
});
});
for (Entry<String, List<DatasetVariable>> entry : variablesGroupedByProjectEntityType.entrySet()) {
views.add(createViewDto(entry.getValue(), entry.getKey(), opalTableFullNameMap));
}
break;
case ENTITY_TYPE:
Map<String, List<DatasetVariable>> variablesGroupedByEntityType = variables.stream().collect(Collectors.groupingBy(DatasetVariable::getEntityType));
for (Entry<String, List<DatasetVariable>> entry : variablesGroupedByEntityType.entrySet()) {
views.add(createViewDto(entry.getValue(), entry.getKey(), opalTableFullNameMap));
}
break;
}
return views;
}
use of org.obiba.mica.dataset.domain.Dataset in project mica2 by obiba.
the class DatasetDtos method fromDto.
@NotNull
public Dataset fromDto(Mica.DatasetDtoOrBuilder dto) {
Dataset dataset = dto.hasExtension(Mica.HarmonizedDatasetDto.type) ? fromDto(dto.getExtension(Mica.HarmonizedDatasetDto.type)) : dto.hasExtension(Mica.CollectedDatasetDto.type) ? fromDto(dto.getExtension(Mica.CollectedDatasetDto.type)) : new StudyDataset();
if (dto.hasId())
dataset.setId(dto.getId());
dataset.setAcronym(localizedStringDtos.fromDto(dto.getAcronymList()));
dataset.setName(localizedStringDtos.fromDto(dto.getNameList()));
dataset.setDescription(localizedStringDtos.fromDto(dto.getDescriptionList()));
dataset.setEntityType(dto.getEntityType());
dataset.setPublished(dto.getPublished());
if (dto.getAttributesCount() > 0) {
dto.getAttributesList().forEach(attributeDto -> dataset.addAttribute(attributeDtos.fromDto(attributeDto)));
}
if (dto.hasContent()) {
dataset.setModel(JSONUtils.toMap(dto.getContent()));
}
return dataset;
}
use of org.obiba.mica.dataset.domain.Dataset in project mica2 by obiba.
the class DatasetController method dataset.
@GetMapping("/dataset/{id:.+}")
public ModelAndView dataset(@PathVariable String id, @RequestParam(value = "draft", required = false) String shareKey) {
Map<String, Object> params = newParameters();
Dataset dataset = getDataset(id, shareKey);
params.put("dataset", dataset);
params.put("type", (dataset instanceof StudyDataset) ? "Collected" : "Harmonized");
params.put("draft", !Strings.isNullOrEmpty(shareKey));
if (dataset instanceof StudyDataset) {
addStudyTableParameters(params, ((StudyDataset) dataset).getStudyTable());
} else {
HarmonizationDataset harmoDataset = (HarmonizationDataset) dataset;
addHarmonizationTableParameters(params, harmoDataset.getHarmonizationTable());
Map<String, BaseStudy> allStudies = Maps.newHashMap();
List<BaseStudyTable> allTables = Lists.newArrayList();
List<Map<String, Object>> studyTables = Lists.newArrayList();
List<String> ids = Lists.newArrayList();
for (StudyTable sTable : harmoDataset.getStudyTables()) {
Map<String, Object> p = new HashMap<>();
if (addStudyTableParameters(p, sTable, ids))
allTables.add(sTable);
if (!p.isEmpty()) {
studyTables.add(p);
allStudies.put(sTable.getStudyId(), (BaseStudy) p.get("study"));
}
}
params.put("studyTables", studyTables);
List<Map<String, Object>> harmonizationTables = Lists.newArrayList();
ids.clear();
for (HarmonizationStudyTable hTable : harmoDataset.getHarmonizationTables()) {
Map<String, Object> p = new HashMap<>();
if (addHarmonizationTableParameters(p, hTable, ids))
allTables.add(hTable);
if (!p.isEmpty()) {
harmonizationTables.add(p);
allStudies.put(hTable.getStudyId(), (BaseStudy) p.get("study"));
}
}
params.put("harmonizationTables", harmonizationTables);
params.put("allTables", allTables);
params.put("allStudies", allStudies);
}
params.put("showDatasetContingencyLink", showDatasetContingencyLink());
return new ModelAndView("dataset", params);
}
use of org.obiba.mica.dataset.domain.Dataset in project mica2 by obiba.
the class DatasetAnalysisController method crosstab.
@GetMapping("/dataset-crosstab/{id:.+}")
public ModelAndView crosstab(HttpServletRequest request, @PathVariable String id, @RequestParam(value = "var1", required = false) String var1, @RequestParam(value = "var2", required = false) String var2) {
// check if service is available
if (!micaConfigService.getConfig().isContingencyEnabled()) {
return new ModelAndView("redirect:/dataset/" + id);
}
Subject subject = SecurityUtils.getSubject();
String contextPath = micaConfigService.getContextPath();
if (!subject.isAuthenticated() && (micaConfigService.getConfig().isVariableSummaryRequiresAuthentication() || subjectAclService.hasDatasetContingencyPermissions())) {
String query = "";
if (!Strings.isNullOrEmpty(var1))
query = "var1=" + var1;
if (!Strings.isNullOrEmpty(var2))
query = (Strings.isNullOrEmpty(query) ? "" : query + "&") + "var2=" + var2;
String redirect = encode(contextPath + "/dataset-crosstab/" + id + (Strings.isNullOrEmpty(query) ? "" : "?") + query);
return new ModelAndView("redirect:/signin?redirect=" + redirect);
}
// check if user is permitted
if (!subjectAclService.isDatasetContingencyPermitted()) {
return new ModelAndView("redirect:/dataset/" + id);
}
ModelAndView mv = new ModelAndView("dataset-crosstab");
Dataset dataset = getDataset(id);
mv.getModelMap().addAttribute("dataset", dataset);
String type = (dataset instanceof StudyDataset) ? "Collected" : "Harmonized";
String variableType = (dataset instanceof StudyDataset) ? "Collected" : "Dataschema";
mv.getModelMap().addAttribute("type", type);
if (!Strings.isNullOrEmpty(var1)) {
mv.getModelMap().addAttribute("var1", var1);
DatasetVariable variable1 = getDatasetVariable(id + ":" + var1 + ":" + variableType, var1);
mv.getModelMap().addAttribute("variable1", getDatasetVariableJSON(variable1));
}
if (!Strings.isNullOrEmpty(var2)) {
mv.getModelMap().addAttribute("var2", var2);
DatasetVariable variable2 = getDatasetVariable(id + ":" + var2 + ":" + variableType, var2);
mv.getModelMap().addAttribute("variable2", getDatasetVariableJSON(variable2));
}
return mv;
}
use of org.obiba.mica.dataset.domain.Dataset in project mica2 by obiba.
the class DraftHarmonizedDatasetResource method update.
@PUT
@Timed
public Response update(Mica.DatasetDto datasetDto, @Context UriInfo uriInfo, @Nullable @QueryParam("comment") String comment) {
checkPermission("/draft/harmonized-dataset", "EDIT");
if (!datasetDto.hasId() || !datasetDto.getId().equals(id))
throw new IllegalArgumentException("Not the expected dataset id");
Dataset dataset = dtos.fromDto(datasetDto);
if (!(dataset instanceof HarmonizationDataset))
throw new IllegalArgumentException("An harmonization dataset is expected");
datasetService.save((HarmonizationDataset) dataset, comment);
return Response.noContent().build();
}
Aggregations