use of org.obiba.mica.dataset.domain.StudyDataset in project mica2 by obiba.
the class DatasetDtosTest method test_study_dataset_dto.
@Test
public void test_study_dataset_dto() throws Exception {
StudyDataset studyDataset = createStudyDataset();
Mica.DatasetDto dto = datasetDtos.asDto(studyDataset);
assertThat(dto.getId(), is("123"));
}
use of org.obiba.mica.dataset.domain.StudyDataset in project mica2 by obiba.
the class DatasetDtosTest method createStudyDataset.
private StudyDataset createStudyDataset() {
StudyDataset studyDataset = new StudyDataset();
studyDataset.setId("123");
return studyDataset;
}
use of org.obiba.mica.dataset.domain.StudyDataset in project mica2 by obiba.
the class DraftCollectedDatasetsResource method create.
@POST
@Path("/collected-datasets")
@Timed
@RequiresPermissions({ "/draft/collected-dataset:ADD" })
public Response create(Mica.DatasetDto datasetDto, @Context UriInfo uriInfo, @Nullable @QueryParam("comment") String comment) {
Dataset dataset = dtos.fromDto(datasetDto);
if (!(dataset instanceof StudyDataset))
throw new IllegalArgumentException("A collected dataset is expected");
datasetService.save((StudyDataset) dataset, comment);
return Response.created(uriInfo.getBaseUriBuilder().segment("draft", "collected-dataset", dataset.getId()).build()).build();
}
use of org.obiba.mica.dataset.domain.StudyDataset in project mica2 by obiba.
the class RQLCriteriaOpalConverter method parseField.
private RQLFieldReferences parseField(String path) {
DatasetVariable.IdResolver resolver = DatasetVariable.IdResolver.from(path);
if (resolver.getType() == null || DatasetVariable.Type.Collected.equals(resolver.getType())) {
StudyDataset ds = collectedDatasetService.findById(resolver.getDatasetId());
BaseStudyTable studyTable = ds.getStudyTable();
BaseStudy study = studyService.findStudy(studyTable.getStudyId());
return new RQLFieldReferences(path, ds, studyTable, study, getDatasetVariableInternal(Indexer.VARIABLE_TYPE, path));
} else if (DatasetVariable.Type.Dataschema.equals(resolver.getType())) {
HarmonizationDataset ds = harmonizedDatasetService.findById(resolver.getDatasetId());
BaseStudy study = studyService.findStudy(ds.getHarmonizationTable().getStudyId());
return new RQLFieldReferences(path, ds, ds.getBaseStudyTables(), study, getDatasetVariableInternal(Indexer.VARIABLE_TYPE, path));
} else if (DatasetVariable.Type.Harmonized.equals(resolver.getType())) {
HarmonizationDataset ds = harmonizedDatasetService.findById(resolver.getDatasetId());
Optional<BaseStudyTable> studyTable = ds.getBaseStudyTables().stream().filter(st -> st.getStudyId().equals(resolver.getStudyId()) && st.getProject().equals(resolver.getProject()) && st.getTable().equals(resolver.getTable())).findFirst();
if (!studyTable.isPresent())
throw new IllegalArgumentException("Not a valid variable: " + path);
BaseStudy study = studyService.findStudy(studyTable.get().getStudyId());
return new RQLFieldReferences(path, ds, studyTable.get(), study, getDatasetVariableInternal(Indexer.HARMONIZED_VARIABLE_TYPE, path));
}
throw new IllegalArgumentException("Not a valid variable: " + path);
}
use of org.obiba.mica.dataset.domain.StudyDataset 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;
}
Aggregations