Search in sources :

Example 1 with MetaverseNode

use of org.pentaho.metaverse.impl.MetaverseNode 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 MetaverseNode

use of org.pentaho.metaverse.impl.MetaverseNode in project pentaho-metaverse by pentaho.

the class RepositoryLocatorTest method setUp.

@Before
public void setUp() throws Exception {
    RepositoryLocator loc = new RepositoryLocator() {

        @Override
        protected IUnifiedRepository getUnifiedRepository(IPentahoSession session) throws Exception {
            return null;
        }

        @Override
        protected Object getContents(RepositoryFile locatedItem) throws Exception {
            return null;
        }

        /**
         * Returns the locator node for this locator. The locator node is the node in the metaverse
         * that represents this locator. It is used to create a link from this locator to the documents
         * that are found by/within it.
         *
         * @return The locator node in the metaverse
         */
        @Override
        public IMetaverseNode getLocatorNode() {
            return new MetaverseNode(mock(Vertex.class));
        }

        @Override
        public URI getRootUri() {
            return null;
        }
    };
    loc.setMetaverseBuilder(metaverseBuilder);
    baseLocator = spy(loc);
    when(baseLocator.getMetaverseBuilder()).thenReturn(metaverseBuilder);
    when(metaverseBuilder.getMetaverseObjectFactory()).thenReturn(metaverseObjectFactory);
    when(metaverseObjectFactory.createDocumentObject()).thenReturn(new MetaverseDocument());
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) MetaverseDocument(org.pentaho.metaverse.api.MetaverseDocument) MetaverseNode(org.pentaho.metaverse.impl.MetaverseNode) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) Before(org.junit.Before)

Example 3 with MetaverseNode

use of org.pentaho.metaverse.impl.MetaverseNode in project pentaho-metaverse by pentaho.

the class BlueprintsGraphMetaverseReader method findNode.

@Override
public IMetaverseNode findNode(String id) {
    Vertex vertex = getGraph().getVertex(id);
    if (vertex == null) {
        return null;
    }
    MetaverseUtil.enhanceVertex(vertex);
    MetaverseNode node = new MetaverseNode(vertex);
    return node;
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) MetaverseNode(org.pentaho.metaverse.impl.MetaverseNode) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode)

Example 4 with MetaverseNode

use of org.pentaho.metaverse.impl.MetaverseNode in project pentaho-metaverse by pentaho.

the class BlueprintsGraphMetaverseReader method findNodes.

@Override
public List<IMetaverseNode> findNodes(String property, String value) {
    Iterable<Vertex> vertices = getGraph().getVertices(property, value);
    if (vertices == null) {
        return null;
    }
    List<IMetaverseNode> result = new ArrayList<IMetaverseNode>();
    Iterator<Vertex> verticesIt = vertices.iterator();
    while (verticesIt.hasNext()) {
        MetaverseNode node = new MetaverseNode(verticesIt.next());
        result.add(node);
    }
    return result;
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) ArrayList(java.util.ArrayList) MetaverseNode(org.pentaho.metaverse.impl.MetaverseNode) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode)

Aggregations

Vertex (com.tinkerpop.blueprints.Vertex)4 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)4 MetaverseNode (org.pentaho.metaverse.impl.MetaverseNode)4 Direction (com.tinkerpop.blueprints.Direction)1 Edge (com.tinkerpop.blueprints.Edge)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 MetaverseLink (org.pentaho.dictionary.MetaverseLink)1 IMetaverseLink (org.pentaho.metaverse.api.IMetaverseLink)1 MetaverseDocument (org.pentaho.metaverse.api.MetaverseDocument)1 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)1 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)1