@SuppressWarnings({"ConstantConditions", "unchecked"}) public static Query to(CanonicalPath entity) { return Query.path().with(With.path(entity)).get(); }
@Override protected void preCreate(OperationType.Blueprint blueprint, Transaction<BE> tx) { //disallow this if the parent resource type is a part of a metadata pack if (tx.traverseToSingle(getParent(tx), Query.path().with(asTargetBy(incorporates), With.type(MetadataPack.class)).get()) != null) { throw new IllegalArgumentException("Cannot create an operation type of resource type included in " + "a meta data pack. This would invalidate the metadata pack's identity."); } }
@Override public final void initialize(Configuration configuration) { this.backend = doInitialize(configuration); tenantContext = new TraversalContext<>(this, Query.empty(), Query.path().with(With.type(Tenant.class)).get(), backend, Tenant.class, configuration, observableContext, transactionConstructor); relationshipContext = new TraversalContext<>(this, Query.empty(), Query.path().get(), backend, Relationship.class, configuration, observableContext, transactionConstructor); this.configuration = configuration; }
private static <BE> boolean isResourceTypeInMetadataPack(BE resourceType, Transaction<BE> tx) { return tx.traverseToSingle(resourceType, Query.path() .with(asTargetBy(incorporates), type(MetadataPack.class)).get()) != null; } }
/** * This is a sort of copy constructor. * Can be used by subclasses when implementing the {@link #cloneWith(TransactionConstructor)} method. * * @param orig the original instance to copy stuff over from * @param backend if not null, then use this backend instead of the one used by {@code orig} * @param transactionConstructor if not null, then use this ctor instead of the one used by {@code orig} */ protected BaseInventory(BaseInventory<E> orig, InventoryBackend<E> backend, TransactionConstructor<E> transactionConstructor) { this.observableContext = orig.observableContext; this.configuration = orig.configuration; this.backend = backend == null ? orig.backend : backend; this.transactionConstructor = transactionConstructor == null ? orig.transactionConstructor : transactionConstructor; tenantContext = new TraversalContext<>(this, Query.empty(), Query.path().with(With.type(Tenant.class)).get(), this.backend, Tenant.class, configuration, observableContext, this.transactionConstructor); relationshipContext = new TraversalContext<>(this, Query.empty(), Query.path().get(), this.backend, Relationship.class, configuration, observableContext, this.transactionConstructor); }
private static <BE> boolean isInMetadataPack(BE metricType, Transaction<BE> tx) { return tx.traverseToSingle(metricType, Query.path().with(Related.asTargetBy(incorporates), With.type(MetadataPack.class)).get()) != null; }
private static <BE> boolean isResourceTypeInMetadataPack(BE operationType, Transaction<BE> tx) { return tx.traverseToSingle(operationType, Query.path().with(asTargetBy(contains), asTargetBy(incorporates), With.type(MetadataPack.class)).get()) != null; } }
public static <BE> void validate(Transaction<BE> tx, StructuredData data, BE dataEntity) { CanonicalPath path = tx.extractCanonicalPath(dataEntity); DataRole role = DataRole.valueOf(path.ids().getDataRole()); if (role.isSchema()) { try { JsonNode schema = new JsonNodeReader(new ObjectMapper()) .fromInputStream(BaseData.class.getResourceAsStream("/json-meta-schema.json")); CanonicalPath dataPath = tx.extractCanonicalPath(dataEntity); validate(dataPath, convert(data), schema); } catch (IOException e) { throw new IllegalStateException("Could not load the embedded JSON Schema meta-schema."); } } else { validateIfSchemaFound(tx, data, dataEntity, Query.path().with(navigateToSchema(role)).get()); } }
@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); }
@Override public void preUpdate(BE dataEntity, DataEntity.Update update, Transaction<BE> tx) { if (update.getValue() == null) { return; } BE mp = tx.traverseToSingle(dataEntity, Query.path().with( Related.asTargetBy(contains), //up to resource type Related.asTargetBy(incorporates), With.type(MetadataPack.class) // up to the pack ).get()); if (mp != null) { CanonicalPath dataPath = tx.extractCanonicalPath(dataEntity); throw new IllegalArgumentException( "Data '" + dataPath.getSegment().getElementId() + "' cannot be updated" + " under resource type " + dataPath.up() + ", because it is part of a meta data pack." + " Doing this would invalidate meta data pack's identity."); } }
@Override public void preUpdate(BE dataEntity, DataEntity.Update update, Transaction<BE> tx) { if (update.getValue() == null) { return; } BE mp = tx.traverseToSingle(dataEntity, Query.path().with( asTargetBy(contains), //up to operation type asTargetBy(contains), //up to resource type asTargetBy(incorporates), With.type(MetadataPack.class) // up to the pack ).get()); if (mp != null) { CanonicalPath dataPath = tx.extractCanonicalPath(dataEntity); throw new IllegalArgumentException( "Data '" + dataPath.getSegment().getElementId() + "' cannot be updated" + " under operation type " + dataPath.up() + ", because the owning resource type is part of a meta data pack." + " Doing this would invalidate meta data pack's identity."); } }
@Override public Element descendToData(Element dataEntityRepresentation, RelativePath dataPath) { Query q = Query.path().with(With.dataAt(dataPath)).get(); GraphTraversal<?, ? extends Element> pipeline = dataEntityRepresentation instanceof Vertex ? context.getGraph().traversal().V(dataEntityRepresentation) : context.getGraph().traversal().E(dataEntityRepresentation); FilterApplicator.applyAll(q, pipeline); return drainAfter(pipeline, () -> { if (pipeline.hasNext()) { return pipeline.next(); } else { return null; } }); }