/** * Check a graph against an LDP interaction model. * * @param interactionModel the interaction model * @param graph the graph * @return any constraint violations on the graph */ default Stream<ConstraintViolation> constrainedBy(IRI interactionModel, Graph graph) { return constrainedBy(interactionModel, graph, TrellisUtils.TRELLIS_DATA_PREFIX); } }
/** * Get a mutable builder for a {@link BinaryMetadata}. * @param identifier the identifier * @return a builder for a {@link BinaryMetadata} */ public static Builder builder(final IRI identifier) { return new Builder(identifier); }
/** * A specialized no-op cache. */ @TrellisProfileCache public class NoopProfileCache extends NoopCacheService<String, String> { }
/** * Retrieve the RDF Quads for a resource. * * @return the RDF quads */ default Dataset dataset() { try (final Stream<Quad> quads = stream()) { return quads.collect(TrellisUtils.toDataset().concurrent()); } }
@Test public void testBadPersist() { final Quad testQuad = createQuad(badId, testResourceId1, testResourceId1, badId); final Resource testResource = new TestResource(badId, testQuad); assertThrows(CompletionException.class, () -> testable.create(Metadata.builder(testResource).build(), testResource.dataset()).toCompletableFuture() .join(), "Could create a resource when underlying services should reject it!"); }
@Override public CompletionStage<Resource> get(final IRI identifier) { return mutableData.get(identifier).thenCombine(immutableData.get(identifier), (mutable, immutable) -> { if (MISSING_RESOURCE.equals(mutable) && MISSING_RESOURCE.equals(immutable)) { return MISSING_RESOURCE; } else if (MISSING_RESOURCE.equals(mutable)) { return immutable; } else if (MISSING_RESOURCE.equals(immutable)) { return mutable; } else { return new RetrievableResource(mutable, immutable); } }); }
@Override public IRI getInteractionModel() { return mutable.getInteractionModel(); }
@Override public boolean hasAcl() { return mutable.hasAcl(); } }
@Override public CompletionStage<Void> create(final Metadata metadata, final Dataset dataset) { resources.put(metadata.getIdentifier(), new TestResource(metadata.getIdentifier(), dataset)); return isntBadId(metadata.getIdentifier()); }
@Override public CompletionStage<Void> add(final IRI identifier, final Dataset dataset) { resources.compute(identifier, (id, old) -> { final TestResource newRes = new TestResource(id, dataset); return old == null ? newRes : new RetrievableResource(old, newRes); }); return isntBadId(identifier); } }
@Override public CompletionStage<Void> delete(final Metadata metadata) { resources.remove(metadata.getIdentifier()); return isntBadId(metadata.getIdentifier()); } };
/** * A mutable builder for a {@link Metadata} object. * * @param identifier the resource identifier * @return a builder for a {@link Metadata} object */ public static Builder builder(final IRI identifier) { return new Builder(identifier); }
/** * Build the Metadata object, transitioning this builder to the built state. * @return the built Metadata */ public Metadata build() { return new Metadata(identifier, ixnModel, container, membershipResource, memberRelation, memberOfRelation, insertedContentRelation, binary); } }
/** * Collect a stream of Quads into a Dataset. * * @return a {@link Collector} that accumulates a {@link Stream} of * {@link Quad}s into a {@link Dataset} */ public static DatasetCollector toDataset() { return new DatasetCollector(); }
/** * Collect a stream of {@link Quad}s into a {@link Dataset} with concurrent * operation. * * @return a {@link Collector} that accumulates a {@link Stream} of * {@link Quad}s into a {@link Dataset} */ public ConcurrentDatasetCollector concurrent() { return new ConcurrentDatasetCollector(); } }
/** * Retrieve the RDF Quads for a resource. * * @return the RDF quads */ default Dataset dataset() { try (final Stream<Quad> quads = stream()) { return quads.collect(TrellisUtils.toDataset().concurrent()); } }
@Override public CompletionStage<Resource> get(final IRI identifier) { return mutableData.get(identifier).thenCombine(immutableData.get(identifier), (mutable, immutable) -> { if (MISSING_RESOURCE.equals(mutable) && MISSING_RESOURCE.equals(immutable)) { return MISSING_RESOURCE; } else if (MISSING_RESOURCE.equals(mutable)) { return immutable; } else if (MISSING_RESOURCE.equals(immutable)) { return mutable; } else { return new RetrievableResource(mutable, immutable); } }); }
@Override public CompletionStage<Void> replace(final Metadata metadata, final Dataset dataset) { resources.replace(metadata.getIdentifier(), new TestResource(metadata.getIdentifier(), dataset)); return isntBadId(metadata.getIdentifier()); }
/** * Check a graph against an LDP interaction model. * * @param interactionModel the interaction model * @param graph the graph * @return any constraint violations on the graph */ default Stream<ConstraintViolation> constrainedBy(IRI interactionModel, Graph graph) { return constrainedBy(interactionModel, graph, TrellisUtils.TRELLIS_DATA_PREFIX); } }
/** * A specialized no-op cache. */ @TrellisProfileCache public class NoopProfileCache extends NoopCacheService<String, String> { }