Search in sources :

Example 81 with User

use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.

the class AccumuloSingleIDRetrieverTest method testEntityIdQueryEntitiesOnly.

private void testEntityIdQueryEntitiesOnly(final AccumuloStore store) throws StoreException {
    setupGraph(store, NUM_ENTRIES);
    final User user = new User();
    // Create set to query for
    final Set<ElementId> ids = new HashSet<>();
    for (int i = 0; i < NUM_ENTRIES; i++) {
        ids.add(new EntitySeed("" + i));
    }
    final View view = new View.Builder().entity(TestGroups.ENTITY).build();
    AccumuloSingleIDRetriever retriever = null;
    final GetElements operation = new GetElements.Builder().view(view).input(ids).build();
    try {
        retriever = new AccumuloSingleIDRetriever(store, operation, user);
    } catch (final IteratorSettingException e) {
        throw new RuntimeException(e);
    }
    // Should find only the entities i
    assertEquals(NUM_ENTRIES, Iterables.size(retriever));
}
Also used : User(uk.gov.gchq.gaffer.user.User) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) IteratorSettingException(uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) HashSet(java.util.HashSet)

Example 82 with User

use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.

the class CreateSplitPointsTest method shouldAddElementsFromHdfs.

@Test
public void shouldAddElementsFromHdfs() throws Exception {
    // Given
    createInputFile();
    final SingleUseAccumuloStoreWithTabletServers store = new SingleUseAccumuloStoreWithTabletServers();
    store.initialise("graphId1", Schema.fromJson(StreamUtil.schemas(getClass())), PROPERTIES);
    final Graph graph = new Graph.Builder().store(store).build();
    // When
    graph.execute(new OperationChain.Builder().first(new SampleDataForSplitPoints.Builder().jobInitialiser(new TextJobInitialiser()).addInputMapperPair(inputDir, TextMapperGeneratorImpl.class.getName()).outputPath(outputDir).proportionToSample(1f).validate(true).mappers(5).splitsFilePath(splitsFile).compressionCodec(null).build()).then(new SplitStoreFromFile.Builder().inputPath(splitsFile).build()).build(), new User());
    // Then
    final List<Text> splitsOnTable = Lists.newArrayList(store.getConnection().tableOperations().listSplits(store.getTableName(), 10));
    final List<String> stringSplitsOnTable = Lists.transform(splitsOnTable, t -> StringUtil.toString(t.getBytes()));
    final List<String> fileSplitsDecoded = new ArrayList<>();
    BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(new Path(splitsFile))));
    while (br.ready()) {
        fileSplitsDecoded.add(new String(Base64.decodeBase64(br.readLine())));
    }
    assertThat(stringSplitsOnTable).isEqualTo(fileSplitsDecoded);
    assertThat(splitsOnTable).hasSize(2);
    assertThat(stringSplitsOnTable.get(0)).isEqualTo(VERTEX_ID_PREFIX + "53\u0000\u0001");
    assertThat(stringSplitsOnTable.get(1)).isEqualTo(VERTEX_ID_PREFIX + "99\u0000\u0001");
}
Also used : Path(org.apache.hadoop.fs.Path) User(uk.gov.gchq.gaffer.user.User) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) SplitStoreFromFile(uk.gov.gchq.gaffer.operation.impl.SplitStoreFromFile) Graph(uk.gov.gchq.gaffer.graph.Graph) TextJobInitialiser(uk.gov.gchq.gaffer.hdfs.operation.handler.job.initialiser.TextJobInitialiser) BufferedReader(java.io.BufferedReader) SampleDataForSplitPoints(uk.gov.gchq.gaffer.hdfs.operation.SampleDataForSplitPoints) Test(org.junit.jupiter.api.Test)

Example 83 with User

use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.

the class CountAllElementsDefaultViewHandler method doOperation.

