Search in sources :

Example 91 with GetElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.

the class AggregatorIteratorTest method test.

private void test(final AccumuloStore store) throws OperationException {
    // Given
    final Edge expectedResult = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("2").directed(true).property(AccumuloPropertyNames.COUNT, 13).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 1).property(AccumuloPropertyNames.PROP_4, 1).build();
    final Edge edge1 = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("2").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.COUNT, 1).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 1).property(AccumuloPropertyNames.PROP_4, 0).build();
    final Edge edge2 = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("2").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.COUNT, 2).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 1).build();
    final Edge edge3 = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("2").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.COUNT, 10).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 0).build();
    final User user = new User();
    store.execute(new AddElements.Builder().input(edge1, edge2, edge3).build(), new Context(user));
    final GetElements get = new GetElements.Builder().view(new View.Builder().edge(TestGroups.EDGE).build()).input(new EntitySeed("1")).build();
    // When
    final List<Element> results = Lists.newArrayList(store.execute(get, new Context(user)));
    // Then
    assertThat(results).hasSize(1);
    final Edge aggregatedEdge = (Edge) results.get(0);
    assertEquals(expectedResult, aggregatedEdge);
    assertEquals(expectedResult.getProperties(), aggregatedEdge.getProperties());
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Example 92 with GetElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.

the class AccumuloStoreTest method testAbleToInsertAndRetrieveEntityQueryingEqualAndRelated.

private void testAbleToInsertAndRetrieveEntityQueryingEqualAndRelated(final AccumuloStore store) throws OperationException {
    final Entity e = new Entity(TestGroups.ENTITY, "1");
    e.putProperty(TestPropertyNames.PROP_1, 1);
    e.putProperty(TestPropertyNames.PROP_2, 2);
    e.putProperty(TestPropertyNames.PROP_3, 3);
    e.putProperty(TestPropertyNames.PROP_4, 4);
    e.putProperty(TestPropertyNames.COUNT, 1);
    final User user = new User();
    final AddElements add = new AddElements.Builder().input(e).build();
    store.execute(add, new Context(user));
    final EntityId entityId1 = new EntitySeed("1");
    final GetElements getBySeed = new GetElements.Builder().view(new View.Builder().entity(TestGroups.ENTITY).build()).input(entityId1).build();
    CloseableIterable<? extends Element> results = null;
    try {
        results = store.execute(getBySeed, new Context(user));
        assertEquals(1, Iterables.size(results));
        assertTrue(Iterables.contains(results, e));
    } finally {
        if (results != null) {
            results.close();
        }
    }
    final GetElements getRelated = new GetElements.Builder().view(new View.Builder().entity(TestGroups.ENTITY).build()).input(entityId1).build();
    CloseableIterable<? extends Element> relatedResults = null;
    try {
        relatedResults = store.execute(getRelated, store.createContext(user));
        assertEquals(1, Iterables.size(relatedResults));
        assertTrue(Iterables.contains(relatedResults, e));
        final GetElements getRelatedWithPostAggregationFilter = new GetElements.Builder().view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.PROP_1).execute(new IsMoreThan(0)).build()).postAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.COUNT).execute(new IsMoreThan(6)).build()).build()).build()).input(entityId1).build();
        relatedResults = store.execute(getRelatedWithPostAggregationFilter, store.createContext(user));
        assertEquals(0, Iterables.size(relatedResults));
    } finally {
        if (relatedResults != null) {
            relatedResults.close();
        }
    }
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Context(uk.gov.gchq.gaffer.store.Context) Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)

Example 93 with GetElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.

the class InputFormatTest method shouldReturnCorrectDataToMapReduceJobWithView.

@Test
public void shouldReturnCorrectDataToMapReduceJobWithView() throws Exception {
    final Schema schema = getSchema();
    final GetElements op = new GetElements.Builder().view(new View.Builder().edge(TestGroups.EDGE).build()).build();
    final Set<String> expectedResults = new HashSet<>();
    for (final Element element : DATA) {
        if (element.getGroup().equals(TestGroups.EDGE)) {
            expectedResults.add(getJsonString(element));
        }
    }
    shouldReturnCorrectDataToMapReduceJob(schema, KeyPackage.BYTE_ENTITY_KEY_PACKAGE, DATA, op, new User(), "instance3", expectedResults, tempDir.resolve(UUID.randomUUID().toString()));
    shouldReturnCorrectDataToMapReduceJob(schema, KeyPackage.CLASSIC_KEY_PACKAGE, DATA, op, new User(), "instance4", expectedResults, tempDir.resolve(UUID.randomUUID().toString()));
}
Also used : User(uk.gov.gchq.gaffer.user.User) 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) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 94 with GetElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.

