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)));
}
}));
}
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)));
}
}));
}
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");
}
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);
}
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();
}
Aggregations