SimpleCatalogUtilsService implements CatalogUtilsService { @Override public Set<Conflict> getConflicts(Resource sourceCommitId, Resource targetCommitId, RepositoryConnection conn) { long start = System.currentTimeMillis(); validateResource(sourceCommitId, commitFactory.getTypeIRI(), conn); validateResource(targetCommitId, commitFactory.getTypeIRI(), conn); ArrayList<Resource> sourceCommits = new ArrayList<>(getCommitChain(sourceCommitId, true, conn)); ArrayList<Resource> targetCommits = new ArrayList<>(getCommitChain(targetCommitId, true, conn)); ArrayList<Resource> commonCommits = new ArrayList<>(sourceCommits); commonCommits.retainAll(targetCommits); sourceCommits.removeAll(commonCommits); targetCommits.removeAll(commonCommits); sourceCommits.trimToSize(); targetCommits.trimToSize(); Difference sourceDiff = getCommitDifference(sourceCommits, conn); Difference targetDiff = getCommitDifference(targetCommits, conn); Model sourceAdds = sourceDiff.getAdditions(); Set<Resource> sourceAddSubjects = sourceAdds.subjects(); Model targetAdds = targetDiff.getAdditions(); Set<Resource> targetAddSubjects = targetAdds.subjects(); Model sourceDels = sourceDiff.getDeletions(); Model targetDels = targetDiff.getDeletions(); Set<Conflict> result = new HashSet<>(); Model original = getCompiledResource(commonCommits, conn); Set<Statement> statementsToRemove = new HashSet<>(); sourceDels.subjects().forEach(subject -> { Model sourceDelSubjectStatements = sourceDels.filter(subject, null, null); sourceDelSubjectStatements.forEach(statement -> { IRI pred = statement.getPredicate(); Value obj = statement.getObject(); if (targetDels.contains(subject, pred, obj) && sourceAdds.contains(subject, pred, null) && targetAdds.contains(subject, pred, null)) { result.add(createConflict(subject, pred, sourceAdds, sourceDels, targetAdds, targetDels)); statementsToRemove.add(statement); } }); if (commonCommits.size() != 0) { Model targetSubjectAdd = targetAdds.filter(subject, null, null); boolean sourceEntityDeleted = !sourceAddSubjects.contains(subject) && sourceDelSubjectStatements.equals(original.filter(subject, null, null)); boolean targetEntityDeleted = targetDels.containsAll(sourceDelSubjectStatements); if (sourceEntityDeleted && !targetEntityDeleted && targetSubjectAdd.size() > 0) { result.add(createConflict(subject, null, sourceAdds, sourceDels, targetAdds, targetDels)); statementsToRemove.addAll(targetSubjectAdd); } } }); statementsToRemove.forEach(statement -> Stream.of(sourceAdds, sourceDels, targetAdds, targetDels) .forEach(model -> model.remove(statement.getSubject(), statement.getPredicate(), null))); if (commonCommits.size() != 0) { targetDels.subjects().forEach(subject -> { Model targetDelSubjectStatements = targetDels.filter(subject, null, null); Model sourceSubjectAdd = sourceAdds.filter(subject, null, null); boolean targetEntityDeleted = !targetAddSubjects.contains(subject) && targetDelSubjectStatements.equals(original.filter(subject, null, null)); boolean sourceEntityDeleted = sourceDels.containsAll(targetDelSubjectStatements); if (targetEntityDeleted && !sourceEntityDeleted && sourceSubjectAdd.size() > 0) { result.add(createConflict(subject, null, sourceAdds, sourceDels, targetAdds, targetDels)); } }); } log.trace("getConflicts took {}ms", System.currentTimeMillis() - start); return result; }  @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 testGetConflictsChainAddsAndRemovesStatement() throws Exception { Resource leftId = VALUE_FACTORY.createIRI(COMMITS + "conflict4-1"); Resource rightId = VALUE_FACTORY.createIRI(COMMITS + "conflict4-3"); try (RepositoryConnection conn = repo.getConnection()) { Set<Conflict> results = service.getConflicts(leftId, rightId, conn); assertEquals(0, results.size()); } }
@Test public void testGetConflictsPropertyChangeOnSingleBranch() throws Exception { Resource leftId = VALUE_FACTORY.createIRI(COMMITS + "conflict5-1"); Resource rightId = VALUE_FACTORY.createIRI(COMMITS + "conflict5-2"); try (RepositoryConnection conn = repo.getConnection()) { Set<Conflict> result = service.getConflicts(leftId, rightId, conn); assertEquals(0, result.size()); } }
@Test public void testGetConflictsOneRemovesOtherAddsToProperty() throws Exception { Resource leftId = VALUE_FACTORY.createIRI(COMMITS + "conflict6-1"); Resource rightId = VALUE_FACTORY.createIRI(COMMITS + "conflict6-2"); try (RepositoryConnection conn = repo.getConnection()) { Set<Conflict> result = service.getConflicts(leftId, rightId, conn); assertEquals(0, result.size()); } }
@Test public void testGetConflictsWithOnlyOneCommit() throws Exception { Resource leftId = VALUE_FACTORY.createIRI(COMMITS + "conflict7-1"); Resource rightId = VALUE_FACTORY.createIRI(COMMITS + "conflict7-0"); try (RepositoryConnection conn = repo.getConnection()) { Set<Conflict> result = service.getConflicts(leftId, rightId, conn); assertEquals(0, result.size()); } }
@Test public void testGetConflictsDisconnectedNodes() throws Exception { Resource leftId = VALUE_FACTORY.createIRI(COMMITS + "conflict8-1"); Resource rightId = VALUE_FACTORY.createIRI(COMMITS + "conflict8-0"); try (RepositoryConnection conn = repo.getConnection()) { Set<Conflict> result = service.getConflicts(leftId, rightId, conn); assertEquals(0, result.size()); } }
@Test public void testGetConflictsDisconnectedNodesSamePropertyAltered() throws Exception { IRI sub = VALUE_FACTORY.createIRI("http: Resource leftId = VALUE_FACTORY.createIRI(COMMITS + "conflict9-1"); Resource rightId = VALUE_FACTORY.createIRI(COMMITS + "conflict9-2"); try (RepositoryConnection conn = repo.getConnection()) { Set<Conflict> result = service.getConflicts(leftId, rightId, conn); assertEquals(0, result.size()); } }
@Test public void testGetConflictsDisconnectedNodesFullDeletionWithAddition() throws Exception { Resource leftId = VALUE_FACTORY.createIRI(COMMITS + "conflict10-1"); Resource rightId = VALUE_FACTORY.createIRI(COMMITS + "conflict10-2"); try (RepositoryConnection conn = repo.getConnection()) { Set<Conflict> result = service.getConflicts(leftId, rightId, conn); assertEquals(0, result.size()); } }
@Test public void testGetConflictsDisconnectedNodesPropertyChangeOnSingleBranch() throws Exception { Resource leftId = VALUE_FACTORY.createIRI(COMMITS + "conflict11-1"); Resource rightId = VALUE_FACTORY.createIRI(COMMITS + "conflict11-2"); try (RepositoryConnection conn = repo.getConnection()) { Set<Conflict> result = service.getConflicts(leftId, rightId, conn); assertEquals(0, result.size()); } }
@Test public void testGetConflictsDisconnectedNodesOneRemovesOtherAddsToProperty() throws Exception { Resource leftId = VALUE_FACTORY.createIRI(COMMITS + "conflict12-1"); Resource rightId = VALUE_FACTORY.createIRI(COMMITS + "conflict12-2"); try (RepositoryConnection conn = repo.getConnection()) { Set<Conflict> result = service.getConflicts(leftId, rightId, conn); assertEquals(0, result.size()); } }
@Test public void testGetConflictDisconnectedNodesFullDeletionWithModification() throws Exception { IRI sub = VALUE_FACTORY.createIRI("http: Resource leftId = VALUE_FACTORY.createIRI(COMMITS + "conflict13-1"); Resource rightId = VALUE_FACTORY.createIRI(COMMITS + "conflict13-2"); try (RepositoryConnection conn = repo.getConnection()) { Set<Conflict> result = service.getConflicts(leftId, rightId, conn); assertEquals(0, result.size()); } }