Search in sources :

Example 11 with SearchCondition

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

the class FiqlParserTest method testParseInstantWithDefaultFormat.

@Test
public void testParseInstantWithDefaultFormat() throws SearchParseException, ParseException {
    SearchCondition<Condition> filter = parser.parse("instant=le=2010-03-11");
    DateFormat df = new SimpleDateFormat(SearchUtils.DEFAULT_DATE_FORMAT);
    assertTrue(filter.isMet(new Condition("whatever", 15, null, df.parse("2010-03-11").toInstant())));
    assertTrue(filter.isMet(new Condition(null, null, null, df.parse("2010-03-10").toInstant())));
    assertFalse(filter.isMet(new Condition("blah", null, null, df.parse("2010-03-12").toInstant())));
    assertFalse(filter.isMet(new Condition(null, 123, null, df.parse("2010-03-12").toInstant())));
}
Also used : SearchCondition(org.apache.cxf.jaxrs.ext.search.SearchCondition) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 12 with SearchCondition

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

the class FiqlParserTest method testParseZonedDateTimeWithDefaultFormat.

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

Example 13 with SearchCondition

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

the class FiqlParserTest method testParseOffsetDateTimeWithCustomFormat.

@Test
public void testParseOffsetDateTimeWithCustomFormat() throws SearchParseException, ParseException {
    Map<String, String> props = new HashMap<>();
    props.put(SearchUtils.DATE_FORMAT_PROPERTY, "yyyy-MM-dd'T'HH:mm:ssZ");
    props.put(SearchUtils.TIMEZONE_SUPPORT_PROPERTY, "true");
    parser = new FiqlParser<>(Condition.class, props);
    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) HashMap(java.util.HashMap) DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.junit.Test)

Example 14 with SearchCondition

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

the class FiqlParserTest method testParseComplex1.

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

Example 15 with SearchCondition

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

the class FiqlParserTest method testParseDateDuration.

@Test
public void testParseDateDuration() throws Exception {
    SearchCondition<Condition> filter = parser.parse("time=gt=-PT1M");
    Date now = new Date();
    Date tenMinutesAgo = new Date();
    DatatypeFactory.newInstance().newDuration("-PT10M").addTo(tenMinutesAgo);
    assertTrue(filter.isMet(new Condition(null, null, now)));
    assertFalse(filter.isMet(new Condition(null, null, tenMinutesAgo)));
}
Also used : SearchCondition(org.apache.cxf.jaxrs.ext.search.SearchCondition) Date(java.util.Date) LocalDate(java.time.LocalDate) Test(org.junit.Test)

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