Search in sources :

Example 1 with ProjectionResult

use of org.apache.atlas.catalog.projection.ProjectionResult 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 2 with ProjectionResult

use of org.apache.atlas.catalog.projection.ProjectionResult 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 3 with ProjectionResult

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

the class ProjectionQueryExpression method evaluate.

@Override
public boolean evaluate(VertexWrapper vWrapper) {
    boolean result = false;
    Iterator<ProjectionResult> projectionIterator = resourceDefinition.getProjections().get(fieldSegments[0]).values(vWrapper).iterator();
    while (!result && projectionIterator.hasNext()) {
        ProjectionResult projectionResult = projectionIterator.next();
        for (Map<String, Object> propertyMap : projectionResult.getPropertyMaps()) {
            Object val = propertyMap.get(fieldSegments[1]);
            if (val != null && underlyingExpression.evaluate(QueryFactory.escape(val))) {
                result = true;
                break;
            }
        }
    }
    return negate ^ result;
}
Also used : ProjectionResult(org.apache.atlas.catalog.projection.ProjectionResult)

Example 4 with ProjectionResult

use of org.apache.atlas.catalog.projection.ProjectionResult 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 5 with ProjectionResult

use of org.apache.atlas.catalog.projection.ProjectionResult 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)

Aggregations

ProjectionResult (org.apache.atlas.catalog.projection.ProjectionResult)5 PipeFunction (com.tinkerpop.pipes.PipeFunction)4 VertexWrapper (org.apache.atlas.catalog.VertexWrapper)4 Projection (org.apache.atlas.catalog.projection.Projection)4 ResourceComparator (org.apache.atlas.catalog.ResourceComparator)3 TermPath (org.apache.atlas.catalog.TermPath)2