SimpleCatalogUtilsService implements CatalogUtilsService { @Override public void removeInProgressCommit(InProgressCommit commit, RepositoryConnection conn) { Revision revision = getRevision(commit.getResource(), conn); removeObject(commit, conn); Set<Resource> graphs = new HashSet<>(); revision.getAdditions().ifPresent(graphs::add); revision.getDeletions().ifPresent(graphs::add); revision.getGraphRevision().forEach(graphRevision -> { graphRevision.getAdditions().ifPresent(graphs::add); graphRevision.getDeletions().ifPresent(graphs::add); }); graphs.forEach(resource -> { if (!conn.contains(null, null, resource)) { remove(resource, conn); } }); }  @Override void validateResource(Resource resource, IRI classId, RepositoryConnection conn); @Override void addObject(T object, RepositoryConnection conn); @Override void updateObject(T object, RepositoryConnection conn); @Override Optional<T> optObject(Resource id, OrmFactory<T> factory, RepositoryConnection conn); @Override T getObject(Resource id, OrmFactory<T> factory, RepositoryConnection conn); @Override T getExpectedObject(Resource id, OrmFactory<T> factory, RepositoryConnection conn); @Override void remove(Resource resourceId, RepositoryConnection conn); @Override void removeObject(T object, RepositoryConnection conn); @Override void removeObjectWithRelationship(Resource objectId, Resource removeFromId, String predicate,
                                             RepositoryConnection conn); @Override void validateRecord(Resource catalogId, Resource recordId, IRI recordType,
                               RepositoryConnection conn); @Override T getRecord(Resource catalogId, Resource recordId,
                                          OrmFactory<T> factory,
                                          RepositoryConnection conn); @Override void validateUnversionedDistribution(Resource catalogId, Resource recordId,
                                                Resource distributionId, RepositoryConnection conn); @Override Distribution getUnversionedDistribution(Resource catalogId, Resource recordId, Resource distributionId,
                                                   RepositoryConnection conn); @Override void validateVersion(Resource catalogId, Resource recordId, Resource versionId, RepositoryConnection conn); @Override T getVersion(Resource catalogId, Resource recordId, Resource versionId,
                                            OrmFactory<T> factory, RepositoryConnection conn); @Override void removeVersion(Resource recordId, Version version, RepositoryConnection conn); @Override void removeVersion(Resource recordId, Resource versionId, RepositoryConnection conn); @Override void validateVersionedDistribution(Resource catalogId, Resource recordId, Resource versionId,
                                              Resource distributionId, RepositoryConnection conn); @Override Distribution getVersionedDistribution(Resource catalogId, Resource recordId, Resource versionId,
                                                 Resource distributionId, RepositoryConnection conn); @Override void validateBranch(Resource catalogId, Resource recordId, Resource branchId, RepositoryConnection conn); @Override T getBranch(Resource catalogId, Resource recordId, Resource branchId,
                                          OrmFactory<T> factory, RepositoryConnection conn); @Override T getBranch(VersionedRDFRecord record, Resource branchId, OrmFactory<T> factory,
                                          RepositoryConnection conn); @Override List<Resource> removeBranch(Resource recordId, Resource branchId, RepositoryConnection conn); @Override void removeBranch(Resource recordId, Resource branchId, List<Resource> deletedCommits,
                             RepositoryConnection conn); @Override List<Resource> removeBranch(Resource recordId, Branch branch, RepositoryConnection conn); @Override Resource getHeadCommitIRI(Branch branch); @Override void validateInProgressCommit(Resource catalogId, Resource recordId, Resource commitId,
                                         RepositoryConnection conn); @Override InProgressCommit getInProgressCommit(Resource recordId, Resource userId, RepositoryConnection conn); @Override InProgressCommit getInProgressCommit(Resource catalogId, Resource recordId, Resource commitId,
                                                RepositoryConnection conn); @Override Optional<Resource> getInProgressCommitIRI(Resource recordId, Resource userId, RepositoryConnection conn); @Override void removeInProgressCommit(InProgressCommit commit, RepositoryConnection conn); @Override void updateCommit(Commit commit, Model additions, Model deletions, RepositoryConnection conn); @Override void updateCommit(Resource commitId, Model additions, Model deletions, RepositoryConnection conn); @Override void addCommit(Branch branch, Commit commit, RepositoryConnection conn); @Override Revision getRevision(Resource commitId, RepositoryConnection conn); @Override Stream<Statement> getAdditions(Resource commitId, RepositoryConnection conn); @Override Stream<Statement> getAdditions(Commit commit, RepositoryConnection conn); @Override Stream<Statement> getDeletions(Resource commitId, RepositoryConnection conn); @Override Stream<Statement> getDeletions(Commit commit, RepositoryConnection conn); @Override void addChanges(Resource targetNamedGraph, Resource oppositeNamedGraph, Model changes,
                           RepositoryConnection conn); @Override void validateCommitPath(Resource catalogId, Resource recordId, Resource branchId, Resource commitId,
                                   RepositoryConnection conn); @Override void validateCommitPath(Resource catalogId, Resource recordId, Resource commitId,
                                   RepositoryConnection conn); @Override boolean commitInBranch(Resource branchId, Resource commitId, RepositoryConnection conn); @Override boolean commitInRecord(Resource recordId, Resource commitId, RepositoryConnection conn); @Override List<Resource> getCommitChain(Resource commitId, boolean asc, RepositoryConnection conn); @Override List<Resource> getCommitChain(Resource commitId, Resource entityId, boolean asc, RepositoryConnection conn); @Override List<Resource> getDifferenceChain(final Resource sourceCommitId, final Resource targetCommitId,
                                             final RepositoryConnection conn); @Override List<Resource> getDifferenceChain(final Resource sourceCommitId, final Resource targetCommitId,
                                             final RepositoryConnection conn, boolean asc); @Override List<Resource> getDifferenceChain(final Resource sourceCommitId, final Resource targetCommitId,
                                             final Resource targetEntityId, final RepositoryConnection conn); @Override List<Resource> getDifferenceChain(final Resource sourceCommitId, final Resource targetCommitId,
                                             final Resource targetEntityId, final RepositoryConnection conn,
                                             boolean asc); @Override Difference getCommitDifference(List<Resource> commits, RepositoryConnection conn); @Override Difference getCommitDifference(Resource commitId, RepositoryConnection conn); @Override Model getCompiledResource(Resource commitId, RepositoryConnection conn); @Override Model getCompiledResource(List<Resource> commits, RepositoryConnection conn); @Override Difference getRevisionChanges(Resource commitId, RepositoryConnection conn); @Override Model applyDifference(Model base, Difference diff); @Override Set<Conflict> getConflicts(Resource sourceCommitId, Resource targetCommitId, RepositoryConnection conn); @Override IllegalArgumentException throwAlreadyExists(Resource id, OrmFactory<T> factory); @Override IllegalArgumentException throwDoesNotBelong(Resource child,
                                                                                          OrmFactory<T> childFactory,
                                                                                          Resource parent,
                                                                                          OrmFactory<S> parentFactory); @Override IllegalStateException throwThingNotFound(Resource id, OrmFactory<T> factory);  }
