Search in sources :

Example 1 with RewriteCardinalityException

use of org.antlr.runtime.tree.RewriteCardinalityException in project alfresco-remote-api by Alfresco.

the class RecognizedParamsExtractor method getClause.

/**
 * Gets the clause specificed in paramName
 *
 * @param param
 * @param paramName
 * @return bean property names potentially using JSON Pointer syntax
 */
default List<String> getClause(String param, String paramName) {
    if (param == null)
        return Collections.emptyList();
    try {
        CommonTree selectedPropsTree = WhereCompiler.compileSelectClause(param);
        if (selectedPropsTree instanceof CommonErrorNode) {
            rpeLogger().debug("Error parsing the " + paramName + " clause " + selectedPropsTree);
            throw new InvalidSelectException(paramName, selectedPropsTree);
        }
        if (selectedPropsTree.getChildCount() == 0 && !selectedPropsTree.getText().isEmpty()) {
            return Arrays.asList(selectedPropsTree.getText());
        }
        List<Tree> children = (List<Tree>) selectedPropsTree.getChildren();
        if (children != null && !children.isEmpty()) {
            List<String> properties = new ArrayList<String>(children.size());
            for (Tree child : children) {
                properties.add(child.getText());
            }
            return properties;
        }
    } catch (RewriteCardinalityException re) {
        // Catch any error so it doesn't get thrown up the stack
        rpeLogger().debug("Unhandled Error parsing the " + paramName + " clause: " + re);
    } catch (RecognitionException e) {
        rpeLogger().debug("Error parsing the \"+paramName+\" clause: " + param);
    } catch (InvalidQueryException iqe) {
        throw new InvalidSelectException(paramName, iqe.getQueryParam());
    }
    // Default to throw out an invalid query
    throw new InvalidSelectException(paramName, param);
}
Also used : CommonTree(org.antlr.runtime.tree.CommonTree) ArrayList(java.util.ArrayList) CommonTree(org.antlr.runtime.tree.CommonTree) Tree(org.antlr.runtime.tree.Tree) ArrayList(java.util.ArrayList) List(java.util.List) InvalidSelectException(org.alfresco.rest.framework.resource.parameters.InvalidSelectException) RewriteCardinalityException(org.antlr.runtime.tree.RewriteCardinalityException) RecognitionException(org.antlr.runtime.RecognitionException) InvalidQueryException(org.alfresco.rest.framework.resource.parameters.where.InvalidQueryException) CommonErrorNode(org.antlr.runtime.tree.CommonErrorNode)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 InvalidSelectException (org.alfresco.rest.framework.resource.parameters.InvalidSelectException)1 InvalidQueryException (org.alfresco.rest.framework.resource.parameters.where.InvalidQueryException)1 RecognitionException (org.antlr.runtime.RecognitionException)1 CommonErrorNode (org.antlr.runtime.tree.CommonErrorNode)1 CommonTree (org.antlr.runtime.tree.CommonTree)1 RewriteCardinalityException (org.antlr.runtime.tree.RewriteCardinalityException)1 Tree (org.antlr.runtime.tree.Tree)1