SimpleProvenanceService implements ProvenanceService { @Override public void deleteActivity(Resource activityIRI) { try (RepositoryConnection conn = repo.getConnection()) { if (!conn.contains(activityIRI, null, null)) { throw new IllegalArgumentException("Activity " + activityIRI + " does not exist"); } conn.begin(); List<Resource> generated = getReferencedEntityIRIs(activityIRI, Activity.generated_IRI, conn); List<Resource> invalided = getReferencedEntityIRIs(activityIRI, Activity.invalidated_IRI, conn); List<Resource> used = getReferencedEntityIRIs(activityIRI, Activity.used_IRI, conn); conn.remove(activityIRI, null, null); conn.remove((Resource) null, null, activityIRI); generated.forEach(resource -> removeIfNotReferenced(resource, conn)); invalided.forEach(resource -> removeIfNotReferenced(resource, conn)); used.forEach(resource -> removeIfNotReferenced(resource, conn)); conn.commit(); } }  @Override RepositoryConnection getConnection(); @Override Activity createActivity(ActivityConfig config); @Override void addActivity(Activity activity); @Override Optional<Activity> getActivity(Resource activityIRI); @Override void updateActivity(Activity newActivity); @Override void deleteActivity(Resource activityIRI);  }
@Test public void deleteActivityTest() throws Exception { Activity toRemove = activityFactory.createNew(activityIRI); Activity other = activityFactory.createNew(VALUE_FACTORY.createIRI("http: Entity generated1 = entityFactory.createNew(VALUE_FACTORY.createIRI("http: Entity invalidated1 = entityFactory.createNew(VALUE_FACTORY.createIRI("http: Entity used1 = entityFactory.createNew(VALUE_FACTORY.createIRI("http: Entity generated2 = entityFactory.createNew(VALUE_FACTORY.createIRI("http: Entity invalidated2 = entityFactory.createNew(VALUE_FACTORY.createIRI("http: Entity used2 = entityFactory.createNew(VALUE_FACTORY.createIRI("http: toRemove.setGenerated(Collections.singleton(generated1)); toRemove.setInvalidated(Collections.singleton(invalidated1)); toRemove.setUsed(Collections.singleton(used1)); toRemove.setGenerated(Collections.singleton(generated2)); toRemove.setInvalidated(Collections.singleton(invalidated2)); toRemove.setUsed(Collections.singleton(used2)); other.setGenerated(Collections.singleton(generated1)); other.setInvalidated(Collections.singleton(invalidated1)); other.setUsed(Collections.singleton(used1)); try (RepositoryConnection conn = repo.getConnection()) { conn.add(toRemove.getModel()); conn.add(generated1.getModel()); conn.add(invalidated1.getModel()); conn.add(used1.getModel()); conn.add(generated2.getModel()); conn.add(invalidated2.getModel()); conn.add(used2.getModel()); conn.add(other.getModel()); } service.deleteActivity(activityIRI); try (RepositoryConnection conn = repo.getConnection()) { toRemove.getModel().forEach(statement -> assertFalse(conn.contains(statement.getSubject(), statement.getPredicate(), statement.getObject()))); generated1.getModel().forEach(statement -> assertTrue(conn.contains(statement.getSubject(), statement.getPredicate(), statement.getObject()))); invalidated1.getModel().forEach(statement -> assertTrue(conn.contains(statement.getSubject(), statement.getPredicate(), statement.getObject()))); used1.getModel().forEach(statement -> assertTrue(conn.contains(statement.getSubject(), statement.getPredicate(), statement.getObject()))); generated2.getModel().forEach(statement -> assertFalse(conn.contains(statement.getSubject(), statement.getPredicate(), statement.getObject()))); invalidated2.getModel().forEach(statement -> assertFalse(conn.contains(statement.getSubject(), statement.getPredicate(), statement.getObject()))); used2.getModel().forEach(statement -> assertFalse(conn.contains(statement.getSubject(), statement.getPredicate(), statement.getObject()))); other.getModel().forEach(statement -> assertTrue(conn.contains(statement.getSubject(), statement.getPredicate(), statement.getObject()))); } }