Search in sources :

Example 1 with StoreTrait

use of uk.gov.gchq.gaffer.store.StoreTrait in project Gaffer by gchq.

the class GraphConfigurationServiceTest method setup.

@Before
public void setup() {
    final Store store = mock(Store.class);
    final Schema schema = mock(Schema.class);
    final Set<StoreTrait> traits = new HashSet<>(Arrays.asList(STORE_AGGREGATION, PRE_AGGREGATION_FILTERING, POST_TRANSFORMATION_FILTERING, POST_AGGREGATION_FILTERING, TRANSFORMATION, STORE_VALIDATION));
    given(store.getSchema()).willReturn(schema);
    final Graph graph = new Graph.Builder().store(store).build();
    final Set<Class<? extends Operation>> operations = new HashSet<>();
    operations.add(AddElements.class);
    given(graphFactory.getGraph()).willReturn(graph);
    given(graph.getSupportedOperations()).willReturn(operations);
    given(graph.isSupported(AddElements.class)).willReturn(true);
    given(userFactory.createUser()).willReturn(new User());
    given(graph.getStoreTraits()).willReturn(traits);
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) User(uk.gov.gchq.gaffer.user.User) StoreTrait(uk.gov.gchq.gaffer.store.StoreTrait) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) Operation(uk.gov.gchq.gaffer.operation.Operation) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 2 with StoreTrait

use of uk.gov.gchq.gaffer.store.StoreTrait in project Gaffer by gchq.

the class ProxyStore method fetchTraits.

protected Set<StoreTrait> fetchTraits(final ProxyProperties proxyProps) throws StoreException {
    final URL url = proxyProps.getGafferUrl("graph/storeTraits");
    Set<StoreTrait> newTraits = doGet(url, new TypeReferenceStoreImpl.StoreTraits(), null);
    if (null == newTraits) {
        newTraits = new HashSet<>(0);
    } else {
        // This proxy store cannot handle visibility due to the simple rest api using a default user.
        newTraits.remove(StoreTrait.VISIBILITY);
    }
    return newTraits;
}
Also used : StoreTrait(uk.gov.gchq.gaffer.store.StoreTrait) TypeReferenceStoreImpl(uk.gov.gchq.gaffer.store.TypeReferenceStoreImpl) URL(java.net.URL)

Example 3 with StoreTrait

use of uk.gov.gchq.gaffer.store.StoreTrait in project Gaffer by gchq.

the class GraphConfigurationServiceTest method setup.

@BeforeEach
public void setup() {
    final Set<StoreTrait> traits = new HashSet<>(Arrays.asList(INGEST_AGGREGATION, PRE_AGGREGATION_FILTERING, POST_TRANSFORMATION_FILTERING, POST_AGGREGATION_FILTERING, TRANSFORMATION, STORE_VALIDATION));
    lenient().when(store.getSchema()).thenReturn(new Schema());
    lenient().when(store.getProperties()).thenReturn(new StoreProperties());
    final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).build()).store(store).build();
    final Set<Class<? extends Operation>> operations = new HashSet<>();
    operations.add(AddElements.class);
    lenient().when(graphFactory.getGraph()).thenReturn(graph);
    lenient().when(graph.getSupportedOperations()).thenReturn(operations);
    lenient().when(graph.isSupported(AddElements.class)).thenReturn(true);
    lenient().when(userFactory.createContext()).thenReturn(new Context());
    lenient().when(graph.getStoreTraits()).thenReturn(traits);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) StoreTrait(uk.gov.gchq.gaffer.store.StoreTrait) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Operation(uk.gov.gchq.gaffer.operation.Operation) GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) Graph(uk.gov.gchq.gaffer.graph.Graph) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) HashSet(java.util.HashSet) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with StoreTrait

use of uk.gov.gchq.gaffer.store.StoreTrait in project Gaffer by gchq.

the class FederatedGraphStorage method getTraits.

/**
 * returns a set of {@link StoreTrait} that are common for all visible graphs.
 * traits1 = [a,b,c]
 * traits2 = [b,c]
 * traits3 = [a,b]
 * return [b]
 *
 * @param op      the GetTraits operation
 * @param context the user context
 * @return the set of {@link StoreTrait} that are common for all visible graphs
 * @deprecated use {@link uk.gov.gchq.gaffer.store.Store#execute(uk.gov.gchq.gaffer.operation.Operation, Context)} with GetTraits Operation.
 */
