Search in sources :

Example 6 with StepInjectionMetaEntry

use of org.pentaho.di.trans.step.StepInjectionMetaEntry in project pentaho-kettle by pentaho.

the class JaninoMetaInjection method getStepInjectionMetadataEntries.

@Override
public List<StepInjectionMetaEntry> getStepInjectionMetadataEntries() throws KettleException {
    List<StepInjectionMetaEntry> all = new ArrayList<StepInjectionMetaEntry>();
    // The fields
    // 
    StepInjectionMetaEntry fieldsEntry = new StepInjectionMetaEntry(Entry.EXPRESSION_FIELDS.name(), ValueMetaInterface.TYPE_NONE, Entry.EXPRESSION_FIELDS.description);
    all.add(fieldsEntry);
    StepInjectionMetaEntry fieldEntry = new StepInjectionMetaEntry(Entry.EXPRESSION_FIELD.name(), ValueMetaInterface.TYPE_NONE, Entry.EXPRESSION_FIELD.description);
    fieldsEntry.getDetails().add(fieldEntry);
    Entry[] fieldsEntries = new Entry[] { Entry.NEW_FIELDNAME, Entry.JAVA_EXPRESSION, Entry.VALUE_TYPE, Entry.LENGTH, Entry.PRECISION, Entry.REPLACE_VALUE };
    for (Entry entry : fieldsEntries) {
        StepInjectionMetaEntry metaEntry = new StepInjectionMetaEntry(entry.name(), entry.getValueType(), entry.getDescription());
        fieldEntry.getDetails().add(metaEntry);
    }
    return all;
}
Also used : StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) ArrayList(java.util.ArrayList)

Example 7 with StepInjectionMetaEntry

use of org.pentaho.di.trans.step.StepInjectionMetaEntry in project pentaho-kettle by pentaho.

the class JaninoMetaInjection method injectStepMetadataEntries.

@Override
public void injectStepMetadataEntries(List<StepInjectionMetaEntry> all) throws KettleException {
    List<String> fieldNames = new ArrayList<String>();
    List<String> javaExpressions = new ArrayList<String>();
    List<String> valueTypes = new ArrayList<String>();
    List<String> lengths = new ArrayList<String>();
    List<String> precisions = new ArrayList<String>();
    List<String> replaceValues = new ArrayList<String>();
    // 
    for (StepInjectionMetaEntry lookFields : all) {
        Entry fieldsEntry = Entry.findEntry(lookFields.getKey());
        if (fieldsEntry == null) {
            continue;
        }
        switch(fieldsEntry) {
            case EXPRESSION_FIELDS:
                for (StepInjectionMetaEntry lookField : lookFields.getDetails()) {
                    Entry fieldEntry = Entry.findEntry(lookField.getKey());
                    if (fieldEntry == Entry.EXPRESSION_FIELD) {
                        String newFieldname = null;
                        String javaExpression = null;
                        String valueType = null;
                        String length = null;
                        String precision = null;
                        String replaceValue = null;
                        List<StepInjectionMetaEntry> entries = lookField.getDetails();
                        for (StepInjectionMetaEntry entry : entries) {
                            Entry metaEntry = Entry.findEntry(entry.getKey());
                            if (metaEntry != null) {
                                String value = (String) entry.getValue();
                                switch(metaEntry) {
                                    case NEW_FIELDNAME:
                                        newFieldname = value;
                                        break;
                                    case JAVA_EXPRESSION:
                                        javaExpression = value;
                                        break;
                                    case VALUE_TYPE:
                                        valueType = value;
                                        break;
                                    case LENGTH:
                                        length = value;
                                        break;
                                    case PRECISION:
                                        precision = value;
                                        break;
                                    case REPLACE_VALUE:
                                        replaceValue = value;
                                        break;
                                    default:
                                        break;
                                }
                            }
                        }
                        fieldNames.add(newFieldname);
                        javaExpressions.add(javaExpression);
                        valueTypes.add(valueType);
                        lengths.add(length);
                        precisions.add(precision);
                        replaceValues.add(replaceValue);
                    }
                }
                break;
            default:
                break;
        }
    }
    // 
    if (fieldNames.size() > 0) {
        JaninoMetaFunction[] fields = new JaninoMetaFunction[fieldNames.size()];
        Iterator<String> iFieldNames = fieldNames.iterator();
        Iterator<String> iJavaExpressions = javaExpressions.iterator();
        Iterator<String> iValueTypes = valueTypes.iterator();
        Iterator<String> iLengths = lengths.iterator();
        Iterator<String> iPrecisions = precisions.iterator();
        Iterator<String> iReplaceValues = replaceValues.iterator();
        int i = 0;
        while (iFieldNames.hasNext()) {
            fields[i] = new JaninoMetaFunction(iFieldNames.next(), iJavaExpressions.next(), ValueMetaFactory.getIdForValueMeta(iValueTypes.next()), Const.toInt(iLengths.next(), -1), Const.toInt(iPrecisions.next(), -1), iReplaceValues.next());
            i++;
        }
        meta.setFormula(fields);
    }
}
Also used : StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) ArrayList(java.util.ArrayList) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry)

