Search in sources :

Example 6 with Network

use of org.obiba.mica.network.domain.Network in project mica2 by obiba.

the class NetworkQuery method getStudyCountsByNetwork.

public Map<String, List<String>> getStudyCountsByNetwork() {
    Map<String, List<String>> map = Maps.newHashMap();
    if (!micaConfigService.getConfig().isNetworkEnabled())
        return map;
    Properties props = new Properties();
    props.setProperty("id", "");
    Properties subProps = new Properties();
    subProps.setProperty(JOIN_FIELD, "");
    Map<String, Properties> subAggregations = Maps.newHashMap();
    subAggregations.put("id", subProps);
    try {
        Searcher.DocumentResults results = searcher.cover(getSearchIndex(), getSearchType(), getQuery(), props, subAggregations, null);
        results.getAggregations().stream().filter(agg -> "terms".equals(agg.getType())).forEach(aggregation -> aggregation.asTerms().getBuckets().stream().filter(bucket -> bucket.getDocCount() > 0).forEach(bucket -> map.put(bucket.getKeyAsString(), getStudyCounts(bucket.getAggregations()))));
    } catch (Exception e) {
        log.warn("Study counts by network failed", e);
    }
    return map;
}
Also used : Arrays(java.util.Arrays) NetworkTaxonomyMetaDataProvider(org.obiba.mica.search.aggregations.NetworkTaxonomyMetaDataProvider) LoggerFactory(org.slf4j.LoggerFactory) QueryResultDto(org.obiba.mica.web.model.MicaSearch.QueryResultDto) Indexer(org.obiba.mica.spi.search.Indexer) AggregationMetaDataProvider(org.obiba.mica.micaConfig.service.helper.AggregationMetaDataProvider) Scope(org.springframework.context.annotation.Scope) NetworkResultDto(org.obiba.mica.web.model.MicaSearch.NetworkResultDto) QueryMode(org.obiba.mica.spi.search.QueryMode) Inject(javax.inject.Inject) MicaSearch(org.obiba.mica.web.model.MicaSearch) Lists(com.google.common.collect.Lists) CountStatsData(org.obiba.mica.spi.search.CountStatsData) NetworkAggregationMetaDataProvider(org.obiba.mica.search.aggregations.NetworkAggregationMetaDataProvider) Mica(org.obiba.mica.web.model.Mica) Map(java.util.Map) Network(org.obiba.mica.network.domain.Network) Dtos(org.obiba.mica.web.model.Dtos) Nullable(javax.annotation.Nullable) QueryScope(org.obiba.mica.spi.search.QueryScope) Logger(org.slf4j.Logger) Properties(java.util.Properties) Searcher(org.obiba.mica.spi.search.Searcher) Collection(java.util.Collection) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) Component(org.springframework.stereotype.Component) List(java.util.List) NetworkState(org.obiba.mica.network.domain.NetworkState) PublishedNetworkService(org.obiba.mica.network.service.PublishedNetworkService) NetworkCountStatsBuilder(org.obiba.mica.search.CountStatsDtoBuilders.NetworkCountStatsBuilder) Searcher(org.obiba.mica.spi.search.Searcher) List(java.util.List) Properties(java.util.Properties) IOException(java.io.IOException)

Example 7 with Network

use of org.obiba.mica.network.domain.Network in project mica2 by obiba.

the class NetworkQuery method processHits.

@Override
public void processHits(QueryResultDto.Builder builder, Searcher.DocumentResults results, QueryScope scope, CountStatsData counts) throws IOException {
    NetworkResultDto.Builder resBuilder = NetworkResultDto.newBuilder();
    NetworkCountStatsBuilder networkCountStatsBuilder = counts == null ? null : NetworkCountStatsBuilder.newBuilder(counts);
    Consumer<Network> addDto = networkConsumer(scope, resBuilder, networkCountStatsBuilder);
    List<Network> networks = Lists.newArrayList();
    for (Searcher.DocumentResult result : results.getDocuments()) {
        if (result.hasSource())
            networks.add(objectMapper.readValue(result.getSourceInputStream(), Network.class));
    }
    networks.forEach(addDto);
    builder.setExtension(NetworkResultDto.result, resBuilder.build());
}
Also used : NetworkCountStatsBuilder(org.obiba.mica.search.CountStatsDtoBuilders.NetworkCountStatsBuilder) Network(org.obiba.mica.network.domain.Network) Searcher(org.obiba.mica.spi.search.Searcher) NetworkResultDto(org.obiba.mica.web.model.MicaSearch.NetworkResultDto)

Example 8 with Network

use of org.obiba.mica.network.domain.Network in project mica2 by obiba.

the class NetworkService method publish.

/**
 * Set the publication flag on a {@link Network}.
 *
 * @param id
 * @throws NoSuchNetworkException
 */
@Caching(evict = { @CacheEvict(value = "aggregations-metadata", key = "'network'") })
public void publish(@NotNull String id, boolean publish, PublishCascadingScope cascadingScope) throws NoSuchEntityException {
    Network network = networkRepository.findOne(id);
    if (network == null)
        return;
    if (publish) {
        processNetworkForPublishedNumberOfStudies(network);
        publishState(id);
        eventBus.post(new NetworkPublishedEvent(network, getCurrentUsername(), cascadingScope));
    } else {
        unPublishState(id);
        eventBus.post(new NetworkUnpublishedEvent(network));
    }
}
Also used : NetworkUnpublishedEvent(org.obiba.mica.network.event.NetworkUnpublishedEvent) NetworkPublishedEvent(org.obiba.mica.network.event.NetworkPublishedEvent) Network(org.obiba.mica.network.domain.Network) Caching(org.springframework.cache.annotation.Caching)

