FederatedStore extends Store { public Collection<Graph> getGraphs(final User user, final String graphIdsCsv, final Operation operation) { Collection<Graph> rtn = new ArrayList<>(); if (nonNull(operation)) { String optionKey = FEDERATED_STORE_PROCESSED + id; boolean isIdFound = !operation.getOption(optionKey, "").isEmpty(); if (!isIdFound) { HashMap<String, String> updatedOptions = isNull(operation.getOptions()) ? new HashMap<>() : new HashMap<>(operation.getOptions()); updatedOptions.put(optionKey, getGraphId()); operation.setOptions(updatedOptions); rtn.addAll(graphStorage.get(user, getCleanStrings(graphIdsCsv))); } else { List<String> federatedStoreGraphIds = operation.getOptions() .entrySet() .stream() .filter(e -> e.getKey().startsWith(FEDERATED_STORE_PROCESSED)) .map(Map.Entry::getValue) .collect(Collectors.toList()); String ln = System.lineSeparator(); LOGGER.error("This operation has already been processed by this FederatedStore. " + "This is a symptom of an infinite loop of FederatedStores and Proxies.{}" + "This FederatedStore: {}{}" + "All FederatedStore in this loop: {}", ln, this.getGraphId(), ln, federatedStoreGraphIds.toString()); } } return rtn; } FederatedStore(); @Override void initialise(final String graphId, final Schema unused, final StoreProperties properties); @Override void setGraphLibrary(final GraphLibrary library); @Override FederatedStoreProperties getProperties(); @Deprecated static OP updateOperationForGraph(final OP operation, final Graph graph); void addGraphs(final Set<String> graphAuths, final String addingUserId, final boolean isPublic, final GraphSerialisable... graphs); void addGraphs(
            final Set<String> graphAuths,
            final String addingUserId,
            final boolean isPublic,
            final boolean disabledByDefault,
            final GraphSerialisable... graphs); void addGraphs(
            final Set<String> graphAuths,
            final String addingUserId,
            final boolean isPublic,
            final boolean disabledByDefault,
            final AccessPredicate readAccessPredicate,
            final AccessPredicate writeAccessPredicate,
            final GraphSerialisable... graphs); void addGraphs(final FederatedAccess access, final GraphSerialisable... graphs); @Deprecated void addGraphs(final Set<String> graphAuths, final String addingUserId, final GraphSerialisable... graphs); boolean remove(final String graphId, final User user); boolean remove(final String graphId, final User user, final boolean asAdmin); Collection<String> getAllGraphIds(final User user); Collection<String> getAllGraphIds(final User user, final boolean asAdmin); @Override Schema getSchema(); Schema getSchema(final GetSchema operation, final Context context); Schema getSchema(final Operation operation, final Context context); Schema getSchema(final Map<String, String> config, final Context context); Schema getSchema(final Operation operation, final User user); Schema getSchema(final Map<String, String> config, final User user); @Override Set<StoreTrait> getTraits(); Set<StoreTrait> getTraits(final GetTraits getTraits, final Context context); Collection<Graph> getGraphs(final User user, final String graphIdsCsv, final Operation operation); Map<String, Object> getAllGraphsAndAuths(final User user, final String graphIdsCsv); Map<String, Object> getAllGraphsAndAuths(final User user, final String graphIdsCsv, final boolean isAdmin); boolean isLimitedToLibraryProperties(final User user); boolean changeGraphAccess(final User requestingUser, final String graphId, final FederatedAccess federatedAccess, final boolean isAdmin); boolean changeGraphId(final User requestingUser, final String graphId, final String newGraphId, final boolean isAdmin);  }
