Search in sources :

Example 1 with Criteria

use of com.axelor.rpc.Criteria in project axelor-open-suite by axelor.

the class ProductController method getDisplayedProductIdList.

@SuppressWarnings("unchecked")
private List<Long> getDisplayedProductIdList(ActionRequest request) {
    JpaSecurity security = Beans.get(JpaSecurity.class);
    List<Long> displayedProductIdList = new ArrayList<>();
    Criteria criteria = Criteria.parse(request);
    List<?> products = criteria.createQuery(Product.class, security.getFilter(JpaSecurity.CAN_READ, Product.class)).select("id").fetch(-1, -1);
    for (Object product : products) {
        if (product instanceof Map) {
            Long id = (Long) ((Map<String, Object>) product).get("id");
            displayedProductIdList.add(id);
        }
    }
    return displayedProductIdList;
}
Also used : JpaSecurity(com.axelor.db.JpaSecurity) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) Criteria(com.axelor.rpc.Criteria) Map(java.util.Map)

Example 2 with Criteria

use of com.axelor.rpc.Criteria in project axelor-open-suite by axelor.

the class TestBamlParser method testJsonQuery.

@Test
public void testJsonQuery() {
    Map<String, Object> rawCriteria = new HashMap<String, Object>();
    Map<String, Object> _domainContext = new HashMap<String, Object>();
    _domainContext.put("jsonModel", "File");
    rawCriteria.put("fieldName", "attrs.integer1");
    rawCriteria.put("operator", "=");
    rawCriteria.put("value", 2);
    rawCriteria.put("_domain", "jsonModel = :jsonModel");
    rawCriteria.put("_domainContext", _domainContext);
    Criteria criteria = Criteria.parse(rawCriteria, MetaJsonRecord.class, false);
    criteria.createQuery(MetaJsonRecord.class).toString();
    System.err.println(criteria.toString());
    System.err.println(criteria.createQuery(MetaJsonRecord.class).toString());
}
Also used : HashMap(java.util.HashMap) Criteria(com.axelor.rpc.Criteria) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord) Test(org.junit.Test)

Aggregations

Criteria (com.axelor.rpc.Criteria)2 Product (com.axelor.apps.base.db.Product)1 JpaSecurity (com.axelor.db.JpaSecurity)1 MetaJsonRecord (com.axelor.meta.db.MetaJsonRecord)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1