Search in sources :

Example 31 with NotNull

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

the class AttachmentDtos method fromDto.

@NotNull
Attachment fromDto(@NotNull Mica.AttachmentDtoOrBuilder dto) {
    Attachment attachment = new Attachment();
    attachment.setId(dto.getId());
    attachment.setName(dto.getFileName());
    if (dto.hasType())
        attachment.setType(dto.getType());
    if (dto.getDescriptionCount() > 0)
        attachment.setDescription(localizedStringDtos.fromDto(dto.getDescriptionList()));
    if (dto.hasLang())
        attachment.setLang(new Locale(dto.getLang()));
    attachment.setSize(dto.getSize());
    if (dto.hasMd5())
        attachment.setMd5(dto.getMd5());
    attachment.setJustUploaded(dto.getJustUploaded());
    if (dto.hasTimestamps())
        TimestampsDtos.fromDto(dto.getTimestamps(), attachment);
    if (dto.getAttributesCount() > 0) {
        dto.getAttributesList().forEach(attributeDto -> attachment.addAttribute(attributeDtos.fromDto(attributeDto)));
    }
    if (dto.hasPath())
        attachment.setPath(dto.getPath());
    return attachment;
}
Also used : Locale(java.util.Locale) Attachment(org.obiba.mica.file.Attachment) NotNull(javax.validation.constraints.NotNull)

Example 32 with NotNull

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

the class DatasetDtos method fromDto.

@NotNull
public Dataset fromDto(Mica.DatasetDtoOrBuilder dto) {
    Dataset dataset = dto.hasExtension(Mica.HarmonizedDatasetDto.type) ? fromDto(dto.getExtension(Mica.HarmonizedDatasetDto.type)) : dto.hasExtension(Mica.CollectedDatasetDto.type) ? fromDto(dto.getExtension(Mica.CollectedDatasetDto.type)) : new StudyDataset();
    if (dto.hasId())
        dataset.setId(dto.getId());
    dataset.setAcronym(localizedStringDtos.fromDto(dto.getAcronymList()));
    dataset.setName(localizedStringDtos.fromDto(dto.getNameList()));
    dataset.setDescription(localizedStringDtos.fromDto(dto.getDescriptionList()));
    dataset.setEntityType(dto.getEntityType());
    dataset.setPublished(dto.getPublished());
    if (dto.getAttributesCount() > 0) {
        dto.getAttributesList().forEach(attributeDto -> dataset.addAttribute(attributeDtos.fromDto(attributeDto)));
    }
    if (dto.hasContent()) {
        dataset.setModel(JSONUtils.toMap(dto.getContent()));
    }
    return dataset;
}
Also used : StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) Dataset(org.obiba.mica.dataset.domain.Dataset) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) NotNull(javax.validation.constraints.NotNull)

Example 33 with NotNull

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

the class NetworkDtos method asDtoBuilderInternal.

