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;
}
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);
}
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);
}
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());
}
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));
}
Aggregations