Search in sources :

Example 11 with ValueMetaNone

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

the class SalesforceInsertDialog method generateMappings.

/**
 * Reads in the fields from the previous steps and from the ONE next step and opens an EnterMappingDialog with this
 * information. After the user did the mapping, those information is put into the Select/Rename table.
 */
private void generateMappings() {
    if (!checkInput()) {
        return;
    }
    // Determine the source and target fields...
    // 
    RowMetaInterface sourceFields;
    RowMetaInterface targetFields = new RowMeta();
    try {
        sourceFields = transMeta.getPrevStepFields(stepMeta);
    } catch (KettleException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.UnableToFindSourceFields.Title"), BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.UnableToFindSourceFields.Message"), e);
        return;
    }
    try {
        SalesforceConnection connection = getConnection();
        Field[] fields = connection.getObjectFields(transMeta.environmentSubstitute(wModule.getText()));
        String[] fieldNames = connection.getFields(fields);
        FieldType dateType = FieldType.date;
        for (int i = 0; i < fields.length; i++) {
            if (dateType.equals(fields[i].getType())) {
                // Mark date columns as TYPE_DATE to strip time part later
                targetFields.addValueMeta(ValueMetaFactory.createValueMeta(fieldNames[i], ValueMetaInterface.TYPE_DATE));
            } else {
                targetFields.addValueMeta(new ValueMetaNone(fieldNames[i]));
            }
        }
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.UnableToFindTargetFields.Title"), BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.UnableToFindTargetFields.Message"), e);
        return;
    }
    String[] inputNames = new String[sourceFields.size()];
    for (int i = 0; i < sourceFields.size(); i++) {
        ValueMetaInterface value = sourceFields.getValueMeta(i);
        inputNames[i] = value.getName() + EnterMappingDialog.STRING_ORIGIN_SEPARATOR + value.getOrigin() + ")";
    }
    // Create the existing mapping list...
    // 
    List<SourceToTargetMapping> mappings = new ArrayList<SourceToTargetMapping>();
    StringBuffer missingSourceFields = new StringBuffer();
    StringBuffer missingTargetFields = new StringBuffer();
    int nrFields = wReturn.nrNonEmpty();
    for (int i = 0; i < nrFields; i++) {
        TableItem item = wReturn.getNonEmpty(i);
        String source = item.getText(2);
        String target = item.getText(1);
        int sourceIndex = sourceFields.indexOfValue(source);
        if (sourceIndex < 0) {
            missingSourceFields.append(Const.CR + "   " + source + " --> " + target);
        }
        int targetIndex = targetFields.indexOfValue(target);
        if (targetIndex < 0) {
            missingTargetFields.append(Const.CR + "   " + source + " --> " + target);
        }
        if (sourceIndex < 0 || targetIndex < 0) {
            continue;
        }
        SourceToTargetMapping mapping = new SourceToTargetMapping(sourceIndex, targetIndex);
        mappings.add(mapping);
    }
    // 
    if (missingSourceFields.length() > 0 || missingTargetFields.length() > 0) {
        String message = "";
        if (missingSourceFields.length() > 0) {
            message += BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.SomeSourceFieldsNotFound", missingSourceFields.toString()) + Const.CR;
        }
        if (missingTargetFields.length() > 0) {
            message += BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.SomeTargetFieldsNotFound", missingSourceFields.toString()) + Const.CR;
        }
        message += Const.CR;
        message += BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.SomeFieldsNotFoundContinue") + Const.CR;
        MessageDialog.setDefaultImage(GUIResource.getInstance().getImageSpoon());
        boolean goOn = MessageDialog.openConfirm(shell, BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.SomeFieldsNotFoundTitle"), message);
        if (!goOn) {
            return;
        }
    }
    EnterMappingDialog d = new EnterMappingDialog(SalesforceInsertDialog.this.shell, sourceFields.getFieldNames(), targetFields.getFieldNames(), mappings);
    mappings = d.open();
    // 
    if (mappings != null) {
        // Clear and re-populate!
        // 
        wReturn.table.removeAll();
        wReturn.table.setItemCount(mappings.size());
        for (int i = 0; i < mappings.size(); i++) {
            SourceToTargetMapping mapping = mappings.get(i);
            TableItem item = wReturn.table.getItem(i);
            item.setText(2, sourceFields.getValueMeta(mapping.getSourcePosition()).getName());
            item.setText(1, targetFields.getValueMeta(mapping.getTargetPosition()).getName());
        }
        wReturn.setRowNums();
        wReturn.optWidth(true);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RowMeta(org.pentaho.di.core.row.RowMeta) EnterMappingDialog(org.pentaho.di.ui.core.dialog.EnterMappingDialog) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) SalesforceConnection(org.pentaho.di.trans.steps.salesforce.SalesforceConnection) KettleException(org.pentaho.di.core.exception.KettleException) FieldType(com.sforce.soap.partner.FieldType) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Field(com.sforce.soap.partner.Field) ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) SourceToTargetMapping(org.pentaho.di.core.SourceToTargetMapping)

