Search in sources :

Example 1 with GetAdjacentEntitySeeds

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

the class OperationChainLimiterTest method shouldRejectOperationChainWhenUserHasAuthScoreLessThanChainScore.

@Test
public void shouldRejectOperationChainWhenUserHasAuthScoreLessThanChainScore() {
    // Given
    final OperationChain opChain = new OperationChain.Builder().first(new GetAdjacentEntitySeeds()).then(new GetAdjacentEntitySeeds()).then(new GetAdjacentEntitySeeds()).then(new GetAdjacentEntitySeeds()).then(new GenerateObjects()).build();
    final User user = new User.Builder().opAuths("User").build();
    try {
        OPERATION_CHAIN_LIMITER.preExecute(opChain, user);
        fail("Exception expected");
    } catch (final UnauthorisedException e) {
        assertNotNull(e.getMessage());
    }
}
Also used : GenerateObjects(uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects) GetAdjacentEntitySeeds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentEntitySeeds) User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) UnauthorisedException(uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException) Test(org.junit.Test)

Example 2 with GetAdjacentEntitySeeds

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

the class OperationAuthoriserTest method shouldAcceptOperationChainWhenUserHasAllOpAuths.

@Test
public void shouldAcceptOperationChainWhenUserHasAllOpAuths() {
    // Given
    final OperationAuthoriser opAuthoriser = new OperationAuthoriser(StreamUtil.opAuths(getClass()));
    final OperationChain opChain = new OperationChain.Builder().first(new GetAdjacentEntitySeeds()).then(new GenerateObjects()).build();
    final User user = new User.Builder().opAuths("SuperUser", "ReadUser", "User").build();
    // When
    opAuthoriser.preExecute(opChain, user);
// Then - no exceptions
}
Also used : GenerateObjects(uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects) GetAdjacentEntitySeeds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentEntitySeeds) User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Test(org.junit.Test)

Example 3 with GetAdjacentEntitySeeds

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

the class ExamplesService method getAdjacentEntitySeeds.

@Override
public GetAdjacentEntitySeeds getAdjacentEntitySeeds() {
    final GetAdjacentEntitySeeds op = new GetAdjacentEntitySeeds();
    final List<EntitySeed> seeds = new ArrayList<>();
    if (hasEntities()) {
        seeds.add(getEntitySeed(1));
    } else if (hasEdges()) {
        seeds.add(new EntitySeed(getEdgeSeed(1, 2).getSource()));
    }
    op.setSeeds(seeds);
    populateOperation(op);
    return op;
}
Also used : GetAdjacentEntitySeeds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentEntitySeeds) ArrayList(java.util.ArrayList) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed)

Example 4 with GetAdjacentEntitySeeds

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

the class LoadAndQuery6 method run.

public CloseableIterable<String> run() throws OperationException {
    // [user] Create a user
    // ---------------------------------------------------------
    final User user = new User("user01");
    // ---------------------------------------------------------
    // [graph] create a graph using our schema and store properties
    // ---------------------------------------------------------
    final Graph graph = new Graph.Builder().addSchemas(getSchemas()).storeProperties(getStoreProperties()).build();
    // ---------------------------------------------------------
    // [add] Create a data generator and add the edges to the graph using an operation chain consisting of:
    // generateElements - generating edges from the data (note these are directed edges)
    // addElements - add the edges to the graph
    // ---------------------------------------------------------
    final DataGenerator6 dataGenerator = new DataGenerator6();
    final List<String> data = DataUtils.loadData(getData());
    final OperationChain addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(dataGenerator).objects(data).build()).then(new AddElements()).build();
    graph.execute(addOpChain, user);
    // ---------------------------------------------------------
    // [get] Create and execute an operation chain consisting of 3 operations:
    //GetAdjacentEntitySeeds - starting at vertex 1 get all adjacent vertices (vertices at other end of outbound edges)
    //GetRelatedEdges - get outbound edges
    //GenerateObjects - convert the edges back into comma separated strings
    // ---------------------------------------------------------
    final OperationChain<CloseableIterable<String>> opChain = new OperationChain.Builder().first(new GetAdjacentEntitySeeds.Builder().addSeed(new EntitySeed("1")).inOutType(IncludeIncomingOutgoingType.OUTGOING).build()).then(new GetEdges.Builder<EntitySeed>().inOutType(IncludeIncomingOutgoingType.OUTGOING).build()).then(new GenerateObjects.Builder<Edge, String>().generator(dataGenerator).build()).build();
    final CloseableIterable<String> results = graph.execute(opChain, user);
    // ---------------------------------------------------------
    log("\nFiltered edges converted back into comma separated strings. The counts have been aggregated\n");
    for (final String result : results) {
        log("RESULT", result);
    }
    return results;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) GetAdjacentEntitySeeds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentEntitySeeds) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) DataGenerator6(uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator6) Graph(uk.gov.gchq.gaffer.graph.Graph) GetEdges(uk.gov.gchq.gaffer.operation.impl.get.GetEdges) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed)

Example 5 with GetAdjacentEntitySeeds

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

the class OperationAuthoriserTest method shouldRejectOperationChainWhenUserDoesntHaveAllowedAuth.

@Test
public void shouldRejectOperationChainWhenUserDoesntHaveAllowedAuth() throws OperationException {
    // Given
    final OperationAuthoriser opAuthoriser = new OperationAuthoriser(StreamUtil.opAuths(getClass()));
    final OperationChain opChain = new OperationChain.Builder().first(new GetAdjacentEntitySeeds()).then(new GetElements()).build();
    final User user = new User.Builder().opAuths("unknownAuth").build();
    // When/Then
    try {
        opAuthoriser.preExecute(opChain, user);
        fail("Exception expected");
    } catch (final UnauthorisedException e) {
        assertNotNull(e.getMessage());
    }
}
Also used : GetAdjacentEntitySeeds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentEntitySeeds) User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) UnauthorisedException(uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException) Test(org.junit.Test)

Aggregations

GetAdjacentEntitySeeds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentEntitySeeds)13 Test (org.junit.Test)10 User (uk.gov.gchq.gaffer.user.User)9 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)8 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)5 GenerateObjects (uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects)5 UnauthorisedException (uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException)4 Builder (uk.gov.gchq.gaffer.operation.OperationChain.Builder)3 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)3 ArrayList (java.util.ArrayList)2 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)2 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)2 Element (uk.gov.gchq.gaffer.data.element.Element)1 DataGenerator6 (uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator6)1 Graph (uk.gov.gchq.gaffer.graph.Graph)1 GetEdges (uk.gov.gchq.gaffer.operation.impl.get.GetEdges)1