ProcessingTree<BE> getChild(RelativePath childPath) { Iterator<Path.Segment> segments = childPath.getPath().iterator(); Set<ProcessingTree<BE>> children = this.children; ProcessingTree<BE> current = null; while (segments.hasNext()) { Path.Segment seg = segments.next(); current = null; for (ProcessingTree<BE> c : children) { //children are bound to each have a different ending segment, otherwise their CP would be the same //which is illegal in inventory. We can therefore just compare the current segment with the last //segment of the child path and if they match, move on to that child. if (seg.equals(c.cp.getSegment())) { current = c; children = c.children; break; } } //no child found matching this segment... if (current == null) { break; } } return segments.hasNext() ? null : current; }
default Single descendContained(RelativePath resourcePath) { ReadContained parent = this; Single access = null; for(Path.Segment s : resourcePath.getPath()) { access = parent.get(s.getElementId()); parent = access.resources(); } if (access == null) { throw new IllegalArgumentException("Empty resource path"); } return access; } }
RelativePath newStructurePath = myPath.modified().extend(strippedStructurePath.getPath()).get();
@SuppressWarnings("unchecked") private FullNode doGet(RelativePath path) { CanonicalPath pathToElement = rootEntity.getPath().modified().extend(path.getPath()).get(); try { FullNode cached = cache.get(pathToElement); if (cached != null) { return cached == FullNode.EMPTY ? null : cached; } Entity<Entity.Blueprint, ?> entity = (Entity<Entity.Blueprint, ?>) inventory.inspect(pathToElement, ResolvableToSingle.class).entity(); Entity.Blueprint b = Inventory.asBlueprint(entity); FullNode ret = new FullNode(b, entity); cache.put(entity.getPath(), ret); return ret; } catch (EntityNotFoundException e) { cache.put(pathToElement, FullNode.EMPTY); return null; } } };
/** * Returns all direct children of the specified parent. * * <b>WARNING</b>: the returned stream MUST BE closed after processing. * * @param parent the parent of which to return the children * @return the stream of all children of the parent */ @SuppressWarnings({"unchecked", "rawtypes"}) default Stream<FullNode> getAllChildNodes(RelativePath parent) { Stream<FullNode> ret = Stream.empty(); RelativePath.Extender check = RelativePath.empty() .extend(Blueprint.getSegmentTypeOf(getRoot()),getRoot().getId()) .extend(parent.getPath()); for (EntityType et : EntityType.values()) { SegmentType st = et.segmentType; if (check.canExtendTo(st)) { List<FullNode> res; Class entityType = Entity.entityTypeFromSegmentType(st); try (Stream<FullNode> next = (Stream<FullNode>) getChildNodes(parent, entityType)) { res = next.collect(Collectors.toList()); } ret = Stream.concat(ret, res.stream()); } } return ret; }
/** * Returns all direct children of the specified parent. * * <b>WARNING</b>: the returned stream MUST BE closed after processing. * * @param parent the parent of which to return the children * @return the stream of all children of the parent */ @SuppressWarnings({"unchecked", "rawtypes"}) default Stream<FullNode> getAllChildNodes(RelativePath parent) { Stream<FullNode> ret = Stream.empty(); RelativePath.Extender check = RelativePath.empty() .extend(Blueprint.getSegmentTypeOf(getRoot()),getRoot().getId()) .extend(parent.getPath()); for (EntityType et : EntityType.values()) { SegmentType st = et.segmentType; if (check.canExtendTo(st)) { List<FullNode> res; Class entityType = Entity.entityTypeFromSegmentType(st); try (Stream<FullNode> next = (Stream<FullNode>) getChildNodes(parent, entityType)) { res = next.collect(Collectors.toList()); } ret = Stream.concat(ret, res.stream()); } } return ret; }
@Override public Stream<FullNode> getAllChildNodes(RelativePath parent) { CanonicalPath absoluteParent = rootEntity.getPath().modified().extend(parent.getPath()).get(); Query q = Query.path().with(With.path(absoluteParent), Related.by(contains)).get(); @SuppressWarnings("rawtypes") Page<Entity> results = inventory.execute(q, Entity.class, Pager.none()); return StreamSupport.stream(results.spliterator(), false) .map(e -> { @SuppressWarnings("unchecked") FullNode n = new FullNode((Entity.Blueprint) Inventory.asBlueprint(e), e); cache.put(e.getPath(), n); return n; }) .sorted(ENTITY_ORDER) .onClose(results::close); }
private void convertToPipeline(RelativePath path, GraphTraversal<?, ?> pipeline) { for (Path.Segment s : path.getPath()) { if (SegmentType.up.equals(s.getElementType())) { pipeline.in(Relationships.WellKnown.contains.name()); } else { pipeline.out(Relationships.WellKnown.contains.name()) .hasLabel(Constants.Type.of(s.getElementType()).name()); apply(s, pipeline); } } }
@Override public <EE extends Entity<? extends BB, ?>, BB extends Entity.Blueprint> Stream<FullNode> getChildNodes(RelativePath parent, Class<EE> childType) { CanonicalPath absoluteParent = rootEntity.getPath().modified().extend(parent.getPath()).get(); SegmentType parentType = absoluteParent.getSegment().getElementType();
if (rp.getPath().isEmpty()) {
@SuppressWarnings("unchecked") public void visit(GraphTraversal<?, ?> query, With.DataAt dataPos, QueryTranslationState state) { goBackFromEdges(query, state); query.out(hasData.name()); for (Path.Segment seg : dataPos.getDataPath().getPath()) { if (SegmentType.up.equals(seg.getElementType())) { query.in(contains.name()); } else { query.out(contains.name()); } query.has(__type.name(), Constants.Type.structuredData.name()); // map members have both index and key (so that the order of the elements is preserved) // list members have only the index Integer index = toInteger(seg.getElementId()); if (index == null) { query.has(Constants.Property.__structuredDataKey.name(), seg.getElementId()); } else { //well, the map could have a numeric key, so we cannot say it has to be a list index here. GraphTraversal<?, ?>[] indexOrKey = new GraphTraversal<?, ?>[2]; indexOrKey[0] = __.has(Constants.Property.__structuredDataIndex.name(), index) .hasNot(Constants.Property.__structuredDataKey.name()); indexOrKey[1] = __.has(Constants.Property.__structuredDataKey.name(), seg.getElementId()); query.or((Traversal[]) indexOrKey); } } }