Search in sources :

Example 1 with Condition

use of org.pentaho.di.core.Condition in project pentaho-kettle by pentaho.

the class TableView method setFilter.

// Filtering...
public void setFilter() {
    if (condition == null) {
        condition = new Condition();
    }
    RowMetaInterface f = getRowWithoutValues();
    EnterConditionDialog ecd = new EnterConditionDialog(parent.getShell(), SWT.NONE, f, condition);
    Condition cond = ecd.open();
    if (cond != null) {
        ArrayList<Integer> tokeep = new ArrayList<Integer>();
        // Apply the condition to the TableView...
        int nr = table.getItemCount();
        for (int i = nr - 1; i >= 0; i--) {
            RowMetaAndData r = getRow(i);
            boolean keep = cond.evaluate(r.getRowMeta(), r.getData());
            if (keep) {
                tokeep.add(Integer.valueOf(i));
            }
        }
        int[] sels = new int[tokeep.size()];
        for (int i = 0; i < sels.length; i++) {
            sels[i] = (tokeep.get(i)).intValue();
        }
        table.setSelection(sels);
    }
}
Also used : Condition(org.pentaho.di.core.Condition) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ArrayList(java.util.ArrayList) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) EnterConditionDialog(org.pentaho.di.ui.core.dialog.EnterConditionDialog) Point(org.eclipse.swt.graphics.Point)

Example 2 with Condition

use of org.pentaho.di.core.Condition in project pentaho-kettle by pentaho.

the class StringSearcher method stringSearchInObject.

private static void stringSearchInObject(Object obj, int level, List<StringSearchResult> stringList, Object parentObject, Object grandParentObject, Field field) {
    String fieldName = field.getName();
    if (obj instanceof String) {
        // OK, let's add the String
        stringList.add(new StringSearchResult((String) obj, parentObject, grandParentObject, fieldName));
    } else if (obj instanceof String[]) {
        String[] array = (String[]) obj;
        for (int x = 0; x < array.length; x++) {
            if (array[x] != null) {
                stringList.add(new StringSearchResult(array[x], parentObject, grandParentObject, fieldName + " #" + (x + 1)));
            }
        }
    } else if (obj instanceof Boolean) {
        // OK, let's add the String
        stringList.add(new StringSearchResult(((Boolean) obj).toString(), parentObject, grandParentObject, fieldName + " (Boolean)"));
    } else if (obj instanceof Condition) {
        stringList.add(new StringSearchResult(((Condition) obj).toString(), parentObject, grandParentObject, fieldName + " (Condition)"));
    } else if (obj instanceof DatabaseInterface) {
        // Make sure we read the attributes. This is not picked up by default. (getDeclaredFields doesn't pick up
        // inherited fields)
        // 
        DatabaseInterface databaseInterface = (DatabaseInterface) obj;
        findMapMetaData(databaseInterface.getAttributes(), level + 1, stringList, parentObject, grandParentObject, field);
        findMetaData(obj, level + 1, stringList, parentObject, grandParentObject);
    } else if (obj instanceof Map) {
        findMapMetaData((Map<?, ?>) obj, level, stringList, parentObject, grandParentObject, field);
    } else if (obj instanceof Object[]) {
        for (int j = 0; j < ((Object[]) obj).length; j++) {
            findMetaData(((Object[]) obj)[j], level + 1, stringList, parentObject, grandParentObject);
        }
    } else {
        findMetaData(obj, level + 1, stringList, parentObject, grandParentObject);
    }
}
Also used : Condition(org.pentaho.di.core.Condition) DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) Map(java.util.Map)

Example 3 with Condition

use of org.pentaho.di.core.Condition in project pentaho-kettle by pentaho.

the class FilterRowsMeta method readData.

