use of org.obiba.mica.study.domain.Study in project mica2 by obiba.
the class StudySummaryDtos method asDtoFromDceUid.
Mica.StudySummaryDto asDtoFromDceUid(String dceUid) {
String[] splitId = dceUid.split(":");
String studyId = splitId[0];
String populationId = splitId[1];
String dceId = splitId[2];
EntityState studyState = studyService.getEntityState(studyId);
BaseStudy study = null;
Mica.StudySummaryDto.Builder builder = Mica.StudySummaryDto.newBuilder();
if (studyState.isPublished()) {
study = publishedStudyService.findById(studyId);
} else {
study = studyService.findStudy(studyId);
}
builder.setPublished(studyState.isPublished()).setId(study.getId()).setTimestamps(TimestampsDtos.asDto(study)).addAllName(localizedStringDtos.asDto(study.getName())).addAllAcronym(localizedStringDtos.asDto(study.getAcronym())).addAllObjectives(localizedStringDtos.asDto(study.getObjectives())).setStudyResourcePath(study.getResourcePath());
Optional<Population> optionalPopulation = study.getPopulations().stream().filter(population -> population.getId().equals(populationId)).findFirst();
if (optionalPopulation.isPresent()) {
Population population = optionalPopulation.get();
Mica.PopulationSummaryDto.Builder populationBuilder = Mica.PopulationSummaryDto.newBuilder().setId(population.getId()).addAllName(localizedStringDtos.asDto(population.getName()));
if (population.getDescription() != null)
populationBuilder.addAllDescription(localizedStringDtos.asDto(population.getDescription()));
Optional<DataCollectionEvent> optionalDce = population.getDataCollectionEvents().stream().filter(dce -> dce.getId().equals(dceId)).findFirst();
if (optionalDce.isPresent()) {
DataCollectionEvent dce = optionalDce.get();
Mica.DataCollectionEventSummaryDto.Builder dceBuilder = Mica.DataCollectionEventSummaryDto.newBuilder().setId(dceUid).addAllName(localizedStringDtos.asDto(dce.getName()));
if (dce.getDescription() != null)
dceBuilder.addAllDescription(localizedStringDtos.asDto(dce.getDescription()));
if (dce.hasStart())
dceBuilder.setStart(dce.getStart().getYearMonth());
if (dce.hasEnd())
dceBuilder.setEnd(dce.getEnd().getYearMonth());
populationBuilder.addDataCollectionEventSummaries(dceBuilder.build());
}
builder.addPopulationSummaries(populationBuilder.build());
}
return builder.build();
}
use of org.obiba.mica.study.domain.Study in project mica2 by obiba.
the class TestDataCollectionEventSort method test_study_populations_sort_with_duplicate_events.
@Test
public void test_study_populations_sort_with_duplicate_events() {
Study study = new Study();
study.setId("01234567889");
study.addPopulation(createPopulation("Population001", createEvent("A", "A", 2010, 1, 2020, 12)));
study.addPopulation(createPopulation("Population002", createEvent("A", "A", 2010, 1, 2020, 12)));
study.addPopulation(createPopulation("Population003", createEvent("A", "A", 2010, 1, 2020, 12)));
SortedSet<Population> populations = study.getPopulations();
assertThat(populations.size()).isEqualTo(3);
assertThat(Iterables.get(Iterables.get(populations, 0).getDataCollectionEvents(), 0).getStart()).isEqualTo(of(2010, 1));
assertThat(Iterables.get(Iterables.get(populations, 1).getDataCollectionEvents(), 0).getStart()).isEqualTo(of(2010, 1));
assertThat(Iterables.get(Iterables.get(populations, 2).getDataCollectionEvents(), 0).getStart()).isEqualTo(of(2010, 1));
}
use of org.obiba.mica.study.domain.Study in project mica2 by obiba.
the class IndividualStudyServiceTest method test_loosing_git_base_repo.
@Test
public void test_loosing_git_base_repo() throws IOException {
Study study = new Study();
Stream.of("a", "b", "c").forEach(name -> {
study.setName(en(name + " en").forFr(name + " fr"));
individualStudyService.save(study);
individualStudyService.publish(study.getId(), true);
});
FileUtil.delete(Config.BASE_REPO);
Study draft = individualStudyService.findDraft(study.getId());
draft.setName(en("d en").forFr("d fr"));
individualStudyService.save(draft);
individualStudyService.publish(draft.getId(), true);
StudyState studyState = individualStudyService.findStateById(draft.getId());
assertThat(studyState.isPublished()).isTrue();
assertThat(studyState.getPublishedTag()).isEqualTo("4");
}
use of org.obiba.mica.study.domain.Study in project mica2 by obiba.
the class IndividualStudyServiceTest method test_publish_current.
@Test
public void test_publish_current() throws Exception {
Study study = new Study();
study.setName(en("name en").forFr("name fr"));
individualStudyService.save(study);
assertThat(individualStudyService.findAllStates()).hasSize(1);
assertThat(individualStudyService.findPublishedStates()).isEmpty();
individualStudyService.publish(study.getId(), true);
List<StudyState> publishedStates = individualStudyService.findPublishedStates();
assertThat(publishedStates).hasSize(1);
StudyState publishedState = publishedStates.get(0);
assertThat(publishedState.getId()).isEqualTo(study.getId());
assertThat(publishedState.getPublishedTag()).isEqualTo("1");
Study draft = individualStudyService.findDraft(study.getId());
draft.setName(en("new name en").forFr("new name fr"));
individualStudyService.save(draft);
assertThat(individualStudyService.findDraft(study.getId())).areFieldsEqualToEachOther(draft);
}
use of org.obiba.mica.study.domain.Study in project mica2 by obiba.
the class IndividualStudyServiceTest method test_delete_study.
@Test
public void test_delete_study() {
Study study = new Study();
study.setName(en("name en").forFr("name fr"));
individualStudyService.save(study);
assertThat(studyStateRepository.findAll()).hasSize(1);
individualStudyService.delete(study.getId());
assertThat(studyRepository.findAll()).hasSize(0);
assertThat(studyStateRepository.findAll()).hasSize(0);
}
Aggregations