private Long doOperation(final Context context, final MapStore mapStore) {
    final User user = context.getUser();
    final Schema schema = mapStore.getSchema();
    final boolean supportsVisibility = mapStore.getTraits().contains(StoreTrait.VISIBILITY);
    Stream<Element> elementStream = Stream.concat(mapStore.getMapImpl().getAllAggElements(schema.getGroups()), mapStore.getMapImpl().getAllNonAggElements(schema.getGroups()));
    if (supportsVisibility) {
        elementStream = GetElementsUtil.applyVisibilityFilter(elementStream, schema, user);
    }
    return elementStream.count();
}
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)

Example 84 with User

use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.

the class GetElementsHandlerTest method shouldReturnHBaseRetrieverWithIncludeMatchedVertexWhenSeedMatchingIsNull.

@Test
public void shouldReturnHBaseRetrieverWithIncludeMatchedVertexWhenSeedMatchingIsNull() throws OperationException, StoreException {
    // Given
    final Iterable<EntityId> ids = mock(Iterable.class);
    final Context context = mock(Context.class);
    final User user = mock(User.class);
    final HBaseStore store = mock(HBaseStore.class);
    final HBaseRetriever<GetElements> hbaseRetriever = mock(HBaseRetriever.class);
    final GetElementsHandler handler = new GetElementsHandler();
    final GetElements getElements = new GetElements.Builder().inputIds(ids).seedMatching(null).build();
    given(context.getUser()).willReturn(user);
    given(store.createRetriever(getElements, user, ids, true)).willReturn(hbaseRetriever);
    // When
    final HBaseRetriever<GetElements> result = (HBaseRetriever<GetElements>) handler.doOperation(getElements, context, store);
    // Then
    assertSame(hbaseRetriever, result);
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) HBaseStore(uk.gov.gchq.gaffer.hbasestore.HBaseStore) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) HBaseRetriever(uk.gov.gchq.gaffer.hbasestore.retriever.HBaseRetriever) Test(org.junit.jupiter.api.Test)

Example 85 with User

use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.

the class GetElementsHandlerTest method shouldReturnHBaseRetrieverWithoutIncludeMatchdxVertex.

@Test
public void shouldReturnHBaseRetrieverWithoutIncludeMatchdxVertex() throws OperationException, StoreException {
    // Given
    final Iterable<EntityId> ids = mock(Iterable.class);
    final Context context = mock(Context.class);
    final User user = mock(User.class);
    final HBaseStore store = mock(HBaseStore.class);
    final HBaseRetriever<GetElements> hbaseRetriever = mock(HBaseRetriever.class);
    final GetElementsHandler handler = new GetElementsHandler();
    final GetElements getElements = new GetElements.Builder().inputIds(ids).seedMatching(SeedMatching.SeedMatchingType.EQUAL).build();
    given(context.getUser()).willReturn(user);
    given(store.createRetriever(getElements, user, ids, false)).willReturn(hbaseRetriever);
    // When
    final HBaseRetriever<GetElements> result = (HBaseRetriever<GetElements>) handler.doOperation(getElements, context, store);
    // Then
    assertSame(hbaseRetriever, result);
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) HBaseStore(uk.gov.gchq.gaffer.hbasestore.HBaseStore) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) HBaseRetriever(uk.gov.gchq.gaffer.hbasestore.retriever.HBaseRetriever) Test(org.junit.jupiter.api.Test)

Aggregations

User (uk.gov.gchq.gaffer.user.User)378 Test (org.junit.jupiter.api.Test)188 Graph (uk.gov.gchq.gaffer.graph.Graph)155 Element (uk.gov.gchq.gaffer.data.element.Element)143 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)128 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)110 HashSet (java.util.HashSet)109 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)104 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)103 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)98 Edge (uk.gov.gchq.gaffer.data.element.Edge)85 Context (uk.gov.gchq.gaffer.store.Context)85 Entity (uk.gov.gchq.gaffer.data.element.Entity)77 Test (org.junit.Test)61 ArrayList (java.util.ArrayList)57 OperationException (uk.gov.gchq.gaffer.operation.OperationException)52 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)49 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)48 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)45 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)43