@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); }
@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; } } };
private ProcessingTree<BE> extendTreeTo(CanonicalPath entityPath) { Set<ProcessingTree<BE>> children = this.children; CanonicalPath.Extender cp = CanonicalPath.empty(); ProcessingTree<BE> found = null; for (Path.Segment seg : entityPath.getPath()) { cp.extend(seg); found = null; for (ProcessingTree<BE> child : children) { if (seg.equals(child.path)) { found = child; break; } } if (found == null) { found = new ProcessingTree<>(seg, cp.get()); children.add(found); } children = found.children; } if (found == null) { throw new IllegalStateException("Could not figure out the processing tree element for entity on path " + entityPath); } return found; }
@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();
throw new IllegalArgumentException("Resource type '" + blueprint.getResourceTypePath() + "' not found" + " when resolved to '" + resourceTypePath + "' while trying to wire up a new resource on path '" + parentPath.extend(SegmentType.r, blueprint.getId()).get() + "'."); tx.extractId(entity)).get(), null, null, null, resourceType, blueprint.getProperties());
tx.extractId(entity)).get(), null, null, null, metricType, blueprint.getCollectionInterval(), blueprint.getProperties());
public DataEntity(CanonicalPath owner, DataRole role, StructuredData value) { super(null, owner.extend(DataEntity.SEGMENT_TYPE, role.name()).get()); this.value = value; }
public DataEntity(CanonicalPath owner, DataRole role, StructuredData value, Map<String, Object> properties) { super(owner.extend(DataEntity.SEGMENT_TYPE, role.name()).get(), properties); this.value = value; }
public DataEntity(CanonicalPath owner, DataRole role, StructuredData value, String identityHash, String contentHash, String syncHash, Map<String, Object> properties) { super(owner.extend(DataEntity.SEGMENT_TYPE, role.name()).get(), identityHash, contentHash, syncHash, properties); this.value = value; }
@Override protected EntityAndPendingNotifications<BE, Feed> wireUpNewEntity(BE entity, Feed.Blueprint blueprint, CanonicalPath parentPath, BE parent, Transaction<BE> transaction) { return new EntityAndPendingNotifications<>(entity, new Feed(blueprint.getName(), parentPath.extend(Feed.SEGMENT_TYPE, transaction.extractId(entity)).get(), null, null, null, blueprint.getProperties()), emptyList()); }
@Override protected String getProposedId(Transaction<BE> tx, Feed.Blueprint blueprint) { BE tenant = tx.querySingle(context.sourcePath.extend().filter() .with(type(Tenant.class)).get()); if (tenant == null) { throw new EntityNotFoundException(Tenant.class, Query.filters(context.sourcePath)); } CanonicalPath feedPath = tx.extractCanonicalPath(tenant) .extend(Feed.SEGMENT_TYPE, blueprint.getId()).get(); return context.configuration.getFeedIdStrategy().generate(context.inventory.keepTransaction(tx), new Feed(feedPath, null, null, null)); }
@Override protected EntityAndPendingNotifications<BE, ResourceType> wireUpNewEntity(BE entity, ResourceType.Blueprint blueprint, CanonicalPath parentPath, BE parent, Transaction<BE> tx) { tx.update(entity, ResourceType.Update.builder().build()); ResourceType resourceType = new ResourceType(blueprint.getName(), parentPath.extend(ResourceType.SEGMENT_TYPE, tx.extractId(entity)).get(), null, null, null, blueprint.getProperties()); return new EntityAndPendingNotifications<>(entity, resourceType, emptyList()); }
@Override protected EntityAndPendingNotifications<BE, OperationType> wireUpNewEntity(BE entity, OperationType.Blueprint blueprint, CanonicalPath parentPath, BE parent, Transaction<BE> tx) { return new EntityAndPendingNotifications<>(entity, new OperationType(blueprint.getName(), parentPath.extend(OperationType.SEGMENT_TYPE, tx.extractId(entity)).get(), null, null, null, blueprint.getProperties()), emptyList()); }
@Override protected EntityAndPendingNotifications<BE, MetricType> wireUpNewEntity(BE entity, MetricType.Blueprint blueprint, CanonicalPath parentPath, BE parent, Transaction<BE> tx) { tx.update(entity, MetricType.Update.builder().withUnit(blueprint.getUnit()).build()); MetricType metricType = new MetricType(blueprint.getName(), parentPath.extend(MetricType.SEGMENT_TYPE, tx.extractId(entity)).get(), null, null, null, blueprint.getUnit(), blueprint.getMetricDataType(), blueprint.getProperties(), blueprint.getCollectionInterval()); return new EntityAndPendingNotifications<>(entity, metricType, emptyList()); }
IntermediateHashContext progress(Entity.Blueprint bl) { SegmentType st = Blueprint.getSegmentTypeOf(bl); String id = bl.getId(); return new IntermediateHashContext(origin == null ? null : origin.modified().extend(st, id).get(), root.modified().extend(st, id).get()); } }
public DataEntity(CanonicalPath owner, DataRole role, StructuredData value, String identityHash, String contentHash, String syncHash) { super(null, owner.extend(DataEntity.SEGMENT_TYPE, role.name()).get(), identityHash, contentHash, syncHash); this.value = value; }
@Override protected EntityAndPendingNotifications<BE, Environment> wireUpNewEntity(BE entity, Environment.Blueprint blueprint, CanonicalPath parentPath, BE parent, Transaction<BE> tx) { return new EntityAndPendingNotifications<>(entity, new Environment(blueprint.getName(), parentPath.extend(Environment.SEGMENT_TYPE, tx.extractId(entity)).get(), null, blueprint.getProperties()), emptyList()); }