Search in sources :

Example 6 with VertexiumCypherTypeErrorException

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);
}
Also used : VertexiumCypherTypeErrorException(org.vertexium.cypher.exceptions.VertexiumCypherTypeErrorException) Element(org.vertexium.Element)

Example 7 with VertexiumCypherTypeErrorException

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);
}
Also used : VertexiumCypherTypeErrorException(org.vertexium.cypher.exceptions.VertexiumCypherTypeErrorException)

Example 8 with VertexiumCypherTypeErrorException

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);
}
Also used : Vertex(org.vertexium.Vertex) VertexiumCypherTypeErrorException(org.vertexium.cypher.exceptions.VertexiumCypherTypeErrorException) CypherAstBase(org.vertexium.cypher.ast.model.CypherAstBase) Edge(org.vertexium.Edge) VertexiumException(org.vertexium.VertexiumException)

Aggregations

VertexiumCypherTypeErrorException (org.vertexium.cypher.exceptions.VertexiumCypherTypeErrorException)8 Stream (java.util.stream.Stream)3 List (java.util.List)2 Element (org.vertexium.Element)2 Lists (com.google.common.collect.Lists)1 java.util (java.util)1 Collection (java.util.Collection)1 Date (java.util.Date)1 Collectors (java.util.stream.Collectors)1 Edge (org.vertexium.Edge)1 Vertex (org.vertexium.Vertex)1 VertexiumException (org.vertexium.VertexiumException)1 org.vertexium.cypher.ast.model (org.vertexium.cypher.ast.model)1 CypherAstBase (org.vertexium.cypher.ast.model.CypherAstBase)1 org.vertexium.cypher.executor.models.match (org.vertexium.cypher.executor.models.match)1