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