private static <BE> BaseResourceTypes.Read<BE> proceedToResourceTypes(TraversalContext<BE, Tenant> context, Tenants.ResourceTypeParents... parents) { return new BaseResourceTypes.Read<>(context.proceedWithParents(ResourceType.class, Tenants.ResourceTypeParents.class, Tenants.ResourceTypeParents.TENANT, parents, (p, extender) -> { switch (p) { case FEED: extender.path() .with(by(contains), type(Feed.class), by(contains), type(ResourceType.class)); break; case TENANT: extender.path().with(by(contains), type(ResourceType.class)); break; default: throw new AssertionError("Unhandled parent type " + p); } })); }
private static <BE> BaseMetricTypes.Read<BE> proceedToMetricTypes(TraversalContext<BE, Tenant> context, Tenants.MetricTypeParents... parents) { return new BaseMetricTypes.Read<>(context.proceedWithParents(MetricType.class, Tenants.MetricTypeParents.class, Tenants.MetricTypeParents.TENANT, parents, (p, extender) -> { switch (p) { case FEED: extender.path().with(by(contains), type(Feed.class), by(contains), type(MetricType.class)); break; case TENANT: extender.path().with(by(contains), type(MetricType.class)); break; default: throw new AssertionError("Unhandled parent type " + p); } })); } }
private static <BE> BaseResources.Read<BE> proceedToResources(TraversalContext<BE, Feed> context, Feeds.ResourceParents... parents) { return new BaseResources.Read<>(context.proceedWithParents(Resource.class, Feeds.ResourceParents.class, Feeds.ResourceParents.FEED, parents, (p, extender) -> { switch (p) { case FEED: extender.path().with(by(contains), type(Resource.class)); break; case RESOURCE: extender.path().with(by(contains), type(Resource.class), RecurseFilter.builder() .addChain(by(contains), type(Resource.class)).build()); break; default: throw new AssertionError("Unhandled type of resource parent under feed."); } })); }
private static <BE> BaseResources.Read<BE> proceedToResources(TraversalContext<BE, Environment> context, Environments.ResourceParents... parents) { return new BaseResources.Read<>(context.proceedWithParents(Resource.class, Environments.ResourceParents.class, Environments.ResourceParents.ENVIRONMENT, parents, (p, extender) -> { switch (p) { case ENVIRONMENT: extender.path().with(by(contains), type(Resource.class)); break; case FEED: extender.path() .with(by(incorporates), type(Feed.class), by(contains), type(Resource.class)); break; case RESOURCE: //go to root resources, wherever they are extender.path().with(new Filter[][]{ {by(contains), type(Resource.class)}, {by(incorporates), type(Feed.class), by(contains), type(Resource.class)}}); //and then go to the child resources extender.path().with(RecurseFilter.builder().addChain(by(isParentOf), type(Resource .class)).build()); break; default: throw new AssertionError("Unhandled type of resource parent under environment."); } })); }
private static <BE> BaseMetrics.Read<BE> proceedToMetrics(TraversalContext<BE, Environment> context, Environments.MetricParents... parents) { return new BaseMetrics.Read<>(context.proceedWithParents(Metric.class, Environments.MetricParents.class, Environments.MetricParents.ENVIRONMENT, parents, (p, extender) -> { switch (p) { case ENVIRONMENT: extender.path().with(by(contains), type(Metric.class)); break; case FEED: extender.path().with(by(incorporates), type(Feed.class), by(contains), type(Metric.class)); break; case RESOURCE: //out by all possible paths from env to a resource extender.path().with(new Filter[][]{ {by(contains), type(Resource.class)}, {by(incorporates), type(Feed.class), by(contains), type(Resource.class)}}); //out to direct metrics and also metrics of child resources extender.path().with(new Filter[][]{ {by(contains), type(Metric.class)}, {RecurseFilter.builder().addChain(by(contains), type(Resource.class)).build(), by(contains), type(Metric.class)}}); break; default: throw new AssertionError("Unhandled type of metric parent under environment."); } })); }
private static <BE> BaseMetrics.Read<BE> proceedToMetrics(TraversalContext<BE, Feed> context, Feeds.MetricParents... parents) { return new BaseMetrics.Read<>(context.proceedWithParents(Metric.class, Feeds.MetricParents.class, Feeds.MetricParents.FEED, parents, (p, extender) -> { switch (p) { case FEED: extender.path().with(by(contains), type(Metric.class)); break; case RESOURCE: //go to the root resources and their children extender.path().with(new Filter[][]{ {by(contains), type(Resource.class)}, {by(contains), type(Resource.class), RecurseFilter.builder().addChain( by(contains), type(Resource.class)).build()}}); //and from the resources, go to the metrics extender.path().with(by(contains), type(Metric.class)); break; default: throw new AssertionError("Unhandled type of resource parent under feed."); } })); } }
@Override public void preCreate(DataEntity.Blueprint blueprint, Transaction<BE> tx) { BE pack = tx.querySingle(context.select().path().with(Related .asTargetBy(incorporates), With.type(MetadataPack.class)).get()); if (pack != null) { BE rt = tx.querySingle(context.select().get()); throw new IllegalArgumentException( "Data '" + blueprint.getId() + "' cannot be created" + " under resource type " + tx.extractCanonicalPath(rt) + ", because it is part of a meta data pack." + " Doing this would invalidate meta data pack's identity."); } }
@Override public void preCreate(DataEntity.Blueprint blueprint, Transaction<BE> transaction) { BE mp = transaction.querySingle(context.select().path().with(asTargetBy(contains), asTargetBy(incorporates), With.type(MetadataPack.class)).get()); if (mp != null) { BE ot = transaction.querySingle(context.select().get()); throw new IllegalArgumentException( "Data '" + blueprint.getId() + "' cannot be created" + " under operation type " + transaction.extractCanonicalPath(ot) + ", because the owning resource type is part of a meta data pack." + " Doing this would invalidate meta data pack's identity."); } }
/** * Appends the provided set of filters to the current select candidates. * The filters are applied as path fragments. * * @param filters the set of filters to append as path fragments * @return this builder */ public Builder<BE, E> hop(Filter... filters) { selectExtender.path().with(filters); return this; }
/** * Create query branches in the select candidates with each of the provided sets of filters. * The filters are applied as path fragments. * * @param filters the sets of the filters to append as path fragments * @return this builder */ public Builder<BE, E> hop(Filter[][] filters) { selectExtender.path().with(filters); return this; }
/** * @return a symmetric builder that will start appending path fragments to the query */ public static SymmetricExtender path() { return empty().extend().path(); }
@SuppressWarnings("unchecked") public static Query extendTo(TraversalContext<?, ?> context, Path path) { if (path instanceof CanonicalPath) { return context.select().with(With.path((CanonicalPath) path)).get(); } else { Marker marker = Marker.next(); return context.sourcePath.extend().path().with(marker).with(context.selectCandidates) .with(With.relativePath(marker.getLabel(), (RelativePath) path)).get(); } }
/** * @return appends the select candidates to the source path. The only difference between this and {@link #select()} * is that this method returns the extender set up to append path fragments. */ Query.SymmetricExtender hop() { return sourcePath.extend().path().withExact(selectCandidates).path(); }
@SuppressWarnings("unchecked") public static Query queryTo(Query sourcePath, Path path) { if (path instanceof CanonicalPath) { return Query.to((CanonicalPath) path); } else { Query.SymmetricExtender extender = sourcePath.extend().path(); extender.with(With.relativePath(null, (RelativePath) path)); return extender.get(); } }