Search in sources :

Example 26 with Study

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));
}
Also used : Study(org.obiba.mica.study.domain.Study) Population(org.obiba.mica.study.domain.Population) Test(org.junit.Test)

Example 27 with Study

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);
}
Also used : Study(org.obiba.mica.study.domain.Study) Attachment(org.obiba.mica.file.Attachment) Test(org.junit.Test)

Example 28 with 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);
}
Also used : Study(org.obiba.mica.study.domain.Study) ObjectId(org.bson.types.ObjectId) Test(org.junit.Test)

Example 29 with 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();
}
Also used : Study(org.obiba.mica.study.domain.Study) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Example 30 with Study

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;
}
Also used : RevisionStatus(org.obiba.mica.core.domain.RevisionStatus) PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ConstraintException(org.obiba.mica.study.ConstraintException) Path(javax.ws.rs.Path) HashMap(java.util.HashMap) Scope(org.springframework.context.annotation.Scope) Inject(javax.inject.Inject) MediaType(javax.ws.rs.core.MediaType) AbstractGitPersistableResource(org.obiba.mica.AbstractGitPersistableResource) QueryParam(javax.ws.rs.QueryParam) PublishCascadingScope(org.obiba.mica.core.domain.PublishCascadingScope) SubjectAclResource(org.obiba.mica.security.rest.SubjectAclResource) Map(java.util.Map) Mica(org.obiba.mica.web.model.Mica) DefaultValue(javax.ws.rs.DefaultValue) StudyState(org.obiba.mica.study.domain.StudyState) Dtos(org.obiba.mica.web.model.Dtos) Nullable(javax.annotation.Nullable) DELETE(javax.ws.rs.DELETE) FileResource(org.obiba.mica.file.rest.FileResource) Attachment(org.obiba.mica.file.Attachment) FileSystemService(org.obiba.mica.file.service.FileSystemService) IOException(java.io.IOException) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) ApplicationContext(org.springframework.context.ApplicationContext) Maps(com.google.common.collect.Maps) NoSuchEntityException(org.obiba.mica.NoSuchEntityException) IndividualStudyService(org.obiba.mica.study.service.IndividualStudyService) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) Component(org.springframework.stereotype.Component) Study(org.obiba.mica.study.domain.Study) Response(javax.ws.rs.core.Response) PUT(javax.ws.rs.PUT) AbstractGitPersistableService(org.obiba.mica.core.service.AbstractGitPersistableService) Study(org.obiba.mica.study.domain.Study) FileResource(org.obiba.mica.file.rest.FileResource) Attachment(org.obiba.mica.file.Attachment) Path(javax.ws.rs.Path)

Aggregations

Study (org.obiba.mica.study.domain.Study)33 Test (org.junit.Test)16 StudyState (org.obiba.mica.study.domain.StudyState)8 BaseStudy (org.obiba.mica.study.domain.BaseStudy)6 List (java.util.List)5 Population (org.obiba.mica.study.domain.Population)5 Timed (com.codahale.metrics.annotation.Timed)4 HashMap (java.util.HashMap)4 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 NotNull (javax.validation.constraints.NotNull)4 Component (org.springframework.stereotype.Component)4 Strings (com.google.common.base.Strings)3 Maps (com.google.common.collect.Maps)3 Map (java.util.Map)3 Collectors.toList (java.util.stream.Collectors.toList)3 NoSuchEntityException (org.obiba.mica.NoSuchEntityException)3 Membership (org.obiba.mica.core.domain.Membership)3 DataCollectionEvent (org.obiba.mica.study.domain.DataCollectionEvent)3 HarmonizationStudy (org.obiba.mica.study.domain.HarmonizationStudy)3