Search in sources :

Example 21 with SchemaEdgeDefinition

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

the class ExportToOtherGraphHandlerTest method shouldValidateSchemaUsedWhenGraphIdAlreadyExistsAndIsSame.

@Test
public void shouldValidateSchemaUsedWhenGraphIdAlreadyExistsAndIsSame() {
    // Given
    Schema schema1 = new Schema.Builder().edge("testEdge", new SchemaEdgeDefinition()).build();
    graphLibrary.add(GRAPH_ID + 1, SCHEMA_ID + 1, schema1, STORE_PROPS_ID, new StoreProperties());
    final ExportToOtherGraph export = new ExportToOtherGraph.Builder().graphId(GRAPH_ID + 1).schema(schema1).build();
    // When / Then
    validate(export);
}
Also used : ExportToOtherGraph(uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherGraph) Schema(uk.gov.gchq.gaffer.store.schema.Schema) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 22 with SchemaEdgeDefinition

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

the class ExportToOtherGraphHandlerTest method shouldValidateParentSchemaIdCannotBeUsedWhenGraphIdAlreadyExists.

@Test
public void shouldValidateParentSchemaIdCannotBeUsedWhenGraphIdAlreadyExists() {
    // Given
    graphLibrary.add(GRAPH_ID + 1, SCHEMA_ID_1, new Schema.Builder().edge("edge", new SchemaEdgeDefinition()).build(), STORE_PROPS_ID, new StoreProperties());
    graphLibrary.addSchema(SCHEMA_ID, new Schema.Builder().build());
    final ExportToOtherGraph export = new ExportToOtherGraph.Builder().graphId(GRAPH_ID + 1).parentSchemaIds(SCHEMA_ID).build();
    // When / Then
    final String expectedMessage = "Validation errors: \n" + String.format(GRAPH_S_ALREADY_EXISTS_SO_YOU_CANNOT_USE_A_DIFFERENT_S_DO_NOT_SET_THE_S_FIELD, "graphId1", SCHEMA_STRING, "parentSchemaIds");
    assertThatIllegalArgumentException().isThrownBy(() -> createGraph(export)).withMessage(expectedMessage);
}
Also used : ExportToOtherGraph(uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherGraph) Schema(uk.gov.gchq.gaffer.store.schema.Schema) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 23 with SchemaEdgeDefinition

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

the class FilterValidator method validateOperation.

@Override
protected ValidationResult validateOperation(final Filter operation, final Schema schema) {
    final ValidationResult result = new ValidationResult();
    final Map<String, ?> entities = null != operation.getEntities() ? operation.getEntities() : new HashMap<>();
    final Map<String, ?> edges = null != operation.getEdges() ? operation.getEdges() : new HashMap<>();
    for (final Map.Entry<String, ?> entry : edges.entrySet()) {
        result.add(validateEdge(entry, schema));
        result.add(validateElementFilter((ElementFilter) entry.getValue()));
        result.add(validateFilterPropertyClasses(schema.getEdge(entry.getKey()), (ElementFilter) entry.getValue()));
    }
    for (final Map.Entry<String, ?> entry : entities.entrySet()) {
        result.add(validateEntity(entry, schema));
        result.add(validateElementFilter((ElementFilter) entry.getValue()));
        result.add(validateFilterPropertyClasses(schema.getEntity(entry.getKey()), (ElementFilter) entry.getValue()));
    }
    if (null != operation.getGlobalElements()) {
        for (final SchemaEdgeDefinition edgeDefinition : schema.getEdges().values()) {
            result.add(validateFilterPropertyClasses(edgeDefinition, operation.getGlobalElements()));
        }
        for (final SchemaEntityDefinition entityDefinition : schema.getEntities().values()) {
            result.add(validateFilterPropertyClasses(entityDefinition, operation.getGlobalElements()));
        }
    }
    if (null != operation.getGlobalEdges()) {
        for (final SchemaEdgeDefinition edgeDefinition : schema.getEdges().values()) {
            result.add(validateFilterPropertyClasses(edgeDefinition, operation.getGlobalEdges()));
        }
    }
    if (null != operation.getGlobalEntities()) {
        for (final SchemaEntityDefinition entityDefinition : schema.getEntities().values()) {
            result.add(validateFilterPropertyClasses(entityDefinition, operation.getGlobalEntities()));
        }
    }
    return result;
}
Also used : ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) SchemaEntityDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) HashMap(java.util.HashMap) Map(java.util.Map)

