Search in sources :

Example 6 with SearchCondition

use of org.apache.cxf.jaxrs.ext.search.SearchCondition in project cxf by apache.

the class FiqlParserTest method testParseOffsetDateTimeWithDefaultFormat.

@Test
public void testParseOffsetDateTimeWithDefaultFormat() throws SearchParseException, ParseException {
    SearchCondition<Condition> filter = parser.parse("offsetDateTime=le=2010-03-11T18:00:00+01:00");
    DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
    assertTrue(filter.isMet(new Condition("whatever", 15, null, OffsetDateTime.parse("2010-03-11T18:00:00+0100", df))));
    assertTrue(filter.isMet(new Condition(null, null, null, OffsetDateTime.parse("2010-03-10T22:22:00+0100", df))));
    assertFalse(filter.isMet(new Condition("blah", null, null, OffsetDateTime.parse("2010-03-12T00:00:00+0100", df))));
    assertFalse(filter.isMet(new Condition(null, 123, null, OffsetDateTime.parse("2010-03-12T00:00:00+0100", df))));
}
Also used : SearchCondition(org.apache.cxf.jaxrs.ext.search.SearchCondition) DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.junit.Test)

Example 7 with SearchCondition

use of org.apache.cxf.jaxrs.ext.search.SearchCondition in project cxf by apache.

the class FiqlParserTest method doTestParseName2.

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")));
}
Also used : SearchCondition(org.apache.cxf.jaxrs.ext.search.SearchCondition) Date(java.util.Date) LocalDate(java.time.LocalDate)

Example 8 with SearchCondition

use of org.apache.cxf.jaxrs.ext.search.SearchCondition in project cxf by apache.

the class FiqlParserTest method testParseInstantDuration.

@Test
public void testParseInstantDuration() throws Exception {
    SearchCondition<Condition> filter = parser.parse("localDateTime=gt=-PT1M");
    LocalDateTime now = LocalDateTime.now();
    LocalDateTime tenMinutesAgo = now.minusMinutes(10);
    assertTrue(filter.isMet(new Condition(null, null, null, now)));
    assertFalse(filter.isMet(new Condition(null, null, null, tenMinutesAgo)));
}
Also used : SearchCondition(org.apache.cxf.jaxrs.ext.search.SearchCondition) LocalDateTime(java.time.LocalDateTime) Test(org.junit.Test)

Example 9 with SearchCondition

use of org.apache.cxf.jaxrs.ext.search.SearchCondition in project cxf by apache.

the class ODataParser method parse.

@Override
@SuppressWarnings("unchecked")
public SearchCondition<T> parse(String searchExpression) throws SearchParseException {
    try {
        final T condition = conditionClass.newInstance();
        final FilterExpression expression = parser.parseFilterString(searchExpression);
        final FilterExpressionVisitor visitor = new FilterExpressionVisitor(condition);
        return (SearchCondition<T>) expression.accept(visitor);
    } catch (ODataMessageException | ODataApplicationException | InstantiationException | IllegalAccessException ex) {
        throw new SearchParseException(ex);
    }
}
Also used : AndSearchCondition(org.apache.cxf.jaxrs.ext.search.AndSearchCondition) PrimitiveSearchCondition(org.apache.cxf.jaxrs.ext.search.PrimitiveSearchCondition) OrSearchCondition(org.apache.cxf.jaxrs.ext.search.OrSearchCondition) SearchCondition(org.apache.cxf.jaxrs.ext.search.SearchCondition) SearchParseException(org.apache.cxf.jaxrs.ext.search.SearchParseException) ODataMessageException(org.apache.olingo.odata2.api.exception.ODataMessageException) FilterExpression(org.apache.olingo.odata2.api.uri.expression.FilterExpression) ODataApplicationException(org.apache.olingo.odata2.api.exception.ODataApplicationException)

Example 10 with SearchCondition

use of org.apache.cxf.jaxrs.ext.search.SearchCondition in project cxf by apache.

the class FiqlParserTest method doTestParseName.

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)));
}
Also used : SearchCondition(org.apache.cxf.jaxrs.ext.search.SearchCondition) Date(java.util.Date) LocalDate(java.time.LocalDate)

Aggregations

SearchCondition (org.apache.cxf.jaxrs.ext.search.SearchCondition)21 Test (org.junit.Test)18 DateTimeFormatter (java.time.format.DateTimeFormatter)7 Date (java.util.Date)7 LocalDate (java.time.LocalDate)6 HashMap (java.util.HashMap)4 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 AndSearchCondition (org.apache.cxf.jaxrs.ext.search.AndSearchCondition)2 PrimitiveSearchCondition (org.apache.cxf.jaxrs.ext.search.PrimitiveSearchCondition)2 PrimitiveStatement (org.apache.cxf.jaxrs.ext.search.PrimitiveStatement)2 SearchParseException (org.apache.cxf.jaxrs.ext.search.SearchParseException)2 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 OrSearchCondition (org.apache.cxf.jaxrs.ext.search.OrSearchCondition)1 SBThreadLocalVisitorState (org.apache.cxf.jaxrs.ext.search.visitor.SBThreadLocalVisitorState)1 ODataApplicationException (org.apache.olingo.odata2.api.exception.ODataApplicationException)1 ODataMessageException (org.apache.olingo.odata2.api.exception.ODataMessageException)1 FilterExpression (org.apache.olingo.odata2.api.uri.expression.FilterExpression)1 Criteria (org.opennms.core.criteria.Criteria)1