use of org.obiba.mica.dataset.domain.StudyDataset in project mica2 by obiba.
the class DatasetDtos method fromDto.
private Dataset fromDto(@NotNull Mica.CollectedDatasetDto dto) {
Assert.notNull(dto, "StudyDataset dt cannot be null.");
StudyDataset studyDataset = new StudyDataset();
Optional.ofNullable(dto).ifPresent(ext -> studyDataset.setStudyTable(fromDto(ext.getStudyTable())));
return studyDataset;
}
use of org.obiba.mica.dataset.domain.StudyDataset in project mica2 by obiba.
the class CollectedDatasetServiceTest method buildStudyDataset.
private StudyDataset buildStudyDataset() {
StudyDataset ds = new StudyDataset();
StudyTable st = new StudyTable();
st.setProject("proj");
st.setTable("tab");
ds.setStudyTable(st);
ds.setName(new LocalizedString(Locale.CANADA, "test"));
return ds;
}
use of org.obiba.mica.dataset.domain.StudyDataset in project mica2 by obiba.
the class DraftCollectedDatasetResource method update.
@PUT
public Response update(Mica.DatasetDto datasetDto, @Context UriInfo uriInfo, @Nullable @QueryParam("comment") String comment) {
checkPermission("/draft/collected-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 StudyDataset))
throw new IllegalArgumentException("A study dataset is expected");
datasetService.save((StudyDataset) dataset, comment);
return Response.noContent().build();
}
use of org.obiba.mica.dataset.domain.StudyDataset in project mica2 by obiba.
the class CollectedDatasetService method processVariablesForStudyDataset.
public List<DatasetVariable> processVariablesForStudyDataset(StudyDataset dataset, Iterable<DatasetVariable> variables) {
if (!dataset.hasStudyTable()) {
return Lists.newArrayList(variables);
}
StudyTable studyTable = dataset.getStudyTable();
BaseStudy study = studyService.findStudy(dataset.getStudyTable().getStudyId());
Population population = study.findPopulation(studyTable.getPopulationId());
if (population == null) {
return Lists.newArrayList(variables);
}
int populationWeight = population.getWeight();
DataCollectionEvent dataCollectionEvent = population.findDataCollectionEvent(studyTable.getDataCollectionEventId());
if (dataCollectionEvent == null) {
return Lists.newArrayList(variables);
}
int dataCollectionEventWeight = dataCollectionEvent.getWeight();
return StreamSupport.stream(variables.spliterator(), false).map(datasetVariable -> {
datasetVariable.setPopulationWeight(populationWeight);
datasetVariable.setDataCollectionEventWeight(dataCollectionEventWeight);
return datasetVariable;
}).collect(toList());
}
use of org.obiba.mica.dataset.domain.StudyDataset in project mica2 by obiba.
the class CollectedDatasetService method saveInternal.
private void saveInternal(StudyDataset dataset, String comment) {
StudyDataset saved = prepareSave(dataset);
StudyDatasetState studyDatasetState = findEntityState(dataset, StudyDatasetState::new);
if (!dataset.isNew())
ensureGitRepository(studyDatasetState);
studyDatasetState.incrementRevisionsAhead();
studyDatasetStateRepository.save(studyDatasetState);
saved.setLastModifiedDate(DateTime.now());
studyDatasetRepository.save(saved);
gitService.save(saved, comment);
eventBus.post(new DatasetUpdatedEvent(saved));
}
Aggregations