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
}
}
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
}
});
}
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);
}
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());
}
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"
}
Aggregations