Search in sources :

Example 11 with PipeFunction

use of com.tinkerpop.pipes.PipeFunction 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 12 with PipeFunction

use of com.tinkerpop.pipes.PipeFunction in project incubator-atlas by apache.

the class EntityTagResourceDefinition method getTermProjection.

private Projection getTermProjection() {
    return new Projection("term", 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/");
            String fullyQualifiedName = start.getVertex().getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY);
            String[] paths = fullyQualifiedName.split("\\.");
            // first path segment is the taxonomy
            sb.append(paths[0]);
            for (int i = 1; i < paths.length; ++i) {
                String path = paths[i];
                if (path != null && !path.isEmpty()) {
                    sb.append("/terms/");
                    sb.append(path);
                }
            }
            map.put("href", sb.toString());
            return Collections.singleton(new ProjectionResult("term", 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) PipeFunction(com.tinkerpop.pipes.PipeFunction)

Example 13 with PipeFunction

use of com.tinkerpop.pipes.PipeFunction in project incubator-atlas by apache.

the class TaxonomyResourceDefinition method getTermsProjection.

private Projection getTermsProjection() {
    final String termsProjectionName = "terms";
    return new Projection(termsProjectionName, Projection.Cardinality.SINGLE, new TransformFunctionPipe<>(new PipeFunction<VertexWrapper, Collection<ProjectionResult>>() {

        private String baseHref = "v1/taxonomies/";

        @Override
        public Collection<ProjectionResult> compute(VertexWrapper v) {
            Map<String, Object> map = new HashMap<>();
            map.put("href", baseHref + v.getProperty("name") + "/terms");
            return Collections.singleton(new ProjectionResult(termsProjectionName, v, Collections.singleton(map)));
        }
    }));
}
Also used : ProjectionResult(org.apache.atlas.catalog.projection.ProjectionResult) VertexWrapper(org.apache.atlas.catalog.VertexWrapper) Projection(org.apache.atlas.catalog.projection.Projection) PipeFunction(com.tinkerpop.pipes.PipeFunction)

Example 14 with PipeFunction

use of com.tinkerpop.pipes.PipeFunction in project gremlin by tinkerpop.

the class IfThenElseStepTest method test_g_v1_out_ifThenElseXlang_eq_java__it__outX_name.

public void test_g_v1_out_ifThenElseXlang_eq_java__it__outX_name() {
    super.test_g_v1_out_ifThenElseXlang_eq_java__it__outX_name(new GremlinPipeline(g.getVertex(1)).out().ifThenElse(new PipeFunction<Vertex, Boolean>() {

        public Boolean compute(Vertex vertex) {
            return vertex.getProperty("lang") != null && vertex.getProperty("lang").equals("java");
        }
    }, new PipeFunction<Vertex, Vertex>() {

        public Vertex compute(Vertex vertex) {
            return vertex;
        }
    }, new PipeFunction<Vertex, Iterable<Vertex>>() {

        public Iterable<Vertex> compute(Vertex vertex) {
            return new GremlinPipeline(vertex).out();
        }
    }));
    super.test_g_v1_out_ifThenElseXlang_eq_java__it__outX_name(new GremlinPipeline(g.getVertex(1)).optimize(false).out().ifThenElse(new PipeFunction<Vertex, Boolean>() {

        public Boolean compute(Vertex vertex) {
            return vertex.getProperty("lang") != null && vertex.getProperty("lang").equals("java");
        }
    }, new PipeFunction<Vertex, Vertex>() {

        public Vertex compute(Vertex vertex) {
            return vertex;
        }
    }, new PipeFunction<Vertex, Iterable<Vertex>>() {

        public Iterable<Vertex> compute(Vertex vertex) {
            return new GremlinPipeline(vertex).out();
        }
    }));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) PipeFunction(com.tinkerpop.pipes.PipeFunction)

Example 15 with PipeFunction

use of com.tinkerpop.pipes.PipeFunction in project gremlin by tinkerpop.

the class FilterStepTest method test_g_V_filterXtrueX.

public void test_g_V_filterXtrueX() {
    super.test_g_V_filterXtrueX(new GremlinPipeline(g).V().filter(new PipeFunction<Vertex, Boolean>() {

        public Boolean compute(Vertex vertex) {
            return true;
        }
    }));
    super.test_g_V_filterXtrueX(new GremlinPipeline(g.getVertices()).optimize(false).filter(new PipeFunction<Vertex, Boolean>() {

        public Boolean compute(Vertex vertex) {
            return true;
        }
    }));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) PipeFunction(com.tinkerpop.pipes.PipeFunction)

Aggregations

PipeFunction (com.tinkerpop.pipes.PipeFunction)17 GremlinPipeline (com.tinkerpop.gremlin.java.GremlinPipeline)13 Vertex (com.tinkerpop.blueprints.Vertex)11 VertexWrapper (org.apache.atlas.catalog.VertexWrapper)5 Projection (org.apache.atlas.catalog.projection.Projection)4 ProjectionResult (org.apache.atlas.catalog.projection.ProjectionResult)4 ResourceComparator (org.apache.atlas.catalog.ResourceComparator)3 HashMap (java.util.HashMap)2 List (java.util.List)2 TermPath (org.apache.atlas.catalog.TermPath)2 Edge (com.tinkerpop.blueprints.Edge)1 TermVertexWrapper (org.apache.atlas.catalog.TermVertexWrapper)1