@Test public void shouldLoadGraphsWithIds() throws Exception { int before = store.getGraphs(blankUser, null, ignore).size(); addGraphWithIds(ACC_ID_2, ID_PROPS_ACC_2, ID_SCHEMA_EDGE); addGraphWithIds(ACC_ID_1, ID_PROPS_ACC_1, ID_SCHEMA_ENTITY); Collection<Graph> graphs = store.getGraphs(blankUser, null, ignore); int after = graphs.size(); assertEquals(0, before); assertEquals(2, after); ArrayList<String> graphNames = Lists.newArrayList(ACC_ID_1, ACC_ID_2); for (Graph graph : graphs) { assertTrue(graphNames.contains(graph.getGraphId())); } }
@Test public void shouldTakeCompleteSchemaFromTwoFiles() throws Exception { int before = store.getGraphs(blankUser, null, ignore).size(); addGraphWithPaths(ACC_ID_1, PROPERTIES_ALT, PATH_INCOMPLETE_SCHEMA, PATH_INCOMPLETE_SCHEMA_PART_2); int after = store.getGraphs(blankUser, null, ignore).size(); assertEquals(0, before); assertEquals(1, after); }
@Test public void shouldAddTwoGraphs() throws Exception { int sizeBefore = store.getGraphs(blankUser, null, ignore).size(); addGraphWithPaths(ACC_ID_2, PROPERTIES_ALT, PATH_BASIC_ENTITY_SCHEMA_JSON); addGraphWithPaths(ACC_ID_1, PROPERTIES_ALT, PATH_BASIC_EDGE_SCHEMA_JSON); int sizeAfter = store.getGraphs(blankUser, null, ignore).size(); assertEquals(0, sizeBefore); assertEquals(2, sizeAfter); }
@Test public void shouldReturnSpecificGraphsFromCSVString() throws Exception { final List<Collection<GraphSerialisable>> graphLists = populateGraphs(1, 2, 4); final Collection<GraphSerialisable> expectedGraphs = graphLists.get(0); final Collection<GraphSerialisable> unexpectedGraphs = graphLists.get(1); final Collection<Graph> returnedGraphs = store.getGraphs(blankUser, "mockGraphId1,mockGraphId2,mockGraphId4", ignore); assertTrue(returnedGraphs.size() == 3); assertTrue(returnedGraphs.containsAll(toGraphs(expectedGraphs))); assertFalse(checkUnexpected(toGraphs(unexpectedGraphs), returnedGraphs)); }
@Test public void shouldReturnEnabledByDefaultGraphsForNullString() throws Exception { populateGraphs(); final Collection<Graph> returnedGraphs = store.getGraphs(blankUser, null, ignore); final Set<String> graphIds = returnedGraphs.stream().map(Graph::getGraphId).collect(Collectors.toSet()); assertEquals(Sets.newHashSet("mockGraphId0", "mockGraphId2", "mockGraphId4"), graphIds); }
@Test public void shouldReturnNotReturnEnabledOrDisabledGraphsWhenNotInCsv() throws Exception { populateGraphs(); final Collection<Graph> returnedGraphs = store.getGraphs(blankUser, "mockGraphId0,mockGraphId1", ignore); final Set<String> graphIds = returnedGraphs.stream().map(Graph::getGraphId).collect(Collectors.toSet()); assertEquals(Sets.newHashSet("mockGraphId0", "mockGraphId1"), graphIds); }
@Test public void shouldReturnNoGraphsFromEmptyString() throws Exception { final List<Collection<GraphSerialisable>> graphLists = populateGraphs(); final Collection<GraphSerialisable> expectedGraphs = graphLists.get(0); final Collection<Graph> returnedGraphs = store.getGraphs(blankUser, "", ignore); assertTrue(returnedGraphs.isEmpty(), returnedGraphs.toString()); assertTrue(expectedGraphs.isEmpty(), expectedGraphs.toString()); }
@Test public void shouldReturnGraphsWithLeadingCommaString() throws Exception { final List<Collection<GraphSerialisable>> graphLists = populateGraphs(2, 4); final Collection<GraphSerialisable> expectedGraphs = graphLists.get(0); final Collection<GraphSerialisable> unexpectedGraphs = graphLists.get(1); final Collection<Graph> returnedGraphs = store.getGraphs(blankUser, ",mockGraphId2,mockGraphId4", ignore); assertTrue(returnedGraphs.size() == 2); assertTrue(returnedGraphs.containsAll(toGraphs(expectedGraphs))); assertFalse(checkUnexpected(toGraphs(unexpectedGraphs), returnedGraphs)); }
@Test public void shouldReturnASingleGraph() throws Exception { final List<Collection<GraphSerialisable>> graphLists = populateGraphs(1); final Collection<GraphSerialisable> expectedGraphs = graphLists.get(0); final Collection<GraphSerialisable> unexpectedGraphs = graphLists.get(1); final Collection<Graph> returnedGraphs = store.getGraphs(blankUser, "mockGraphId1", ignore); assertEquals(1, returnedGraphs.size()); assertTrue(returnedGraphs.containsAll(toGraphs(expectedGraphs))); assertFalse(checkUnexpected(toGraphs(unexpectedGraphs), returnedGraphs)); }