Search in sources :

Example 1 with ConsumerProducerFunctionContext

use of uk.gov.gchq.gaffer.function.context.ConsumerProducerFunctionContext in project Gaffer by gchq.

the class ViewIT method shouldDeserialiseJsonView.

@Test
public void shouldDeserialiseJsonView() throws IOException {
    // Given
    // When
    View view = loadView();
    // Then
    final ViewElementDefinition edge = view.getEdge(TestGroups.EDGE);
    final ElementTransformer transformer = edge.getTransformer();
    assertNotNull(transformer);
    final List<ConsumerProducerFunctionContext<String, TransformFunction>> contexts = transformer.getFunctions();
    assertEquals(1, contexts.size());
    final List<String> selection = contexts.get(0).getSelection();
    assertEquals(2, selection.size());
    assertEquals(TestPropertyNames.PROP_1, selection.get(0));
    assertEquals(IdentifierType.SOURCE.name(), selection.get(1));
    final List<String> projection = contexts.get(0).getProjection();
    assertEquals(1, projection.size());
    assertEquals(TestPropertyNames.TRANSIENT_1, projection.get(0));
    assertTrue(contexts.get(0).getFunction() instanceof ExampleTransformFunction);
    final ElementFilter postFilter = edge.getPostTransformFilter();
    assertNotNull(postFilter);
    final List<ConsumerFunctionContext<String, FilterFunction>> filterContexts = postFilter.getFunctions();
    assertEquals(1, contexts.size());
    final List<String> postFilterSelection = filterContexts.get(0).getSelection();
    assertEquals(1, postFilterSelection.size());
    assertEquals(TestPropertyNames.TRANSIENT_1, postFilterSelection.get(0));
    assertTrue(filterContexts.get(0).getFunction() instanceof ExampleFilterFunction);
}
Also used : ConsumerProducerFunctionContext(uk.gov.gchq.gaffer.function.context.ConsumerProducerFunctionContext) ConsumerFunctionContext(uk.gov.gchq.gaffer.function.context.ConsumerFunctionContext) ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) ExampleFilterFunction(uk.gov.gchq.gaffer.function.ExampleFilterFunction) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ExampleTransformFunction(uk.gov.gchq.gaffer.function.ExampleTransformFunction) Test(org.junit.Test)

Example 2 with ConsumerProducerFunctionContext

use of uk.gov.gchq.gaffer.function.context.ConsumerProducerFunctionContext in project Gaffer by gchq.

the class Transformer method cloneFunctions.

/**
     * Create a deep copy of the {@link uk.gov.gchq.gaffer.function.context.ConsumerProducerFunctionContext}s executed by this
     * <code>Transformer</code>.
     *
     * @return Deep copy of {@link uk.gov.gchq.gaffer.function.context.ConsumerProducerFunctionContext}s.
     */
protected List<ConsumerProducerFunctionContext<R, TransformFunction>> cloneFunctions() {
    final List<ConsumerProducerFunctionContext<R, TransformFunction>> functionClones = new ArrayList<>();
    for (final ConsumerProducerFunctionContext<R, TransformFunction> function : functions) {
        ConsumerProducerFunctionContext<R, TransformFunction> cloneContext = new ConsumerProducerFunctionContext<>();
        cloneContext.setSelection(function.getSelection());
        cloneContext.setProjection(function.getProjection());
        TransformFunction af = function.getFunction();
        if (af != null) {
            cloneContext.setFunction(af.statelessClone());
        }
        functionClones.add(cloneContext);
    }
    return functionClones;
}
Also used : ConsumerProducerFunctionContext(uk.gov.gchq.gaffer.function.context.ConsumerProducerFunctionContext) TransformFunction(uk.gov.gchq.gaffer.function.TransformFunction) ArrayList(java.util.ArrayList)

Aggregations

ConsumerProducerFunctionContext (uk.gov.gchq.gaffer.function.context.ConsumerProducerFunctionContext)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)1 ElementTransformer (uk.gov.gchq.gaffer.data.element.function.ElementTransformer)1 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)1 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)1 ExampleFilterFunction (uk.gov.gchq.gaffer.function.ExampleFilterFunction)1 ExampleTransformFunction (uk.gov.gchq.gaffer.function.ExampleTransformFunction)1 TransformFunction (uk.gov.gchq.gaffer.function.TransformFunction)1 ConsumerFunctionContext (uk.gov.gchq.gaffer.function.context.ConsumerFunctionContext)1