Search in sources :

Example 6 with TermPath

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

use of org.apache.atlas.catalog.TermPath 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 8 with TermPath

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

the class QueryFactoryTest method testCreateTermQuery.

@Test
public void testCreateTermQuery() throws Exception {
    Map<String, Object> requestProps = new HashMap<>();
    requestProps.put("name", "test_taxonomy.term1");
    requestProps.put("termPath", new TermPath("test_taxonomy.term1"));
    Request request = new InstanceRequest(requestProps);
    QueryFactory factory = new QueryFactory();
    AtlasTermQuery query = (AtlasTermQuery) factory.createTermQuery(request);
    QueryExpression queryExpression = query.getQueryExpression();
    assertEquals(queryExpression.getClass(), TermQueryExpression.class);
    assertEquals(queryExpression.getField(), "name");
    assertEquals(queryExpression.getExpectedValue(), "test_taxonomy.term1");
    assertEquals(query.getRequest(), request);
    assertEquals(query.getResourceDefinition().getTypeName(), "Term");
}
Also used : HashMap(java.util.HashMap) TermPath(org.apache.atlas.catalog.TermPath) CollectionRequest(org.apache.atlas.catalog.CollectionRequest) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) Request(org.apache.atlas.catalog.Request) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) Test(org.testng.annotations.Test)

Example 9 with TermPath

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

the class QueryFactory method createTermQuery.

public AtlasQuery createTermQuery(Request request) throws InvalidQueryException {
    ResourceDefinition termDefinition = new TermResourceDefinition();
    QueryExpression queryExpression = create(request, termDefinition);
    TermPath termPath = request.getProperty("termPath");
    return new AtlasTermQuery(queryExpression, termDefinition, termPath, request);
}
Also used : TermPath(org.apache.atlas.catalog.TermPath)

Example 10 with TermPath

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

the class TermResourceDefinition method resolveHref.

//todo
@Override
public String resolveHref(Map<String, Object> properties) {
    StringBuilder sb = new StringBuilder();
    sb.append("v1/taxonomies/");
    TermPath termPath = new TermPath(String.valueOf(properties.get("name")));
    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);
        }
    }
    return sb.toString();
}
Also used : TermPath(org.apache.atlas.catalog.TermPath)

Aggregations

TermPath (org.apache.atlas.catalog.TermPath)13 Request (org.apache.atlas.catalog.Request)9 Test (org.testng.annotations.Test)9 Response (javax.ws.rs.core.Response)8 UriInfo (javax.ws.rs.core.UriInfo)8 ResourceProvider (org.apache.atlas.catalog.ResourceProvider)8 TaxonomyResourceProvider (org.apache.atlas.catalog.TaxonomyResourceProvider)8 MetadataService (org.apache.atlas.services.MetadataService)8 AtlasTypeDefStore (org.apache.atlas.store.AtlasTypeDefStore)8 URI (java.net.URI)7 HashMap (java.util.HashMap)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 JsonSerializer (org.apache.atlas.catalog.JsonSerializer)4 Result (org.apache.atlas.catalog.Result)4 PipeFunction (com.tinkerpop.pipes.PipeFunction)2 PathSegment (javax.ws.rs.core.PathSegment)2 ResourceComparator (org.apache.atlas.catalog.ResourceComparator)2 VertexWrapper (org.apache.atlas.catalog.VertexWrapper)2 Projection (org.apache.atlas.catalog.projection.Projection)2