Example 24 with SchemaEdgeDefinition

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

the class FunctionValidator method validateEdge.

protected ValidationResult validateEdge(final Map.Entry<String, ?> edgeEntry, final Schema schema) {
    final ValidationResult result = new ValidationResult();
    if (null != edgeEntry) {
        final String group = edgeEntry.getKey();
        final SchemaEdgeDefinition schemaEdgeDefinition = schema.getEdge(group);
        if (null == schemaEdgeDefinition) {
            result.addError("Edge group: " + group + " does not exist in the schema.");
        }
    }
    return result;
}
Also used : SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) ValidationResult(uk.gov.gchq.koryphe.ValidationResult)

Example 25 with SchemaEdgeDefinition

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

the class AccumuloKeyValueReducerTest method shouldGetGroupFromElementConverter.

@Test
public void shouldGetGroupFromElementConverter() throws IOException, InterruptedException {
    // Given
    MockAccumuloElementConverter.mock = mock(AccumuloElementConverter.class);
    final Key key = mock(Key.class);
    final List<Value> values = Arrays.asList(mock(Value.class), mock(Value.class));
    final Reducer.Context context = mock(Reducer.Context.class);
    final Configuration conf = mock(Configuration.class);
    final Schema schema = new Schema.Builder().edge(TestGroups.ENTITY, new SchemaEdgeDefinition()).build();
    final ByteSequence colFamData = mock(ByteSequence.class);
    final byte[] colFam = StringUtil.toBytes(TestGroups.ENTITY);
    given(context.nextKey()).willReturn(true, false);
    given(context.getCurrentKey()).willReturn(key);
    given(context.getValues()).willReturn(values);
    given(context.getConfiguration()).willReturn(conf);
    given(context.getCounter(any(), any())).willReturn(mock(Counter.class));
    given(conf.get(SCHEMA)).willReturn(StringUtil.toString(schema.toCompactJson()));
    given(conf.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS)).willReturn(MockAccumuloElementConverter.class.getName());
    given(colFamData.getBackingArray()).willReturn(colFam);
    given(key.getColumnFamilyData()).willReturn(colFamData);
    given(MockAccumuloElementConverter.mock.getGroupFromColumnFamily(colFam)).willReturn(TestGroups.ENTITY);
    final AccumuloKeyValueReducer reducer = new AccumuloKeyValueReducer();
    // When
    reducer.run(context);
    // Then
    verify(MockAccumuloElementConverter.mock, times(1)).getGroupFromColumnFamily(colFam);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Counter(org.apache.hadoop.mapreduce.Counter) AccumuloElementConverter(uk.gov.gchq.gaffer.accumulostore.key.AccumuloElementConverter) MockAccumuloElementConverter(uk.gov.gchq.gaffer.accumulostore.key.MockAccumuloElementConverter) Value(org.apache.accumulo.core.data.Value) MockAccumuloElementConverter(uk.gov.gchq.gaffer.accumulostore.key.MockAccumuloElementConverter) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) Reducer(org.apache.hadoop.mapreduce.Reducer) Key(org.apache.accumulo.core.data.Key) ByteSequence(org.apache.accumulo.core.data.ByteSequence) Test(org.junit.jupiter.api.Test)

Aggregations

SchemaEdgeDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition)25 Test (org.junit.jupiter.api.Test)15 Schema (uk.gov.gchq.gaffer.store.schema.Schema)15 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)11 SchemaEntityDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition)10 Store (uk.gov.gchq.gaffer.store.Store)8 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)7 Context (uk.gov.gchq.gaffer.store.Context)7 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)6 UpdateViewHook (uk.gov.gchq.gaffer.graph.hook.UpdateViewHook)5 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)5 Operation (uk.gov.gchq.gaffer.operation.Operation)5 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)5 HashMap (java.util.HashMap)4 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)4 OperationView (uk.gov.gchq.gaffer.operation.graph.OperationView)4 BeforeAll (org.junit.jupiter.api.BeforeAll)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)3 ByteSequence (org.apache.accumulo.core.data.ByteSequence)2