Search in sources :

Example 1 with LookupRecord

use of org.openforis.collect.persistence.jooq.tables.records.LookupRecord in project collect by openforis.

the class DynamicTableDao method addFilterConditions.

protected void addFilterConditions(Lookup lookupTable, SelectJoinStep<? extends Record> select, NameValueEntry[] filters) {
    for (NameValueEntry filter : filters) {
        String colName = filter.getKey();
        @SuppressWarnings("unchecked") TableField<LookupRecord, Object> tableField = (TableField<LookupRecord, Object>) lookupTable.field(colName);
        if (tableField != null) {
            Object filterValue = filter.getValue();
            Condition condition;
            if ((tableField.getType().equals(String.class)) && (filterValue == null || filterValue instanceof String && StringUtils.isEmpty((String) filterValue))) {
                condition = tableField.isNull().or(tableField.trim().equal(""));
            } else if (filterValue == null) {
                condition = tableField.isNull();
            } else {
                condition = tableField.equal(filterValue);
            }
            select.where(condition);
        } else {
            log.warn("Filter not applied: " + filter);
        }
    }
}
Also used : Condition(org.jooq.Condition) LookupRecord(org.openforis.collect.persistence.jooq.tables.records.LookupRecord) TableField(org.jooq.TableField) NameValueEntry(org.openforis.collect.model.NameValueEntry)

Aggregations

Condition (org.jooq.Condition)1 TableField (org.jooq.TableField)1 NameValueEntry (org.openforis.collect.model.NameValueEntry)1 LookupRecord (org.openforis.collect.persistence.jooq.tables.records.LookupRecord)1