Search in sources :

Example 6 with BaseStudy

use of org.obiba.mica.study.domain.BaseStudy in project mica2 by obiba.

the class PersonDtos method asStudyMembershipDto.

private Mica.PersonDto.MembershipDto asStudyMembershipDto(Person.Membership membership, boolean asDraft) {
    Mica.PersonDto.MembershipDto.Builder builder = Mica.PersonDto.MembershipDto.newBuilder();
    builder.setRole(membership.getRole());
    builder.setParentId(membership.getParentId());
    if (membership.getParentId() != null) {
        BaseStudy study = asDraft ? studyService.findStudy(membership.getParentId()) : publishedStudyService.findById(membership.getParentId());
        if (study != null) {
            builder.addAllParentAcronym(localizedStringDtos.asDto(study.getAcronym()));
            builder.addAllParentName(localizedStringDtos.asDto(study.getName()));
            builder.setExtension(Mica.PersonDto.StudyMembershipDto.meta, Mica.PersonDto.StudyMembershipDto.newBuilder().setType(study.getResourcePath()).build());
        }
    }
    return builder.build();
}
Also used : BaseStudy(org.obiba.mica.study.domain.BaseStudy)

Example 7 with BaseStudy

use of org.obiba.mica.study.domain.BaseStudy in project mica2 by obiba.

the class StudyDtos method fromDto.

@NotNull
BaseStudy fromDto(@NotNull Mica.StudyDtoOrBuilder dto) {
    Assert.isTrue(dto.hasExtension(Mica.CollectionStudyDto.type) || dto.hasExtension(Mica.HarmonizationStudyDto.type), "StudyDto must of a type extension.");
    BaseStudy study = dto.hasExtension(Mica.CollectionStudyDto.type) ? new Study() : new HarmonizationStudy();
    if (dto.hasId())
        study.setId(dto.getId());
    if (dto.getNameCount() > 0)
        study.setName(localizedStringDtos.fromDto(dto.getNameList()));
    if (dto.getAcronymCount() > 0)
        study.setAcronym(localizedStringDtos.fromDto(dto.getAcronymList()));
    if (dto.hasLogo())
        study.setLogo(attachmentDtos.fromDto(dto.getLogo()));
    if (dto.hasTimestamps())
        TimestampsDtos.fromDto(dto.getTimestamps(), study);
    if (dto.getObjectivesCount() > 0)
        study.setObjectives(localizedStringDtos.fromDto(dto.getObjectivesList()));
    if (dto.hasOpal())
        study.setOpal(dto.getOpal());
    if (dto.getMembershipsCount() > 0) {
        Map<String, List<Membership>> memberships = Maps.newHashMap();
        dto.getMembershipsList().forEach(e -> memberships.put(e.getRole(), e.getMembersList().stream().map(p -> new Membership(personDtos.fromDto(p), e.getRole())).collect(toList())));
        study.setMemberships(memberships);
    }
    if (dto.getPopulationsCount() > 0) {
        study.setPopulations(dto.getPopulationsList().stream().map(populationDtos::fromDto).collect(Collectors.toCollection(TreeSet<org.obiba.mica.study.domain.Population>::new)));
    }
    if (dto.hasContent() && !Strings.isNullOrEmpty(dto.getContent()))
        study.setModel(JSONUtils.toMap(dto.getContent()));
    else
        study.setModel(new HashMap<>());
    return study;
}
Also used : HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) HarmonizationStudyService(org.obiba.mica.study.service.HarmonizationStudyService) BaseStudy(org.obiba.mica.study.domain.BaseStudy) Membership(org.obiba.mica.core.domain.Membership) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) HashMap(java.util.HashMap) NotNull(javax.validation.constraints.NotNull) Assert(io.jsonwebtoken.lang.Assert) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) TreeSet(java.util.TreeSet) Inject(javax.inject.Inject) IndividualStudyService(org.obiba.mica.study.service.IndividualStudyService) Strings(com.google.common.base.Strings) List(java.util.List) Component(org.springframework.stereotype.Component) Collectors.toList(java.util.stream.Collectors.toList) Study(org.obiba.mica.study.domain.Study) MicaConfigService(org.obiba.mica.micaConfig.service.MicaConfigService) Map(java.util.Map) JSONUtils(org.obiba.mica.JSONUtils) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) HarmonizedDatasetHelper(org.obiba.mica.dataset.support.HarmonizedDatasetHelper) HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) BaseStudy(org.obiba.mica.study.domain.BaseStudy) Study(org.obiba.mica.study.domain.Study) HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) Membership(org.obiba.mica.core.domain.Membership) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) BaseStudy(org.obiba.mica.study.domain.BaseStudy) NotNull(javax.validation.constraints.NotNull)

Example 8 with BaseStudy

use of org.obiba.mica.study.domain.BaseStudy in project mica2 by obiba.

the class StudyEntitiesCountService method newQueries.

/**
 * Parse the RQL query and translate each node as a Opal query wrapped in a {@link StudyEntitiesCountQuery}.
 *
 * @param query
 * @param entityType
 * @return
 */
