Search in sources :

Example 56 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class AccumuloAggregationIT method shouldAggregateOverAllPropertiesExceptForGroupByProperties.

@Test
public void shouldAggregateOverAllPropertiesExceptForGroupByProperties() throws OperationException, UnsupportedEncodingException {
    final Graph graph = createGraph();
    final Entity entity1 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "some value").property(AccumuloPropertyNames.COLUMN_QUALIFIER_2, "some value 2").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "some value 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "some value 4").property(AccumuloPropertyNames.VISIBILITY, PUBLIC_VISIBILITY).build();
    final Entity entity2 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "some value").property(AccumuloPropertyNames.COLUMN_QUALIFIER_2, "some value 2b").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "some value 3b").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "some value 4b").property(AccumuloPropertyNames.VISIBILITY, PRIVATE_VISIBILITY).build();
    final Entity entity3 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "some value c").property(AccumuloPropertyNames.COLUMN_QUALIFIER_2, "some value 2c").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "some value 3c").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "some value 4c").property(AccumuloPropertyNames.VISIBILITY, PRIVATE_VISIBILITY).build();
    graph.execute(new AddElements(Arrays.asList((Element) entity1, entity2, entity3)), USER);
    // Given
    final GetEntities<EntitySeed> getElements = new GetEntities.Builder<EntitySeed>().addSeed(new EntitySeed(VERTEX)).view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().groupBy(AccumuloPropertyNames.COLUMN_QUALIFIER).build()).build()).build();
    // When
    final List<Entity> results = Lists.newArrayList(graph.execute(getElements, USER));
    // Then
    assertNotNull(results);
    assertEquals(2, results.size());
    final Entity expectedEntity = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "some value").property(AccumuloPropertyNames.COLUMN_QUALIFIER_2, "some value 2,some value 2b").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "some value 3,some value 3b").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "some value 4,some value 4b").property(AccumuloPropertyNames.VISIBILITY, PUBLIC_VISIBILITY + "," + PRIVATE_VISIBILITY).build();
    assertThat(results, IsCollectionContaining.hasItems(expectedEntity, entity3));
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Entity(uk.gov.gchq.gaffer.data.element.Entity) Graph(uk.gov.gchq.gaffer.graph.Graph) Builder(uk.gov.gchq.gaffer.graph.Graph.Builder) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetEntities(uk.gov.gchq.gaffer.operation.impl.get.GetEntities) Test(org.junit.Test)

Example 57 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class StoreTest method shouldThrowExceptionIfOperationViewIsInvalid.

@Test
public void shouldThrowExceptionIfOperationViewIsInvalid() throws OperationException, StoreException {
    // Given
    // Given
    final Schema schema = createSchemaMock();
    final StoreProperties properties = mock(StoreProperties.class);
    final AddElements addElements = new AddElements();
    final View view = mock(View.class);
    final ViewValidator viewValidator = mock(ViewValidator.class);
    final StoreImpl store = new StoreImpl(viewValidator);
    addElements.setView(view);
    given(schema.validate()).willReturn(true);
    given(viewValidator.validate(view, schema, true)).willReturn(false);
    store.initialise(schema, properties);
    // When / Then
    try {
        store.execute(addElements, user);
        fail("Exception expected");
    } catch (final SchemaException e) {
        verify(viewValidator).validate(view, schema, true);
        assertTrue(e.getMessage().contains("View"));
    }
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) ViewValidator(uk.gov.gchq.gaffer.store.schema.ViewValidator) Schema(uk.gov.gchq.gaffer.store.schema.Schema) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.Test)

Example 58 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class StoreTest method shouldCreateStoreWithValidSchemasAndRegisterOperations.

