Search in sources :

Example 1 with SearchCondition

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

the class CriteriaBuilderSearchVisitorIT method testScanReportAndCondition.

@Test
public void testScanReportAndCondition() {
    CriteriaBuilder builder = new ScanReportRestService().getCriteriaBuilder(null);
    CriteriaBuilderSearchVisitor<ScanReport, ScanReport> visitor = new CriteriaBuilderSearchVisitor<>(builder, ScanReport.class);
    // Simulates /opennms/api/v2/scanreports?_s=applications%3D%3DLocal+Access;timestamp%3Dle%3D2016-02-01T15:07:14.340-0500&limit=20&offset=0&order=desc&orderBy=timestamp
    List<SearchCondition<ScanReport>> conditions = new ArrayList<SearchCondition<ScanReport>>();
    conditions.add(new PrimitiveSearchCondition<ScanReport>("applications", "blah", String.class, ConditionType.EQUALS, new ScanReport()));
    conditions.add(new PrimitiveSearchCondition<ScanReport>("timestamp", new Date(), Date.class, ConditionType.LESS_OR_EQUALS, new ScanReport()));
    SearchCondition<ScanReport> andCondition = new AndSearchCondition<ScanReport>(conditions);
    visitor.visit(andCondition);
    Criteria criteria = visitor.getQuery().toCriteria();
    System.out.println(criteria.toString());
    m_dao.countMatching(criteria);
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) ScanReport(org.opennms.netmgt.model.ScanReport) ArrayList(java.util.ArrayList) Criteria(org.opennms.core.criteria.Criteria) Date(java.util.Date) ScanReportRestService(org.opennms.web.rest.v2.ScanReportRestService) AndSearchCondition(org.apache.cxf.jaxrs.ext.search.AndSearchCondition) PrimitiveSearchCondition(org.apache.cxf.jaxrs.ext.search.PrimitiveSearchCondition) SearchCondition(org.apache.cxf.jaxrs.ext.search.SearchCondition) AndSearchCondition(org.apache.cxf.jaxrs.ext.search.AndSearchCondition) Test(org.junit.Test)

Example 2 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)

Example 3 with SearchCondition

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

the class SQLPrinterVisitorTest method testSQL4WithTLStateAndSingleThread.

@Test
public void testSQL4WithTLStateAndSingleThread() throws SearchParseException {
    SearchCondition<Condition> filter = parser.parse("(name==test,level==18);(name==test1,level!=19)");
    SQLPrinterVisitor<Condition> visitor = new SQLPrinterVisitor<Condition>("table");
    visitor.setVisitorState(new SBThreadLocalVisitorState());
    filter.accept(visitor);
    String sql = visitor.getQuery();
    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));
}
Also used : SearchCondition(org.apache.cxf.jaxrs.ext.search.SearchCondition) SBThreadLocalVisitorState(org.apache.cxf.jaxrs.ext.search.visitor.SBThreadLocalVisitorState) Test(org.junit.Test)

Example 4 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 ex) {
        throw new SearchParseException(ex);
    } catch (ODataApplicationException ex) {
        throw new SearchParseException(ex);
    } catch (InstantiationException ex) {
        throw new SearchParseException(ex);
    } catch (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 5 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)

Aggregations

SearchCondition (org.apache.cxf.jaxrs.ext.search.SearchCondition)11 Test (org.junit.Test)8 Date (java.util.Date)7 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 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 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 OrSearchCondition (org.apache.cxf.jaxrs.ext.search.OrSearchCondition)1 SearchParseException (org.apache.cxf.jaxrs.ext.search.SearchParseException)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 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)1 ScanReport (org.opennms.netmgt.model.ScanReport)1 ScanReportRestService (org.opennms.web.rest.v2.ScanReportRestService)1