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());
}
}
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
}
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;
}
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;
}
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());
}
}
Aggregations