Example 8 with StepInjectionMetaEntry

use of org.pentaho.di.trans.step.StepInjectionMetaEntry in project pentaho-kettle by pentaho.

the class JaninoMetaInjection method extractStepMetadataEntries.

public List<StepInjectionMetaEntry> extractStepMetadataEntries() throws KettleException {
    List<StepInjectionMetaEntry> list = new ArrayList<StepInjectionMetaEntry>();
    StepInjectionMetaEntry fieldsEntry = StepInjectionUtil.getEntry(Entry.EXPRESSION_FIELDS);
    list.add(fieldsEntry);
    for (int i = 0; i < meta.getFormula().length; i++) {
        StepInjectionMetaEntry fieldEntry = StepInjectionUtil.getEntry(Entry.EXPRESSION_FIELD);
        List<StepInjectionMetaEntry> details = fieldEntry.getDetails();
        details.add(StepInjectionUtil.getEntry(Entry.NEW_FIELDNAME, meta.getFormula()[i].getFieldName()));
        details.add(StepInjectionUtil.getEntry(Entry.JAVA_EXPRESSION, meta.getFormula()[i].getFormula()));
        details.add(StepInjectionUtil.getEntry(Entry.VALUE_TYPE, ValueMetaFactory.getValueMetaName(meta.getFormula()[i].getValueType())));
        details.add(StepInjectionUtil.getEntry(Entry.LENGTH, meta.getFormula()[i].getValueLength()));
        details.add(StepInjectionUtil.getEntry(Entry.PRECISION, meta.getFormula()[i].getValuePrecision()));
        details.add(StepInjectionUtil.getEntry(Entry.REPLACE_VALUE, meta.getFormula()[i].getReplaceField()));
        fieldsEntry.getDetails().add(fieldEntry);
    }
    return list;
}
Also used : StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) ArrayList(java.util.ArrayList)

Example 9 with StepInjectionMetaEntry

use of org.pentaho.di.trans.step.StepInjectionMetaEntry in project pentaho-kettle by pentaho.

the class TextFileInputMetaInjectionTest method createInjectionValues.

private static List<StepInjectionMetaEntry> createInjectionValues(TextFileInputMetaInjection.Entry[] entries) {
    Map<TextFileInputMetaInjection.Entry, Generator<?>> generators = createGeneratorsMapping();
    List<StepInjectionMetaEntry> result = new ArrayList<StepInjectionMetaEntry>(entries.length);
    for (TextFileInputMetaInjection.Entry entry : entries) {
        StepInjectionMetaEntry injectionEntry = StepInjectionUtil.getEntry(entry);
        if (entry.getValueType() != ValueMetaInterface.TYPE_NONE) {
            injectionEntry.setValue(generators.get(entry).generateValue());
        }
        result.add(injectionEntry);
    }
    return result;
}
Also used : StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) ArrayList(java.util.ArrayList)

