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;
}
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;
}
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;
}
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;
}
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();
}
Aggregations