the class InputFormatTest method shouldReturnCorrectDataToMapReduceJobRespectingAuthorizations.

@Test
public void shouldReturnCorrectDataToMapReduceJobRespectingAuthorizations() throws Exception {
    final Schema schema = getSchemaWithVisibilities();
    final GetElements op = new GetElements.Builder().view(new View()).build();
    final Set<String> expectedResultsPublicNotPrivate = new HashSet<>();
    final Set<String> expectedResultsPrivate = new HashSet<>();
    for (final Element element : DATA_WITH_VISIBILITIES) {
        expectedResultsPrivate.add(getJsonString(element));
        if (element.getProperty("visibility").equals("public")) {
            expectedResultsPublicNotPrivate.add(getJsonString(element));
        }
    }
    final Set<String> privateAuth = new HashSet<>();
    privateAuth.add("public");
    privateAuth.add("private");
    final Set<String> publicNotPrivate = new HashSet<>();
    publicNotPrivate.add("public");
    final User userWithPrivate = new User("user1", privateAuth);
    final User userWithPublicNotPrivate = new User("user1", publicNotPrivate);
    shouldReturnCorrectDataToMapReduceJob(schema, KeyPackage.BYTE_ENTITY_KEY_PACKAGE, DATA_WITH_VISIBILITIES, op, userWithPublicNotPrivate, "instance5", expectedResultsPublicNotPrivate, tempDir.resolve(UUID.randomUUID().toString()));
    shouldReturnCorrectDataToMapReduceJob(schema, KeyPackage.BYTE_ENTITY_KEY_PACKAGE, DATA_WITH_VISIBILITIES, op, userWithPrivate, "instance6", expectedResultsPrivate, tempDir.resolve(UUID.randomUUID().toString()));
    shouldReturnCorrectDataToMapReduceJob(schema, KeyPackage.CLASSIC_KEY_PACKAGE, DATA_WITH_VISIBILITIES, op, userWithPublicNotPrivate, "instance7", expectedResultsPublicNotPrivate, tempDir.resolve(UUID.randomUUID().toString()));
    shouldReturnCorrectDataToMapReduceJob(schema, KeyPackage.CLASSIC_KEY_PACKAGE, DATA_WITH_VISIBILITIES, op, userWithPrivate, "instance8", expectedResultsPrivate, tempDir.resolve(UUID.randomUUID().toString()));
}
Also used : User(uk.gov.gchq.gaffer.user.User) 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) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 95 with GetElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.

the class InputFormatTest method shouldReturnCorrectDataToMapReduceJob.

@Test
public void shouldReturnCorrectDataToMapReduceJob() throws Exception {
    final GetElements op = new GetElements.Builder().view(new View()).build();
    final Set<String> expectedResults = new HashSet<>();
    for (final Element element : DATA) {
        expectedResults.add(getJsonString(element));
    }
    shouldReturnCorrectDataToMapReduceJob(getSchema(), KeyPackage.CLASSIC_KEY_PACKAGE, DATA, op, new User(), "instance1", expectedResults, tempDir.resolve(UUID.randomUUID().toString()));
    shouldReturnCorrectDataToMapReduceJob(getSchema(), KeyPackage.BYTE_ENTITY_KEY_PACKAGE, DATA, op, new User(), "instance2", expectedResults, tempDir.resolve(UUID.randomUUID().toString()));
}
Also used : User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)256 Test (org.junit.jupiter.api.Test)153 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)112 User (uk.gov.gchq.gaffer.user.User)102 Element (uk.gov.gchq.gaffer.data.element.Element)91 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)84 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)83 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)67 Context (uk.gov.gchq.gaffer.store.Context)60 Test (org.junit.Test)56 HashSet (java.util.HashSet)52 Graph (uk.gov.gchq.gaffer.graph.Graph)49 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)46 Entity (uk.gov.gchq.gaffer.data.element.Entity)42 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)38 Operation (uk.gov.gchq.gaffer.operation.Operation)35 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)35 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)34 Edge (uk.gov.gchq.gaffer.data.element.Edge)32 ArrayList (java.util.ArrayList)31