Search in sources :

Example 1 with InvalidQueryException

use of org.alfresco.rest.framework.resource.parameters.where.InvalidQueryException in project alfresco-remote-api by Alfresco.

the class WhereTests method matchesClauseTest.

@Test
public void matchesClauseTest() {
    Query theQuery = getWhereClause("(fred matches(bob))");
    matchesChecks(theQuery, "fred", "bob");
    theQuery = getWhereClause("( king/kong/hair/shoulders/knees/toes matches ('fred%') )");
    matchesChecks(theQuery, "king/kong/hair/shoulders/knees/toes", "fred%");
    theQuery = getWhereClause("( niceone matches (bob) )");
    matchesChecks(theQuery, "niceone", "bob");
    try {
        theQuery = getWhereClause("( fred matches bob )");
        fail("Should throw an InvalidQueryException, Need brackets.");
    } catch (InvalidQueryException error) {
    // this is correct
    }
}
Also used : Query(org.alfresco.rest.framework.resource.parameters.where.Query) InvalidQueryException(org.alfresco.rest.framework.resource.parameters.where.InvalidQueryException) Test(org.junit.Test)

Example 2 with InvalidQueryException

use of org.alfresco.rest.framework.resource.parameters.where.InvalidQueryException in project alfresco-remote-api by Alfresco.

the class WhereTests method betweenClauseTest.

@Test
public void betweenClauseTest() {
    Query theQuery = getWhereClause("( dueAt between (5,8) )");
    betweenChecks(theQuery, "dueAt", "5", "8");
    theQuery = getWhereClause("( fred/bloggs between (head,elbow) )");
    betweenChecks(theQuery, "fred/bloggs", "head", "elbow");
    try {
        theQuery = getWhereClause("( nextOne between (5,8,4) )");
        fail("Should throw an InvalidQueryException, between can have only two values.");
    } catch (InvalidQueryException error) {
    // this is correct
    }
    try {
        theQuery = getWhereClause("( nextOne between 5,8 )");
        fail("Should throw an InvalidQueryException, Need brackets.");
    } catch (InvalidQueryException error) {
    // this is correct
    }
    theQuery = getWhereClause("(NOT dueAt between (5,8) AND nextOne between (green,blue))");
    QueryHelper.walk(theQuery, new WalkerCallbackAdapter() {

        @Override
        public void between(String property, String firstVal, String secondVal, boolean negated) {
            if (negated) {
                assertTrue("Property name should be " + "dueAt", "dueAt".equals(property));
                assertTrue("First value should be " + "5", "5".equals(firstVal));
                assertTrue("Second value should be " + "8", "8".equals(secondVal));
            } else {
                assertTrue("Property name should be " + "nextOne", "nextOne".equals(property));
                assertTrue("First value should be " + "green", "green".equals(firstVal));
                assertTrue("Second value should be " + "blue", "blue".equals(secondVal));
            }
        }

        @Override
        public void and() {
        // do nothing
        }
    });
}
Also used : Query(org.alfresco.rest.framework.resource.parameters.where.Query) InvalidQueryException(org.alfresco.rest.framework.resource.parameters.where.InvalidQueryException) WalkerCallbackAdapter(org.alfresco.rest.framework.resource.parameters.where.QueryHelper.WalkerCallbackAdapter) Test(org.junit.Test)

Example 3 with InvalidQueryException

use of org.alfresco.rest.framework.resource.parameters.where.InvalidQueryException 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)

Example 4 with InvalidQueryException

use of org.alfresco.rest.framework.resource.parameters.where.InvalidQueryException in project alfresco-remote-api by Alfresco.

the class ExceptionResolverTests method testMatchException.

// 04180006 Authentication failed for Web Script org/alfresco/api/ResourceWebScript.get
@Test
public void testMatchException() {
    ErrorResponse response = assistant.resolveException(new ApiException(null));
    assertNotNull(response);
    // default to INTERNAL_SERVER_ERROR
    assertEquals(500, response.getStatusCode());
    response = assistant.resolveException(new InvalidArgumentException(null));
    // default to STATUS_BAD_REQUEST
    assertEquals(400, response.getStatusCode());
    response = assistant.resolveException(new InvalidQueryException(null));
    // default to STATUS_BAD_REQUEST
    assertEquals(400, response.getStatusCode());
    response = assistant.resolveException(new NotFoundException(null));
    // default to STATUS_NOT_FOUND
    assertEquals(404, response.getStatusCode());
    response = assistant.resolveException(new EntityNotFoundException(null));
    // default to STATUS_NOT_FOUND
    assertEquals(404, response.getStatusCode());
    response = assistant.resolveException(new RelationshipResourceNotFoundException(null, null));
    // default to STATUS_NOT_FOUND
    assertEquals(404, response.getStatusCode());
    response = assistant.resolveException(new PermissionDeniedException(null));
    // default to STATUS_FORBIDDEN
    assertEquals(403, response.getStatusCode());
    response = assistant.resolveException(new UnsupportedResourceOperationException(null));
    // default to STATUS_METHOD_NOT_ALLOWED
    assertEquals(405, response.getStatusCode());
    response = assistant.resolveException(new DeletedResourceException(null));
    // default to STATUS_METHOD_NOT_ALLOWED
    assertEquals(405, response.getStatusCode());
    response = assistant.resolveException(new ConstraintViolatedException(null));
    // default to STATUS_CONFLICT
    assertEquals(409, response.getStatusCode());
    response = assistant.resolveException(new StaleEntityException(null));
    // default to STATUS_CONFLICT
    assertEquals(409, response.getStatusCode());
    // Try a random exception
    response = assistant.resolveException(new FormNotFoundException(null));
    // default to INTERNAL_SERVER_ERROR
    assertEquals(500, response.getStatusCode());
    response = assistant.resolveException(new InsufficientStorageException(null));
    assertEquals(507, response.getStatusCode());
    response = assistant.resolveException(new IntegrityException(null));
    assertEquals(422, response.getStatusCode());
}
Also used : UnsupportedResourceOperationException(org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException) InsufficientStorageException(org.alfresco.rest.framework.core.exceptions.InsufficientStorageException) FormNotFoundException(org.alfresco.repo.forms.FormNotFoundException) RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) DeletedResourceException(org.alfresco.rest.framework.core.exceptions.DeletedResourceException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) ErrorResponse(org.alfresco.rest.framework.core.exceptions.ErrorResponse) RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) FormNotFoundException(org.alfresco.repo.forms.FormNotFoundException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) StaleEntityException(org.alfresco.rest.framework.core.exceptions.StaleEntityException) InvalidQueryException(org.alfresco.rest.framework.resource.parameters.where.InvalidQueryException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException) Test(org.junit.Test)