@Test public void removeInProgressCommitTest() { try (RepositoryConnection conn = repo.getConnection()) { InProgressCommit commit = getThing(IN_PROGRESS_COMMIT_IRI, inProgressCommitFactory, conn); Resource additionsResource = getAdditionsResource(IN_PROGRESS_COMMIT_IRI); Resource deletionsResource = getDeletionsResource(IN_PROGRESS_COMMIT_IRI); assertTrue(conn.size(additionsResource) > 0); assertTrue(conn.size(deletionsResource) > 0); service.removeInProgressCommit(commit, conn); assertFalse(conn.getStatements(null, null, null, IN_PROGRESS_COMMIT_IRI).hasNext()); assertTrue(conn.size(additionsResource) == 0); assertTrue(conn.size(deletionsResource) == 0); } }
@Test public void removeInProgressCommitWithQuadsTest() throws Exception { IRI quadInProgressCommit = VALUE_FACTORY.createIRI(COMMITS + "quad-in-progress-commit"); try (RepositoryConnection conn = repo.getConnection()) { InProgressCommit commit = getThing(quadInProgressCommit, inProgressCommitFactory, conn); Resource additionsResource = getAdditionsResource(quadInProgressCommit); Resource deletionsResource = getDeletionsResource(quadInProgressCommit); assertTrue(conn.containsContext(additionsResource)); assertTrue(conn.containsContext(deletionsResource)); IRI graph1AdditionsResource = getQuadAdditionsResource(quadInProgressCommit, GRAPHS + "quad-graph1"); IRI graph1DeletionsResource = getQuadDeletionsResource(quadInProgressCommit, GRAPHS + "quad-graph1"); assertTrue(conn.containsContext(graph1AdditionsResource)); assertTrue(conn.containsContext(graph1DeletionsResource)); service.removeInProgressCommit(commit, conn); assertFalse(conn.containsContext(quadInProgressCommit)); assertFalse(conn.containsContext(additionsResource)); assertFalse(conn.containsContext(deletionsResource)); assertFalse(conn.containsContext(graph1AdditionsResource)); assertFalse(conn.containsContext(graph1DeletionsResource)); } }
@Test public void removeInProgressCommitWithReferencedChangesTest() { try (RepositoryConnection conn = repo.getConnection()) { InProgressCommit commit = inProgressCommitFactory.createNew(VALUE_FACTORY.createIRI("http: Resource additionsResource = getAdditionsResource(COMMIT_IRI); Resource deletionsResource = getDeletionsResource(COMMIT_IRI); commit.getModel().add(commit.getResource(), VALUE_FACTORY.createIRI(Revision.additions_IRI), additionsResource, commit.getResource()); commit.getModel().add(commit.getResource(), VALUE_FACTORY.createIRI(Revision.deletions_IRI), deletionsResource, commit.getResource()); assertTrue(conn.getStatements(null, null, null, commit.getResource()).hasNext()); assertTrue(conn.size(additionsResource) > 0); assertTrue(conn.size(deletionsResource) > 0); service.removeInProgressCommit(commit, conn); assertFalse(conn.getStatements(null, null, null, commit.getResource()).hasNext()); assertTrue(conn.size(additionsResource) > 0); assertTrue(conn.size(deletionsResource) > 0); } }