Search in sources :

Example 1 with VertexWrapper

use of org.apache.atlas.catalog.VertexWrapper in project incubator-atlas by apache.

the class TraitRelation method traverse.

@Override
public Collection<RelationSet> traverse(VertexWrapper vWrapper) {
    Vertex v = vWrapper.getVertex();
    Collection<VertexWrapper> vertices = new ArrayList<>();
    for (Edge e : v.getEdges(Direction.OUT)) {
        if (e.getLabel().startsWith(v.<String>getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY))) {
            VertexWrapper trait = new TermVertexWrapper(e.getVertex(Direction.IN));
            if (!trait.getPropertyKeys().contains("available_as_tag") && !isDeleted(trait.getVertex())) {
                vertices.add(trait);
            }
        }
    }
    return Collections.singletonList(new RelationSet("traits", vertices));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TermVertexWrapper(org.apache.atlas.catalog.TermVertexWrapper) TermVertexWrapper(org.apache.atlas.catalog.TermVertexWrapper) VertexWrapper(org.apache.atlas.catalog.VertexWrapper) ArrayList(java.util.ArrayList) Edge(com.tinkerpop.blueprints.Edge)

Example 2 with VertexWrapper

use of org.apache.atlas.catalog.VertexWrapper in project incubator-atlas by apache.

the class AtlasEntityTagQuery method getQueryPipe.

@Override
protected Pipe getQueryPipe() {
    GremlinPipeline p;
    if (guid.equals("*")) {
        p = new GremlinPipeline().has(Constants.ENTITY_TEXT_PROPERTY_KEY).hasNot(Constants.ENTITY_TYPE_PROPERTY_KEY, "Taxonomy").outE();
    } else {
        p = new GremlinPipeline().has(Constants.GUID_PROPERTY_KEY, guid).outE();
    }
    //todo: this is basically the same pipeline used in TagRelation.asPipe()
    p.add(new FilterFunctionPipe<>(new PipeFunction<Edge, Boolean>() {

        @Override
        public Boolean compute(Edge edge) {
            String type = edge.getVertex(Direction.OUT).getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY);
            VertexWrapper v = new TermVertexWrapper(edge.getVertex(Direction.IN));
            return edge.getLabel().startsWith(type) && v.getPropertyKeys().contains("available_as_tag");
        }
    }));
    return p.inV();
}
Also used : GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) TermVertexWrapper(org.apache.atlas.catalog.TermVertexWrapper) TermVertexWrapper(org.apache.atlas.catalog.TermVertexWrapper) VertexWrapper(org.apache.atlas.catalog.VertexWrapper) PipeFunction(com.tinkerpop.pipes.PipeFunction) Edge(com.tinkerpop.blueprints.Edge)

Example 3 with VertexWrapper

use of org.apache.atlas.catalog.VertexWrapper in project incubator-atlas by apache.

the class TermResourceDefinition method getHierarchyProjection.

private Projection getHierarchyProjection() {
    final String projectionName = "hierarchy";
    return new Projection(projectionName, Projection.Cardinality.SINGLE, new TransformFunctionPipe<>(new PipeFunction<VertexWrapper, Collection<ProjectionResult>>() {

        @Override
        public Collection<ProjectionResult> compute(VertexWrapper start) {
            Map<String, Object> map = new TreeMap<>(new ResourceComparator());
            TermPath termPath = new TermPath(start.getVertex().<String>getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY));
            map.put("path", termPath.getPath());
            map.put("short_name", termPath.getShortName());
            map.put("taxonomy", termPath.getTaxonomyName());
            return Collections.singleton(new ProjectionResult(projectionName, start, Collections.singleton(map)));
        }
    }));
}
Also used : ResourceComparator(org.apache.atlas.catalog.ResourceComparator) ProjectionResult(org.apache.atlas.catalog.projection.ProjectionResult) VertexWrapper(org.apache.atlas.catalog.VertexWrapper) TermPath(org.apache.atlas.catalog.TermPath) Projection(org.apache.atlas.catalog.projection.Projection) PipeFunction(com.tinkerpop.pipes.PipeFunction)

Example 4 with VertexWrapper

use of org.apache.atlas.catalog.VertexWrapper in project incubator-atlas by apache.

the class TermResourceDefinition method getSubTermProjection.

private Projection getSubTermProjection() {
    //todo: combine with other term projections
    final String termsProjectionName = "terms";
    return new Projection(termsProjectionName, Projection.Cardinality.SINGLE, new TransformFunctionPipe<>(new PipeFunction<VertexWrapper, Collection<ProjectionResult>>() {

        @Override
        public Collection<ProjectionResult> compute(VertexWrapper start) {
            Map<String, Object> map = new TreeMap<>(new ResourceComparator());
            StringBuilder sb = new StringBuilder();
            sb.append("v1/taxonomies/");
            TermPath termPath = new TermPath(start.getVertex().<String>getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY));
            String[] paths = termPath.getPathSegments();
            sb.append(termPath.getTaxonomyName());
            for (String path : paths) {
                //todo: shouldn't need to check for null or empty after TermPath addition
                if (path != null && !path.isEmpty()) {
                    sb.append("/terms/");
                    sb.append(path);
                }
            }
            sb.append("/terms");
            map.put("href", sb.toString());
            return Collections.singleton(new ProjectionResult(termsProjectionName, start, Collections.singleton(map)));
        }
    }));
}
Also used : ResourceComparator(org.apache.atlas.catalog.ResourceComparator) Projection(org.apache.atlas.catalog.projection.Projection) ProjectionResult(org.apache.atlas.catalog.projection.ProjectionResult) VertexWrapper(org.apache.atlas.catalog.VertexWrapper) TermPath(org.apache.atlas.catalog.TermPath) PipeFunction(com.tinkerpop.pipes.PipeFunction)

Example 5 with VertexWrapper

use of org.apache.atlas.catalog.VertexWrapper in project incubator-atlas by apache.

the class AlwaysQueryExpressionTest method testGetProperties.

@Test
public void testGetProperties() {
    VertexWrapper v = createStrictMock(VertexWrapper.class);
    replay(v);
    QueryExpression expression = new AlwaysQueryExpression();
    assertTrue(expression.getProperties().isEmpty());
    verify(v);
}
Also used : VertexWrapper(org.apache.atlas.catalog.VertexWrapper) Test(org.testng.annotations.Test)

Aggregations

VertexWrapper (org.apache.atlas.catalog.VertexWrapper)15 Vertex (com.tinkerpop.blueprints.Vertex)6 Test (org.testng.annotations.Test)6 PipeFunction (com.tinkerpop.pipes.PipeFunction)5 Edge (com.tinkerpop.blueprints.Edge)4 ArrayList (java.util.ArrayList)4 Projection (org.apache.atlas.catalog.projection.Projection)4 ProjectionResult (org.apache.atlas.catalog.projection.ProjectionResult)4 GremlinPipeline (com.tinkerpop.gremlin.java.GremlinPipeline)3 ResourceComparator (org.apache.atlas.catalog.ResourceComparator)3 TermVertexWrapper (org.apache.atlas.catalog.TermVertexWrapper)3 Pipe (com.tinkerpop.pipes.Pipe)2 Map (java.util.Map)2 Request (org.apache.atlas.catalog.Request)2 TermPath (org.apache.atlas.catalog.TermPath)2 ResourceDefinition (org.apache.atlas.catalog.definition.ResourceDefinition)2 AtlasGraph (org.apache.atlas.repository.graphdb.AtlasGraph)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)1