Example 12 with ValueMetaNone

use of org.pentaho.di.core.row.value.ValueMetaNone in project pentaho-metaverse by pentaho.

the class AnnotationDrivenStepMetaAnalyzer method getOutputRowMetaInterfaces.

/**
 * Adds any linked resource nodes to the output row meta.
 * Applicable to something like a Message field being sent to an external queue.
 */
@Override
protected Map<String, RowMetaInterface> getOutputRowMetaInterfaces(BaseStepMeta meta) {
    Map<String, RowMetaInterface> rowMetas = super.getOutputRowMetaInterfaces(meta);
    AnnotatedClassFields nodeTree = new AnnotatedClassFields(meta);
    RowMeta resourceRowMeta = new RowMeta();
    new AnnotatedClassFields(meta).links().filter(field -> nodeTree.node(field.annotation.nodeName()).get().annotation.link().equals(LINK_OUTPUTS)).forEach(field -> resourceRowMeta.addValueMeta(new ValueMetaNone(field.name)));
    if (resourceRowMeta.size() > 0) {
        rowMetas.put(RESOURCE, resourceRowMeta);
    }
    return rowMetas;
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) KettleAnalyzerUtil(org.pentaho.metaverse.api.analyzer.kettle.KettleAnalyzerUtil) KettleException(org.pentaho.di.core.exception.KettleException) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) Messages(org.pentaho.metaverse.api.messages.Messages) SubtransAnalyzer(org.pentaho.metaverse.api.analyzer.kettle.step.SubtransAnalyzer) LoggerFactory(org.slf4j.LoggerFactory) StepField(org.pentaho.metaverse.api.StepField) LINK_OUTPUTS(org.pentaho.dictionary.DictionaryConst.LINK_OUTPUTS) TransExecutorMeta(org.pentaho.di.trans.steps.transexecutor.TransExecutorMeta) MetaverseComponentDescriptor(org.pentaho.metaverse.api.MetaverseComponentDescriptor) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) PROPERTY_TYPE(org.pentaho.dictionary.DictionaryConst.PROPERTY_TYPE) StepWithMappingMeta(org.pentaho.di.trans.StepWithMappingMeta) TransMeta(org.pentaho.di.trans.TransMeta) Collectors.toMap(java.util.stream.Collectors.toMap) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) StepNodes(org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes) VariableSpace(org.pentaho.di.core.variables.VariableSpace) StepAnalyzer(org.pentaho.metaverse.api.analyzer.kettle.step.StepAnalyzer) Collectors.toSet(java.util.stream.Collectors.toSet) Logger(org.slf4j.Logger) DictionaryHelper(org.pentaho.dictionary.DictionaryHelper) ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) Set(java.util.Set) BaseStreamStepMeta(org.pentaho.di.trans.streaming.common.BaseStreamStepMeta) Collectors(java.util.stream.Collectors) ISubTransAwareMeta(org.pentaho.di.trans.ISubTransAwareMeta) IClonableStepAnalyzer(org.pentaho.metaverse.api.analyzer.kettle.step.IClonableStepAnalyzer) List(java.util.List) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) Optional(java.util.Optional) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Direction(com.tinkerpop.blueprints.Direction) Collections(java.util.Collections) Arrays.stream(java.util.Arrays.stream) RESOURCE(org.pentaho.metaverse.api.analyzer.kettle.step.ExternalResourceStepAnalyzer.RESOURCE) ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface)