Example 9 with Network

use of org.obiba.mica.network.domain.Network in project mica2 by obiba.

the class NetworkDtos method asDtoBuilder.

@NotNull
Mica.NetworkDto.Builder asDtoBuilder(@NotNull Network network, boolean asDraft) {
    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()));
    Mica.PermissionsDto permissionsDto = permissionsDtos.asDto(network);
    NetworkState networkState = networkService.getEntityState(network.getId());
    builder.setPublished(networkState.isPublished());
    if (asDraft) {
        // 
        builder.setTimestamps(TimestampsDtos.asDto(network)).setPublished(// 
        networkState.isPublished()).setExtension(Mica.EntityStateDto.state, entityStateDtos.asDto(networkState).setPermissions(permissionsDto).build());
    }
    builder.setPermissions(permissionsDto);
    List<String> roles = micaConfigService.getConfig().getRoles();
    if (network.getMemberships() != null) {
        List<Mica.MembershipsDto> memberships = network.getMemberships().entrySet().stream().filter(e -> roles.contains(e.getKey())).map(e -> Mica.MembershipsDto.newBuilder().setRole(e.getKey()).addAllMembers(e.getValue().stream().map(m -> personDtos.asDto(m.getPerson(), asDraft)).collect(toList())).build()).collect(toList());
        builder.addAllMemberships(memberships);
    }
    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());
            builder.addStudySummaries(studySummaryDtos.asDtoBuilder(study, true, datasetVariableCounts == null ? 0 : datasetVariableCounts.get(study.getId())));
        });
    }
    unpublishedStudyIds.forEach(studyId -> {
        try {
            builder.addStudySummaries(studySummaryDtos.asDto(studyId));
            builder.addStudyIds(studyId);
        } catch (NoSuchEntityException e) {
            log.warn("Study not found in network {}: {}", network.getId(), studyId);
        // ignore
        }
    });
    if (network.getLogo() != null) {
        builder.setLogo(attachmentDtos.asDto(network.getLogo()));
    }
    network.getNetworkIds().stream().filter(nId -> asDraft && subjectAclService.isPermitted("/draft/network", "VIEW", nId) || subjectAclService.isAccessible("/network", nId)).forEach(nId -> {
        try {
            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) 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) PublishedDatasetVariableService(org.obiba.mica.study.service.PublishedDatasetVariableService) ImmutableSet(com.google.common.collect.ImmutableSet) SubjectAclService(org.obiba.mica.security.service.SubjectAclService) Logger(org.slf4j.Logger) HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) BaseStudy(org.obiba.mica.study.domain.BaseStudy) Set(java.util.Set) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) 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) Study(org.obiba.mica.study.domain.Study) 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) NotNull(javax.validation.constraints.NotNull)

Example 10 with Network

use of org.obiba.mica.network.domain.Network 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.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())));
        network.setMemberships(memberships);
    }
    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.hasContent() && !Strings.isNullOrEmpty(dto.getContent()))
        network.setModel(JSONUtils.toMap(dto.getContent()));
    else
        network.setModel(new HashMap<>());
    return network;
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) Membership(org.obiba.mica.core.domain.Membership) HashMap(java.util.HashMap) AbstractGitPersistable(org.obiba.mica.core.domain.AbstractGitPersistable) 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) PublishedDatasetVariableService(org.obiba.mica.study.service.PublishedDatasetVariableService) ImmutableSet(com.google.common.collect.ImmutableSet) SubjectAclService(org.obiba.mica.security.service.SubjectAclService) Logger(org.slf4j.Logger) HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) BaseStudy(org.obiba.mica.study.domain.BaseStudy) Set(java.util.Set) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) 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) Study(org.obiba.mica.study.domain.Study) MicaConfigService(org.obiba.mica.micaConfig.service.MicaConfigService) NetworkState(org.obiba.mica.network.domain.NetworkState) NetworkService(org.obiba.mica.network.service.NetworkService) HashMap(java.util.HashMap) Network(org.obiba.mica.network.domain.Network) Membership(org.obiba.mica.core.domain.Membership) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) NotNull(javax.validation.constraints.NotNull)

Aggregations

Network (org.obiba.mica.network.domain.Network)19 NetworkState (org.obiba.mica.network.domain.NetworkState)6 Map (java.util.Map)5 Inject (javax.inject.Inject)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Maps (com.google.common.collect.Maps)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Strings (com.google.common.base.Strings)3 Sets (com.google.common.collect.Sets)3 Set (java.util.Set)3 NotNull (javax.validation.constraints.NotNull)3 NoSuchEntityException (org.obiba.mica.NoSuchEntityException)3 LocalizedString (org.obiba.mica.core.domain.LocalizedString)3 Attachment (org.obiba.mica.file.Attachment)3 NetworkService (org.obiba.mica.network.service.NetworkService)3 SubjectAclService (org.obiba.mica.security.service.SubjectAclService)3 BaseStudy (org.obiba.mica.study.domain.BaseStudy)3 Component (org.springframework.stereotype.Component)3