@Deprecated
public Set<StoreTrait> getTraits(final GetTraits op, final Context context) {
    boolean firstPass = true;
    final Set<StoreTrait> traits = new HashSet<>();
    if (null != op) {
        final List<String> graphIds = FederatedStoreUtil.getGraphIds(op.getOptions());
        final Collection<Graph> graphs = get(context.getUser(), graphIds);
        final GetTraits getTraits = op.shallowClone();
        for (final Graph graph : graphs) {
            try {
                Set<StoreTrait> execute = graph.execute(getTraits, context);
                if (firstPass) {
                    traits.addAll(execute);
                    firstPass = false;
                } else {
                    traits.retainAll(execute);
                }
            } catch (final OperationException e) {
                throw new RuntimeException("Unable to fetch traits from graph " + graph.getGraphId(), e);
            }
        }
    }
    return traits;
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) StoreTrait(uk.gov.gchq.gaffer.store.StoreTrait) GetTraits(uk.gov.gchq.gaffer.store.operation.GetTraits) CacheOperationException(uk.gov.gchq.gaffer.cache.exception.CacheOperationException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 5 with StoreTrait

use of uk.gov.gchq.gaffer.store.StoreTrait in project Gaffer by gchq.

the class GetTraitsHandler method createCurrentTraits.

private Set<StoreTrait> createCurrentTraits(final Store store) {
    final Set<StoreTrait> traits = Sets.newHashSet(store.getTraits());
    final Schema schema = store.getSchema();
    final boolean hasAggregatedGroups = isNotEmpty(schema.getAggregatedGroups());
    final boolean hasVisibility = nonNull(schema.getVisibilityProperty());
    boolean hasGroupBy = false;
    boolean hasValidation = false;
    for (final SchemaElementDefinition def : new ChainedIterable<SchemaElementDefinition>(schema.getEntities().values(), schema.getEdges().values())) {
        hasValidation = hasValidation || def.hasValidation();
        hasGroupBy = hasGroupBy || isNotEmpty(def.getGroupBy());
        if (hasGroupBy && hasValidation) {
            break;
        }
    }
    if (!hasAggregatedGroups) {
        traits.remove(StoreTrait.INGEST_AGGREGATION);
        traits.remove(StoreTrait.QUERY_AGGREGATION);
    }
    if (!hasGroupBy && traits.contains(StoreTrait.INGEST_AGGREGATION)) {
        traits.remove(StoreTrait.QUERY_AGGREGATION);
    }
    if (!hasValidation) {
        traits.remove(StoreTrait.STORE_VALIDATION);
    }
    if (!hasVisibility) {
        traits.remove(StoreTrait.VISIBILITY);
    }
    return traits;
}
Also used : StoreTrait(uk.gov.gchq.gaffer.store.StoreTrait) Schema(uk.gov.gchq.gaffer.store.schema.Schema) ChainedIterable(uk.gov.gchq.gaffer.commonutil.iterable.ChainedIterable) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)

Aggregations

StoreTrait (uk.gov.gchq.gaffer.store.StoreTrait)29 Schema (uk.gov.gchq.gaffer.store.schema.Schema)16 Test (org.junit.jupiter.api.Test)15 Context (uk.gov.gchq.gaffer.store.Context)11 HashSet (java.util.HashSet)9 Graph (uk.gov.gchq.gaffer.graph.Graph)8 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)8 GetTraits (uk.gov.gchq.gaffer.store.operation.GetTraits)8 GraphConfig (uk.gov.gchq.gaffer.graph.GraphConfig)7 GraphSerialisable (uk.gov.gchq.gaffer.graph.GraphSerialisable)4 Test (org.junit.Test)3 MapStoreProperties (uk.gov.gchq.gaffer.mapstore.MapStoreProperties)3 Operation (uk.gov.gchq.gaffer.operation.Operation)3 Store (uk.gov.gchq.gaffer.store.Store)3 Annotation (java.lang.annotation.Annotation)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 Before (org.junit.Before)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2