SimpleProvenanceService implements ProvenanceService { @Override public void updateActivity(Activity newActivity) { try (RepositoryConnection conn = repo.getConnection()) { if (!conn.contains(newActivity.getResource(), null, null)) { throw new IllegalArgumentException("Activity " + newActivity.getResource() + " does not exist"); } conn.begin(); Model activityModel = RepositoryResults.asModel(conn.getStatements(newActivity.getResource(), null, null), mf); conn.remove(activityModel); Activity activity = activityFactory.getExisting(newActivity.getResource(), activityModel).orElseThrow(() -> new IllegalStateException("Activity " + newActivity.getResource() + " could not be found")); activity.getGenerated_resource().forEach(resource -> conn.remove(resource, null, null)); activity.getInvalidated_resource().forEach(resource -> conn.remove(resource, null, null)); activity.getUsed_resource().forEach(resource -> conn.remove(resource, null, null)); conn.add(newActivity.getModel()); 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 updateActivityTest() throws Exception { IRI titleIRI = VALUE_FACTORY.createIRI(_Thing.title_IRI); Activity activity = activityFactory.createNew(activityIRI); Entity generated = entityFactory.createNew(VALUE_FACTORY.createIRI("http: Entity invalidated = entityFactory.createNew(VALUE_FACTORY.createIRI("http: Entity used = entityFactory.createNew(VALUE_FACTORY.createIRI("http: activity.setGenerated(Collections.singleton(generated)); activity.setInvalidated(Collections.singleton(invalidated)); activity.setUsed(Collections.singleton(used)); try (RepositoryConnection conn = repo.getConnection()) { conn.add(activity.getModel()); } activity.addProperty(VALUE_FACTORY.createLiteral("Activity"), titleIRI); generated.addProperty(VALUE_FACTORY.createLiteral("Generated"), titleIRI); invalidated.addProperty(VALUE_FACTORY.createLiteral("Invalidated"), titleIRI); used.addProperty(VALUE_FACTORY.createLiteral("Used"), titleIRI); service.updateActivity(activity); try (RepositoryConnection conn = repo.getConnection()) { activity.getModel().forEach(statement -> conn.contains(statement.getSubject(), statement.getPredicate(), statement.getObject())); } }
@Test(expected = IllegalArgumentException.class) public void updateActivityThatDoesNotExistTest() { service.updateActivity(activityFactory.createNew(VALUE_FACTORY.createIRI("http: }