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 StudyDtosTest method test_full_dto.
@Test
public void test_full_dto() throws Exception {
when(attachmentDtos.asDto(any(Attachment.class))).thenReturn(Mica.AttachmentDto.newBuilder().setId("123").setFileName("logo123").build());
when(attachmentDtos.fromDto(any(Mica.AttachmentDtoOrBuilder.class))).thenReturn(createAttachment());
Study study = createStudy();
Mica.StudyDto dto = studyDtos.asDto(study, true);
Study fromDto = (Study) studyDtos.fromDto(dto);
assertTimestamps(study, dto);
assertThat(fromDto).isEqualTo(study);
}
use of org.obiba.mica.study.domain.Study in project mica2 by obiba.
the class StudyDtosTest method test_required_only_dto.
@Test
public void test_required_only_dto() throws Exception {
Study study = new Study();
study.setId(new ObjectId().toString());
study.setName(en("Canadian Longitudinal Study on Aging"));
study.setObjectives(en("The Canadian Longitudinal Study on Aging (CLSA) is a large, national, long-term study"));
Mica.StudyDto dto = studyDtos.asDto(study, true);
Study fromDto = (Study) studyDtos.fromDto(dto);
assertTimestamps(study, dto);
assertThat(fromDto).areFieldsEqualToEachOther(study);
}
use of org.obiba.mica.study.domain.Study in project mica2 by obiba.
the class DraftIndividualStudiesResource method create.
@POST
@Path("/individual-studies")
@Timed
@RequiresPermissions({ "/draft/individual-study:ADD" })
public Response create(@SuppressWarnings("TypeMayBeWeakened") Mica.StudyDto studyDto, @Context UriInfo uriInfo, @Nullable @QueryParam("comment") String comment) {
Study study = (Study) dtos.fromDto(studyDto);
individualStudyService.save(study, comment);
return Response.created(uriInfo.getBaseUriBuilder().path(DraftIndividualStudiesResource.class, "study").build(study.getId())).build();
}
use of org.obiba.mica.study.domain.Study in project mica2 by obiba.
the class DraftIndividualStudyResource method file.
@Path("/file/{fileId}")
public FileResource file(@PathParam("fileId") String fileId, @QueryParam("key") String key) {
checkPermission("/draft/individual-study", "VIEW", key);
FileResource fileResource = applicationContext.getBean(FileResource.class);
Study study = individualStudyService.findDraft(id);
if (study.hasLogo() && study.getLogo().getId().equals(fileId)) {
fileResource.setAttachment(study.getLogo());
} else {
List<Attachment> attachments = fileSystemService.findAttachments(String.format("^/individual-study/%s", study.getId()), false).stream().filter(a -> a.getId().equals(fileId)).collect(Collectors.toList());
if (attachments.isEmpty())
throw NoSuchEntityException.withId(Attachment.class, fileId);
fileResource.setAttachment(attachments.get(0));
}
return fileResource;
}
Aggregations