Search in sources :

Example 1 with WalkerCallbackAdapter

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

the class WhereTests method inClauseTest.

@Test
public void inClauseTest() {
    Query theQuery = getWhereClause("( dueAt in (5,8) )");
    inChecks(theQuery, "dueAt", "5", "8");
    theQuery = getWhereClause("( fred/bloggs in (head,elbow) )");
    inChecks(theQuery, "fred/bloggs", "head", "elbow");
    theQuery = getWhereClause("( nextOne in (5,8,4) )");
    inChecks(theQuery, "nextOne", "5", "8", "4");
    theQuery = getWhereClause("( nextOne in (5,56,fred) )");
    inChecks(theQuery, "nextOne", "5", "56", "fred");
    theQuery = getWhereClause("( nextOne in (5,56,'fred&') )");
    inChecks(theQuery, "nextOne", "5", "56", "fred&");
    theQuery = getWhereClause("( nextOne in ('me , you',56,egg) )");
    inChecks(theQuery, "nextOne", "me , you", "56", "egg");
    theQuery = getWhereClause("( NOT nextOne in (5,56,fred, king, kong, 'fred\\'^') )");
    CommonTree tree = theQuery.getTree();
    assertNotNull(tree);
    QueryHelper.walk(theQuery, new WalkerCallbackAdapter() {

        @Override
        public void in(String property, boolean negated, String... propertyValues) {
            assertTrue("Property name should be " + "nextOne", "nextOne".equals(property));
            assertTrue(negated);
            String[] values = { "5", "56", "fred", "king", "kong", "fred\\'^" };
            for (int i = 0; i < values.length; i++) {
                assertTrue("Value must match:" + values[i], values[i].equals(propertyValues[i]));
            }
        }
    });
}
Also used : Query(org.alfresco.rest.framework.resource.parameters.where.Query) CommonTree(org.antlr.runtime.tree.CommonTree) WalkerCallbackAdapter(org.alfresco.rest.framework.resource.parameters.where.QueryHelper.WalkerCallbackAdapter) Test(org.junit.Test)

Example 2 with WalkerCallbackAdapter

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

the class WhereTests method matchesChecks.

/**
 * Used by the matchesClauseTest
 * @param theQuery Query
 * @param propName String
 * @param propVal String
 */
private void matchesChecks(Query theQuery, final String propName, final String propVal) {
    assertNotNull(theQuery);
    CommonTree tree = theQuery.getTree();
    assertNotNull(tree);
    assertEquals(WhereClauseParser.PROPERTYNAME, tree.getChild(0).getType());
    assertTrue(propName.equals(tree.getChild(0).getText()));
    assertEquals(WhereClauseParser.PROPERTYVALUE, tree.getChild(1).getType());
    QueryHelper.walk(theQuery, new WalkerCallbackAdapter() {

        @Override
        public void matches(String propertyName, String propertyValue, boolean negated) {
            assertTrue("Property name should be " + propName, propName.equals(propertyName));
            assertTrue("Property value should be " + propVal, propVal.equals(propertyValue));
        }
    });
}
Also used : CommonTree(org.antlr.runtime.tree.CommonTree) WalkerCallbackAdapter(org.alfresco.rest.framework.resource.parameters.where.QueryHelper.WalkerCallbackAdapter)

Example 3 with WalkerCallbackAdapter

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

the class WhereTests method inChecks.

/**
 * Use by the inClauseTest
 * @param theQuery Query
 * @param propName String
 * @param values String...
 */
private void inChecks(Query theQuery, final String propName, final String... values) {
    assertNotNull(theQuery);
    CommonTree tree = theQuery.getTree();
    assertNotNull(tree);
    assertEquals(WhereClauseParser.IN, tree.getType());
    assertEquals(WhereClauseParser.PROPERTYNAME, tree.getChild(0).getType());
    assertTrue(propName.equals(tree.getChild(0).getText()));
    QueryHelper.walk(theQuery, new WalkerCallbackAdapter() {

        @Override
        public void in(String property, boolean negated, String... propertyValues) {
            assertTrue("Property name should be " + propName, propName.equals(property));
            for (int i = 0; i < values.length; i++) {
                assertTrue("Value must match:" + values[i], values[i].equals(propertyValues[i]));
            }
        }
    });
}
Also used : CommonTree(org.antlr.runtime.tree.CommonTree) WalkerCallbackAdapter(org.alfresco.rest.framework.resource.parameters.where.QueryHelper.WalkerCallbackAdapter)

Example 4 with WalkerCallbackAdapter

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

the class WhereTests method comparisonChecks.

/**
 * Used by ComparisonClauseTest, validates the clause
 * @param theQuery Query
 * @param comparisonOperator One of EQUALS LESSTHAN GREATERTHAN LESSTHANOREQUALS GREATERTHANOREQUALS
 * @param propName String
 * @param propVal String
 */
private void comparisonChecks(Query theQuery, final int comparisonOperator, final String propName, final String propVal) {
    assertNotNull(theQuery);
    CommonTree tree = theQuery.getTree();
    assertNotNull(tree);
    assertEquals(comparisonOperator, tree.getType());
    assertEquals(WhereClauseParser.PROPERTYNAME, tree.getChild(0).getType());
    assertTrue(propName.equals(tree.getChild(0).getText()));
    assertEquals(WhereClauseParser.PROPERTYVALUE, tree.getChild(1).getType());
    QueryHelper.walk(theQuery, new WalkerCallbackAdapter() {

        @Override
        public void comparison(int comparisonType, String propertyName, String propertyValue, boolean negated) {
            assertTrue("Property name should be " + propName, propName.equals(propertyName));
            assertTrue(comparisonOperator == comparisonType);
            assertTrue("Property value should be " + propVal, propVal.equals(propertyValue));
        }
    });
}
Also used : CommonTree(org.antlr.runtime.tree.CommonTree) WalkerCallbackAdapter(org.alfresco.rest.framework.resource.parameters.where.QueryHelper.WalkerCallbackAdapter)

Example 5 with WalkerCallbackAdapter

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

Aggregations

WalkerCallbackAdapter (org.alfresco.rest.framework.resource.parameters.where.QueryHelper.WalkerCallbackAdapter)9 CommonTree (org.antlr.runtime.tree.CommonTree)7 Query (org.alfresco.rest.framework.resource.parameters.where.Query)3 Test (org.junit.Test)3 InvalidQueryException (org.alfresco.rest.framework.resource.parameters.where.InvalidQueryException)2 HashSet (java.util.HashSet)1 PersonFavourite (org.alfresco.repo.favourites.PersonFavourite)1 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)1 Paging (org.alfresco.rest.framework.resource.parameters.Paging)1 Type (org.alfresco.service.cmr.favourites.FavouritesService.Type)1