@Test
public void shouldCreateStoreWithValidSchemasAndRegisterOperations() throws StoreException {
    // Given
    final StoreProperties properties = mock(StoreProperties.class);
    final StoreImpl store = new StoreImpl();
    final OperationHandler<AddElements, Void> addElementsHandlerOverridden = mock(OperationHandler.class);
    final OperationDeclarations opDeclarations = new OperationDeclarations.Builder().declaration(new OperationDeclaration.Builder().operation(AddElements.class).handler(addElementsHandlerOverridden).build()).build();
    given(properties.getOperationDeclarations()).willReturn(opDeclarations);
    // When
    store.initialise(schema, properties);
    // Then
    assertNotNull(store.getOperationHandlerExposed(Validate.class));
    assertSame(addElementsHandlerOverridden, store.getOperationHandlerExposed(AddElements.class));
    assertSame(getAllElementsHandler, store.getOperationHandlerExposed(GetAllElements.class));
    assertSame(getAllElementsHandler, store.getOperationHandlerExposed(GetAllEntities.class));
    assertSame(getAllElementsHandler, store.getOperationHandlerExposed(GetAllEdges.class));
    assertTrue(store.getOperationHandlerExposed(GenerateElements.class) instanceof GenerateElementsHandler);
    assertTrue(store.getOperationHandlerExposed(GenerateObjects.class) instanceof GenerateObjectsHandler);
    assertTrue(store.getOperationHandlerExposed(CountGroups.class) instanceof CountGroupsHandler);
    assertTrue(store.getOperationHandlerExposed(Deduplicate.class) instanceof DeduplicateHandler);
    assertTrue(store.getOperationHandlerExposed(ExportToSet.class) instanceof ExportToSetHandler);
    assertTrue(store.getOperationHandlerExposed(GetSetExport.class) instanceof GetSetExportHandler);
    assertEquals(1, store.getCreateOperationHandlersCallCount());
    assertSame(schema, store.getSchema());
    assertSame(properties, store.getProperties());
    verify(schemaOptimiser).optimise(schema, true);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) GetAllEntities(uk.gov.gchq.gaffer.operation.impl.get.GetAllEntities) CountGroupsHandler(uk.gov.gchq.gaffer.store.operation.handler.CountGroupsHandler) GenerateObjectsHandler(uk.gov.gchq.gaffer.store.operation.handler.generate.GenerateObjectsHandler) OperationDeclaration(uk.gov.gchq.gaffer.store.operationdeclaration.OperationDeclaration) ExportToSetHandler(uk.gov.gchq.gaffer.store.operation.handler.export.set.ExportToSetHandler) GetSetExportHandler(uk.gov.gchq.gaffer.store.operation.handler.export.set.GetSetExportHandler) DeduplicateHandler(uk.gov.gchq.gaffer.store.operation.handler.DeduplicateHandler) Validate(uk.gov.gchq.gaffer.operation.impl.Validate) GetAllEdges(uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) GenerateElementsHandler(uk.gov.gchq.gaffer.store.operation.handler.generate.GenerateElementsHandler) OperationDeclarations(uk.gov.gchq.gaffer.store.operationdeclaration.OperationDeclarations) Test(org.junit.Test)

Example 59 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class StoreTest method shouldHandleMultiStepOperations.

@Test
public void shouldHandleMultiStepOperations() throws Exception {
    // Given
    final Schema schema = createSchemaMock();
    final StoreProperties properties = mock(StoreProperties.class);
    final StoreImpl store = new StoreImpl();
    final CloseableIterable<Element> getElementsResult = mock(CloseableIterable.class);
    final AddElements addElements1 = new AddElements();
    final GetElements<ElementSeed, Element> getElements = new GetElements<>();
    final OperationChain<CloseableIterable<Element>> opChain = new OperationChain.Builder().first(addElements1).then(getElements).build();
    given(addElementsHandler.doOperation(addElements1, context, store)).willReturn(null);
    given(getElementsHandler.doOperation(getElements, context, store)).willReturn(getElementsResult);
    store.initialise(schema, properties);
    // When
    final CloseableIterable<Element> result = store.execute(opChain, user);
    // Then
    assertSame(getElementsResult, result);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) Test(org.junit.Test)

Example 60 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class GetElementsinRangesHandlerTest method setupGraph.

private static void setupGraph(final AccumuloStore store, final int numEntries) {
    final List<Element> elements = new ArrayList<>();
    for (int i = 0; i < numEntries; i++) {
        String s = "" + i;
        while (s.length() < 4) {
            s = "0" + s;
        }
        final Edge edge = new Edge(TestGroups.EDGE);
        edge.setSource(s);
        edge.putProperty(AccumuloPropertyNames.COLUMN_QUALIFIER, 1);
        edge.setDestination("B");
        edge.setDirected(true);
        elements.add(edge);
        final Edge edge2 = new Edge(TestGroups.EDGE);
        edge2.setSource(s);
        edge2.putProperty(AccumuloPropertyNames.COLUMN_QUALIFIER, 3);
        edge2.setDestination("B");
        edge2.setDirected(true);
        elements.add(edge2);
        final Edge edge3 = new Edge(TestGroups.EDGE);
        edge3.setSource(s);
        edge3.putProperty(AccumuloPropertyNames.COLUMN_QUALIFIER, 5);
        edge3.setDestination("B");
        edge3.setDirected(true);
        elements.add(edge3);
    }
    try {
        store.execute(new AddElements(elements), user);
    } catch (OperationException e) {
        fail("Couldn't add element: " + e);
    }
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) Edge(uk.gov.gchq.gaffer.data.element.Edge) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Aggregations

AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)64 Test (org.junit.Test)38 User (uk.gov.gchq.gaffer.user.User)36 Graph (uk.gov.gchq.gaffer.graph.Graph)35 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)31 Element (uk.gov.gchq.gaffer.data.element.Element)30 Edge (uk.gov.gchq.gaffer.data.element.Edge)29 Entity (uk.gov.gchq.gaffer.data.element.Entity)28 ArrayList (java.util.ArrayList)17 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)17 HashSet (java.util.HashSet)13 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)12 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)9 GetEntities (uk.gov.gchq.gaffer.operation.impl.get.GetEntities)8 Builder (uk.gov.gchq.gaffer.graph.Graph.Builder)7 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)7 JSONSerialiser (uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser)7 DataOutputStream (java.io.DataOutputStream)6 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)6 Configuration (org.apache.hadoop.conf.Configuration)6