SimpleCatalogManager implements CatalogManager { @Override public Commit createCommit(@Nonnull InProgressCommit inProgressCommit, @Nonnull String message, Commit baseCommit, Commit auxCommit) { if (auxCommit != null && baseCommit == null) { throw new IllegalArgumentException("Commit must have a base commit in order to have an auxiliary commit"); } IRI associatedWith = vf.createIRI(Activity.wasAssociatedWith_IRI); IRI generatedIRI = vf.createIRI(Activity.generated_IRI); OffsetDateTime now = OffsetDateTime.now(); Resource revisionIRI = (Resource) inProgressCommit.getProperty(generatedIRI).get(); Value user = inProgressCommit.getProperty(associatedWith).get(); StringBuilder metadata = new StringBuilder(now.toString() + user.stringValue()); Set<Value> generatedParents = new HashSet<>(); if (baseCommit != null) { metadata.append(baseCommit.getResource().stringValue()); generatedParents.add(baseCommit.getProperty(generatedIRI).get()); } if (auxCommit != null) { metadata.append(auxCommit.getResource().stringValue()); generatedParents.add(auxCommit.getProperty(generatedIRI).get()); } Commit commit = commitFactory.createNew(vf.createIRI(Catalogs.COMMIT_NAMESPACE + DigestUtils.sha1Hex(metadata.toString()))); commit.setProperty(revisionIRI, generatedIRI); commit.setProperty(vf.createLiteral(now), vf.createIRI(PROV_AT_TIME)); commit.setProperty(vf.createLiteral(message), vf.createIRI(_Thing.title_IRI)); commit.setProperty(user, associatedWith); if (baseCommit != null) { commit.setBaseCommit(baseCommit); } if (auxCommit != null) { commit.setAuxiliaryCommit(auxCommit); } Model revisionModel = mf.createModel(inProgressCommit.getModel()); revisionModel.remove(inProgressCommit.getResource(), null, null); revisionFactory.getExisting(revisionIRI, revisionModel).ifPresent(revision -> { if (generatedParents.size() > 0) { revision.setProperties(generatedParents, vf.createIRI(Entity.wasDerivedFrom_IRI)); } }); commit.getModel().addAll(revisionModel); return commit; } SimpleCatalogManager(); @Override Catalog getDistributedCatalog(); @Override Catalog getLocalCatalog(); @Override PaginatedSearchResults<Record> findRecord(Resource catalogId, PaginatedSearchParams searchParams); @Override Set<Resource> getRecordIds(Resource catalogId); @Override T createRecord(User user, RecordOperationConfig config, Class<T> recordClass); @Override T createRecord(RecordConfig config, OrmFactory<T> factory); @Override void addRecord(Resource catalogId, T record); @Override void updateRecord(Resource catalogId, T newRecord); @Override T removeRecord(Resource catalogId, Resource recordId, OrmFactory<T> factory); @Override T deleteRecord(User user, Resource recordId, Class<T> recordClass); @Override Optional<T> getRecord(Resource catalogId, Resource recordId, OrmFactory<T> factory); @Override Set<Distribution> getUnversionedDistributions(Resource catalogId, Resource unversionedRecordId); @Override Distribution createDistribution(DistributionConfig config); @Override void addUnversionedDistribution(Resource catalogId, Resource unversionedRecordId,
                                           Distribution distribution); @Override void updateUnversionedDistribution(Resource catalogId, Resource unversionedRecordId,
                                              Distribution newDistribution); @Override void removeUnversionedDistribution(Resource catalogId, Resource unversionedRecordId,
                                              Resource distributionId); @Override Optional<Distribution> getUnversionedDistribution(Resource catalogId, Resource unversionedRecordId,
                                                             Resource distributionId); @Override Set<Version> getVersions(Resource catalogId, Resource versionedRecordId); @Override T createVersion(@Nonnull String title, String description, OrmFactory<T> factory); @Override void addVersion(Resource catalogId, Resource versionedRecordId, T version); @Override void updateVersion(Resource catalogId, Resource versionedRecordId, T newVersion); @Override void removeVersion(Resource catalogId, Resource versionedRecordId, Resource versionId); @Override Optional<T> getVersion(Resource catalogId, Resource versionedRecordId,
                                                      Resource versionId, OrmFactory<T> factory); @Override Optional<T> getLatestVersion(Resource catalogId, Resource versionedRecordId,
                                                            OrmFactory<T> factory); @Override Commit getTaggedCommit(Resource catalogId, Resource versionedRecordId, Resource versionId); @Override Set<Distribution> getVersionedDistributions(Resource catalogId, Resource versionedRecordId,
                                                       Resource versionId); @Override void addVersionedDistribution(Resource catalogId, Resource versionedRecordId, Resource versionId,
                                         Distribution distribution); @Override void updateVersionedDistribution(Resource catalogId, Resource versionedRecordId, Resource versionId,
                                            Distribution newDistribution); @Override void removeVersionedDistribution(Resource catalogId, Resource versionedRecordId, Resource versionId,
                                            Resource distributionId); @Override Optional<Distribution> getVersionedDistribution(Resource catalogId, Resource recordId, Resource versionId,
                                                           Resource distributionId); @Override Set<Branch> getBranches(Resource catalogId, Resource versionedRDFRecordId); @Override T createBranch(@Nonnull String title, String description, OrmFactory<T> factory); @Override void addBranch(Resource catalogId, Resource versionedRDFRecordId, T branch); @Override void addMasterBranch(Resource catalogId, Resource versionedRDFRecordId); @Override void updateBranch(Resource catalogId, Resource versionedRDFRecordId, T newBranch); @Override void updateHead(Resource catalogId, Resource versionedRDFRecordId, Resource branchId, Resource commitId); @Override List<Resource> removeBranch(Resource catalogId, Resource versionedRDFRecordId, Resource branchId); @Override Optional<T> getBranch(Resource catalogId, Resource versionedRDFRecordId,
                                                    Resource branchId, OrmFactory<T> factory); @Override Branch getMasterBranch(Resource catalogId, Resource versionedRDFRecordId); @Override Commit createCommit(@Nonnull InProgressCommit inProgressCommit, @Nonnull String message, Commit baseCommit,
                               Commit auxCommit); @Override InProgressCommit createInProgressCommit(User user); @Override void updateInProgressCommit(Resource catalogId, Resource versionedRDFRecordId, Resource commitId,
                                       @Nullable Model additions, @Nullable Model deletions); @Override void updateInProgressCommit(Resource catalogId, Resource versionedRDFRecordId, User user,
                                       @Nullable Model additions, @Nullable Model deletions); @Override void addInProgressCommit(Resource catalogId, Resource versionedRDFRecordId,
                                    InProgressCommit inProgressCommit); @Override Optional<Commit> getCommit(Resource commitId); @Override Optional<Commit> getCommit(Resource catalogId, Resource versionedRDFRecordId, Resource branchId,
                                      Resource commitId); @Override Commit getHeadCommit(Resource catalogId, Resource versionedRDFRecordId, Resource branchId); @Override Optional<InProgressCommit> getInProgressCommit(Resource catalogId, Resource versionedRDFRecordId,
                                                          User user); @Override Optional<InProgressCommit> getInProgressCommit(Resource catalogId, Resource versionedRDFRecordId,
                                                          Resource inProgressCommitId); @Override Revision getRevision(Resource commitId); @Override Difference getRevisionChanges(Resource commitId); @Override Difference getCommitDifference(Resource commitId); @Override void removeInProgressCommit(Resource catalogId, Resource versionedRDFRecordId,
                                       Resource inProgressCommitId); @Override void removeInProgressCommit(Resource catalogId, Resource versionedRDFRecordId, User user); @Override Model applyInProgressCommit(Resource inProgressCommitId, Model entity); @Override List<Commit> getCommitChain(Resource commitId); @Override List<Commit> getCommitChain(Resource commitId, Resource targetId); @Override List<Commit> getCommitChain(Resource catalogId, Resource versionedRDFRecordId, Resource branchId); @Override List<Commit> getCommitChain(Resource catalogId, Resource versionedRDFRecordId, Resource branchId,
                                       final Resource targetBranchId); @Override List<Commit> getCommitEntityChain(Resource commitId, Resource entityId); @Override List<Commit> getCommitEntityChain(Resource commitId, Resource targetId, Resource entityId); @Override Model getCompiledResource(Resource commitId); @Override Model getCompiledResource(List<Commit> commitList); @Override Model getCompiledResource(Resource versionedRDFRecordId, Resource branchId, Resource commitId); @Override Difference getDifference(Resource sourceCommitId, Resource targetCommitId); @Override Set<Conflict> getConflicts(Resource leftId, Resource rightId); @Override Difference getDiff(Model original, Model changed); @Override void export(Resource recordIRI, RecordOperationConfig config); @Override void export(List<Resource> recordIRIs, RecordOperationConfig config);  }
