Search in sources :

Example 1 with MetaverseLink

use of org.pentaho.dictionary.MetaverseLink in project pentaho-metaverse by pentaho.

the class MetaverseLinkTest method before.

@Before
public void before() {
    link = new MetaverseLink(fromNode, "uses", toNode);
    emptyLink = new MetaverseLink();
}
Also used : MetaverseLink(org.pentaho.dictionary.MetaverseLink) Before(org.junit.Before)

Example 2 with MetaverseLink

use of org.pentaho.dictionary.MetaverseLink in project pentaho-metaverse by pentaho.

the class BlueprintsGraphMetaverseReader method findLink.

@Override
public IMetaverseLink findLink(String leftNodeID, String linkType, String rightNodeID, Direction direction) {
    Vertex vertex = getGraph().getVertex(leftNodeID);
    if (vertex == null) {
        return null;
    }
    Iterable<Edge> edges = linkType == null ? vertex.getEdges(direction) : vertex.getEdges(direction, linkType);
    IMetaverseLink link = new MetaverseLink();
    IMetaverseNode node1 = new MetaverseNode(vertex);
    Direction opDirection = direction == Direction.IN ? Direction.OUT : Direction.IN;
    Vertex vertex2 = null;
    if (rightNodeID != null) {
        Iterator<Edge> it = edges.iterator();
        while (it.hasNext()) {
            Edge edge = it.next();
            if (rightNodeID.equals((String) edge.getVertex(opDirection).getId())) {
                vertex2 = edge.getVertex(opDirection);
                IMetaverseNode node2 = new MetaverseNode(vertex2);
                String label = edge.getLabel();
                link.setLabel(label);
                String localized = Messages.getString(MetaverseUtil.MESSAGE_PREFIX_LINKTYPE + label);
                if (!localized.startsWith("!")) {
                    link.setProperty(DictionaryConst.PROPERTY_TYPE_LOCALIZED, localized);
                }
                if (direction == Direction.OUT) {
                    link.setFromNode(node1);
                    link.setToNode(node2);
                } else {
                    link.setFromNode(node2);
                    link.setToNode(node1);
                }
                return link;
            }
        }
    }
    return null;
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) MetaverseLink(org.pentaho.dictionary.MetaverseLink) IMetaverseLink(org.pentaho.metaverse.api.IMetaverseLink) IMetaverseLink(org.pentaho.metaverse.api.IMetaverseLink) MetaverseNode(org.pentaho.metaverse.impl.MetaverseNode) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) Edge(com.tinkerpop.blueprints.Edge) Direction(com.tinkerpop.blueprints.Direction)

Example 3 with MetaverseLink

use of org.pentaho.dictionary.MetaverseLink in project pentaho-metaverse by pentaho.

the class MetaverseBuilderTest method testCopyLinkPropertiesToEdge.

@Test
public void testCopyLinkPropertiesToEdge() {
    final String LABEL = "myLabel";
    IMetaverseLink link = new MetaverseLink();
    link.setLabel("sourceLabel");
    // Create from/to nodes and an edge between them
    Vertex fromNode = graph.addVertex("from");
    Vertex toNode = graph.addVertex("to");
    Edge edge = graph.addEdge("myId", fromNode, toNode, LABEL);
    // Call with null for branch coverage (and to prove no NPE occurs)
    builder.copyLinkPropertiesToEdge(null, edge);
    builder.copyLinkPropertiesToEdge(link, null);
    // Call with empty list for branch coverage (and to prove no NPE occurs)
    builder.copyLinkPropertiesToEdge(link, edge);
    // Set some properties on the source link
    link.setProperty(DictionaryConst.PROPERTY_LABEL, "sourceLabel");
    link.setProperty(DictionaryConst.PROPERTY_NAME, "sourceLink");
    // Set some properties on the target edge (including the reserved one "label")
    edge.setProperty(DictionaryConst.PROPERTY_NAME, "myEdge");
    edge.setProperty(DictionaryConst.PROPERTY_TYPE, "relates to");
    // Invoke the method under test and see that the appropriate properties are set on the target edge
    builder.copyLinkPropertiesToEdge(link, edge);
    assertEquals("sourceLink", edge.getProperty(DictionaryConst.PROPERTY_NAME));
    assertEquals("relates to", edge.getProperty(DictionaryConst.PROPERTY_TYPE));
    // The label should not be overridden (Blueprints does not allow it)
    assertEquals(LABEL, edge.getLabel());
    // The property "label" is not set on the edge by either setLabel() or the method under test
    // It's a Blueprints thing
    assertNull(edge.getProperty(DictionaryConst.PROPERTY_LABEL));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) MetaverseLink(org.pentaho.dictionary.MetaverseLink) IMetaverseLink(org.pentaho.metaverse.api.IMetaverseLink) IMetaverseLink(org.pentaho.metaverse.api.IMetaverseLink) Edge(com.tinkerpop.blueprints.Edge) Test(org.junit.Test)

