Search in sources :

Example 1 with EdgeDomainObject

use of uk.gov.gchq.gaffer.integration.domain.EdgeDomainObject in project Gaffer by gchq.

the class GeneratorsIT method shouldConvertFromDomainObjects.

@Test
public void shouldConvertFromDomainObjects() throws OperationException, UnsupportedEncodingException {
    // Given
    final OperationChain<Void> opChain = new OperationChain.Builder().first(new GenerateElements.Builder<DomainObject>().generator(new BasicGenerator()).objects(Arrays.asList(new EntityDomainObject(NEW_VERTEX, "1", null), new EdgeDomainObject(NEW_SOURCE, NEW_DEST, false, 1, 1L))).build()).then(new AddElements()).build();
    // When - add
    graph.execute(opChain, getUser());
    // Then - check they were added correctly
    final List<Element> results = Lists.newArrayList(graph.execute(new GetElements.Builder<>().addSeed(new EntitySeed(NEW_VERTEX)).addSeed(new EdgeSeed(NEW_SOURCE, NEW_DEST, false)).build(), getUser()));
    final Edge expectedEdge = new Edge(TestGroups.EDGE, NEW_SOURCE, NEW_DEST, false);
    expectedEdge.putProperty(TestPropertyNames.INT, 1);
    expectedEdge.putProperty(TestPropertyNames.COUNT, 1L);
    final Entity expectedEntity = new Entity(TestGroups.ENTITY, NEW_VERTEX);
    expectedEntity.putProperty(TestPropertyNames.STRING, "1");
    assertNotNull(results);
    assertEquals(2, results.size());
    assertThat(results, IsCollectionContaining.hasItems(expectedEntity, expectedEdge));
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Entity(uk.gov.gchq.gaffer.data.element.Entity) BasicGenerator(uk.gov.gchq.gaffer.integration.generators.BasicGenerator) Element(uk.gov.gchq.gaffer.data.element.Element) EntityDomainObject(uk.gov.gchq.gaffer.integration.domain.EntityDomainObject) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) EdgeDomainObject(uk.gov.gchq.gaffer.integration.domain.EdgeDomainObject) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test)

Example 2 with EdgeDomainObject

use of uk.gov.gchq.gaffer.integration.domain.EdgeDomainObject in project Gaffer by gchq.

the class GeneratorsIT method shouldConvertToDomainObjects.

@Test
public void shouldConvertToDomainObjects() throws OperationException, UnsupportedEncodingException {
    // Given
    final OperationChain<CloseableIterable<DomainObject>> opChain = new OperationChain.Builder().first(new GetElements.Builder<>().addSeed(new EntitySeed(SOURCE_1)).build()).then(new GenerateObjects.Builder<Element, DomainObject>().generator(new BasicGenerator()).outputType(new TypeReference<CloseableIterable<DomainObject>>() {
    }).build()).build();
    // When
    final List<DomainObject> results = Lists.newArrayList(graph.execute(opChain, getUser()));
    final EntityDomainObject entityDomainObject = new EntityDomainObject(SOURCE_1, "3", null);
    final EdgeDomainObject edgeDomainObject = new EdgeDomainObject(SOURCE_1, DEST_1, false, 1, 1L);
    // Then
    assertNotNull(results);
    assertEquals(2, results.size());
    assertThat(results, IsCollectionContaining.hasItems(entityDomainObject, edgeDomainObject));
}
Also used : BasicGenerator(uk.gov.gchq.gaffer.integration.generators.BasicGenerator) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Element(uk.gov.gchq.gaffer.data.element.Element) EntityDomainObject(uk.gov.gchq.gaffer.integration.domain.EntityDomainObject) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) EdgeDomainObject(uk.gov.gchq.gaffer.integration.domain.EdgeDomainObject) GenerateObjects(uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) EdgeDomainObject(uk.gov.gchq.gaffer.integration.domain.EdgeDomainObject) DomainObject(uk.gov.gchq.gaffer.integration.domain.DomainObject) EntityDomainObject(uk.gov.gchq.gaffer.integration.domain.EntityDomainObject) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 3 with EdgeDomainObject

use of uk.gov.gchq.gaffer.integration.domain.EdgeDomainObject in project Gaffer by gchq.

the class BasicEdgeGenerator method getObject.

@Override
public EdgeDomainObject getObject(final Element element) {
    if (element instanceof Edge) {
        final Edge edge = ((Edge) element);
        final EdgeDomainObject basicEdge = new EdgeDomainObject();
        basicEdge.setSource((String) edge.getSource());
        basicEdge.setDestination((String) edge.getDestination());
        basicEdge.setDirected(edge.isDirected());
        basicEdge.setCount((Long) edge.getProperty(TestPropertyNames.COUNT));
        basicEdge.setIntProperty((Integer) edge.getProperty(TestPropertyNames.INT));
        return basicEdge;
    }
    throw new IllegalArgumentException("Entities cannot be handled with this generator.");
}
Also used : Edge(uk.gov.gchq.gaffer.data.element.Edge) EdgeDomainObject(uk.gov.gchq.gaffer.integration.domain.EdgeDomainObject)

Aggregations

EdgeDomainObject (uk.gov.gchq.gaffer.integration.domain.EdgeDomainObject)3 Test (org.junit.Test)2 Edge (uk.gov.gchq.gaffer.data.element.Edge)2 Element (uk.gov.gchq.gaffer.data.element.Element)2 EntityDomainObject (uk.gov.gchq.gaffer.integration.domain.EntityDomainObject)2 BasicGenerator (uk.gov.gchq.gaffer.integration.generators.BasicGenerator)2 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)2 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)2 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)1 Entity (uk.gov.gchq.gaffer.data.element.Entity)1 DomainObject (uk.gov.gchq.gaffer.integration.domain.DomainObject)1 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)1 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)1 GenerateObjects (uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects)1