Search in sources :

Example 16 with GraphSerialisable

use of uk.gov.gchq.gaffer.graph.GraphSerialisable in project Gaffer by gchq.

the class FederatedStoreGetTraitsTest method shouldGetNonCurrentTraitsForAddingUserButSelectedGraphsOnly.

@Test
public void shouldGetNonCurrentTraitsForAddingUserButSelectedGraphsOnly() throws Exception {
    // given
    final GraphSerialisable acc2 = new GraphSerialisable.Builder().graph(acc.getGraph()).config(new GraphConfig(GRAPH_ID_ACCUMULO + 2)).build();
    federatedStore.addGraphs(ACCESS_UNUSED_AUTH_AND_USER, acc);
    federatedStore.addGraphs(ACCESS_UNUSED_AUTH_WITH_TEST_USER, acc2);
    federatedStore.addGraphs(ACCESS_UNUSED_AUTH_WITH_TEST_USER, map);
    getTraits.addOption(FederatedStoreConstants.KEY_OPERATION_OPTIONS_GRAPH_IDS, GRAPH_ID_MAP);
    getTraits.setCurrentTraits(false);
    // when
    final Set<StoreTrait> traits = federatedStore.execute(getTraits, testUserContext);
    // then
    assertNotEquals(ACCUMULO_TRAITS, traits, "Returning AccumuloStore traits instead of MapStore");
    assertEquals(Collections.emptySet(), traits.stream().filter(ACCUMULO_TRAITS_EXCLUSIVE_OF_MAP::contains).collect(Collectors.toSet()), "Revealing some hidden traits from the AccumuloStore instead of only MapStore");
    assertEquals(MAP_TRAITS, traits);
}
Also used : GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) GraphSerialisable(uk.gov.gchq.gaffer.graph.GraphSerialisable) StoreTrait(uk.gov.gchq.gaffer.store.StoreTrait) Test(org.junit.Test)

Example 17 with GraphSerialisable

use of uk.gov.gchq.gaffer.graph.GraphSerialisable in project Gaffer by gchq.

the class FederatedStoreGetTraitsTest method shouldGetCurrentTraitsForAddingUserButSelectedGraphsOnly.

@Test
public void shouldGetCurrentTraitsForAddingUserButSelectedGraphsOnly() throws Exception {
    // given
    final GraphSerialisable acc2 = new GraphSerialisable.Builder().graph(acc.getGraph()).config(new GraphConfig(GRAPH_ID_ACCUMULO + 2)).build();
    federatedStore.addGraphs(ACCESS_UNUSED_AUTH_AND_USER, acc);
    federatedStore.addGraphs(ACCESS_UNUSED_AUTH_WITH_TEST_USER, acc2);
    federatedStore.addGraphs(ACCESS_UNUSED_AUTH_WITH_TEST_USER, map);
    getTraits.addOption(FederatedStoreConstants.KEY_OPERATION_OPTIONS_GRAPH_IDS, GRAPH_ID_MAP);
    // when
    final Set<StoreTrait> traits = federatedStore.execute(getTraits, testUserContext);
    // then
    assertNotEquals(ACCUMULO_TRAITS, traits, "Returning AccumuloStore traits instead of MapStore");
    assertEquals(Collections.emptySet(), traits.stream().filter(ACCUMULO_TRAITS_EXCLUSIVE_OF_MAP::contains).collect(Collectors.toSet()), "Revealing some hidden traits from the AccumuloStore instead of only MapStore");
    assertEquals(MAP_CURRENT_TRAITS, traits);
}
Also used : GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) GraphSerialisable(uk.gov.gchq.gaffer.graph.GraphSerialisable) StoreTrait(uk.gov.gchq.gaffer.store.StoreTrait) Test(org.junit.Test)

Example 18 with GraphSerialisable

use of uk.gov.gchq.gaffer.graph.GraphSerialisable in project Gaffer by gchq.

the class FederatedAddGraphHandlerParent method doOperation.

