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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations