Search in sources :

Example 61 with NotNull

use of javax.validation.constraints.NotNull in project mica2 by obiba.

the class DatasetDtos method asDtoBuilder.

@NotNull
Mica.DatasetDto.Builder asDtoBuilder(@NotNull HarmonizationDataset dataset, boolean asDraft, boolean studySummary) {
    Mica.DatasetDto.Builder builder = asBuilder(dataset);
    builder.setVariableType(DatasetVariable.Type.Dataschema.name());
    Mica.HarmonizedDatasetDto.Builder hbuilder = Mica.HarmonizedDatasetDto.newBuilder();
    if (dataset.hasHarmonizationTable() && !Strings.isNullOrEmpty(dataset.getHarmonizationTable().getStudyId()) && isStudyTablePermitted(asDraft, "harmonization", dataset.getHarmonizationTable().getStudyId())) {
        hbuilder.setHarmonizationTable(createHarmonizationLinkDtoFromHarmonizationTable(dataset.getHarmonizationTable(), asDraft));
    }
    if (!dataset.getStudyTables().isEmpty()) {
        dataset.getStudyTables().stream().filter(studyTable -> isStudyTablePermitted(asDraft, "individual", studyTable.getStudyId())).forEach(studyTable -> hbuilder.addStudyTables(asDto(studyTable, studySummary)));
    }
    if (!dataset.getHarmonizationTables().isEmpty()) {
        dataset.getHarmonizationTables().stream().filter(studyTable -> isStudyTablePermitted(asDraft, "harmonization", studyTable.getStudyId())).forEach(harmonizationTable -> hbuilder.addHarmonizationTables(asDto(harmonizationTable, studySummary)));
    }
    builder.setExtension(Mica.HarmonizedDatasetDto.type, hbuilder.build());
    Mica.PermissionsDto permissionsDto = permissionsDtos.asDto(dataset);
    if (asDraft) {
        HarmonizationDatasetState state = harmonizationDatasetStateRepository.findOne(dataset.getId());
        if (state != null) {
            builder.setPublished(state.isPublished());
            builder.setExtension(Mica.EntityStateDto.datasetState, entityStateDtos.asDto(state).setPermissions(permissionsDto).build());
        }
    }
    builder.setPermissions(permissionsDto);
    return builder;
}
Also used : Search(org.obiba.opal.web.model.Search) MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) Inject(javax.inject.Inject) Term(org.obiba.opal.core.domain.taxonomy.Term) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) Map(java.util.Map) JSONUtils(org.obiba.mica.JSONUtils) HarmonizationDatasetState(org.obiba.mica.dataset.domain.HarmonizationDatasetState) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) Nullable(javax.annotation.Nullable) SubjectAclService(org.obiba.mica.security.service.SubjectAclService) Math(org.obiba.opal.web.model.Math) Collection(java.util.Collection) DatasetCategory(org.obiba.mica.dataset.domain.DatasetCategory) DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) NotNull(javax.validation.constraints.NotNull) Dataset(org.obiba.mica.dataset.domain.Dataset) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) PublishedStudyService(org.obiba.mica.study.service.PublishedStudyService) List(java.util.List) Component(org.springframework.stereotype.Component) HarmonizationDatasetStateRepository(org.obiba.mica.dataset.HarmonizationDatasetStateRepository) StudyDatasetState(org.obiba.mica.dataset.domain.StudyDatasetState) BooleanType(org.obiba.magma.type.BooleanType) org.obiba.mica.core.domain(org.obiba.mica.core.domain) StudyDatasetStateRepository(org.obiba.mica.dataset.StudyDatasetStateRepository) MicaConfigService(org.obiba.mica.micaConfig.service.MicaConfigService) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) Optional(java.util.Optional) Vocabulary(org.obiba.opal.core.domain.taxonomy.Vocabulary) Collections(java.util.Collections) Assert(org.springframework.util.Assert) HarmonizationDatasetState(org.obiba.mica.dataset.domain.HarmonizationDatasetState) NotNull(javax.validation.constraints.NotNull)

