FederatedRemoveGraphHandler implements OutputOperationHandler<RemoveGraph, Boolean> { @Override public Boolean doOperation(final RemoveGraph operation, final Context context, final Store store) throws OperationException { try { final boolean userRequestingAdminUsage = isUserRequestingAdminUsage(operation); return ((FederatedStore) store).remove(operation.getGraphId(), context.getUser(), userRequestingAdminUsage); } catch (final Exception e) { throw new OperationException("Error removing graph: " + operation.getGraphId(), e); } }  @Override Boolean doOperation(final RemoveGraph operation, final Context context, final Store store);  }
@Test public void shouldRemoveGraphForAddingUser() throws Exception { FederatedStore store = new FederatedStore(); final FederatedStoreProperties federatedStoreProperties = new FederatedStoreProperties(); federatedStoreProperties.setCacheProperties(CACHE_SERVICE_CLASS_STRING); store.initialise(FEDERATEDSTORE_GRAPH_ID, null, federatedStoreProperties); store.addGraphs(testUser.getOpAuths(), testUser.getUserId(), false, new GraphSerialisable.Builder() .config(new GraphConfig(EXPECTED_GRAPH_ID)) .schema(new Schema.Builder().build()) .properties(PROPERTIES) .build()); assertEquals(1, store.getGraphs(testUser, null, ignore).size()); new FederatedRemoveGraphHandler().doOperation( new RemoveGraph.Builder() .graphId(EXPECTED_GRAPH_ID) .build(), new Context(testUser), store); Collection<Graph> graphs = store.getGraphs(testUser, null, ignore); assertEquals(0, graphs.size()); }
@Test public void shouldNotRemoveGraphForNonAddingUser() throws Exception { FederatedStore store = new FederatedStore(); final FederatedStoreProperties federatedStoreProperties = new FederatedStoreProperties(); federatedStoreProperties.setCacheProperties(CACHE_SERVICE_CLASS_STRING); store.initialise(FEDERATEDSTORE_GRAPH_ID, null, federatedStoreProperties); store.addGraphs(testUser.getOpAuths(), "other", false, new GraphSerialisable.Builder() .config(new GraphConfig(EXPECTED_GRAPH_ID)) .schema(new Schema.Builder().build()) .properties(PROPERTIES) .build()); assertEquals(1, store.getGraphs(testUser, null, ignore).size()); new FederatedRemoveGraphHandler().doOperation( new RemoveGraph.Builder() .graphId(EXPECTED_GRAPH_ID) .build(), new Context(testUser), store); Collection<Graph> graphs = store.getGraphs(testUser, null, ignore); assertEquals(1, graphs.size()); }
@Test public void shouldNotRemoveGraphConfiguredWithNoAccessWritePredicate() throws Exception { FederatedStore store = new FederatedStore(); final FederatedStoreProperties federatedStoreProperties = new FederatedStoreProperties(); federatedStoreProperties.setCacheProperties(CACHE_SERVICE_CLASS_STRING); store.initialise(FEDERATEDSTORE_GRAPH_ID, null, federatedStoreProperties); final AccessPredicate noAccessPredicate = new NoAccessPredicate(); store.addGraphs( testUser.getOpAuths(), "other", false, false, null, noAccessPredicate, new GraphSerialisable.Builder() .config(new GraphConfig(EXPECTED_GRAPH_ID)) .schema(new Schema.Builder().build()) .properties(PROPERTIES) .build()); assertEquals(1, store.getGraphs(testUser, null, ignore).size()); new FederatedRemoveGraphHandler().doOperation( new RemoveGraph.Builder() .graphId(EXPECTED_GRAPH_ID) .build(), new Context(testUser), store); Collection<Graph> graphs = store.getGraphs(testUser, null, ignore); assertEquals(1, graphs.size()); }