Search in sources :

Example 16 with NameValueEntry

use of org.openforis.collect.model.NameValueEntry 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

NameValueEntry (org.openforis.collect.model.NameValueEntry)16 ArrayList (java.util.ArrayList)8 CodeList (org.openforis.idm.metamodel.CodeList)7 ExternalCodeListItem (org.openforis.idm.metamodel.ExternalCodeListItem)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 HashSet (java.util.HashSet)1 Entry (java.util.Map.Entry)1 Condition (org.jooq.Condition)1 TableField (org.jooq.TableField)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 LookupRecord (org.openforis.collect.persistence.jooq.tables.records.LookupRecord)1 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)1 CodeListLevel (org.openforis.idm.metamodel.CodeListLevel)1 CodeAttribute (org.openforis.idm.model.CodeAttribute)1