Example 62 with NotNull

use of javax.validation.constraints.NotNull in project mica2 by obiba.

the class DatasetDtos method asContingencyDto.

public Mica.DatasetVariableContingencyDto.Builder asContingencyDto(@NotNull OpalTable opalTable, DatasetVariable variable, DatasetVariable crossVariable, @Nullable Search.QueryResultDto results) {
    Mica.DatasetVariableContingencyDto.Builder crossDto = Mica.DatasetVariableContingencyDto.newBuilder();
    if (opalTable instanceof StudyTable)
        crossDto.setStudyTable(asDto((StudyTable) opalTable, true));
    else if (opalTable instanceof HarmonizationStudyTable)
        crossDto.setHarmonizationStudyTable(asDto((HarmonizationStudyTable) opalTable));
    Mica.DatasetVariableAggregationDto.Builder allAggBuilder = Mica.DatasetVariableAggregationDto.newBuilder();
    if (results == null) {
        allAggBuilder.setN(0);
        allAggBuilder.setTotal(0);
        crossDto.setAll(allAggBuilder);
        return crossDto;
    }
    allAggBuilder.setTotal(results.getTotalHits());
    MicaConfig micaConfig = micaConfigService.getConfig();
    int privacyThreshold = micaConfig.getPrivacyThreshold();
    crossDto.setPrivacyThreshold(privacyThreshold);
    boolean privacyChecks = !crossVariable.hasCategories() || validatePrivacyThreshold(results, privacyThreshold);
    boolean totalPrivacyChecks = validateTotalPrivacyThreshold(results, privacyThreshold);
    // add facet results in the same order as the variable categories
    List<String> catNames = variable.getValueType().equals(BooleanType.get().getName()) ? Lists.newArrayList("true", "false") : variable.getCategories().stream().map(DatasetCategory::getName).collect(Collectors.toList());
    catNames.forEach(catName -> results.getFacetsList().stream().filter(facet -> facet.hasFacet() && catName.equals(facet.getFacet())).forEach(facet -> {
        boolean privacyCheck = privacyChecks && checkPrivacyThreshold(facet.getFilters(0).getCount(), privacyThreshold);
        Mica.DatasetVariableAggregationDto.Builder aggBuilder = Mica.DatasetVariableAggregationDto.newBuilder();
        aggBuilder.setTotal(totalPrivacyChecks ? results.getTotalHits() : 0);
        aggBuilder.setTerm(facet.getFacet());
        DatasetCategory category = variable.getCategory(facet.getFacet());
        aggBuilder.setMissing(category != null && category.isMissing());
        addSummaryStatistics(crossVariable, aggBuilder, facet, privacyCheck, totalPrivacyChecks);
        crossDto.addAggregations(aggBuilder);
    }));
    // add total facet for all variable categories
    results.getFacetsList().stream().filter(facet -> facet.hasFacet() && "_total".equals(facet.getFacet())).forEach(facet -> {
        boolean privacyCheck = privacyChecks && facet.getFilters(0).getCount() >= micaConfig.getPrivacyThreshold();
        addSummaryStatistics(crossVariable, allAggBuilder, facet, privacyCheck, totalPrivacyChecks);
    });
    crossDto.setAll(allAggBuilder);
    return crossDto;
}
Also used : Search(org.obiba.opal.web.model.Search) MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) Inject(javax.inject.Inject) Term(org.obiba.opal.core.domain.taxonomy.Term) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) Map(java.util.Map) JSONUtils(org.obiba.mica.JSONUtils) HarmonizationDatasetState(org.obiba.mica.dataset.domain.HarmonizationDatasetState) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) Nullable(javax.annotation.Nullable) SubjectAclService(org.obiba.mica.security.service.SubjectAclService) Math(org.obiba.opal.web.model.Math) Collection(java.util.Collection) DatasetCategory(org.obiba.mica.dataset.domain.DatasetCategory) DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) NotNull(javax.validation.constraints.NotNull) Dataset(org.obiba.mica.dataset.domain.Dataset) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) PublishedStudyService(org.obiba.mica.study.service.PublishedStudyService) List(java.util.List) Component(org.springframework.stereotype.Component) HarmonizationDatasetStateRepository(org.obiba.mica.dataset.HarmonizationDatasetStateRepository) StudyDatasetState(org.obiba.mica.dataset.domain.StudyDatasetState) BooleanType(org.obiba.magma.type.BooleanType) org.obiba.mica.core.domain(org.obiba.mica.core.domain) StudyDatasetStateRepository(org.obiba.mica.dataset.StudyDatasetStateRepository) MicaConfigService(org.obiba.mica.micaConfig.service.MicaConfigService) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) Optional(java.util.Optional) Vocabulary(org.obiba.opal.core.domain.taxonomy.Vocabulary) Collections(java.util.Collections) Assert(org.springframework.util.Assert) MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig) DatasetCategory(org.obiba.mica.dataset.domain.DatasetCategory)