@Test public void testCreateCommit() throws Exception { IRI provGenerated = VALUE_FACTORY.createIRI(Activity.generated_IRI); IRI provAtTime = VALUE_FACTORY.createIRI(InstantaneousEvent.atTime_IRI); IRI provWasAssociatedWith = VALUE_FACTORY.createIRI(Activity.wasAssociatedWith_IRI); IRI revisionId = VALUE_FACTORY.createIRI("http: Resource generation = VALUE_FACTORY.createIRI("http: Resource generation2 = VALUE_FACTORY.createIRI("http: Commit base = commitFactory.createNew(COMMIT_IRI); base.setProperty(generation, provGenerated); Commit auxiliary = commitFactory.createNew(COMMIT_IRI); auxiliary.setProperty(generation2, provGenerated); InProgressCommit inProgressCommit = inProgressCommitFactory.createNew(IN_PROGRESS_COMMIT_IRI); inProgressCommit.setProperty(VALUE_FACTORY.createIRI("http: inProgressCommit.setProperty(revisionId, provGenerated); Revision revision = revisionFactory.createNew(revisionId); inProgressCommit.getModel().addAll(revision.getModel()); Commit result = manager.createCommit(inProgressCommit, "message", null, null); assertTrue(result.getProperty(provAtTime).isPresent()); assertEquals("message", result.getProperty(titleIRI).get().stringValue()); assertFalse(result.getBaseCommit().isPresent()); assertFalse(result.getAuxiliaryCommit().isPresent()); assertFalse(result.getModel().contains(IN_PROGRESS_COMMIT_IRI, null, null)); assertTrue(result.getModel().contains(revisionId, null, null)); result = manager.createCommit(inProgressCommit, "message", base, auxiliary); assertTrue(result.getProperty(provAtTime).isPresent()); assertEquals("message", result.getProperty(titleIRI).get().stringValue()); assertTrue(result.getBaseCommit_resource().isPresent() && result.getBaseCommit_resource().get().equals(COMMIT_IRI)); assertTrue(result.getAuxiliaryCommit_resource().isPresent() && result.getAuxiliaryCommit_resource().get().equals(COMMIT_IRI)); assertFalse(result.getModel().contains(IN_PROGRESS_COMMIT_IRI, null, null)); assertTrue(result.getModel().contains(revisionId, null, null)); }
@Test public void testCreateCommitWithOnlyAuxiliary() { InProgressCommit inProgressCommit = inProgressCommitFactory.createNew(IN_PROGRESS_COMMIT_IRI); Commit auxiliary = commitFactory.createNew(COMMIT_IRI); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Commit must have a base commit in order to have an auxiliary commit"); manager.createCommit(inProgressCommit, "message", null, auxiliary); }