Search in sources :

Example 6 with ValueMeta

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

the class XMLJoinMeta method getFields.

public void getFields(RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    ValueMetaInterface v = new ValueMeta(this.getValueXMLfield(), ValueMetaInterface.TYPE_STRING);
    v.setOrigin(name);
    TransMeta transMeta = (TransMeta) space;
    try {
        // source fields.
        for (String fieldName : transMeta.getStepFields(transMeta.findStep(getSourceXMLstep()), null, null).getFieldNames()) {
            row.removeValueMeta(fieldName);
        }
    } catch (KettleValueException e) {
    // Pass
    }
    row.addValueMeta(v);
}
Also used : TransMeta(org.pentaho.di.trans.TransMeta) KettleValueException(org.pentaho.di.core.exception.KettleValueException) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 7 with ValueMeta

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

the class XMLInputMeta method getFields.

public void getFields(RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    for (int i = 0; i < inputFields.length; i++) {
        XMLInputField field = inputFields[i];
        int type = field.getType();
        if (type == ValueMeta.TYPE_NONE) {
            type = ValueMeta.TYPE_STRING;
        }
        try {
            ValueMetaInterface v = ValueMetaFactory.createValueMeta(field.getName(), type);
            v.setLength(field.getLength(), field.getPrecision());
            v.setConversionMask(field.getFormat());
            v.setDecimalSymbol(field.getDecimalSymbol());
            v.setGroupingSymbol(field.getGroupSymbol());
            v.setTrimType(field.getTrimType());
            v.setCurrencySymbol(field.getCurrencySymbol());
            v.setOrigin(name);
            r.addValueMeta(v);
        } catch (Exception e) {
            throw new KettleStepException(e);
        }
    }
    if (includeFilename) {
        ValueMetaInterface v = new ValueMeta(filenameField, ValueMeta.TYPE_STRING);
        v.setLength(100);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (includeRowNumber) {
        ValueMetaInterface v = new ValueMeta(rowNumberField, ValueMeta.TYPE_INTEGER);
        v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMeta(org.pentaho.di.core.row.ValueMeta) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 8 with ValueMeta

use of org.pentaho.di.core.row.ValueMeta 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 9 with ValueMeta

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

the class AddXMLMeta method getFields.

public void getFields(RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    ValueMetaInterface v = new ValueMeta(this.getValueName(), ValueMetaInterface.TYPE_STRING);
    v.setOrigin(name);
    row.addValueMeta(v);
}
Also used : ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 10 with ValueMeta

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

the class GetXMLDataMeta method getFields.

public void getFields(RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    int i;
    for (i = 0; i < inputFields.length; i++) {
        GetXMLDataField field = inputFields[i];
        int type = field.getType();
        if (type == ValueMeta.TYPE_NONE) {
            type = ValueMeta.TYPE_STRING;
        }
        try {
            ValueMetaInterface v = ValueMetaFactory.createValueMeta(space.environmentSubstitute(field.getName()), type);
            v.setLength(field.getLength());
            v.setPrecision(field.getPrecision());
            v.setOrigin(name);
            v.setConversionMask(field.getFormat());
            v.setDecimalSymbol(field.getDecimalSymbol());
            v.setGroupingSymbol(field.getGroupSymbol());
            v.setCurrencySymbol(field.getCurrencySymbol());
            r.addValueMeta(v);
        } catch (Exception e) {
            throw new KettleStepException(e);
        }
    }
    if (includeFilename) {
        ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(filenameField), ValueMeta.TYPE_STRING);
        v.setLength(250);
        v.setPrecision(-1);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (includeRowNumber) {
        ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(rowNumberField), ValueMeta.TYPE_INTEGER);
        v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (getShortFileNameField() != null && getShortFileNameField().length() > 0) {
        ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(getShortFileNameField()), ValueMeta.TYPE_STRING);
        v.setLength(100, -1);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (getExtensionField() != null && getExtensionField().length() > 0) {
        ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(getExtensionField()), ValueMeta.TYPE_STRING);
        v.setLength(100, -1);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (getPathField() != null && getPathField().length() > 0) {
        ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(getPathField()), ValueMeta.TYPE_STRING);
        v.setLength(100, -1);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (getSizeField() != null && getSizeField().length() > 0) {
        ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(getSizeField()), ValueMeta.TYPE_INTEGER);
        v.setOrigin(name);
        v.setLength(9);
        r.addValueMeta(v);
    }
    if (isHiddenField() != null && isHiddenField().length() > 0) {
        ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(isHiddenField()), ValueMeta.TYPE_BOOLEAN);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (getLastModificationDateField() != null && getLastModificationDateField().length() > 0) {
        ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(getLastModificationDateField()), ValueMeta.TYPE_DATE);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (getUriField() != null && getUriField().length() > 0) {
        ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(getUriField()), ValueMeta.TYPE_STRING);
        v.setLength(100, -1);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (getRootUriField() != null && getRootUriField().length() > 0) {
        ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(getRootUriField()), ValueMeta.TYPE_STRING);
        v.setLength(100, -1);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMeta(org.pentaho.di.core.row.ValueMeta) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Aggregations

ValueMeta (org.pentaho.di.core.row.ValueMeta)47 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)39 Test (org.junit.Test)18 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)14 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)13 RowMeta (org.pentaho.di.core.row.RowMeta)12 IAnalysisContext (org.pentaho.metaverse.api.IAnalysisContext)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 KettleValueException (org.pentaho.di.core.exception.KettleValueException)5 MetaverseTransientNode (org.pentaho.dictionary.MetaverseTransientNode)5 IComponentDescriptor (org.pentaho.metaverse.api.IComponentDescriptor)5 KettleException (org.pentaho.di.core.exception.KettleException)4 KettleStepException (org.pentaho.di.core.exception.KettleStepException)4 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)3 Matchers.anyString (org.mockito.Matchers.anyString)2 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)2 BatchUpdateException (java.sql.BatchUpdateException)1 Blob (java.sql.Blob)1 ResultSet (java.sql.ResultSet)1