Example 63 with NotNull

use of javax.validation.constraints.NotNull in project mica2 by obiba.

the class DatasetDtos method asDtoBuilder.

@NotNull
Mica.DatasetDto.Builder asDtoBuilder(@NotNull StudyDataset dataset, boolean asDraft, boolean studySummary) {
    Mica.DatasetDto.Builder builder = asBuilder(dataset);
    builder.setVariableType(DatasetVariable.Type.Collected.name());
    if (dataset.hasStudyTable() && !Strings.isNullOrEmpty(dataset.getStudyTable().getStudyId()) && isStudyTablePermitted(asDraft, "individual", dataset.getStudyTable().getStudyId())) {
        Mica.CollectedDatasetDto.Builder sbuilder = Mica.CollectedDatasetDto.newBuilder().setStudyTable(asDto(dataset.getStudyTable(), studySummary));
        builder.setExtension(Mica.CollectedDatasetDto.type, sbuilder.build());
    }
    Mica.PermissionsDto permissionsDto = permissionsDtos.asDto(dataset);
    if (asDraft) {
        StudyDatasetState state = studyDatasetStateRepository.findOne(dataset.getId());
        if (state != null) {
            builder.setPublished(state.isPublished());
            Mica.EntityStateDto.Builder stateBuilder = entityStateDtos.asDto(state).setPermissions(permissionsDto);
            builder.setExtension(Mica.EntityStateDto.datasetState, stateBuilder.setPermissions(permissionsDto).setRequireIndexing(state.isRequireIndexing()).build());
        }
    }
    builder.setPermissions(permissionsDto);
    return builder;
}
Also used : StudyDatasetState(org.obiba.mica.dataset.domain.StudyDatasetState) NotNull(javax.validation.constraints.NotNull)

Example 64 with NotNull

use of javax.validation.constraints.NotNull in project mica2 by obiba.

the class NetworkDtos method fromDto.

@NotNull
Network fromDto(@NotNull Mica.NetworkDtoOrBuilder dto) {
    Network network = new Network();
    if (dto.hasId()) {
        network.setId(dto.getId());
    }
    network.setName(localizedStringDtos.fromDto(dto.getNameList()));
    network.setDescription(localizedStringDtos.fromDto(dto.getDescriptionList()));
    network.setAcronym(localizedStringDtos.fromDto(dto.getAcronymList()));
    if (dto.getStudyIdsCount() > 0) {
        dto.getStudyIdsList().forEach(network::addStudyId);
    }
    if (dto.getAttachmentsCount() > 0) {
        dto.getAttachmentsList().stream().filter(Mica.AttachmentDto::getJustUploaded).findFirst().ifPresent(a -> network.setLogo(attachmentDtos.fromDto(a)));
    }
    if (dto.hasLogo()) {
        network.setLogo(attachmentDtos.fromDto(dto.getLogo()));
    }
    if (dto.getNetworkIdsCount() > 0) {
        network.setNetworkIds(Lists.newArrayList(Sets.newHashSet(dto.getNetworkIdsList())));
    }
    if (dto.getMembershipSortOrderCount() > 0) {
        Map<String, List<String>> membershipSortOrder = new HashMap<>();
        dto.getMembershipSortOrderList().forEach(membership -> {
            membershipSortOrder.put(membership.getRole(), membership.getPersonIdsList());
        });
        network.setMembershipSortOrder(membershipSortOrder);
    }
    if (dto.hasContent() && !Strings.isNullOrEmpty(dto.getContent()))
        network.setModel(JSONUtils.toMap(dto.getContent()));
    else
        network.setModel(new HashMap<>());
    return network;
}
Also used : HashMap(java.util.HashMap) Network(org.obiba.mica.network.domain.Network) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) NotNull(javax.validation.constraints.NotNull)