Example 13 with ValueMetaNone

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

the class AccessInputMeta method getFields.

@Override
public void getFields(RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    int i;
    int nr = inputFields == null ? 0 : inputFields.length;
    for (i = 0; i < nr; i++) {
        AccessInputField field = inputFields[i];
        int type = field.getType();
        if (type == ValueMetaInterface.TYPE_NONE) {
            type = ValueMetaInterface.TYPE_STRING;
        }
        ValueMetaInterface v;
        try {
            v = ValueMetaFactory.createValueMeta(space.environmentSubstitute(field.getName()), type);
        } catch (KettlePluginException e) {
            v = new ValueMetaNone(space.environmentSubstitute(field.getName()));
        }
        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());
        v.setTrimType(field.getTrimType());
        r.addValueMeta(v);
    }
    if (includeFilename) {
        ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(filenameField));
        v.setLength(250);
        v.setPrecision(-1);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (includeTablename) {
        ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(tablenameField));
        v.setLength(250);
        v.setPrecision(-1);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (includeRowNumber) {
        ValueMetaInterface v = new ValueMetaInteger(space.environmentSubstitute(rowNumberField));
        v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (getShortFileNameField() != null && getShortFileNameField().length() > 0) {
        ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getShortFileNameField()));
        v.setLength(100, -1);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (getExtensionField() != null && getExtensionField().length() > 0) {
        ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getExtensionField()));
        v.setLength(100, -1);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (getPathField() != null && getPathField().length() > 0) {
        ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getPathField()));
        v.setLength(100, -1);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (getSizeField() != null && getSizeField().length() > 0) {
        ValueMetaInterface v = new ValueMetaInteger(space.environmentSubstitute(getSizeField()));
        v.setOrigin(name);
        v.setLength(9);
        r.addValueMeta(v);
    }
    if (isHiddenField() != null && isHiddenField().length() > 0) {
        ValueMetaInterface v = new ValueMetaBoolean(space.environmentSubstitute(isHiddenField()));
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (getLastModificationDateField() != null && getLastModificationDateField().length() > 0) {
        ValueMetaInterface v = new ValueMetaDate(space.environmentSubstitute(getLastModificationDateField()));
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (getUriField() != null && getUriField().length() > 0) {
        ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getUriField()));
        v.setLength(100, -1);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (getRootUriField() != null && getRootUriField().length() > 0) {
        ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getRootUriField()));
        v.setLength(100, -1);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 14 with ValueMetaNone

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

the class AccessInputMeta method getValueMetaAndData.

/**
 * Returns kettle type from Microsoft Access database also convert data to prepare kettle value
 *
 * @param : MS Access column
 * @param : destination field name
 * @param : MS Access column value
 * @return valuemeta and data
 */