Example 5 with InvalidQueryException

use of org.alfresco.rest.framework.resource.parameters.where.InvalidQueryException in project alfresco-remote-api by Alfresco.

the class WhereTests method comparisonClauseTest.

@Test
public void comparisonClauseTest() {
    Query theQuery = getWhereClause("( dueAt > '12.04.345' )");
    int comparisonOperator = WhereClauseParser.GREATERTHAN;
    comparisonChecks(theQuery, comparisonOperator, "dueAt", "12.04.345");
    theQuery = getWhereClause("( dueAt >= '12.04.345' )");
    comparisonOperator = WhereClauseParser.GREATERTHANOREQUALS;
    comparisonChecks(theQuery, comparisonOperator, "dueAt", "12.04.345");
    theQuery = getWhereClause("( dueAt < '12.04.345' )");
    comparisonOperator = WhereClauseParser.LESSTHAN;
    comparisonChecks(theQuery, comparisonOperator, "dueAt", "12.04.345");
    theQuery = getWhereClause("( dueAt <= '12.04.345' )");
    comparisonOperator = WhereClauseParser.LESSTHANOREQUALS;
    comparisonChecks(theQuery, comparisonOperator, "dueAt", "12.04.345");
    try {
        theQuery = getWhereClause("( Fred/Bloggs = %$NICE&* )");
        fail("Should throw an InvalidQueryException, needs single quotes");
    } catch (InvalidQueryException error) {
    // this is correct
    }
    theQuery = getWhereClause("( Fred/Bloggs = '%$NICE&*' )");
    comparisonOperator = WhereClauseParser.EQUALS;
    comparisonChecks(theQuery, comparisonOperator, "Fred/Bloggs", "%$NICE&*");
    try {
        theQuery = getWhereClause("( Ken = (456) )");
        fail("Should throw an InvalidQueryException, needs single quotes no brackets");
    } catch (InvalidQueryException error) {
    // this is correct
    }
    theQuery = getWhereClause("( Ken = '456' )");
    comparisonOperator = WhereClauseParser.EQUALS;
    comparisonChecks(theQuery, comparisonOperator, "Ken", "456");
    theQuery = getWhereClause("( DogHouse = 'Cat\\\'s House' )");
    comparisonOperator = WhereClauseParser.EQUALS;
    comparisonChecks(theQuery, comparisonOperator, "DogHouse", "Cat\\\'s House");
    theQuery = getWhereClause("( KING_KONG >= 'Mighty Mouse' )");
    comparisonOperator = WhereClauseParser.GREATERTHANOREQUALS;
    comparisonChecks(theQuery, comparisonOperator, "KING_KONG", "Mighty Mouse");
// dueAt > and < + also string "like"
}
Also used : Query(org.alfresco.rest.framework.resource.parameters.where.Query) InvalidQueryException(org.alfresco.rest.framework.resource.parameters.where.InvalidQueryException) Test(org.junit.Test)

Aggregations

InvalidQueryException (org.alfresco.rest.framework.resource.parameters.where.InvalidQueryException)6 Test (org.junit.Test)5 Query (org.alfresco.rest.framework.resource.parameters.where.Query)4 WalkerCallbackAdapter (org.alfresco.rest.framework.resource.parameters.where.QueryHelper.WalkerCallbackAdapter)2 CommonTree (org.antlr.runtime.tree.CommonTree)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 FormNotFoundException (org.alfresco.repo.forms.FormNotFoundException)1 IntegrityException (org.alfresco.repo.node.integrity.IntegrityException)1 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)1 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)1 DeletedResourceException (org.alfresco.rest.framework.core.exceptions.DeletedResourceException)1 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)1 ErrorResponse (org.alfresco.rest.framework.core.exceptions.ErrorResponse)1 InsufficientStorageException (org.alfresco.rest.framework.core.exceptions.InsufficientStorageException)1 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)1 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)1 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)1 RelationshipResourceNotFoundException (org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException)1 StaleEntityException (org.alfresco.rest.framework.core.exceptions.StaleEntityException)1