SimpleCatalogUtilsService implements CatalogUtilsService { @Override public List<Resource> removeBranch(Resource recordId, Resource branchId, RepositoryConnection conn) { Branch branch = getObject(branchId, branchFactory, conn); return removeBranch(recordId, branch, 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 removeBranchTest() throws Exception { Resource commitIdToRemove = VALUE_FACTORY.createIRI(COMMITS + "commitA1"); IRI additionsToRemove = VALUE_FACTORY.createIRI(ADDITIONS + "commitA1"); IRI deletionsToRemove = VALUE_FACTORY.createIRI(DELETIONS + "commitA1"); IRI revisionToRemove = VALUE_FACTORY.createIRI(REVISIONS + "commitA1"); Resource commitIdToKeep = VALUE_FACTORY.createIRI(COMMITS + "commitA0"); IRI additionsToKeep = VALUE_FACTORY.createIRI(ADDITIONS + "commitA0"); IRI deletionsToKeep = VALUE_FACTORY.createIRI(DELETIONS + "commitA0"); IRI revisionToKeep = VALUE_FACTORY.createIRI(REVISIONS + "commitA0"); try (RepositoryConnection conn = repo.getConnection()) { assertTrue(conn.getStatements(VERSIONED_RDF_RECORD_IRI, BRANCH_CATALOG_IRI, BRANCH_IRI, VERSIONED_RDF_RECORD_IRI).hasNext()); assertTrue(conn.getStatements(VERSIONED_RDF_RECORD_IRI, VERSION_CATALOG_IRI, LATEST_TAG_IRI, VERSIONED_RDF_RECORD_IRI).hasNext()); assertTrue(conn.getStatements(BRANCH_IRI, HEAD_CATALOG_IRI, commitIdToRemove, BRANCH_IRI).hasNext()); assertTrue(conn.getStatements(commitIdToRemove, typeIRI, COMMIT_CATALOG_IRI, commitIdToRemove).hasNext()); assertTrue(conn.getStatements(revisionToRemove, ADDITIONS_CATALOG_IRI, additionsToRemove, commitIdToRemove).hasNext()); assertTrue(conn.getStatements(revisionToRemove, DELETIONS_CATALOG_IRI, deletionsToRemove, commitIdToRemove).hasNext()); assertTrue(conn.getStatements(commitIdToKeep, typeIRI, COMMIT_CATALOG_IRI, commitIdToKeep).hasNext()); assertTrue(conn.getStatements(revisionToKeep, ADDITIONS_CATALOG_IRI, additionsToKeep, commitIdToKeep).hasNext()); assertTrue(conn.getStatements(revisionToKeep, DELETIONS_CATALOG_IRI, deletionsToKeep, commitIdToKeep).hasNext()); List<Resource> deletedCommits = service.removeBranch(VERSIONED_RDF_RECORD_IRI, BRANCH_IRI, conn); assertEquals(1, deletedCommits.size()); assertEquals(commitIdToRemove, deletedCommits.get(0)); assertFalse(conn.getStatements(VERSIONED_RDF_RECORD_IRI, BRANCH_CATALOG_IRI, BRANCH_IRI, VERSIONED_RDF_RECORD_IRI).hasNext()); assertFalse(conn.getStatements(VERSIONED_RDF_RECORD_IRI, VERSION_CATALOG_IRI, LATEST_TAG_IRI, VERSIONED_RDF_RECORD_IRI).hasNext()); assertFalse(conn.getStatements(BRANCH_IRI, HEAD_CATALOG_IRI, commitIdToRemove, BRANCH_IRI).hasNext()); assertFalse(conn.getStatements(commitIdToRemove, typeIRI, COMMIT_CATALOG_IRI, commitIdToRemove).hasNext()); assertFalse(conn.getStatements(revisionToRemove, ADDITIONS_CATALOG_IRI, additionsToRemove, commitIdToRemove).hasNext()); assertFalse(conn.getStatements(revisionToRemove, DELETIONS_CATALOG_IRI, deletionsToRemove, commitIdToRemove).hasNext()); assertTrue(conn.getStatements(commitIdToKeep, typeIRI, COMMIT_CATALOG_IRI, commitIdToKeep).hasNext()); assertTrue(conn.getStatements(revisionToKeep, ADDITIONS_CATALOG_IRI, additionsToKeep, commitIdToKeep).hasNext()); assertTrue(conn.getStatements(revisionToKeep, DELETIONS_CATALOG_IRI, deletionsToKeep, commitIdToKeep).hasNext()); } }
@Test public void removeBranchWithDeletedCommitListTest() throws Exception { Resource commitIdToRemove = VALUE_FACTORY.createIRI(COMMITS + "commitA1"); IRI additionsToRemove = VALUE_FACTORY.createIRI(ADDITIONS + "commitA1"); IRI deletionsToRemove = VALUE_FACTORY.createIRI(DELETIONS + "commitA1"); IRI revisionToRemove = VALUE_FACTORY.createIRI(REVISIONS + "commitA1"); Resource commitIdToKeep = VALUE_FACTORY.createIRI(COMMITS + "commitA0"); IRI additionsToKeep = VALUE_FACTORY.createIRI(ADDITIONS + "commitA0"); IRI deletionsToKeep = VALUE_FACTORY.createIRI(DELETIONS + "commitA0"); IRI revisionToKeep = VALUE_FACTORY.createIRI(REVISIONS + "commitA0"); try (RepositoryConnection conn = repo.getConnection()) { assertTrue(conn.getStatements(VERSIONED_RDF_RECORD_IRI, BRANCH_CATALOG_IRI, BRANCH_IRI, VERSIONED_RDF_RECORD_IRI).hasNext()); assertTrue(conn.getStatements(VERSIONED_RDF_RECORD_IRI, VERSION_CATALOG_IRI, LATEST_TAG_IRI, VERSIONED_RDF_RECORD_IRI).hasNext()); assertTrue(conn.getStatements(BRANCH_IRI, HEAD_CATALOG_IRI, commitIdToRemove, BRANCH_IRI).hasNext()); assertTrue(conn.getStatements(commitIdToRemove, typeIRI, COMMIT_CATALOG_IRI, commitIdToRemove).hasNext()); assertTrue(conn.getStatements(revisionToRemove, ADDITIONS_CATALOG_IRI, additionsToRemove, commitIdToRemove).hasNext()); assertTrue(conn.getStatements(revisionToRemove, DELETIONS_CATALOG_IRI, deletionsToRemove, commitIdToRemove).hasNext()); assertTrue(conn.getStatements(commitIdToKeep, typeIRI, COMMIT_CATALOG_IRI, commitIdToKeep).hasNext()); assertTrue(conn.getStatements(revisionToKeep, ADDITIONS_CATALOG_IRI, additionsToKeep, commitIdToKeep).hasNext()); assertTrue(conn.getStatements(revisionToKeep, DELETIONS_CATALOG_IRI, deletionsToKeep, commitIdToKeep).hasNext()); List<Resource> deletedCommits = new ArrayList<>(); service.removeBranch(VERSIONED_RDF_RECORD_IRI, BRANCH_IRI, deletedCommits, conn); assertEquals(1, deletedCommits.size()); assertEquals(commitIdToRemove, deletedCommits.get(0)); assertFalse(conn.getStatements(VERSIONED_RDF_RECORD_IRI, BRANCH_CATALOG_IRI, BRANCH_IRI, VERSIONED_RDF_RECORD_IRI).hasNext()); assertFalse(conn.getStatements(VERSIONED_RDF_RECORD_IRI, VERSION_CATALOG_IRI, LATEST_TAG_IRI, VERSIONED_RDF_RECORD_IRI).hasNext()); assertFalse(conn.getStatements(BRANCH_IRI, HEAD_CATALOG_IRI, commitIdToRemove, BRANCH_IRI).hasNext()); assertFalse(conn.getStatements(commitIdToRemove, typeIRI, COMMIT_CATALOG_IRI, commitIdToRemove).hasNext()); assertFalse(conn.getStatements(revisionToRemove, ADDITIONS_CATALOG_IRI, additionsToRemove, commitIdToRemove).hasNext()); assertFalse(conn.getStatements(revisionToRemove, DELETIONS_CATALOG_IRI, deletionsToRemove, commitIdToRemove).hasNext()); assertTrue(conn.getStatements(commitIdToKeep, typeIRI, COMMIT_CATALOG_IRI, commitIdToKeep).hasNext()); assertTrue(conn.getStatements(revisionToKeep, ADDITIONS_CATALOG_IRI, additionsToKeep, commitIdToKeep).hasNext()); assertTrue(conn.getStatements(revisionToKeep, DELETIONS_CATALOG_IRI, deletionsToKeep, commitIdToKeep).hasNext()); } }
@Test public void removeBranchCompleteTest() { Resource complexRecordIRI = VALUE_FACTORY.createIRI(RECORDS + "complex-record"); Resource complexBranchIRI = VALUE_FACTORY.createIRI(BRANCHES + "complex-branch"); Resource commitA = VALUE_FACTORY.createIRI(COMMITS + "complex-a"); IRI commitARevision = VALUE_FACTORY.createIRI(REVISIONS + "complex-a"); IRI commitAAdditions = VALUE_FACTORY.createIRI(ADDITIONS + "complex-a"); IRI commitADeletions = VALUE_FACTORY.createIRI(DELETIONS + "complex-a"); Resource commitB = VALUE_FACTORY.createIRI(COMMITS + "complex-b"); Resource commitC = VALUE_FACTORY.createIRI(COMMITS + "complex-c"); IRI commitCRevision = VALUE_FACTORY.createIRI(REVISIONS + "complex-c"); IRI commitCAdditions = VALUE_FACTORY.createIRI(ADDITIONS + "complex-c"); IRI commitCDeletions = VALUE_FACTORY.createIRI(DELETIONS + "complex-c"); Resource commitD = VALUE_FACTORY.createIRI(COMMITS + "complex-d"); try (RepositoryConnection conn = repo.getConnection()) { assertTrue(conn.getStatements(complexRecordIRI, BRANCH_CATALOG_IRI, complexBranchIRI, complexRecordIRI).hasNext()); assertTrue(conn.getStatements(commitA, typeIRI, COMMIT_CATALOG_IRI, commitA).hasNext()); assertTrue(conn.getStatements(commitARevision, ADDITIONS_CATALOG_IRI, commitAAdditions, commitA).hasNext()); assertTrue(conn.getStatements(commitARevision, DELETIONS_CATALOG_IRI, commitADeletions, commitA).hasNext()); assertTrue(conn.getStatements(commitC, typeIRI, COMMIT_CATALOG_IRI, commitC).hasNext()); assertTrue(conn.getStatements(commitCRevision, ADDITIONS_CATALOG_IRI, commitCAdditions, commitC).hasNext()); assertTrue(conn.getStatements(commitCRevision, DELETIONS_CATALOG_IRI, commitCDeletions, commitC).hasNext()); assertTrue(conn.getStatements(commitB, typeIRI, COMMIT_CATALOG_IRI, commitB).hasNext()); assertTrue(conn.getStatements(commitD, typeIRI, COMMIT_CATALOG_IRI, commitD).hasNext()); List<Resource> deletedCommits = service.removeBranch(complexRecordIRI, complexBranchIRI, conn); assertEquals(2, deletedCommits.size()); assertTrue(deletedCommits.contains(commitA)); assertTrue(deletedCommits.contains(commitC)); assertFalse(conn.getStatements(complexRecordIRI, BRANCH_CATALOG_IRI, complexBranchIRI, complexRecordIRI).hasNext()); assertFalse(conn.getStatements(commitA, typeIRI, COMMIT_CATALOG_IRI, commitA).hasNext()); assertFalse(conn.getStatements(commitARevision, ADDITIONS_CATALOG_IRI, commitAAdditions, commitA).hasNext()); assertFalse(conn.getStatements(commitARevision, DELETIONS_CATALOG_IRI, commitADeletions, commitA).hasNext()); assertFalse(conn.getStatements(commitC, typeIRI, COMMIT_CATALOG_IRI, commitC).hasNext()); assertFalse(conn.getStatements(commitCRevision, ADDITIONS_CATALOG_IRI, commitCAdditions, commitC).hasNext()); assertFalse(conn.getStatements(commitCRevision, DELETIONS_CATALOG_IRI, commitCDeletions, commitC).hasNext()); assertTrue(conn.getStatements(commitB, typeIRI, COMMIT_CATALOG_IRI, commitB).hasNext()); assertTrue(conn.getStatements(commitD, typeIRI, COMMIT_CATALOG_IRI, commitD).hasNext()); } }
@Test public void removeBranchWithQuadsTest() throws Exception { Resource quadVersionedRecordId = VALUE_FACTORY.createIRI(RECORDS + "quad-versioned-rdf-record"); IRI branchToRemove = VALUE_FACTORY.createIRI(BRANCHES + "quad-branch"); Resource commit2 = VALUE_FACTORY.createIRI(COMMITS + "quad-test2"); Resource revisionToRemove = VALUE_FACTORY.createIRI(REVISIONS + "revision2"); IRI additionsToRemove = VALUE_FACTORY.createIRI(ADDITIONS + "quad-test2"); IRI deletionsToRemove = VALUE_FACTORY.createIRI(DELETIONS + "quad-test2"); IRI graphAdditionsToRemove = VALUE_FACTORY.createIRI(ADDITIONS + "quad-test2%00http%3A%2F%2Fmobi.com%2Ftest%2Fgraphs%23quad-graph1"); IRI graphDeletionsToRemove = VALUE_FACTORY.createIRI(DELETIONS + "quad-test2%00http%3A%2F%2Fmobi.com%2Ftest%2Fgraphs%23quad-graph1"); Branch branch = branchFactory.createNew(branchToRemove); branch.setHead(commitFactory.createNew(commit2)); try (RepositoryConnection conn = repo.getConnection()) { assertTrue(conn.getStatements(quadVersionedRecordId, BRANCH_CATALOG_IRI, branchToRemove, quadVersionedRecordId).hasNext()); assertTrue(conn.getStatements(commit2, typeIRI, COMMIT_CATALOG_IRI, commit2).hasNext()); assertTrue(conn.getStatements(revisionToRemove, ADDITIONS_CATALOG_IRI, additionsToRemove, commit2).hasNext()); assertTrue(conn.getStatements(revisionToRemove, DELETIONS_CATALOG_IRI, deletionsToRemove, commit2).hasNext()); assertTrue(conn.getStatements(null, null, null, graphAdditionsToRemove).hasNext()); assertTrue(conn.getStatements(null, null, null, graphDeletionsToRemove).hasNext()); List<Resource> deletedCommits = service.removeBranch(quadVersionedRecordId, branchToRemove, conn); assertEquals(1, deletedCommits.size()); assertEquals(commit2, deletedCommits.get(0)); assertFalse(conn.getStatements(quadVersionedRecordId, BRANCH_CATALOG_IRI, branchToRemove, quadVersionedRecordId).hasNext()); assertFalse(conn.getStatements(commit2, typeIRI, COMMIT_CATALOG_IRI, commit2).hasNext()); assertFalse(conn.getStatements(revisionToRemove, ADDITIONS_CATALOG_IRI, additionsToRemove, commit2).hasNext()); assertFalse(conn.getStatements(revisionToRemove, DELETIONS_CATALOG_IRI, deletionsToRemove, commit2).hasNext()); assertFalse(conn.getStatements(null, null, null, graphAdditionsToRemove).hasNext()); assertFalse(conn.getStatements(null, null, null, graphDeletionsToRemove).hasNext()); } }
@Test public void removeBranchWithNoHeadTest() { IRI noHeadBranchIRI = VALUE_FACTORY.createIRI(BRANCHES + "no-head-branch"); try (RepositoryConnection conn = repo.getConnection()) { assertTrue(conn.getStatements(VERSIONED_RDF_RECORD_IRI, BRANCH_CATALOG_IRI, noHeadBranchIRI, VERSIONED_RDF_RECORD_IRI).hasNext()); List<Resource> deletedCommits = service.removeBranch(VERSIONED_RDF_RECORD_IRI, noHeadBranchIRI, conn); assertEquals(0, deletedCommits.size()); assertFalse(conn.getStatements(VERSIONED_RDF_RECORD_IRI, BRANCH_CATALOG_IRI, noHeadBranchIRI, VERSIONED_RDF_RECORD_IRI).hasNext()); } }
@Test public void testRemoveBranchUserBranch() { IRI userBranchIRI = VALUE_FACTORY.createIRI(BRANCHES + "user-branch"); IRI createdFromIRI = VALUE_FACTORY.createIRI(UserBranch.createdFrom_IRI); try (RepositoryConnection conn = repo.getConnection()){ assertTrue(conn.getStatements(VERSIONED_RDF_RECORD_IRI, BRANCH_CATALOG_IRI, BRANCH_IRI, VERSIONED_RDF_RECORD_IRI).hasNext()); assertTrue(conn.getStatements(BRANCH_IRI, null, null).hasNext()); assertTrue(conn.getStatements(VERSIONED_RDF_RECORD_IRI, BRANCH_CATALOG_IRI, userBranchIRI, VERSIONED_RDF_RECORD_IRI).hasNext()); assertTrue(conn.getStatements(userBranchIRI, createdFromIRI, BRANCH_IRI, userBranchIRI).hasNext()); service.removeBranch(VERSIONED_RDF_RECORD_IRI, userBranchIRI, conn); assertTrue(conn.getStatements(VERSIONED_RDF_RECORD_IRI, BRANCH_CATALOG_IRI, BRANCH_IRI, VERSIONED_RDF_RECORD_IRI).hasNext()); assertTrue(conn.getStatements(BRANCH_IRI, null, null).hasNext()); assertFalse(conn.getStatements(VERSIONED_RDF_RECORD_IRI, BRANCH_CATALOG_IRI, userBranchIRI, VERSIONED_RDF_RECORD_IRI).hasNext()); assertFalse(conn.getStatements(userBranchIRI, createdFromIRI, BRANCH_IRI, userBranchIRI).hasNext()); } }