public static ValueMetaAndData getValueMetaAndData(Column c, String name, Object data) {
    ValueMetaAndData valueMetaData = new ValueMetaAndData();
    // get data
    Object o = data;
    // Get column type
    DataType type = c.getType();
    int sourceValueType = ValueMetaInterface.TYPE_STRING;
    // We have to take of Meta AND data
    switch(type) {
        case BINARY:
            sourceValueType = ValueMetaInterface.TYPE_BINARY;
            break;
        case BOOLEAN:
            sourceValueType = ValueMetaInterface.TYPE_BOOLEAN;
            if (o != null) {
                o = Boolean.valueOf(o.toString());
            }
            break;
        case DOUBLE:
            sourceValueType = ValueMetaInterface.TYPE_NUMBER;
            break;
        case FLOAT:
            sourceValueType = ValueMetaInterface.TYPE_BIGNUMBER;
            if (o != null) {
                o = new BigDecimal(Float.toString((Float) o));
            }
            break;
        case INT:
            sourceValueType = ValueMetaInterface.TYPE_NUMBER;
            if (o != null) {
                o = Double.parseDouble(o.toString());
            }
            break;
        case BYTE:
            sourceValueType = ValueMetaInterface.TYPE_NUMBER;
            if (o != null) {
                o = Double.parseDouble(o.toString());
            }
            break;
        case LONG:
            sourceValueType = ValueMetaInterface.TYPE_INTEGER;
            if (o != null) {
                Integer i = (Integer) o;
                o = i.longValue();
            }
            break;
        case MEMO:
            break;
        case MONEY:
            sourceValueType = ValueMetaInterface.TYPE_BIGNUMBER;
            break;
        case NUMERIC:
            sourceValueType = ValueMetaInterface.TYPE_BIGNUMBER;
            break;
        case SHORT_DATE_TIME:
            sourceValueType = ValueMetaInterface.TYPE_DATE;
            break;
        default:
            // Default it's string
            if (o != null) {
                o = o.toString();
            }
            break;
    }
    ValueMetaInterface sourceValueMeta;
    try {
        sourceValueMeta = ValueMetaFactory.createValueMeta(name == null ? c.getName() : name, sourceValueType);
    } catch (KettlePluginException e) {
        sourceValueMeta = new ValueMetaNone(name == null ? c.getName() : name);
    }
    sourceValueMeta.setLength(c.getLength(), c.getPrecision());
    // set value meta data and return it
    valueMetaData.setValueMeta(sourceValueMeta);
    if (o != null) {
        valueMetaData.setValueData(o);
    }
    return valueMetaData;
}
Also used : ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) DataType(com.healthmarketscience.jackcess.DataType) FileObject(org.apache.commons.vfs2.FileObject) ValueMetaAndData(org.pentaho.di.core.row.ValueMetaAndData) BigDecimal(java.math.BigDecimal) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 15 with ValueMetaNone

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

the class RandomValueMeta method getFields.

@Override
public void getFields(RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    for (int i = 0; i < fieldName.length; i++) {
        ValueMetaInterface v;
        switch(fieldType[i]) {
            case TYPE_RANDOM_NUMBER:
                v = new ValueMetaNumber(fieldName[i], 10, 5);
                break;
            case TYPE_RANDOM_INTEGER:
                v = new ValueMetaInteger(fieldName[i], 10, 0);
                break;
            case TYPE_RANDOM_STRING:
                v = new ValueMetaString(fieldName[i], 13, 0);
                break;
            case TYPE_RANDOM_UUID:
                v = new ValueMetaString(fieldName[i], 36, 0);
                break;
            case TYPE_RANDOM_UUID4:
                v = new ValueMetaString(fieldName[i], 36, 0);
                break;
            case TYPE_RANDOM_MAC_HMACMD5:
                v = new ValueMetaString(fieldName[i], 100, 0);
                break;
            case TYPE_RANDOM_MAC_HMACSHA1:
                v = new ValueMetaString(fieldName[i], 100, 0);
                break;
            default:
                v = new ValueMetaNone(fieldName[i]);
                break;
        }
        v.setOrigin(name);
        row.addValueMeta(v);
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Aggregations

ValueMetaNone (org.pentaho.di.core.row.value.ValueMetaNone)18 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)17 RowMeta (org.pentaho.di.core.row.RowMeta)12 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)10 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)10 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)8 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)6 KettleException (org.pentaho.di.core.exception.KettleException)5 ArrayList (java.util.ArrayList)4 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)4 FileObject (org.apache.commons.vfs2.FileObject)3 TableItem (org.eclipse.swt.widgets.TableItem)3 SourceToTargetMapping (org.pentaho.di.core.SourceToTargetMapping)3 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)3 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)3 EnterMappingDialog (org.pentaho.di.ui.core.dialog.EnterMappingDialog)3 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)3 List (java.util.List)2 Map (java.util.Map)2 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)2