Example 10 with StepInjectionMetaEntry

use of org.pentaho.di.trans.step.StepInjectionMetaEntry in project pentaho-kettle by pentaho.

the class DenormaliserMetaInjection method injectStepMetadataEntries.

@Override
public void injectStepMetadataEntries(List<StepInjectionMetaEntry> all) throws KettleException {
    List<DenormaliserTargetField> denormaliserTargetFields = new ArrayList<DenormaliserTargetField>();
    // 
    for (StepInjectionMetaEntry lookFields : all) {
        Entry fieldsEntry = Entry.findEntry(lookFields.getKey());
        if (fieldsEntry != null) {
            if (fieldsEntry == Entry.FIELDS) {
                for (StepInjectionMetaEntry lookField : lookFields.getDetails()) {
                    Entry fieldEntry = Entry.findEntry(lookField.getKey());
                    if (fieldEntry != null) {
                        if (fieldEntry == Entry.FIELD) {
                            DenormaliserTargetField inputField = new DenormaliserTargetField();
                            List<StepInjectionMetaEntry> entries = lookField.getDetails();
                            for (StepInjectionMetaEntry entry : entries) {
                                Entry metaEntry = Entry.findEntry(entry.getKey());
                                if (metaEntry != null) {
                                    String value = (String) entry.getValue();
                                    switch(metaEntry) {
                                        case NAME:
                                            inputField.setFieldName(value);
                                            break;
                                        case KEY_VALUE:
                                            inputField.setKeyValue(value);
                                            break;
                                        case TARGET_NAME:
                                            inputField.setTargetName(value);
                                            break;
                                        case TARGET_TYPE:
                                            inputField.setTargetType(ValueMetaFactory.getIdForValueMeta(value));
                                            break;
                                        case TARGET_LENGTH:
                                            inputField.setTargetLength(Const.toInt(value, -1));
                                            break;
                                        case TARGET_PRECISION:
                                            inputField.setTargetPrecision(Const.toInt(value, -1));
                                            break;
                                        case TARGET_CURRENCY:
                                            inputField.setTargetCurrencySymbol(value);
                                            break;
                                        case TARGET_GROUP:
                                            inputField.setTargetGroupingSymbol(value);
                                            break;
                                        case TARGET_DECIMAL:
                                            inputField.setTargetDecimalSymbol(value);
                                            break;
                                        case TARGET_FORMAT:
                                            inputField.setTargetFormat(value);
                                            break;
                                        case TARGET_AGGREGATION:
                                            inputField.setTargetAggregationType(DenormaliserTargetField.getAggregationType(value));
                                            break;
                                        default:
                                            break;
                                    }
                                }
                            }
                            denormaliserTargetFields.add(inputField);
                        }
                    }
                }
            }
        }
    }
    if (!denormaliserTargetFields.isEmpty()) {
        // Pass the grid to the step metadata
        // 
        meta.setDenormaliserTargetField(denormaliserTargetFields.toArray(new DenormaliserTargetField[denormaliserTargetFields.size()]));
    }
}
Also used : StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) ArrayList(java.util.ArrayList) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry)

Aggregations

StepInjectionMetaEntry (org.pentaho.di.trans.step.StepInjectionMetaEntry)54 ArrayList (java.util.ArrayList)31 Test (org.junit.Test)17 KettleException (org.pentaho.di.core.exception.KettleException)10 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)6 KettleAttributeInterface (org.pentaho.di.core.KettleAttributeInterface)3 TextFileInputField (org.pentaho.di.trans.steps.textfileinput.TextFileInputField)2 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 FocusEvent (org.eclipse.swt.events.FocusEvent)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 ShellEvent (org.eclipse.swt.events.ShellEvent)1