Search in sources :

Example 1 with ValueMetaAndData

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

the class EnterValueDialog method getValue.

private ValueMetaAndData getValue(String valuename) throws KettleValueException {
    try {
        int valtype = ValueMetaFactory.getIdForValueMeta(wValueType.getText());
        ValueMetaAndData val = new ValueMetaAndData(valuename, wInputString.getText());
        ValueMetaInterface valueMeta = ValueMetaFactory.cloneValueMeta(val.getValueMeta(), valtype);
        Object valueData = val.getValueData();
        int formatIndex = wFormat.getSelectionIndex();
        valueMeta.setConversionMask(formatIndex >= 0 ? wFormat.getItem(formatIndex) : wFormat.getText());
        valueMeta.setLength(Const.toInt(wLength.getText(), -1));
        valueMeta.setPrecision(Const.toInt(wPrecision.getText(), -1));
        val.setValueMeta(valueMeta);
        ValueMetaInterface stringValueMeta = new ValueMetaString(valuename);
        stringValueMeta.setConversionMetadata(valueMeta);
        Object targetData = stringValueMeta.convertDataUsingConversionMetaData(valueData);
        val.setValueData(targetData);
        return val;
    } catch (Exception e) {
        throw new KettleValueException(e);
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaAndData(org.pentaho.di.core.row.ValueMetaAndData) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 2 with ValueMetaAndData

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

the class ConditionEditor method drawAtomic.

private void drawAtomic(GC gc, int x, int y, Condition condition) {
    // First the text sizes...
    String left = Const.rightPad(condition.getLeftValuename(), max_field_length);
    Point ext_left = gc.textExtent(left);
    if (condition.getLeftValuename() == null) {
        ext_left = gc.textExtent("<field>");
    }
    String fn_max = Condition.functions[Condition.FUNC_NOT_NULL];
    String fn = condition.getFunctionDesc();
    Point ext_fn = gc.textExtent(fn_max);
    String rightval = Const.rightPad(condition.getRightValuename(), max_field_length);
    Point ext_rval = gc.textExtent(rightval);
    if (condition.getLeftValuename() == null) {
        ext_rval = gc.textExtent("<field>");
    }
    String rightex = condition.getRightExactString();
    String rightex_max = rightex;
    if (rightex == null) {
        rightex_max = Const.rightPad(" ", 10);
    } else {
        if (rightex.length() < 10) {
            rightex_max = Const.rightPad(rightex, 10);
        }
    }
    Point ext_rex = gc.textExtent(rightex_max);
    size_left = new Rectangle(x + 5, y + size_not.height + 5, ext_left.x + 5, ext_left.y + 5);
    size_fn = new Rectangle(size_left.x + size_left.width + 15, y + size_not.height + 5, ext_fn.x + 5, ext_fn.y + 5);
    size_rightval = new Rectangle(size_fn.x + size_fn.width + 15, y + size_not.height + 5, ext_rval.x + 5, ext_rval.y + 5);
    size_rightex = new Rectangle(size_fn.x + size_fn.width + 15, y + size_not.height + 5 + size_rightval.height + 5, ext_rex.x + 5, ext_rex.y + 5);
    if (hover_left) {
        gc.setBackground(gray);
    }
    gc.fillRectangle(Real2Screen(size_left));
    gc.drawRectangle(Real2Screen(size_left));
    gc.setBackground(bg);
    if (hover_fn) {
        gc.setBackground(gray);
    }
    gc.fillRectangle(Real2Screen(size_fn));
    gc.drawRectangle(Real2Screen(size_fn));
    gc.setBackground(bg);
    if (hover_rightval) {
        gc.setBackground(gray);
    }
    gc.fillRectangle(Real2Screen(size_rightval));
    gc.drawRectangle(Real2Screen(size_rightval));
    gc.setBackground(bg);
    if (hover_rightex) {
        gc.setBackground(gray);
    }
    gc.fillRectangle(Real2Screen(size_rightex));
    gc.drawRectangle(Real2Screen(size_rightex));
    gc.setBackground(bg);
    if (condition.getLeftValuename() != null) {
        gc.drawText(left, size_left.x + 1 + offsetx, size_left.y + 1 + offsety, SWT.DRAW_TRANSPARENT);
    } else {
        gc.setForeground(gray);
        gc.drawText("<field>", size_left.x + 1 + offsetx, size_left.y + 1 + offsety, SWT.DRAW_TRANSPARENT);
        gc.setForeground(black);
    }
    gc.drawText(fn, size_fn.x + 1 + offsetx, size_fn.y + 1 + offsety, SWT.DRAW_TRANSPARENT);
    if (condition.getFunction() != Condition.FUNC_NOT_NULL && condition.getFunction() != Condition.FUNC_NULL) {
        String re = rightex == null ? "" : rightex;
        String stype = "";
        ValueMetaAndData v = condition.getRightExact();
        if (v != null) {
            stype = " (" + v.getValueMeta().getTypeDesc() + ")";
        }
        if (condition.getRightValuename() != null) {
            gc.drawText(rightval, size_rightval.x + 1 + offsetx, size_rightval.y + 1 + offsety, SWT.DRAW_TRANSPARENT);
        } else {
            String nothing = rightex == null ? "<field>" : "";
            gc.setForeground(gray);
            gc.drawText(nothing, size_rightval.x + 1 + offsetx, size_rightval.y + 1 + offsety, SWT.DRAW_TRANSPARENT);
            if (condition.getRightValuename() == null) {
                gc.setForeground(black);
            }
        }
        if (rightex != null) {
            gc.drawText(re, size_rightex.x + 1 + offsetx, size_rightex.y + 1 + offsety, SWT.DRAW_TRANSPARENT);
        } else {
            String nothing = condition.getRightValuename() == null ? "<value>" : "";
            gc.setForeground(gray);
            gc.drawText(nothing, size_rightex.x + 1 + offsetx, size_rightex.y + 1 + offsety, SWT.DRAW_TRANSPARENT);
            gc.setForeground(black);
        }
        gc.drawText(stype, size_rightex.x + 1 + size_rightex.width + 10 + offsetx, size_rightex.y + 1 + offsety, SWT.DRAW_TRANSPARENT);
    } else {
        gc.drawText("-", size_rightval.x + 1 + offsetx, size_rightval.y + 1 + offsety, SWT.DRAW_TRANSPARENT);
        gc.drawText("-", size_rightex.x + 1 + offsetx, size_rightex.y + 1 + offsety, SWT.DRAW_TRANSPARENT);
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Point(org.eclipse.swt.graphics.Point) ValueMetaAndData(org.pentaho.di.core.row.ValueMetaAndData)

Example 3 with ValueMetaAndData

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

the class ConditionTest method testNullLessThanNumberEvaluatesAsFalse.

@Test
public void testNullLessThanNumberEvaluatesAsFalse() throws Exception {
    RowMetaInterface rowMeta1 = new RowMeta();
    rowMeta1.addValueMeta(new ValueMetaInteger("name1"));
    String left = "name1";
    ValueMetaAndData right_exact = new ValueMetaAndData(new ValueMetaInteger("name1"), new Long(-10));
    Condition condition = new Condition(left, Condition.FUNC_SMALLER, null, right_exact);
    assertFalse(condition.evaluate(rowMeta1, new Object[] { null, "test" }));
    condition = new Condition(left, Condition.FUNC_SMALLER_EQUAL, null, right_exact);
    assertFalse(condition.evaluate(rowMeta1, new Object[] { null, "test" }));
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaAndData(org.pentaho.di.core.row.ValueMetaAndData) Test(org.junit.Test)

Example 4 with ValueMetaAndData

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

the class XMLInputDialog method getValues.

/**
 * Get all the values defined in a Node
 *
 * @param node
 *          The node to examine
 * @param row
 *          The
 */
private void getValues(Node node, RowMetaInterface row, List<XMLInputFieldPosition> path, int level) throws KettleException {
    String baseName = "";
    for (int p = 0; p < path.size(); p++) {
        XMLInputFieldPosition pos = path.get(p);
        String elementName = pos.getName() + pos.getElementNr();
        if (!elementName.startsWith("#")) {
            baseName += StringUtil.initCap(new ValueMetaAndData("p", elementName).toString());
        }
    }
    // Add the root element
    if (level == 0) {
        if (XMLHandler.getNodeValue(node) != null) {
            XMLInputFieldPosition attrPos = new XMLInputFieldPosition(node.getNodeName(), XMLInputFieldPosition.XML_ROOT);
            path.add(attrPos);
            String root = StringUtil.initCap(new ValueMetaAndData("a", node.getNodeName()).toString());
            String fieldName = baseName + root;
            if (row.searchValueMeta(fieldName) == null) {
                // Not there yet: add it!
                // Add the fieldname...
                ValueMeta field = new ValueMeta(fieldName, ValueMeta.TYPE_STRING);
                // Add the path to this attribute to the origin of the
                // field...
                String encoded = XMLInputFieldPosition.encodePath(path);
                field.setOrigin(encoded);
                row.addValueMeta(field);
            }
            // Now remove the root from the path again, it's not needed
            // realy...
            path.remove(path.size() - 1);
        }
    }
    // First check out the attributes...
    String[] attributes = XMLHandler.getNodeAttributes(node);
    if (attributes != null) {
        for (int i = 0; i < attributes.length; i++) {
            XMLInputFieldPosition attrPos = new XMLInputFieldPosition(attributes[i], XMLInputFieldPosition.XML_ATTRIBUTE);
            path.add(attrPos);
            String attribute = StringUtil.initCap(new ValueMetaAndData("a", attributes[i]).toString());
            String fieldName = baseName + attribute;
            // See if this fieldname already exists in Row...
            if (row.searchValueMeta(fieldName) == null) {
                // Add the fieldname...
                ValueMeta field = new ValueMeta(fieldName, ValueMeta.TYPE_STRING);
                // Add the path to this attribute to the origin of the
                // field...
                String encoded = XMLInputFieldPosition.encodePath(path);
                field.setOrigin(encoded);
                row.addValueMeta(field);
            }
            path.remove(path.size() - 1);
        }
    }
    // Then get the elements
    String[] elements = XMLHandler.getNodeElements(node);
    if (elements != null) {
        for (int e = 0; e < elements.length; e++) {
            // Count the number of occurrences of this element...
            int occurrences = XMLHandler.countNodes(node, elements[e]);
            for (int o = 0; o < occurrences; o++) {
                Node itemNode = XMLHandler.getSubNodeByNr(node, elements[e], o, false);
                XMLInputFieldPosition xmlPos = new XMLInputFieldPosition(elements[e], XMLInputFieldPosition.XML_ELEMENT, o + 1);
                path.add(xmlPos);
                getValues(itemNode, row, path, level + 1);
                // remove the last one again
                path.remove(path.size() - 1);
            }
        }
    } else {
        if (path.size() > 0) {
            int idxLast = path.size() - 1;
            XMLInputFieldPosition last = path.get(idxLast);
            path.remove(idxLast);
            if (path.size() > 0) {
                String encoded = XMLInputFieldPosition.encodePath(path);
                if (row.searchValueMeta(baseName) == null) {
                    ValueMeta value = new ValueMeta(baseName, ValueMeta.TYPE_STRING);
                    value.setOrigin(encoded);
                    row.addValueMeta(value);
                }
            }
            path.add(last);
        }
    }
}
Also used : XMLInputFieldPosition(org.pentaho.di.trans.steps.xmlinput.XMLInputFieldPosition) Node(org.w3c.dom.Node) ValueMetaAndData(org.pentaho.di.core.row.ValueMetaAndData) ValueMeta(org.pentaho.di.core.row.ValueMeta)

Example 5 with ValueMetaAndData

use of org.pentaho.di.core.row.ValueMetaAndData 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)

Aggregations

ValueMetaAndData (org.pentaho.di.core.row.ValueMetaAndData)17 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)6 Condition (org.pentaho.di.core.Condition)4 KettleException (org.pentaho.di.core.exception.KettleException)4 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)4 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)3 KettleValueException (org.pentaho.di.core.exception.KettleValueException)3 RowMeta (org.pentaho.di.core.row.RowMeta)3 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)3 LongObjectId (org.pentaho.di.repository.LongObjectId)2 ObjectId (org.pentaho.di.repository.ObjectId)2 ParameterGenerationTest.newCondition (org.pentaho.di.trans.dataservice.optimization.paramgen.ParameterGenerationTest.newCondition)2 Node (org.w3c.dom.Node)2 Column (com.healthmarketscience.jackcess.Column)1 DataType (com.healthmarketscience.jackcess.DataType)1 DBObject (com.mongodb.DBObject)1 BigDecimal (java.math.BigDecimal)1 FileObject (org.apache.commons.vfs2.FileObject)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1