Example 65 with NotNull

use of javax.validation.constraints.NotNull in project mica2 by obiba.

the class ProjectDtos method asDto.

@NotNull
public Mica.ProjectDto asDto(@NotNull Project project, boolean asDraft) {
    Mica.ProjectDto.Builder builder = Mica.ProjectDto.newBuilder().addAllTitle(// 
    localizedStringDtos.asDto(project.getTitle())).addAllSummary(localizedStringDtos.asDto(project.getSummary()));
    if (project.hasModel())
        builder.setContent(JSONUtils.toJSON(project.getModel()));
    if (project.hasDataAccessRequestId()) {
        try {
            DataAccessRequest request = dataAccessRequestService.findById(project.getDataAccessRequestId());
            Mica.DataAccessRequestSummaryDto.Builder darBuilder = Mica.DataAccessRequestSummaryDto.newBuilder();
            darBuilder.setId(project.getDataAccessRequestId());
            darBuilder.setStatus(request.getStatus().name());
            darBuilder.setApplicant(request.getApplicant());
            darBuilder.setViewable(subjectAclService.isPermitted("/data-access-request", "VIEW", request.getId()));
            builder.setRequest(darBuilder);
        } catch (NoSuchElementException e) {
        // ignore
        }
    }
    if (!project.isNew())
        builder.setId(project.getId());
    Mica.PermissionsDto permissionsDto = permissionsDtos.asDto(project);
    if (asDraft) {
        ProjectState projectState = projectService.getEntityState(project.getId());
        // 
        builder.setTimestamps(TimestampsDtos.asDto(project)).setPublished(// 
        projectState.isPublished()).setExtension(Mica.EntityStateDto.projectState, entityStateDtos.asDto(projectState).setPermissions(permissionsDto).build());
    }
    builder.setPermissions(permissionsDto);
    builder.setTimestamps(TimestampsDtos.asDto(project));
    return builder.build();
}
Also used : DataAccessRequest(org.obiba.mica.access.domain.DataAccessRequest) ProjectState(org.obiba.mica.project.domain.ProjectState) NoSuchElementException(java.util.NoSuchElementException) NotNull(javax.validation.constraints.NotNull)

Aggregations

NotNull (javax.validation.constraints.NotNull)77 List (java.util.List)24 Map (java.util.Map)18 Collectors (java.util.stream.Collectors)16 Inject (javax.inject.Inject)16 Logger (org.slf4j.Logger)14 ArrayList (java.util.ArrayList)13 LoggerFactory (org.slf4j.LoggerFactory)13 HashMap (java.util.HashMap)11 Response (javax.ws.rs.core.Response)10 Optional (java.util.Optional)9 Strings (com.google.common.base.Strings)8 Lists (com.google.common.collect.Lists)8 Set (java.util.Set)8 Valid (javax.validation.Valid)8 Api (io.swagger.annotations.Api)7 ApiParam (io.swagger.annotations.ApiParam)7 IOException (java.io.IOException)7 Collection (java.util.Collection)7 Nullable (javax.annotation.Nullable)7