public List<StudyEntitiesCountQuery> newQueries(String query, String entityType) {
    RQLCriteriaOpalConverter converter = applicationContext.getBean(RQLCriteriaOpalConverter.class);
    converter.parse(query);
    Map<BaseStudy, List<RQLCriterionOpalConverter>> studyConverters = converter.getCriterionConverters().stream().filter(// TODO include Dataschema variables
    c -> !c.hasMultipleStudyTables()).collect(Collectors.groupingBy(c -> c.getVariableReferences().getStudy()));
    return studyConverters.keySet().stream().map(study -> newQuery(entityType, study, studyConverters.get(study))).collect(Collectors.toList());
}
Also used : LocalizedStringDtos(org.obiba.mica.web.model.LocalizedStringDtos) BaseStudy(org.obiba.mica.study.domain.BaseStudy) StudyService(org.obiba.mica.study.service.StudyService) OpalService(org.obiba.mica.micaConfig.service.OpalService) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) Component(org.springframework.stereotype.Component) List(java.util.List) MicaConfigService(org.obiba.mica.micaConfig.service.MicaConfigService) Map(java.util.Map) DocumentDigestDtos(org.obiba.mica.web.model.DocumentDigestDtos) RQLCriteriaOpalConverter(org.obiba.mica.dataset.rest.entity.rql.RQLCriteriaOpalConverter) RQLCriterionOpalConverter(org.obiba.mica.dataset.rest.entity.rql.RQLCriterionOpalConverter) RQLCriteriaOpalConverter(org.obiba.mica.dataset.rest.entity.rql.RQLCriteriaOpalConverter) List(java.util.List) BaseStudy(org.obiba.mica.study.domain.BaseStudy)

Example 9 with BaseStudy

use of org.obiba.mica.study.domain.BaseStudy in project mica2 by obiba.

the class AbstractPublishedStudyResource method getStudyFileResource.

protected FileResource getStudyFileResource(String id, String fileId) {
    checkAccess(id);
    FileResource fileResource = applicationContext.getBean(FileResource.class);
    BaseStudy study = getStudy(id);
    if (study.hasLogo() && study.getLogo().getId().equals(fileId)) {
        fileResource.setAttachment(study.getLogo());
    } else {
        List<Attachment> attachments = fileSystemService.findAttachments(String.format("^/%s/%s", getStudyPath(id), id), true).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 : FileResource(org.obiba.mica.file.rest.FileResource) Attachment(org.obiba.mica.file.Attachment) SubjectAclService(org.obiba.mica.security.service.SubjectAclService) Logger(org.slf4j.Logger) BaseStudy(org.obiba.mica.study.domain.BaseStudy) LoggerFactory(org.slf4j.LoggerFactory) FileSystemService(org.obiba.mica.file.service.FileSystemService) StudyService(org.obiba.mica.study.service.StudyService) Collectors(java.util.stream.Collectors) ApplicationContext(org.springframework.context.ApplicationContext) NoSuchEntityException(org.obiba.mica.NoSuchEntityException) NoSuchStudyException(org.obiba.mica.study.NoSuchStudyException) PublishedStudyService(org.obiba.mica.study.service.PublishedStudyService) Inject(javax.inject.Inject) List(java.util.List) ModelAwareTranslator(org.obiba.mica.core.ModelAwareTranslator) Dtos(org.obiba.mica.web.model.Dtos) FileResource(org.obiba.mica.file.rest.FileResource) Attachment(org.obiba.mica.file.Attachment) BaseStudy(org.obiba.mica.study.domain.BaseStudy)

Example 10 with BaseStudy

use of org.obiba.mica.study.domain.BaseStudy in project mica2 by obiba.

the class PublishedStudyResource method getStudyDto.

@GET
@Timed
public Mica.StudyDto getStudyDto(@PathParam("id") String id, @QueryParam("locale") String locale) {
    checkAccess(id);
    BaseStudy study = getStudy(id, locale);
    return study instanceof Study ? dtos.asDto((Study) study) : dtos.asDto((HarmonizationStudy) study);
}
Also used : HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) BaseStudy(org.obiba.mica.study.domain.BaseStudy) Study(org.obiba.mica.study.domain.Study) HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) BaseStudy(org.obiba.mica.study.domain.BaseStudy) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Aggregations

BaseStudy (org.obiba.mica.study.domain.BaseStudy)15 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 Inject (javax.inject.Inject)6 Study (org.obiba.mica.study.domain.Study)5 Component (org.springframework.stereotype.Component)5 Strings (com.google.common.base.Strings)4 HarmonizationStudy (org.obiba.mica.study.domain.HarmonizationStudy)4 StudyService (org.obiba.mica.study.service.StudyService)4 Map (java.util.Map)3 Collectors.toList (java.util.stream.Collectors.toList)3 NotNull (javax.validation.constraints.NotNull)3 NoSuchEntityException (org.obiba.mica.NoSuchEntityException)3 DatasetVariable (org.obiba.mica.dataset.domain.DatasetVariable)3 MicaConfigService (org.obiba.mica.micaConfig.service.MicaConfigService)3 NoSuchStudyException (org.obiba.mica.study.NoSuchStudyException)3 Population (org.obiba.mica.study.domain.Population)3 PublishedStudyService (org.obiba.mica.study.service.PublishedStudyService)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3