@Override
public Void doOperation(final OP operation, final Context context, final Store store) throws OperationException {
    final User user = context.getUser();
    boolean isLimitedToLibraryProperties = ((FederatedStore) store).isLimitedToLibraryProperties(user);
    if (isLimitedToLibraryProperties && null != operation.getStoreProperties()) {
        throw new OperationException(String.format(USER_IS_LIMITED_TO_ONLY_USING_PARENT_PROPERTIES_ID_FROM_GRAPHLIBRARY_BUT_FOUND_STORE_PROPERTIES_S, operation.getProperties().toString()));
    }
    final GraphSerialisable graphSerialisable;
    try {
        graphSerialisable = _makeGraph(operation, store);
    } catch (final Exception e) {
        throw new OperationException(String.format(ERROR_BUILDING_GRAPH_GRAPH_ID_S, operation.getGraphId()), e);
    }
    try {
        ((FederatedStore) store).addGraphs(operation.getGraphAuths(), context.getUser().getUserId(), operation.getIsPublic(), operation.isDisabledByDefault(), operation.getReadAccessPredicate(), operation.getWriteAccessPredicate(), graphSerialisable);
    } catch (final StorageException e) {
        throw new OperationException(e.getMessage(), e);
    } catch (final Exception e) {
        throw new OperationException(String.format(ERROR_ADDING_GRAPH_GRAPH_ID_S, operation.getGraphId()), e);
    }
    addGenericHandler((FederatedStore) store, graphSerialisable.getGraph());
    return null;
}
Also used : User(uk.gov.gchq.gaffer.user.User) GraphSerialisable(uk.gov.gchq.gaffer.graph.GraphSerialisable) StorageException(uk.gov.gchq.gaffer.federatedstore.exception.StorageException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) StorageException(uk.gov.gchq.gaffer.federatedstore.exception.StorageException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore)

Example 19 with GraphSerialisable

use of uk.gov.gchq.gaffer.graph.GraphSerialisable in project Gaffer by gchq.

the class MapStorePropertiesGraphSerialisableTest method shouldConsumeGraph.

@Test
public void shouldConsumeGraph() throws Exception {
    final MapStoreProperties mapStoreProperties = new MapStoreProperties();
    mapStoreProperties.setProperties(properties);
    final Graph graph = new Graph.Builder().addSchema(schema).addStoreProperties(mapStoreProperties).config(config).build();
    final GraphSerialisable result = new GraphSerialisable.Builder().graph(graph).build();
    assertEquals(expected, result);
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) GraphSerialisable(uk.gov.gchq.gaffer.graph.GraphSerialisable) Test(org.junit.jupiter.api.Test)

Example 20 with GraphSerialisable

use of uk.gov.gchq.gaffer.graph.GraphSerialisable in project Gaffer by gchq.

the class MapStorePropertiesGraphSerialisableTest method shouldSerialiseAndDeserialise.

@Test
public void shouldSerialiseAndDeserialise() throws Exception {
    final JavaSerialiser javaSerialiser = new JavaSerialiser();
    final byte[] serialise = javaSerialiser.serialise(expected);
    final GraphSerialisable result = (GraphSerialisable) javaSerialiser.deserialise(serialise);
    assertEquals(expected, result);
}
Also used : GraphSerialisable(uk.gov.gchq.gaffer.graph.GraphSerialisable) JavaSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser) Test(org.junit.jupiter.api.Test)

Aggregations

GraphSerialisable (uk.gov.gchq.gaffer.graph.GraphSerialisable)20 Test (org.junit.jupiter.api.Test)13 GraphConfig (uk.gov.gchq.gaffer.graph.GraphConfig)10 StorageException (uk.gov.gchq.gaffer.federatedstore.exception.StorageException)5 FederatedGetTraitsHandlerTest (uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedGetTraitsHandlerTest)5 Builder (uk.gov.gchq.gaffer.store.schema.Schema.Builder)5 StoreTrait (uk.gov.gchq.gaffer.store.StoreTrait)4 Schema (uk.gov.gchq.gaffer.store.schema.Schema)4 Graph (uk.gov.gchq.gaffer.graph.Graph)3 SchemaEntityDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 CacheOperationException (uk.gov.gchq.gaffer.cache.exception.CacheOperationException)2 AddGraph (uk.gov.gchq.gaffer.federatedstore.operation.AddGraph)2 RemoveGraph (uk.gov.gchq.gaffer.federatedstore.operation.RemoveGraph)2 OperationException (uk.gov.gchq.gaffer.operation.OperationException)2 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1