private Mica.NetworkDto.Builder asDtoBuilderInternal(@NotNull Network network, boolean asDraft, boolean forListing) {
    Mica.NetworkDto.Builder builder = Mica.NetworkDto.newBuilder();
    if (network.hasModel())
        builder.setContent(JSONUtils.toJSON(network.getModel()));
    // 
    builder.setId(network.getId()).addAllName(// 
    localizedStringDtos.asDto(network.getName())).addAllDescription(// 
    localizedStringDtos.asDto(network.getDescription())).addAllAcronym(localizedStringDtos.asDto(network.getAcronym()));
    NetworkState networkState = networkService.getEntityState(network.getId());
    builder.setPublished(networkState.isPublished());
    if (asDraft) {
        Mica.PermissionsDto permissionsDto = permissionsDtos.asDto(network);
        // 
        builder.setTimestamps(TimestampsDtos.asDto(network)).setPublished(// 
        networkState.isPublished()).setExtension(Mica.EntityStateDto.state, entityStateDtos.asDto(networkState).setPermissions(permissionsDto).build());
        builder.setPermissions(permissionsDto);
    }
    if (network.getLogo() != null) {
        builder.setLogo(attachmentDtos.asDto(network.getLogo()));
    }
    List<BaseStudy> publishedStudies = publishedStudyService.findByIds(network.getStudyIds());
    Set<String> publishedStudyIds = publishedStudies.stream().map(AbstractGitPersistable::getId).collect(Collectors.toSet());
    Sets.SetView<String> unpublishedStudyIds = Sets.difference(ImmutableSet.copyOf(network.getStudyIds().stream().filter(sId -> asDraft && subjectAclService.isPermitted("/draft/individual-study", "VIEW", sId) || subjectAclService.isAccessible("/individual-study", sId)).collect(toList())), publishedStudyIds);
    if (!publishedStudies.isEmpty()) {
        Map<String, Long> datasetVariableCounts = asDraft ? null : datasetVariableService.getCountByStudyIds(Lists.newArrayList(publishedStudyIds));
        publishedStudies.forEach(study -> {
            builder.addStudyIds(study.getId());
            if (!forListing) {
                builder.addStudySummaries(studySummaryDtos.asDtoBuilder(study, true, datasetVariableCounts == null ? 0 : datasetVariableCounts.get(study.getId())));
            }
        });
    }
    unpublishedStudyIds.forEach(studyId -> {
        try {
            if (!forListing)
                builder.addStudySummaries(studySummaryDtos.asDto(studyId));
            builder.addStudyIds(studyId);
        } catch (NoSuchEntityException e) {
            log.warn("Study not found in network {}: {}", network.getId(), studyId);
        // ignore
        }
    });
    network.getNetworkIds().stream().filter(nId -> asDraft && subjectAclService.isPermitted("/draft/network", "VIEW", nId) || subjectAclService.isAccessible("/network", nId)).forEach(nId -> {
        try {
            if (!forListing)
                builder.addNetworkSummaries(networkSummaryDtos.asDtoBuilder(nId, asDraft));
            builder.addNetworkIds(nId);
        } catch (NoSuchEntityException e) {
            log.warn("Network not found in network {}: {}", network.getId(), nId);
        // ignore
        }
    });
    return builder;
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) Membership(org.obiba.mica.core.domain.Membership) HashMap(java.util.HashMap) AbstractGitPersistable(org.obiba.mica.core.domain.AbstractGitPersistable) MembershipSortOrderDto(org.obiba.mica.web.model.Mica.MembershipSortOrderDto) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) Map(java.util.Map) JSONUtils(org.obiba.mica.JSONUtils) Network(org.obiba.mica.network.domain.Network) Lists(jersey.repackaged.com.google.common.collect.Lists) PersonService(org.obiba.mica.core.service.PersonService) PublishedDatasetVariableService(org.obiba.mica.study.service.PublishedDatasetVariableService) ImmutableSet(com.google.common.collect.ImmutableSet) SubjectAclService(org.obiba.mica.security.service.SubjectAclService) Logger(org.slf4j.Logger) BaseStudy(org.obiba.mica.study.domain.BaseStudy) Set(java.util.Set) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) NoSuchEntityException(org.obiba.mica.NoSuchEntityException) PublishedStudyService(org.obiba.mica.study.service.PublishedStudyService) List(java.util.List) Component(org.springframework.stereotype.Component) Collectors.toList(java.util.stream.Collectors.toList) MicaConfigService(org.obiba.mica.micaConfig.service.MicaConfigService) NetworkState(org.obiba.mica.network.domain.NetworkState) NetworkService(org.obiba.mica.network.service.NetworkService) NoSuchEntityException(org.obiba.mica.NoSuchEntityException) Sets(com.google.common.collect.Sets) NetworkState(org.obiba.mica.network.domain.NetworkState) BaseStudy(org.obiba.mica.study.domain.BaseStudy)

Example 34 with NotNull

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

the class ProjectDtos method fromDto.

@NotNull
public Project fromDto(@NotNull Mica.ProjectDto dto) {
    Project.Builder builder = Project.newBuilder();
    builder.content(dto.hasContent() ? dto.getContent() : null);
    builder.title(localizedStringDtos.fromDto(dto.getTitleList()));
    builder.summary(localizedStringDtos.fromDto(dto.getSummaryList()));
    Project project = builder.build();
    if (dto.hasId())
        project.setId(dto.getId());
    TimestampsDtos.fromDto(dto.getTimestamps(), project);
    return project;
}
Also used : Project(org.obiba.mica.project.domain.Project) NotNull(javax.validation.constraints.NotNull)

Example 35 with NotNull

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

the class StudySummaryDtos method asDto.

@NotNull
Mica.DataCollectionEventSummaryDto asDto(@NotNull DataCollectionEvent dce) {
    Mica.DataCollectionEventSummaryDto.Builder builder = Mica.DataCollectionEventSummaryDto.newBuilder().setId(dce.getId()).addAllName(localizedStringDtos.asDto(dce.getName()));
    if (dce.getDescription() != null)
        builder.addAllDescription(localizedStringDtos.asDto(dce.getDescription()));
    if (dce.hasModel())
        builder.setContent(JSONUtils.toJSON(dce.getModel()));
    if (dce.hasStart()) {
        PersistableYearMonth start = dce.getStart();
        builder.setStart(start.getDay() != null ? start.getDay().format(DateTimeFormatter.ISO_DATE) : dce.getStart().getYearMonth());
    }
    if (dce.hasEnd()) {
        PersistableYearMonth end = dce.getEnd();
        builder.setEnd(end.getDay() != null ? end.getDay().format(DateTimeFormatter.ISO_DATE) : end.getYearMonth());
    }
    return builder.build();
}
Also used : PersistableYearMonth(org.obiba.mica.study.date.PersistableYearMonth) NotNull(javax.validation.constraints.NotNull)

Aggregations

NotNull (javax.validation.constraints.NotNull)76 List (java.util.List)24 Map (java.util.Map)18 Collectors (java.util.stream.Collectors)15 Inject (javax.inject.Inject)15 Logger (org.slf4j.Logger)14 ArrayList (java.util.ArrayList)13 LoggerFactory (org.slf4j.LoggerFactory)13 HashMap (java.util.HashMap)11 Set (java.util.Set)10 Optional (java.util.Optional)9 Response (javax.ws.rs.core.Response)9 Strings (com.google.common.base.Strings)8 Lists (com.google.common.collect.Lists)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 Valid (javax.validation.Valid)7