use of com.tinkerpop.gremlin.java.GremlinPipeline in project incubator-atlas by apache.
the class AtlasEntityQueryTest method testExecute_Collection_rollbackOnException.
@Test
public void testExecute_Collection_rollbackOnException() throws Exception {
AtlasGraph graph = createStrictMock(AtlasGraph.class);
QueryExpression expression = createStrictMock(QueryExpression.class);
ResourceDefinition resourceDefinition = createStrictMock(ResourceDefinition.class);
Request request = createStrictMock(Request.class);
GremlinPipeline initialPipeline = createStrictMock(GremlinPipeline.class);
Pipe queryPipe = createStrictMock(Pipe.class);
Pipe expressionPipe = createStrictMock(Pipe.class);
Pipe notDeletedPipe = createStrictMock(Pipe.class);
GremlinPipeline rootPipeline = createStrictMock(GremlinPipeline.class);
GremlinPipeline queryPipeline = createStrictMock(GremlinPipeline.class);
GremlinPipeline expressionPipeline = createStrictMock(GremlinPipeline.class);
GremlinPipeline notDeletedPipeline = createStrictMock(GremlinPipeline.class);
// mock expectations
expect(initialPipeline.add(queryPipe)).andReturn(queryPipeline);
expect(initialPipeline.add(notDeletedPipe)).andReturn(notDeletedPipeline);
expect(initialPipeline.as("root")).andReturn(rootPipeline);
expect(expression.asPipe()).andReturn(expressionPipe);
expect(rootPipeline.add(expressionPipe)).andReturn(expressionPipeline);
expect(expressionPipeline.back("root")).andReturn(rootPipeline);
expect(rootPipeline.toList()).andThrow(new RuntimeException("something bad happened"));
graph.rollback();
replay(graph, expression, resourceDefinition, request, initialPipeline, queryPipe, expressionPipe, notDeletedPipe, rootPipeline, queryPipeline, expressionPipeline, notDeletedPipeline);
// end mock expectations
AtlasEntityQuery query = new TestAtlasEntityQuery(expression, resourceDefinition, request, initialPipeline, queryPipe, notDeletedPipe, graph, null);
try {
// invoke method being tested
query.execute();
fail("expected exception");
} catch (RuntimeException e) {
assertEquals(e.getMessage(), "something bad happened");
}
verify(graph, expression, resourceDefinition, request, initialPipeline, queryPipe, expressionPipe, notDeletedPipe, rootPipeline, queryPipeline, expressionPipeline, notDeletedPipeline);
}
use of com.tinkerpop.gremlin.java.GremlinPipeline 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();
}
use of com.tinkerpop.gremlin.java.GremlinPipeline in project incubator-atlas by apache.
the class ProjectionQueryExpression method asPipe.
@Override
public Pipe asPipe() {
//todo: encapsulate all of this path logic including path sep escaping and normalizing
final int sepIdx = getField().indexOf(QueryFactory.PATH_SEP_TOKEN);
final String edgeToken = getField().substring(0, sepIdx);
GremlinPipeline pipeline = new GremlinPipeline();
Relation relation = resourceDefinition.getRelations().get(fieldSegments[0]);
if (relation != null) {
pipeline = pipeline.outE();
pipeline.add(relation.asPipe()).inV();
} else {
if (resourceDefinition.getProjections().get(fieldSegments[0]) != null) {
return super.asPipe();
} else {
//todo: default Relation implementation
pipeline = pipeline.outE().has("label", Text.REGEX, String.format(".*\\.%s", edgeToken)).inV();
}
}
//todo: set resource definition from relation on underlying expression where appropriate
String childFieldName = getField().substring(sepIdx + QueryFactory.PATH_SEP_TOKEN.length());
underlyingExpression.setField(childFieldName);
Pipe childPipe;
if (childFieldName.contains(QueryFactory.PATH_SEP_TOKEN)) {
childPipe = new ProjectionQueryExpression(underlyingExpression, resourceDefinition).asPipe();
} else {
childPipe = underlyingExpression.asPipe();
}
pipeline.add(childPipe);
return negate ? new FilterFunctionPipe(new ExcludePipeFunction(pipeline)) : pipeline;
}
use of com.tinkerpop.gremlin.java.GremlinPipeline in project incubator-atlas by apache.
the class BaseQuery method executeQuery.
private List<Vertex> executeQuery() {
GremlinPipeline pipeline = buildPipeline().as("root");
Pipe expressionPipe = queryExpression.asPipe();
// AlwaysQuery returns null for pipe
return expressionPipe == null ? pipeline.toList() : pipeline.add(expressionPipe).back("root").toList();
}
use of com.tinkerpop.gremlin.java.GremlinPipeline in project gremlin by tinkerpop.
the class SideEffectStepTest method test_g_v1_sideEffectXstore_aX_propertyXnameX.
public void test_g_v1_sideEffectXstore_aX_propertyXnameX() {
final List<Vertex> a = new ArrayList<Vertex>();
super.test_g_v1_sideEffectXstore_aX_propertyXnameX(new GremlinPipeline(g.getVertex(1)).sideEffect(new PipeFunction<Vertex, Object>() {
public Object compute(Vertex vertex) {
a.clear();
a.add(vertex);
return null;
}
}).property("name"));
assertEquals(a.get(0), g.getVertex(1));
}
Aggregations