Search in sources :

Example 1 with IMetaverseLink

use of org.pentaho.metaverse.api.IMetaverseLink 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 2 with IMetaverseLink

use of org.pentaho.metaverse.api.IMetaverseLink in project pentaho-metaverse by pentaho.

the class MetaverseBuilder method addLink.

/**
 * Adds the specified link to the model
 *
 * @param fromNode the from node
 * @param label    the label
 * @param toNode   the to node
 * @return this metaverse builder
 * @see IMetaverseBuilder#addLink(
 *IMetaverseNode,
 * java.lang.String,
 * IMetaverseNode)
 */
@Override
public IMetaverseBuilder addLink(IMetaverseNode fromNode, String label, IMetaverseNode toNode) {
    IMetaverseLink link = createLinkObject();
    link.setFromNode(fromNode);
    link.setLabel(label);
    link.setToNode(toNode);
    return addLink(link);
}
Also used : IMetaverseLink(org.pentaho.metaverse.api.IMetaverseLink)

Example 3 with IMetaverseLink

use of org.pentaho.metaverse.api.IMetaverseLink in project pentaho-metaverse by pentaho.

the class MetaverseBuilderTest method testDeleteLink.

@Test
public void testDeleteLink() {
    IMetaverseLink link = createAndTestLink();
    // now lets try to delete the link
    builder.deleteLink(link);
    Vertex fromResult = graph.getVertex(link.getFromNode().getStringID());
    Vertex toResult = graph.getVertex(link.getToNode().getStringID());
    // the from node was explicitly added, it should still be there
    assertNotNull(fromResult);
    // the link should be gone
    assertFalse(fromResult.getEdges(Direction.OUT, "uses").iterator().hasNext());
    // any virtual nodes that were associated with the link should also be removed
    assertNull(toResult);
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) IMetaverseLink(org.pentaho.metaverse.api.IMetaverseLink) Test(org.junit.Test)

Example 4 with IMetaverseLink

use of org.pentaho.metaverse.api.IMetaverseLink in project pentaho-metaverse by pentaho.

the class MetaverseBuilderTest method testUpdateLinkLabel_nullLabel.

@Test
public void testUpdateLinkLabel_nullLabel() {
    // if a null value is passed in for a label, it should NOT perform an update
    IMetaverseLink link = createAndTestLink();
    Vertex v = graph.getVertex(link.getFromNode().getStringID());
    assertNotNull(v.getEdges(Direction.OUT, "uses"));
    builder.updateLinkLabel(link, null);
    assertEquals("uses", link.getLabel());
    v = graph.getVertex(link.getFromNode().getStringID());
    assertTrue(v.getEdges(Direction.OUT, "uses").iterator().hasNext());
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) IMetaverseLink(org.pentaho.metaverse.api.IMetaverseLink) Test(org.junit.Test)

Example 5 with IMetaverseLink

use of org.pentaho.metaverse.api.IMetaverseLink 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)

Aggregations

IMetaverseLink (org.pentaho.metaverse.api.IMetaverseLink)12 Vertex (com.tinkerpop.blueprints.Vertex)8 Test (org.junit.Test)8 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)5 Edge (com.tinkerpop.blueprints.Edge)3 MetaverseLink (org.pentaho.dictionary.MetaverseLink)2 Direction (com.tinkerpop.blueprints.Direction)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Date (java.util.Date)1 KettleException (org.pentaho.di.core.exception.KettleException)1 UnknownParamException (org.pentaho.di.core.parameters.UnknownParamException)1 Trans (org.pentaho.di.trans.Trans)1 TransHopMeta (org.pentaho.di.trans.TransHopMeta)1 TransMeta (org.pentaho.di.trans.TransMeta)1 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)1 StepMeta (org.pentaho.di.trans.step.StepMeta)1 GenericStepMetaAnalyzer (org.pentaho.metaverse.analyzer.kettle.step.GenericStepMetaAnalyzer)1 IComponentDescriptor (org.pentaho.metaverse.api.IComponentDescriptor)1 INamespace (org.pentaho.metaverse.api.INamespace)1 MetaverseAnalyzerException (org.pentaho.metaverse.api.MetaverseAnalyzerException)1