Example 4 with MetaverseLink

use of org.pentaho.dictionary.MetaverseLink in project pentaho-metaverse by pentaho.

the class MetaverseBuilderTest method testAddLink_OneExistingNode.

@Test
public void testAddLink_OneExistingNode() {
    // explicitly add the fromNode
    builder.addNode(node);
    MetaverseTransientNode node2 = new MetaverseTransientNode();
    node2.setStringID("nodeToId");
    node2.setName("to name");
    MetaverseLink link = new MetaverseLink(node, "uses", node2);
    builder.addLink(link);
    Vertex fromResult = graph.getVertex(node.getStringID());
    Vertex toResult = graph.getVertex(node2.getStringID());
    // we added this node explicitly through the addNode, it should be flagged as NOT virtual
    assertFalse((Boolean) fromResult.getProperty(DictionaryConst.NODE_VIRTUAL));
    // we added this node implicitly through the addLink, it should be flagged as virtual
    assertTrue((Boolean) toResult.getProperty(DictionaryConst.NODE_VIRTUAL));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) MetaverseTransientNode(org.pentaho.dictionary.MetaverseTransientNode) MetaverseLink(org.pentaho.dictionary.MetaverseLink) IMetaverseLink(org.pentaho.metaverse.api.IMetaverseLink) Test(org.junit.Test)

Example 5 with MetaverseLink

use of org.pentaho.dictionary.MetaverseLink in project pentaho-metaverse by pentaho.

the class MetaverseBuilderTest method testAddLink.

@Test
public void testAddLink() {
    MetaverseTransientNode node2 = new MetaverseTransientNode();
    node2.setStringID("nodeToId");
    node2.setName("to name");
    MetaverseLink link = new MetaverseLink(node, "uses", node2);
    builder.addLink(link);
    Vertex fromResult = graph.getVertex(node.getStringID());
    Vertex toResult = graph.getVertex(node2.getStringID());
    // we added this node implicitly through the addLink, it should be flagged as virtual
    assertTrue((Boolean) fromResult.getProperty(DictionaryConst.NODE_VIRTUAL));
    // we added this node implicitly through the addLink, it should be flagged as virtual
    assertTrue((Boolean) toResult.getProperty(DictionaryConst.NODE_VIRTUAL));
    assertNotNull(fromResult.getEdges(Direction.OUT, "uses"));
    for (Edge e : fromResult.getEdges(Direction.OUT, "uses")) {
        assertEquals(e.getVertex(Direction.OUT).getProperty("name"), node.getName());
        assertEquals(e.getVertex(Direction.IN).getProperty("name"), node2.getName());
        // we added this node implicitly through the addLink, it should be flagged as virtual
        assertTrue((Boolean) e.getVertex(Direction.OUT).getProperty(DictionaryConst.NODE_VIRTUAL));
    }
    assertNotNull(toResult.getEdges(Direction.IN, "uses"));
    for (Edge e : fromResult.getEdges(Direction.IN, "uses")) {
        assertEquals(e.getVertex(Direction.OUT).getProperty("name"), node.getName());
        assertEquals(e.getVertex(Direction.IN).getProperty("name"), node2.getName());
        // we added this node implicitly through the addLink, it should be flagged as virtual
        assertTrue((Boolean) e.getVertex(Direction.IN).getProperty(DictionaryConst.NODE_VIRTUAL));
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) MetaverseTransientNode(org.pentaho.dictionary.MetaverseTransientNode) MetaverseLink(org.pentaho.dictionary.MetaverseLink) IMetaverseLink(org.pentaho.metaverse.api.IMetaverseLink) Edge(com.tinkerpop.blueprints.Edge) Test(org.junit.Test)

Aggregations

MetaverseLink (org.pentaho.dictionary.MetaverseLink)6 Vertex (com.tinkerpop.blueprints.Vertex)5 IMetaverseLink (org.pentaho.metaverse.api.IMetaverseLink)5 Edge (com.tinkerpop.blueprints.Edge)4 Test (org.junit.Test)4 MetaverseTransientNode (org.pentaho.dictionary.MetaverseTransientNode)3 Direction (com.tinkerpop.blueprints.Direction)1 Before (org.junit.Before)1 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)1 MetaverseNode (org.pentaho.metaverse.impl.MetaverseNode)1