lundi 3 août 2015

Tinkerpop Typed Graph returns all adjacencies instead of ones of type

I've created a typed graph. When I try to get adjacent vertices, all are returned instead of only ones of the specified type. Here's the code for the company:

public interface Company extends VertexFrame {

    @Adjacency(label = "has", direction = Direction.OUT)
    void addAddress(Address address);
    @Adjacency(label = "has", direction = Direction.OUT)
    void removeAddress(Address address);
    @Adjacency(label = "has", direction = Direction.OUT)
    Iterable<Address> getAddresses();

    @Adjacency(label = "has", direction = Direction.OUT)
    void addPhone(Phone phone);
    @Adjacency(label = "has", direction = Direction.OUT)
    void removePhone(Phone phone);
    @Adjacency(label = "has", direction = Direction.OUT)
    Iterable<Phone> getPhones();

    ...
}

Both address and phone are types of information:

@TypeField("type")
public interface Information extends VertexFrame {
    ...
}
@TypeValue("text")
public interface Address extends Information {
    ...
}
@TypeValue("text")
public interface Phone extends Information {
    ...
}

I'm testing this out using a simple in-memory graph:

private Graph graph = new TinkerGraph();
private FramedGraphFactory factory = new FramedGraphFactory(
        new TypedGraphModuleBuilder()
                .withClass(Address.class)
                .withClass(Phone.class)
                .build()
);
this.framedGraph = this.factory.create(this.graph);

And here's the test that I'm working with:

@Test
public void testCompany() {
    Address a = this.framedGraph.addVertex(null, Address.class);
    c.addAddress(a);
    Phone p = this.framedGraph.addVertex(null, Phone.class);
    c.addPhone(p);
    assertEquals(c.getAddresses().iterator().next(), a);
    assertEquals(c.getPhones().iterator().next(), p);
}

The second assertEquals is failing because c.getPhones() is returning an iterator of all adjacent vertices with a 'has' relationship instead of just adjacent Phones with a 'has' relationship. How can I remedy this?

Aucun commentaire:

Enregistrer un commentaire