private void readData(Node stepnode) throws KettleXMLException {
    try {
        setTrueStepname(XMLHandler.getTagValue(stepnode, "send_true_to"));
        setFalseStepname(XMLHandler.getTagValue(stepnode, "send_false_to"));
        Node compare = XMLHandler.getSubNode(stepnode, "compare");
        Node condnode = XMLHandler.getSubNode(compare, "condition");
        // The new situation...
        if (condnode != null) {
            condition = new Condition(condnode);
        } else {
            // Old style condition: Line1 OR Line2 OR Line3: @deprecated!
            condition = new Condition();
            int nrkeys = XMLHandler.countNodes(compare, "key");
            if (nrkeys == 1) {
                Node knode = XMLHandler.getSubNodeByNr(compare, "key", 0);
                String key = XMLHandler.getTagValue(knode, "name");
                String value = XMLHandler.getTagValue(knode, "value");
                String field = XMLHandler.getTagValue(knode, "field");
                String comparator = XMLHandler.getTagValue(knode, "condition");
                condition.setOperator(Condition.OPERATOR_NONE);
                condition.setLeftValuename(key);
                condition.setFunction(Condition.getFunction(comparator));
                condition.setRightValuename(field);
                condition.setRightExact(new ValueMetaAndData("value", value));
            } else {
                for (int i = 0; i < nrkeys; i++) {
                    Node knode = XMLHandler.getSubNodeByNr(compare, "key", i);
                    String key = XMLHandler.getTagValue(knode, "name");
                    String value = XMLHandler.getTagValue(knode, "value");
                    String field = XMLHandler.getTagValue(knode, "field");
                    String comparator = XMLHandler.getTagValue(knode, "condition");
                    Condition subc = new Condition();
                    if (i > 0) {
                        subc.setOperator(Condition.OPERATOR_OR);
                    } else {
                        subc.setOperator(Condition.OPERATOR_NONE);
                    }
                    subc.setLeftValuename(key);
                    subc.setFunction(Condition.getFunction(comparator));
                    subc.setRightValuename(field);
                    subc.setRightExact(new ValueMetaAndData("value", value));
                    condition.addCondition(subc);
                }
            }
        }
    } catch (Exception e) {
        throw new KettleXMLException(BaseMessages.getString(PKG, "FilterRowsMeta.Exception..UnableToLoadStepInfoFromXML"), e);
    }
}
Also used : Condition(org.pentaho.di.core.Condition) Node(org.w3c.dom.Node) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) ValueMetaAndData(org.pentaho.di.core.row.ValueMetaAndData) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleStepException(org.pentaho.di.core.exception.KettleStepException)

Example 4 with Condition

use of org.pentaho.di.core.Condition in project pentaho-kettle by pentaho.

the class JoinRowsMeta method readRep.

@Override
public void readRep(Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases) throws KettleException {
    try {
        directory = rep.getStepAttributeString(id_step, "directory");
        prefix = rep.getStepAttributeString(id_step, "prefix");
        cacheSize = (int) rep.getStepAttributeInteger(id_step, "cache_size");
        mainStepname = rep.getStepAttributeString(id_step, "main");
        condition = rep.loadConditionFromStepAttribute(id_step, "id_condition");
        if (condition == null) {
            condition = new Condition();
        }
    } catch (Exception e) {
        throw new KettleException(BaseMessages.getString(PKG, "JoinRowsMeta.Exception.UnexpectedErrorInReadStepInfoFromRepository"), e);
    }
}
Also used : Condition(org.pentaho.di.core.Condition) KettleException(org.pentaho.di.core.exception.KettleException) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleStepException(org.pentaho.di.core.exception.KettleStepException)

Example 5 with Condition

use of org.pentaho.di.core.Condition in project pentaho-kettle by pentaho.

the class JoinRowsMeta method readData.

private void readData(Node stepnode) throws KettleXMLException {
    try {
        directory = XMLHandler.getTagValue(stepnode, "directory");
        prefix = XMLHandler.getTagValue(stepnode, "prefix");
        cacheSize = Const.toInt(XMLHandler.getTagValue(stepnode, "cache_size"), -1);
        mainStepname = XMLHandler.getTagValue(stepnode, "main");
        Node compare = XMLHandler.getSubNode(stepnode, "compare");
        Node condnode = XMLHandler.getSubNode(compare, "condition");
        // The new situation...
        if (condnode != null) {
            condition = new Condition(condnode);
        } else {
            condition = new Condition();
        }
    } catch (Exception e) {
        throw new KettleXMLException(BaseMessages.getString(PKG, "JoinRowsMeta.Exception.UnableToReadStepInfoFromXML"), e);
    }
}
Also used : Condition(org.pentaho.di.core.Condition) Node(org.w3c.dom.Node) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleStepException(org.pentaho.di.core.exception.KettleStepException)

Aggregations

Condition (org.pentaho.di.core.Condition)42 Test (org.junit.Test)14 Matchers.anyString (org.mockito.Matchers.anyString)6 RowMeta (org.pentaho.di.core.row.RowMeta)6 SQLCondition (org.pentaho.di.core.sql.SQLCondition)6 StepMeta (org.pentaho.di.trans.step.StepMeta)6 KettleException (org.pentaho.di.core.exception.KettleException)5 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)5 SQL (org.pentaho.di.core.sql.SQL)5 ParameterGenerationTest.newCondition (org.pentaho.di.trans.dataservice.optimization.paramgen.ParameterGenerationTest.newCondition)5 KettleStepException (org.pentaho.di.core.exception.KettleStepException)4 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)4 ValueMetaAndData (org.pentaho.di.core.row.ValueMetaAndData)4 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)3 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2