use of org.vertexium.cypher.exceptions.VertexiumCypherTypeErrorException in project vertexium by visallo.
the class RemoveClauseExecutor method executeRemoveProperty.
private void executeRemoveProperty(VertexiumCypherQueryContext ctx, CypherRemovePropertyExpressionItem removeItem, VertexiumCypherScope.Item item) {
CypherAstBase propertyExpression = removeItem.getPropertyExpression();
if (propertyExpression instanceof CypherLookup) {
CypherLookup cypherLookup = (CypherLookup) propertyExpression;
Object elementObj = ctx.getExpressionExecutor().executeExpression(ctx, cypherLookup.getAtom(), item);
if (elementObj == null) {
return;
}
if (elementObj instanceof Element) {
Element element = (Element) elementObj;
ExistingElementMutation<Element> m = element.prepareMutation();
ctx.removeProperty(m, cypherLookup.getProperty());
ctx.saveElement(m);
return;
}
throw new VertexiumCypherTypeErrorException(elementObj, Element.class, null);
}
throw new VertexiumCypherTypeErrorException(propertyExpression, CypherLookup.class);
}
use of org.vertexium.cypher.exceptions.VertexiumCypherTypeErrorException in project vertexium by visallo.
the class SubstringFunction method invoke.
@Override
public Object invoke(VertexiumCypherQueryContext ctx, CypherAstBase[] arguments, ExpressionScope scope) {
assertArgumentCount(arguments, 2, 3);
Object originalObj = ctx.getExpressionExecutor().executeExpression(ctx, arguments[0], scope);
Object startObj = ctx.getExpressionExecutor().executeExpression(ctx, arguments[1], scope);
Object lengthObj = arguments.length > 2 ? ctx.getExpressionExecutor().executeExpression(ctx, arguments[2], scope) : null;
int start;
if (startObj instanceof Number) {
start = ((Number) startObj).intValue();
} else {
throw new VertexiumCypherTypeErrorException(startObj, Number.class);
}
Integer length;
if (lengthObj == null) {
length = null;
} else if (lengthObj instanceof Number) {
length = ((Number) lengthObj).intValue();
} else {
throw new VertexiumCypherTypeErrorException(lengthObj, Number.class, null);
}
if (originalObj instanceof String) {
String original = (String) originalObj;
String result = original.substring(start);
if (length != null) {
result = result.substring(length);
}
return result;
}
throw new VertexiumCypherTypeErrorException(originalObj, String.class);
}
use of org.vertexium.cypher.exceptions.VertexiumCypherTypeErrorException in project vertexium by visallo.
the class LabelsFunction method invoke.
@Override
public Object invoke(VertexiumCypherQueryContext ctx, CypherAstBase[] arguments, ExpressionScope scope) {
CypherAstBase lookup = arguments[0];
Object item = ctx.getExpressionExecutor().executeExpression(ctx, lookup, scope);
if (item == null) {
throw new VertexiumException("Could not find Vertex using " + lookup);
}
if (item instanceof Vertex) {
Vertex vertex = (Vertex) item;
return ctx.getVertexLabels(vertex);
}
if (item instanceof Edge) {
Edge edge = (Edge) item;
return Lists.newArrayList(edge.getLabel());
}
throw new VertexiumCypherTypeErrorException(item, Vertex.class, Edge.class);
}
Aggregations