mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
REPO-484: [REST API] 400 error for unsupported NOT operator in the 'where' predicate.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@130610 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -27,7 +27,6 @@ package org.alfresco.rest.framework.resource.parameters.where;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -67,7 +66,7 @@ public abstract class QueryHelper
|
|||||||
/**
|
/**
|
||||||
* One of EQUALS LESSTHAN GREATERTHAN LESSTHANOREQUALS GREATERTHANOREQUALS;
|
* One of EQUALS LESSTHAN GREATERTHAN LESSTHANOREQUALS GREATERTHANOREQUALS;
|
||||||
*/
|
*/
|
||||||
void comparison(int type, String propertyName, String propertyValue);
|
void comparison(int type, String propertyName, String propertyValue, boolean negated);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called any time an IN clause is encountered.
|
* Called any time an IN clause is encountered.
|
||||||
@@ -110,7 +109,7 @@ public abstract class QueryHelper
|
|||||||
@Override
|
@Override
|
||||||
public void between(String propertyName, String firstValue, String secondValue, boolean negated) { throw UNSUPPORTED;}
|
public void between(String propertyName, String firstValue, String secondValue, boolean negated) { throw UNSUPPORTED;}
|
||||||
@Override
|
@Override
|
||||||
public void comparison(int type, String propertyName, String propertyValue) { throw UNSUPPORTED;}
|
public void comparison(int type, String propertyName, String propertyValue, boolean negated) { throw UNSUPPORTED;}
|
||||||
@Override
|
@Override
|
||||||
public void in(String propertyName, boolean negated, String... propertyValues) { throw UNSUPPORTED;}
|
public void in(String propertyName, boolean negated, String... propertyValues) { throw UNSUPPORTED;}
|
||||||
@Override
|
@Override
|
||||||
@@ -191,7 +190,7 @@ public abstract class QueryHelper
|
|||||||
if (WhereClauseParser.PROPERTYNAME == tree.getChild(0).getType() &&
|
if (WhereClauseParser.PROPERTYNAME == tree.getChild(0).getType() &&
|
||||||
WhereClauseParser.PROPERTYVALUE == tree.getChild(1).getType())
|
WhereClauseParser.PROPERTYVALUE == tree.getChild(1).getType())
|
||||||
{
|
{
|
||||||
callback.comparison(tree.getType(), tree.getChild(0).getText(), stripQuotes(tree.getChild(1).getText()));
|
callback.comparison(tree.getType(), tree.getChild(0).getText(), stripQuotes(tree.getChild(1).getText()), negated);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@@ -175,91 +175,94 @@ public class MapBasedQueryWalker extends WalkerCallbackAdapter
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void comparison(int type, String propertyName, String propertyValue)
|
public void comparison(int type, String propertyName, String propertyValue, boolean negated)
|
||||||
{
|
{
|
||||||
boolean throwError = false;
|
|
||||||
|
|
||||||
if (variablesEnabled && propertyName.startsWith("variables/"))
|
if (variablesEnabled && propertyName.startsWith("variables/"))
|
||||||
{
|
{
|
||||||
processVariable(propertyName, propertyValue, type);
|
processVariable(propertyName, propertyValue, type);
|
||||||
}
|
return;
|
||||||
else
|
}
|
||||||
|
|
||||||
|
boolean throwError = false;
|
||||||
|
if (type == WhereClauseParser.EQUALS)
|
||||||
{
|
{
|
||||||
if (type == WhereClauseParser.EQUALS)
|
if (supportedEqualsParameters != null && supportedEqualsParameters.contains(propertyName))
|
||||||
{
|
{
|
||||||
if (supportedEqualsParameters != null && supportedEqualsParameters.contains(propertyName))
|
equalsProperties.put(propertyName, propertyValue);
|
||||||
{
|
|
||||||
equalsProperties.put(propertyName, propertyValue);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throwError = !handleUnmatchedComparison(type, propertyName, propertyValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (type == WhereClauseParser.MATCHES)
|
|
||||||
{
|
|
||||||
if (supportedMatchesParameters != null && supportedMatchesParameters.contains(propertyName))
|
|
||||||
{
|
|
||||||
matchesProperties.put(propertyName, propertyValue);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throwError = !handleUnmatchedComparison(type, propertyName, propertyValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (type == WhereClauseParser.GREATERTHAN)
|
|
||||||
{
|
|
||||||
if (supportedGreaterThanParameters != null && supportedGreaterThanParameters.contains(propertyName))
|
|
||||||
{
|
|
||||||
greaterThanProperties.put(propertyName, propertyValue);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throwError = !handleUnmatchedComparison(type, propertyName, propertyValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (type == WhereClauseParser.GREATERTHANOREQUALS)
|
|
||||||
{
|
|
||||||
if (supportedGreaterThanOrEqualParameters != null && supportedGreaterThanOrEqualParameters.contains(propertyName))
|
|
||||||
{
|
|
||||||
greaterThanOrEqualProperties.put(propertyName, propertyValue);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throwError = !handleUnmatchedComparison(type, propertyName, propertyValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (type == WhereClauseParser.LESSTHAN)
|
|
||||||
{
|
|
||||||
if (supportedLessThanParameters != null && supportedLessThanParameters.contains(propertyName))
|
|
||||||
{
|
|
||||||
lessThanProperties.put(propertyName, propertyValue);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throwError = !handleUnmatchedComparison(type, propertyName, propertyValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (type == WhereClauseParser.LESSTHANOREQUALS)
|
|
||||||
{
|
|
||||||
if (supportedLessThanOrEqualParameters != null && supportedLessThanOrEqualParameters.contains(propertyName))
|
|
||||||
{
|
|
||||||
lessThanOrEqualProperties.put(propertyName, propertyValue);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throwError = !handleUnmatchedComparison(type, propertyName, propertyValue);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throwError = !handleUnmatchedComparison(type, propertyName, propertyValue);
|
throwError = !handleUnmatchedComparison(type, propertyName, propertyValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (type == WhereClauseParser.MATCHES)
|
||||||
|
{
|
||||||
|
if (supportedMatchesParameters != null && supportedMatchesParameters.contains(propertyName))
|
||||||
|
{
|
||||||
|
matchesProperties.put(propertyName, propertyValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throwError = !handleUnmatchedComparison(type, propertyName, propertyValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (type == WhereClauseParser.GREATERTHAN)
|
||||||
|
{
|
||||||
|
if (supportedGreaterThanParameters != null && supportedGreaterThanParameters.contains(propertyName))
|
||||||
|
{
|
||||||
|
greaterThanProperties.put(propertyName, propertyValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throwError = !handleUnmatchedComparison(type, propertyName, propertyValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (type == WhereClauseParser.GREATERTHANOREQUALS)
|
||||||
|
{
|
||||||
|
if (supportedGreaterThanOrEqualParameters != null && supportedGreaterThanOrEqualParameters.contains(propertyName))
|
||||||
|
{
|
||||||
|
greaterThanOrEqualProperties.put(propertyName, propertyValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throwError = !handleUnmatchedComparison(type, propertyName, propertyValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (type == WhereClauseParser.LESSTHAN)
|
||||||
|
{
|
||||||
|
if (supportedLessThanParameters != null && supportedLessThanParameters.contains(propertyName))
|
||||||
|
{
|
||||||
|
lessThanProperties.put(propertyName, propertyValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throwError = !handleUnmatchedComparison(type, propertyName, propertyValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (type == WhereClauseParser.LESSTHANOREQUALS)
|
||||||
|
{
|
||||||
|
if (supportedLessThanOrEqualParameters != null && supportedLessThanOrEqualParameters.contains(propertyName))
|
||||||
|
{
|
||||||
|
lessThanOrEqualProperties.put(propertyName, propertyValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throwError = !handleUnmatchedComparison(type, propertyName, propertyValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throwError = !handleUnmatchedComparison(type, propertyName, propertyValue);
|
||||||
|
}
|
||||||
|
|
||||||
if (throwError)
|
if (throwError)
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException("framework.exception.InvalidProperty", new Object[] {propertyName, propertyValue, WhereClauseParser.tokenNames[type]});
|
throw new InvalidArgumentException("framework.exception.InvalidProperty", new Object[] {propertyName, propertyValue, WhereClauseParser.tokenNames[type]});
|
||||||
|
}
|
||||||
|
else if (negated)
|
||||||
|
{
|
||||||
|
// Throw error for the unsupported NOT operator only if the property was valid for comparison, show the more meaningful error first.
|
||||||
|
throw new InvalidArgumentException("NOT operator is not supported for " + WhereClauseParser.tokenNames[type] + " comparison.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -37,7 +37,7 @@ public class TaskVariablesWalkerCallback extends WalkerCallbackAdapter
|
|||||||
private VariableScope scope = VariableScope.ANY;
|
private VariableScope scope = VariableScope.ANY;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void comparison(int type, String propertyName, String propertyValue)
|
public void comparison(int type, String propertyName, String propertyValue, boolean negated)
|
||||||
{
|
{
|
||||||
if (PROPERTY_SCOPE.equals(propertyName))
|
if (PROPERTY_SCOPE.equals(propertyName))
|
||||||
{
|
{
|
||||||
|
@@ -519,6 +519,12 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
|||||||
// -ve test - list folder children with relative path to unknown node should return 400
|
// -ve test - list folder children with relative path to unknown node should return 400
|
||||||
params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "/unknown");
|
params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "/unknown");
|
||||||
getAll(getNodeChildrenUrl(content1_Id), paging, params, 400);
|
getAll(getNodeChildrenUrl(content1_Id), paging, params, 400);
|
||||||
|
|
||||||
|
// filtering, via where clause - negated comparison
|
||||||
|
params = new HashMap<>();
|
||||||
|
params.put("where", "(NOT "+Nodes.PARAM_ISFILE+"=true)");
|
||||||
|
getAll(childrenUrl, paging, params, 400);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -485,7 +485,7 @@ public class WhereTests implements RecognizedParamsExtractor
|
|||||||
assertEquals(WhereClauseParser.PROPERTYVALUE, tree.getChild(1).getType());
|
assertEquals(WhereClauseParser.PROPERTYVALUE, tree.getChild(1).getType());
|
||||||
QueryHelper.walk(theQuery, new WalkerCallbackAdapter(){
|
QueryHelper.walk(theQuery, new WalkerCallbackAdapter(){
|
||||||
@Override
|
@Override
|
||||||
public void comparison(int comparisonType, String propertyName, String propertyValue) {
|
public void comparison(int comparisonType, String propertyName, String propertyValue, boolean negated) {
|
||||||
assertTrue("Property name should be "+propName,propName.equals(propertyName));
|
assertTrue("Property name should be "+propName,propName.equals(propertyName));
|
||||||
assertTrue(comparisonOperator == comparisonType);
|
assertTrue(comparisonOperator == comparisonType);
|
||||||
assertTrue("Property value should be "+propVal,propVal.equals(propertyValue));
|
assertTrue("Property value should be "+propVal,propVal.equals(propertyValue));
|
||||||
|
Reference in New Issue
Block a user