org.apache.cxf.jaxrs.ext.search.SearchParseException Java Examples
The following examples show how to use
org.apache.cxf.jaxrs.ext.search.SearchParseException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SyncopeFiqlParser.java From syncope with Apache License 2.0 | 6 votes |
@Override public SearchCondition<T> build() throws SearchParseException { String templateName = getSetter(name); T cond = createTemplate(templateName); ConditionType ct = operatorsMap.get(operator); if (isPrimitive(cond)) { return new SyncopeFiqlSearchCondition<>(ct, cond); } else { String templateNameLCase = templateName.toLowerCase(); return new SyncopeFiqlSearchCondition<>(Map.of(templateNameLCase, ct), Map.of(templateNameLCase, name), Map.of(templateNameLCase, tvalue.getTypeInfo()), cond, operator); } }
Example #2
Source File: SyncopeFiqlParser.java From syncope with Apache License 2.0 | 6 votes |
@Override protected ASTNode<T> parseComparison(final String expr) throws SearchParseException { Matcher m = comparatorsPattern.matcher(expr); if (m.find()) { String propertyName = expr.substring(0, m.start(1)); String operator = m.group(1); String value = expr.substring(m.end(1)); if ("".equals(value)) { throw new SearchParseException("Not a comparison expression: " + expr); } String name = unwrapSetter(propertyName); name = getActualSetterName(name); TypeInfoObject castedValue = parseType(propertyName, name, value); if (castedValue != null) { return new SyncopeComparison(name, operator, castedValue); } else { return null; } } else { throw new SearchParseException("Not a comparison expression: " + expr); } }
Example #3
Source File: FiqlParser.java From cxf with Apache License 2.0 | 6 votes |
protected ASTNode<T> parseComparison(String expr) throws SearchParseException { Matcher m = comparatorsPattern.matcher(expr); if (m.find()) { String propertyName = expr.substring(0, m.start(1)); String operator = m.group(1); String value = expr.substring(m.end(1)); if ("".equals(value)) { throw new SearchParseException("Not a comparison expression: " + expr); } String name = unwrapSetter(propertyName); name = getActualSetterName(name); TypeInfoObject castedValue = parseType(propertyName, name, value); if (castedValue != null) { return new Comparison(name, operator, castedValue); } return null; } throw new SearchParseException("Not a comparison expression: " + expr); }
Example #4
Source File: FiqlParserTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testParseComplex1() throws SearchParseException { SearchCondition<Condition> filter = parser.parse("name==ami*;level=gt=10"); assertEquals(ConditionType.AND, filter.getConditionType()); List<SearchCondition<Condition>> conditions = filter.getSearchConditions(); assertEquals(2, conditions.size()); PrimitiveStatement st1 = conditions.get(0).getStatement(); PrimitiveStatement st2 = conditions.get(1).getStatement(); assertTrue((ConditionType.EQUALS.equals(st1.getCondition()) && ConditionType.GREATER_THAN.equals(st2.getCondition())) || (ConditionType.EQUALS.equals(st2.getCondition()) && ConditionType.GREATER_THAN.equals(st1.getCondition()))); assertTrue(filter.isMet(new Condition("amichalec", 12, new Date()))); assertTrue(filter.isMet(new Condition("ami", 12, new Date()))); assertFalse(filter.isMet(new Condition("ami", 8, null))); assertFalse(filter.isMet(new Condition("am", 20, null))); }
Example #5
Source File: FiqlParserTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testParseComplex2() throws SearchParseException { SearchCondition<Condition> filter = parser.parse("name==ami*,level=gt=10"); assertEquals(ConditionType.OR, filter.getConditionType()); List<SearchCondition<Condition>> conditions = filter.getSearchConditions(); assertEquals(2, conditions.size()); PrimitiveStatement st1 = conditions.get(0).getStatement(); PrimitiveStatement st2 = conditions.get(1).getStatement(); assertTrue((ConditionType.EQUALS.equals(st1.getCondition()) && ConditionType.GREATER_THAN.equals(st2.getCondition())) || (ConditionType.EQUALS.equals(st2.getCondition()) && ConditionType.GREATER_THAN.equals(st1.getCondition()))); assertTrue(filter.isMet(new Condition("ami", 0, new Date()))); assertTrue(filter.isMet(new Condition("foo", 20, null))); assertFalse(filter.isMet(new Condition("foo", 0, null))); }
Example #6
Source File: FiqlCollectionsTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testWithCollectionAfterFirstLevelOnCollection() throws SearchParseException { FiqlParser<Place> placeParser = new FiqlParser<>(Place.class); SearchCondition<Place> placeCondition = placeParser .parse("specs.features.description==description"); Place place = placeCondition.getCondition(); assertNotNull(place); }
Example #7
Source File: SQLPrinterVisitorTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testSQLCamelNameSearchBean() throws SearchParseException { FiqlParser<SearchBean> beanParser = new FiqlParser<>(SearchBean.class); SearchCondition<SearchBean> filter = beanParser.parse("theName==ami*;theLevel=gt=10"); SQLPrinterVisitor<SearchBean> visitor = new SQLPrinterVisitor<>("table"); filter.accept(visitor); String sql = visitor.getQuery(); assertTrue("SELECT * FROM table WHERE (theName LIKE 'ami%') AND (theLevel > '10')".equals(sql) || "SELECT * FROM table WHERE (theLevel > '10') AND (theName LIKE 'ami%')".equals(sql)); }
Example #8
Source File: FiqlCollectionsTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testWithCollectionAfterFirstLevelOnSingleObject() throws SearchParseException { FiqlParser<Room> roomParser = new FiqlParser<>(Room.class); SearchCondition<Room> roomCondition = roomParser .parse("furniture.spec.features.description==description"); Room room = roomCondition.getCondition(); assertNotNull(room); }
Example #9
Source File: SQLPrinterVisitorTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testSQL5() throws SearchParseException { SearchCondition<Condition> filter = parser.parse("name==test"); SQLPrinterVisitor<Condition> visitor = new SQLPrinterVisitor<>("table"); filter.accept(visitor); String sql = visitor.getQuery(); assertEquals("SELECT * FROM table WHERE name = 'test'", sql); }
Example #10
Source File: ODataParserTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testFilterByFirstAndLastNameEqualValueWithAlternative() throws SearchParseException { SearchCondition< Person > filter = parser.parse( "(FirstName eq 'Tom' and LastName eq 'Tommyknocker')" + " or (FirstName eq 'Peter' and LastName eq 'Bombadil')"); assertTrue(filter.isMet(new Person("Tom", "Tommyknocker"))); assertTrue(filter.isMet(new Person("Peter", "Bombadil"))); assertFalse(filter.isMet(new Person("Tom", "Bombadil"))); }
Example #11
Source File: ODataParserTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testFilterByFirstOrLastNameEqualValue() throws SearchParseException { SearchCondition< Person > filter = parser.parse("FirstName eq 'Tom' or FirstName eq 'Peter' and LastName eq 'Bombadil'"); assertTrue(filter.isMet(new Person("Tom", "Bombadil"))); assertTrue(filter.isMet(new Person("Peter", "Bombadil"))); assertFalse(filter.isMet(new Person("Barry", "Bombadil"))); }
Example #12
Source File: SQLHierarchicalQueryTest.java From cxf with Apache License 2.0 | 5 votes |
@Test(expected = SearchParseException.class) public void testTooManyJoins() { FiqlParser<SearchBean> parser = new FiqlParser<>(SearchBean.class); SearchCondition<SearchBean> filter = parser.parse("cartridges.colour==blue;cartridges.location==Japan"); SQLPrinterVisitor<SearchBean> visitor = new SQLPrinterVisitor<>("printers"); filter.accept(visitor.visitor()); }
Example #13
Source File: SQLHierarchicalQueryTest.java From cxf with Apache License 2.0 | 5 votes |
@Test(expected = SearchParseException.class) public void testLongHierarchicalQuery() { FiqlParser<SearchBean> parser = new FiqlParser<>(SearchBean.class); SearchCondition<SearchBean> filter = parser.parse("cartridges.producer.location==Japan"); SQLPrinterVisitor<SearchBean> visitor = new SQLPrinterVisitor<>("printers"); filter.accept(visitor.visitor()); }
Example #14
Source File: SQLHierarchicalQueryTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testAndHierarchicalQuery() throws SearchParseException { FiqlParser<SearchBean> parser = new FiqlParser<>(SearchBean.class); SearchCondition<SearchBean> filter = parser.parse("name==Epson;cartridges.colour==blue"); SQLPrinterVisitor<SearchBean> visitor = new SQLPrinterVisitor<>("printers"); filter.accept(visitor.visitor()); String sql = visitor.getQuery(); assertEquals("SELECT * FROM printers left join cartridges" + " on printers.id = cartridges.printer_id" + " WHERE (name = 'Epson') AND (cartridges.colour = 'blue')", sql); }
Example #15
Source File: SQLHierarchicalQueryTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testSimpleHierarchicalQuery() throws SearchParseException { FiqlParser<SearchBean> parser = new FiqlParser<>(SearchBean.class); SearchCondition<SearchBean> filter = parser.parse("cartridges.colour==blue"); SQLPrinterVisitor<SearchBean> visitor = new SQLPrinterVisitor<>("printers"); filter.accept(visitor.visitor()); String sql = visitor.getQuery(); assertEquals("SELECT * FROM printers left join cartridges" + " on printers.id = cartridges.printer_id" + " WHERE cartridges.colour = 'blue'", sql); }
Example #16
Source File: SQLPrinterVisitorTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testSQL5WithFieldMap() throws SearchParseException { SearchCondition<Condition> filter = parser.parse("name==test"); SQLPrinterVisitor<Condition> visitor = new SQLPrinterVisitor<Condition>( Collections.singletonMap("name", "NAMES"), "table", Collections.singletonList("NAMES")); filter.accept(visitor); String sql = visitor.getQuery(); assertEquals("SELECT NAMES FROM table WHERE NAMES = 'test'", sql); }
Example #17
Source File: SQLPrinterVisitorTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testSQL5WithColumns() throws SearchParseException { SearchCondition<Condition> filter = parser.parse("name==test"); SQLPrinterVisitor<Condition> visitor = new SQLPrinterVisitor<>("table", "NAMES"); filter.accept(visitor); String sql = visitor.getQuery(); assertEquals("SELECT NAMES FROM table WHERE name = 'test'", sql); }
Example #18
Source File: FiqlParserTest.java From cxf with Apache License 2.0 | 5 votes |
private void doTestParseName2(String exp) throws SearchParseException { SearchCondition<Condition> filter = parser.parse(exp); assertTrue(filter.isMet(new Condition("king", 10, new Date(), "king2"))); assertTrue(filter.isMet(new Condition("king", 0, null, "king2"))); assertFalse(filter.isMet(new Condition("diamond", 10, new Date(), "theking2"))); assertFalse(filter.isMet(new Condition("diamond", 0, null, "theking2"))); }
Example #19
Source File: FiqlParserTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testWildcard() throws SearchParseException { SearchCondition<Condition> filter = parser.parse("name==*"); try { filter.isMet(new Condition("foobaz", 0, null)); fail("Failure expected on an invalid search condition"); } catch (SearchParseException ex) { // expected } }
Example #20
Source File: FiqlParserTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testMultipleLists() throws SearchParseException { FiqlParser<Job> jobParser = new FiqlParser<>(Job.class, Collections.<String, String>emptyMap(), Collections.singletonMap("itemName", "tasks.items.itemName")); SearchCondition<Job> jobCondition = jobParser.parse("itemName==myitem"); Job job = jobCondition.getCondition(); assertEquals("myitem", job.getTasks().get(0).getItems().get(0).getItemName()); }
Example #21
Source File: FiqlParserTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testParseComplex4() throws SearchParseException { SearchCondition<Condition> filter = parser.parse("name==foo*;name!=*bar,level=gt=10"); assertTrue(filter.isMet(new Condition("zonk", 20, null))); assertTrue(filter.isMet(new Condition("foobaz", 0, null))); assertTrue(filter.isMet(new Condition("foobar", 20, null))); assertFalse(filter.isMet(new Condition("fooxxxbar", 0, null))); }
Example #22
Source File: FiqlParserTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testSQL4() throws SearchParseException { SearchCondition<Condition> filter = parser.parse("(name==test,level==18);(name==test1,level!=19)"); String sql = SearchUtils.toSQL(filter, "table"); assertTrue(("SELECT * FROM table WHERE ((name = 'test') OR (level = '18'))" + " AND ((name = 'test1') OR (level <> '19'))").equals(sql) || ("SELECT * FROM table WHERE ((name = 'test1') OR (level <> '19'))" + " AND ((name = 'test') OR (level = '18'))").equals(sql)); }
Example #23
Source File: FiqlParserTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testSQL3() throws SearchParseException { SearchCondition<Condition> filter = parser.parse("name==foo*;(name!=*bar,level=gt=10)"); String sql = SearchUtils.toSQL(filter, "table"); assertTrue(("SELECT * FROM table WHERE (name LIKE 'foo%') AND ((name NOT LIKE '%bar') " + "OR (level > '10'))").equals(sql) || ("SELECT * FROM table WHERE (name LIKE 'foo%') AND " + "((level > '10') OR (name NOT LIKE '%bar'))").equals(sql)); }
Example #24
Source File: FiqlParserTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testParseComplex3() throws SearchParseException { SearchCondition<Condition> filter = parser.parse("name==foo*;(name!=*bar,level=gt=10)"); assertTrue(filter.isMet(new Condition("fooooo", 0, null))); assertTrue(filter.isMet(new Condition("fooooobar", 20, null))); assertFalse(filter.isMet(new Condition("fooobar", 0, null))); assertFalse(filter.isMet(new Condition("bar", 20, null))); }
Example #25
Source File: FiqlParserTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testSQL2() throws SearchParseException { SearchCondition<Condition> filter = parser.parse("name==ami*,level=gt=10"); String sql = SearchUtils.toSQL(filter, "table"); assertTrue("SELECT * FROM table WHERE (name LIKE 'ami%') OR (level > '10')".equals(sql) || "SELECT * FROM table WHERE (level > '10') OR (name LIKE 'ami%')".equals(sql)); }
Example #26
Source File: FiqlParserTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testSQL1() throws SearchParseException { SearchCondition<Condition> filter = parser.parse("name==ami*;level=gt=10"); String sql = SearchUtils.toSQL(filter, "table"); assertTrue("SELECT * FROM table WHERE (name LIKE 'ami%') AND (level > '10')".equals(sql) || "SELECT * FROM table WHERE (level > '10') AND (name LIKE 'ami%')".equals(sql)); }
Example #27
Source File: FiqlParserTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testParseDateWithCustomFormat() throws SearchParseException, ParseException { Map<String, String> props = new HashMap<>(); props.put(SearchUtils.DATE_FORMAT_PROPERTY, "yyyy-MM-dd'T'HH:mm:ss"); props.put(SearchUtils.TIMEZONE_SUPPORT_PROPERTY, "false"); parser = new FiqlParser<>(Condition.class, props); SearchCondition<Condition> filter = parser.parse("time=le=2010-03-11T18:00:00"); DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); assertTrue(filter.isMet(new Condition("whatever", 15, df.parse("2010-03-11T18:00:00")))); assertTrue(filter.isMet(new Condition(null, null, df.parse("2010-03-10T22:22:00")))); assertFalse(filter.isMet(new Condition("blah", null, df.parse("2010-03-12T00:00:00")))); assertFalse(filter.isMet(new Condition(null, 123, df.parse("2010-03-12T00:00:00")))); }
Example #28
Source File: FiqlParserTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testParseDateWithDefaultFormat() throws SearchParseException, ParseException { SearchCondition<Condition> filter = parser.parse("time=le=2010-03-11T18:00:00.000+00:00"); DateFormat df = new SimpleDateFormat(SearchUtils.DEFAULT_DATE_FORMAT); assertTrue(filter.isMet(new Condition("whatever", 15, df.parse("2010-03-11T18:00:00.000+0000")))); assertTrue(filter.isMet(new Condition(null, null, df.parse("2010-03-10T22:22:00.000+0000")))); assertFalse(filter.isMet(new Condition("blah", null, df.parse("2010-03-12T00:00:00.000+0000")))); assertFalse(filter.isMet(new Condition(null, 123, df.parse("2010-03-12T00:00:00.000+0000")))); }
Example #29
Source File: FiqlParserTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testParseLevel() throws SearchParseException { SearchCondition<Condition> filter = parser.parse("level=gt=10"); assertTrue(filter.isMet(new Condition("whatever", 15, new Date()))); assertTrue(filter.isMet(new Condition(null, 15, null))); assertFalse(filter.isMet(new Condition("blah", 5, new Date()))); assertFalse(filter.isMet(new Condition("foobar", 0, null))); }
Example #30
Source File: FiqlParserTest.java From cxf with Apache License 2.0 | 5 votes |
private void doTestParseName(String exp) throws SearchParseException { SearchCondition<Condition> filter = parser.parse(exp); assertTrue(filter.isMet(new Condition("king", 10, new Date()))); assertTrue(filter.isMet(new Condition("king", 0, null))); assertFalse(filter.isMet(new Condition("diamond", 10, new Date()))); assertFalse(filter.isMet(new Condition("diamond", 0, null))); }