use of com.bakdata.conquery.apiv1.frontend.FENode in project conquery by bakdata.
the class FrontEndConceptBuilder method createCTRoot.
private static FENode createCTRoot(Concept<?> c, StructureNode[] structureNodes) {
MatchingStats matchingStats = c.getMatchingStats();
StructureNodeId structureParent = Arrays.stream(structureNodes).filter(sn -> sn.getContainedRoots().contains(c.getId())).findAny().map(StructureNode::getId).orElse(null);
FENode n = FENode.builder().active(true).description(c.getDescription()).label(c.getLabel()).additionalInfos(c.getAdditionalInfos()).matchingEntries(matchingStats.countEvents()).matchingEntities(matchingStats.countEntities()).dateRange(matchingStats.spanEvents() != null ? matchingStats.spanEvents().toSimpleRange() : null).detailsAvailable(Boolean.TRUE).codeListResolvable(c.countElements() > 1).parent(structureParent).selects(c.getSelects().stream().map(FrontEndConceptBuilder::createSelect).collect(Collectors.toList())).tables(c.getConnectors().stream().map(FrontEndConceptBuilder::createTable).collect(Collectors.toList())).build();
if (c instanceof ConceptTreeNode) {
ConceptTreeNode<?> tree = (ConceptTreeNode<?>) c;
if (tree.getChildren() != null) {
n.setChildren(tree.getChildren().stream().map(ConceptTreeChild::getId).toArray(ConceptTreeChildId[]::new));
}
}
return n;
}
use of com.bakdata.conquery.apiv1.frontend.FENode in project conquery by bakdata.
the class FrontEndConceptBuilder method createRoot.
public static FERoot createRoot(NamespaceStorage storage, Subject subject) {
FERoot root = new FERoot();
Map<IId<?>, FENode> roots = root.getConcepts();
List<? extends Concept<?>> allConcepts = new ArrayList<>(storage.getAllConcepts());
// Remove any hidden concepts
allConcepts.removeIf(Concept::isHidden);
if (allConcepts.isEmpty()) {
log.warn("There are no displayable concepts in the dataset {}", storage.getDataset().getId());
}
// Submit all permissions to Shiro
boolean[] isPermitted = subject.isPermitted(allConcepts, Ability.READ);
for (int i = 0; i < allConcepts.size(); i++) {
if (isPermitted[i]) {
roots.put(allConcepts.get(i).getId(), createCTRoot(allConcepts.get(i), storage.getStructure()));
}
}
if (roots.isEmpty()) {
log.warn("No concepts could be collected for {} on dataset {}. The subject is possibly lacking the permission to use them.", subject.getId(), storage.getDataset().getId());
} else {
log.trace("Collected {} concepts for {} on dataset {}.", roots.size(), subject.getId(), storage.getDataset().getId());
}
// add the structure tree
for (StructureNode sn : storage.getStructure()) {
FENode node = createStructureNode(sn, roots);
if (node == null) {
log.trace("Did not create a structure node entry for {}. Contained no concepts.", sn.getId());
continue;
}
roots.put(sn.getId(), node);
}
// add all secondary IDs
root.getSecondaryIds().addAll(storage.getSecondaryIds().stream().map(sid -> new FESecondaryId(sid.getId().toString(), sid.getLabel(), sid.getDescription())).collect(Collectors.toSet()));
return root;
}
use of com.bakdata.conquery.apiv1.frontend.FENode in project conquery by bakdata.
the class FrontEndConceptBuilder method createCTNode.
private static FENode createCTNode(ConceptElement<?> ce) {
MatchingStats matchingStats = ce.getMatchingStats();
FENode n = FENode.builder().active(null).description(ce.getDescription()).label(ce.getLabel()).additionalInfos(ce.getAdditionalInfos()).matchingEntries(matchingStats.countEvents()).matchingEntities(matchingStats.countEntities()).dateRange(matchingStats.spanEvents() != null ? matchingStats.spanEvents().toSimpleRange() : null).build();
if (ce instanceof ConceptTreeNode) {
ConceptTreeNode<?> tree = (ConceptTreeNode<?>) ce;
if (tree.getChildren() != null) {
n.setChildren(tree.getChildren().stream().map(IdentifiableImpl::getId).toArray(ConceptTreeChildId[]::new));
}
if (tree.getParent() != null) {
n.setParent(tree.getParent().getId());
}
}
return n;
}
Aggregations