Search in sources :

Example 16 with StepInjectionMetaEntry

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

the class JaninoMetaInjectionIT method testInjectionEntries.

public void testInjectionEntries() throws Exception {
    JaninoMeta meta = populateJaninoMeta();
    List<StepInjectionMetaEntry> entries = meta.getStepMetaInjectionInterface().getStepInjectionMetadataEntries();
    assertEquals(1, entries.size());
    StepInjectionMetaEntry fieldsEntry = StepInjectionUtil.findEntry(entries, JaninoMetaInjection.Entry.EXPRESSION_FIELDS);
    assertNotNull(fieldsEntry);
    StepInjectionMetaEntry fieldEntry = StepInjectionUtil.findEntry(fieldsEntry.getDetails(), JaninoMetaInjection.Entry.EXPRESSION_FIELD);
    assertNotNull(fieldEntry);
    assertNotNull(StepInjectionUtil.findEntry(fieldEntry.getDetails(), JaninoMetaInjection.Entry.NEW_FIELDNAME));
    assertNotNull(StepInjectionUtil.findEntry(fieldEntry.getDetails(), JaninoMetaInjection.Entry.JAVA_EXPRESSION));
    assertNotNull(StepInjectionUtil.findEntry(fieldEntry.getDetails(), JaninoMetaInjection.Entry.VALUE_TYPE));
    assertNotNull(StepInjectionUtil.findEntry(fieldEntry.getDetails(), JaninoMetaInjection.Entry.LENGTH));
    assertNotNull(StepInjectionUtil.findEntry(fieldEntry.getDetails(), JaninoMetaInjection.Entry.PRECISION));
    assertNotNull(StepInjectionUtil.findEntry(fieldEntry.getDetails(), JaninoMetaInjection.Entry.REPLACE_VALUE));
}
Also used : StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry)

Example 17 with StepInjectionMetaEntry

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

the class JsonOutputMetaInjection method getStepInjectionMetadataEntries.

@Override
public List<StepInjectionMetaEntry> getStepInjectionMetadataEntries() throws KettleException {
    List<StepInjectionMetaEntry> all = new ArrayList<StepInjectionMetaEntry>();
    Entry[] topEntries = new Entry[] { Entry.OPERATION, Entry.JSON_BLOC_NAME, Entry.NR_ROWS_IN_BLOC, Entry.OUTPUT_VALUE, Entry.COMPATIBILITY_MODE, Entry.FILE_NAME, Entry.APPEND, Entry.CREATE_PARENT_FOLDER, Entry.DONT_CREATE_AT_START, Entry.EXTENSION, Entry.ENCODING, Entry.PASS_TO_SERVLET, Entry.INC_DATE_IN_FILENAME, Entry.INC_TIME_IN_FILENAME, Entry.ADD_TO_RESULT };
    for (Entry topEntry : topEntries) {
        all.add(new StepInjectionMetaEntry(topEntry.name(), topEntry.getValueType(), topEntry.getDescription()));
    }
    // The fields
    // 
    StepInjectionMetaEntry fieldsEntry = new StepInjectionMetaEntry(Entry.JSON_FIELDS.name(), ValueMetaInterface.TYPE_NONE, Entry.JSON_FIELDS.description);
    all.add(fieldsEntry);
    StepInjectionMetaEntry fieldEntry = new StepInjectionMetaEntry(Entry.JSON_FIELD.name(), ValueMetaInterface.TYPE_NONE, Entry.JSON_FIELD.description);
    fieldsEntry.getDetails().add(fieldEntry);
    Entry[] fieldsEntries = new Entry[] { Entry.JSON_FIELDNAME, Entry.JSON_ELEMENTNAME };
    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 18 with StepInjectionMetaEntry

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

the class MetaInject method oldInjection.

private void oldInjection(String targetStep) throws KettleException {
    if (log.isDetailed()) {
        logDetailed("Handing step '" + targetStep + "' injection!");
    }
    // This is the injection interface:
    // 
    StepMetaInjectionInterface injectionInterface = data.stepInjectionMap.get(targetStep);
    // This is the injection description:
    // 
    List<StepInjectionMetaEntry> metadataEntries = injectionInterface.getStepInjectionMetadataEntries();
    // Create a new list of metadata injection entries...
    // 
    List<StepInjectionMetaEntry> inject = new ArrayList<StepInjectionMetaEntry>();
    // Collect all the metadata for this target step...
    // 
    Map<TargetStepAttribute, SourceStepField> targetMap = meta.getTargetSourceMapping();
    for (TargetStepAttribute target : targetMap.keySet()) {
        SourceStepField source = targetMap.get(target);
        if (target.getStepname().equalsIgnoreCase(targetStep)) {
            // This is the step to collect data for...
            // We also know which step to read the data from. (source)
            // 
            List<RowMetaAndData> rows = data.rowMap.get(source.getStepname());
            if (rows != null && rows.size() > 0) {
                // Which metadata key is this referencing? Find the attribute key in the metadata entries...
                // 
                StepInjectionMetaEntry entry = findMetaEntry(metadataEntries, target.getAttributeKey());
                if (entry != null) {
                    if (!target.isDetail()) {
                        setEntryValueIfFieldExists(entry, rows.get(0), source);
                        inject.add(entry);
                    } else {
                        // We are going to pass this entry N times for N target mappings
                        // As such, we have to see if it's already in the injection list...
                        // 
                        StepInjectionMetaEntry metaEntries = findMetaEntry(inject, entry.getKey());
                        if (metaEntries == null) {
                            StepInjectionMetaEntry rootEntry = findDetailRootEntry(metadataEntries, entry);
                            // Inject an empty copy
                            // 
                            metaEntries = rootEntry.clone();
                            metaEntries.setDetails(new ArrayList<StepInjectionMetaEntry>());
                            inject.add(metaEntries);
                            // We also need to pre-populate the whole grid: X rows by Y attributes
                            // 
                            StepInjectionMetaEntry metaEntry = rootEntry.getDetails().get(0);
                            for (int i = 0; i < rows.size(); i++) {
                                StepInjectionMetaEntry metaCopy = metaEntry.clone();
                                metaEntries.getDetails().add(metaCopy);
                                metaCopy.setDetails(new ArrayList<StepInjectionMetaEntry>());
                                for (StepInjectionMetaEntry me : metaEntry.getDetails()) {
                                    StepInjectionMetaEntry meCopy = me.clone();
                                    metaCopy.getDetails().add(meCopy);
                                }
                            }
                        // From now on we can simply refer to the correct X,Y coordinate.
                        } else {
                            StepInjectionMetaEntry rootEntry = findDetailRootEntry(inject, metaEntries);
                            metaEntries = rootEntry;
                        }
                        for (int i = 0; i < rows.size(); i++) {
                            RowMetaAndData row = rows.get(i);
                            try {
                                List<StepInjectionMetaEntry> rowEntries = metaEntries.getDetails().get(i).getDetails();
                                for (StepInjectionMetaEntry rowEntry : rowEntries) {
                                    // We have to look up the sources for these targets again in the target-2-source mapping
                                    // That is because we only want handle this as few times as possible...
                                    // 
                                    SourceStepField detailSource = findDetailSource(targetMap, targetStep, rowEntry.getKey());
                                    if (detailSource != null) {
                                        setEntryValueIfFieldExists(rowEntry, row, detailSource);
                                    } else {
                                        if (log.isDetailed()) {
                                            logDetailed("No detail source found for key: " + rowEntry.getKey() + " and target step: " + targetStep);
                                        }
                                    }
                                }
                            } catch (Exception e) {
                                throw new KettleException("Unexpected error occurred while injecting metadata", e);
                            }
                        }
                        if (log.isDetailed()) {
                            logDetailed("injected entry: " + entry);
                        }
                    }
                // End of TopLevel/Detail if block
                } else {
                    if (log.isDetailed()) {
                        logDetailed("entry not found: " + target.getAttributeKey());
                    }
                }
            } else {
                if (log.isDetailed()) {
                    logDetailed("No rows found for source step: " + source.getStepname());
                }
            }
        }
    }
    // Inject the metadata into the step!
    // 
    injectionInterface.injectStepMetadataEntries(inject);
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ArrayList(java.util.ArrayList) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) StepMetaInjectionInterface(org.pentaho.di.trans.step.StepMetaInjectionInterface)

Example 19 with StepInjectionMetaEntry

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

the class MetaInjectDialog method processOldMDIDescription.

private void processOldMDIDescription(StepMeta stepMeta, TreeItem stepItem, StepMetaInjectionInterface injection) throws KettleException {
    List<StepInjectionMetaEntry> entries = injection.getStepInjectionMetadataEntries();
    for (final StepInjectionMetaEntry entry : entries) {
        if (entry.getValueType() != ValueMetaInterface.TYPE_NONE) {
            TreeItem entryItem = new TreeItem(stepItem, SWT.NONE);
            entryItem.setText(entry.getKey());
            entryItem.setText(1, entry.getDescription());
            TargetStepAttribute target = new TargetStepAttribute(stepMeta.getName(), entry.getKey(), false);
            treeItemTargetMap.put(entryItem, target);
            SourceStepField source = targetSourceMapping.get(target);
            if (source != null) {
                entryItem.setText(2, Const.NVL(source.getStepname(), ""));
                entryItem.setText(3, Const.NVL(source.getField(), ""));
            }
        } else {
            // Fields...
            // 
            TreeItem listsItem = new TreeItem(stepItem, SWT.NONE);
            listsItem.setText(entry.getKey());
            listsItem.setText(1, entry.getDescription());
            StepInjectionMetaEntry listEntry = entry.getDetails().get(0);
            listsItem.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event arg0) {
                    System.out.println(entry.getKey() + " - " + entry.getDescription());
                }
            });
            for (StepInjectionMetaEntry me : listEntry.getDetails()) {
                TreeItem treeItem = new TreeItem(listsItem, SWT.NONE);
                treeItem.setText(me.getKey());
                treeItem.setText(1, me.getDescription());
                TargetStepAttribute target = new TargetStepAttribute(stepMeta.getName(), me.getKey(), true);
                treeItemTargetMap.put(treeItem, target);
                SourceStepField source = targetSourceMapping.get(target);
                if (source != null) {
                    treeItem.setText(2, Const.NVL(source.getStepname(), ""));
                    treeItem.setText(3, Const.NVL(source.getField(), ""));
                }
            }
        }
    }
}
Also used : Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) TreeItem(org.eclipse.swt.widgets.TreeItem) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) FocusEvent(org.eclipse.swt.events.FocusEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Event(org.eclipse.swt.widgets.Event) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TargetStepAttribute(org.pentaho.di.trans.steps.metainject.TargetStepAttribute) SourceStepField(org.pentaho.di.trans.steps.metainject.SourceStepField)

Example 20 with StepInjectionMetaEntry

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

the class GetXMLDataMetaInjection method injectStepMetadataEntries.

@Override
public void injectStepMetadataEntries(List<StepInjectionMetaEntry> all) throws KettleException {
    List<GetXMLDataMetaInjection.FilenameLine> filenameLines = new ArrayList<GetXMLDataMetaInjection.FilenameLine>();
    List<GetXMLDataField> fields = new ArrayList<GetXMLDataField>();
    // 
    for (StepInjectionMetaEntry lookFields : all) {
        String lookFieldsValue = lookFields.getValue() instanceof String ? (String) lookFields.getValue() : null;
        Entry fieldsEntry = Entry.findEntry(lookFields.getKey());
        if (fieldsEntry != null) {
            switch(fieldsEntry) {
                case FILENAMES:
                    for (StepInjectionMetaEntry lookField : lookFields.getDetails()) {
                        Entry fieldEntry = Entry.findEntry(lookField.getKey());
                        if (fieldEntry != null) {
                            if (fieldEntry == Entry.FILENAME) {
                                String fileName = null;
                                String fileMask = null;
                                String fileRequired = null;
                                String excludeFileMask = null;
                                String includeSubFolders = 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 FILE_PATH:
                                                fileName = value;
                                                break;
                                            case FILE_INCLUDE_MASK:
                                                fileMask = value;
                                                break;
                                            case FILE_EXCLUDE_MASK:
                                                excludeFileMask = value;
                                                break;
                                            case FILE_REQUIRED:
                                                fileRequired = value;
                                                break;
                                            case FILE_INCLUDE_SUBFOLDERS:
                                                includeSubFolders = value;
                                                break;
                                            default:
                                                break;
                                        }
                                    }
                                }
                                if (!Utils.isEmpty(fileName)) {
                                    filenameLines.add(new FilenameLine(fileName, fileMask, fileRequired, excludeFileMask, includeSubFolders));
                                }
                            }
                        }
                    }
                    break;
                case INPUTFIELDS:
                    for (StepInjectionMetaEntry lookField : lookFields.getDetails()) {
                        Entry fieldEntry = Entry.findEntry(lookField.getKey());
                        if (fieldEntry != null) {
                            if (fieldEntry == Entry.INPUTFIELD) {
                                GetXMLDataField field = new GetXMLDataField();
                                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 INPUTFIELD_NAME:
                                                field.setName(value);
                                                break;
                                            case INPUTFIELD_XPATH:
                                                field.setXPath(value);
                                                break;
                                            case INPUTFIELD_TYPE:
                                                field.setType(ValueMetaFactory.getIdForValueMeta(value));
                                                break;
                                            case INPUTFIELD_ELEMENT_TYPE:
                                                field.setElementType(GetXMLDataField.getElementTypeByCode(value));
                                                break;
                                            case INPUTFIELD_RESULT_TYPE:
                                                field.setResultType(GetXMLDataField.getResultTypeByCode(value));
                                                break;
                                            case INPUTFIELD_LENGTH:
                                                field.setLength(Const.toInt(value, -1));
                                                break;
                                            case INPUTFIELD_PRECISION:
                                                field.setPrecision(Const.toInt(value, -1));
                                                break;
                                            case INPUTFIELD_FORMAT:
                                                field.setFormat(value);
                                                break;
                                            case INPUTFIELD_TRIM_TYPE:
                                                field.setTrimType(ValueMeta.getTrimTypeByCode(value));
                                                break;
                                            case INPUTFIELD_CURRENCY:
                                                field.setCurrencySymbol(value);
                                                break;
                                            case INPUTFIELD_GROUPING:
                                                field.setGroupSymbol(value);
                                                break;
                                            case INPUTFIELD_DECIMAL:
                                                field.setDecimalSymbol(value);
                                                break;
                                            case INPUTFIELD_REPEAT:
                                                field.setRepeated("Y".equalsIgnoreCase(value));
                                                break;
                                            default:
                                                break;
                                        }
                                    }
                                }
                                fields.add(field);
                            }
                        }
                    }
                    break;
                case INCLUDE_ROWNUMBER:
                    meta.setIncludeRowNumber("Y".equalsIgnoreCase(lookFieldsValue));
                    break;
                case ROWNUMBER_FIELD:
                    meta.setRowNumberField(lookFieldsValue);
                    break;
                case ROWLIMIT:
                    meta.setRowLimit(Const.toLong(lookFieldsValue, 0L));
                    break;
                case LOOP_XPATH:
                    meta.setLoopXPath(lookFieldsValue);
                    break;
                case ENCODING:
                    meta.setEncoding(lookFieldsValue);
                    break;
                case XML_FIELD:
                    meta.setXMLField(lookFieldsValue);
                    break;
                case IN_FIELD:
                    meta.setInFields("Y".equalsIgnoreCase(lookFieldsValue));
                    break;
                case IN_FILE:
                    meta.setIsAFile("Y".equalsIgnoreCase(lookFieldsValue));
                    break;
                case ADD_RESULT_FILE:
                    meta.setAddResultFile("Y".equalsIgnoreCase(lookFieldsValue));
                    break;
                case NAMESPACE_AWARE:
                    meta.setNamespaceAware("Y".equalsIgnoreCase(lookFieldsValue));
                    break;
                case VALIDATE:
                    meta.setValidating("Y".equalsIgnoreCase(lookFieldsValue));
                    break;
                case USE_TOKENS:
                    meta.setuseToken("Y".equalsIgnoreCase(lookFieldsValue));
                    break;
                case IGNORE_EMPTY_FILES:
                    meta.setIgnoreEmptyFile("Y".equalsIgnoreCase(lookFieldsValue));
                    break;
                case IGNORE_MISSING_FILES:
                    meta.setdoNotFailIfNoFile("Y".equalsIgnoreCase(lookFieldsValue));
                    break;
                case IGNORE_COMMENTS:
                    meta.setIgnoreComments("Y".equalsIgnoreCase(lookFieldsValue));
                    break;
                case READ_URL:
                    meta.setReadUrl("Y".equalsIgnoreCase(lookFieldsValue));
                    break;
                case PRUNE_PATH:
                    meta.setPrunePath(lookFieldsValue);
                    break;
                case SHORT_FILE_FIELDNAME:
                    meta.setShortFileNameField(lookFieldsValue);
                    break;
                case FILE_PATH_FIELDNAME:
                    meta.setFilenameField(lookFieldsValue);
                    break;
                case FILE_HIDDEN_FIELDNAME:
                    meta.setIsHiddenField(lookFieldsValue);
                    break;
                case FILE_MODIFICATION_FIELDNAME:
                    meta.setLastModificationDateField(lookFieldsValue);
                    break;
                case FILE_URI_NAME_FIELDNAME:
                    meta.setUriField(lookFieldsValue);
                    break;
                case FILE_ROOT_URI_FIELDNAME:
                    meta.setRootUriField(lookFieldsValue);
                    break;
                case FILE_EXTENSION_FIELDNAME:
                    meta.setExtensionField(lookFieldsValue);
                    break;
                case FILE_SIZE_FIELDNAME:
                    meta.setSizeField(lookFieldsValue);
                    break;
                default:
                    break;
            }
        }
    }
    // 
    if (fields.size() > 0) {
        meta.setInputFields(fields.toArray(new GetXMLDataField[fields.size()]));
    }
    if (filenameLines.size() > 0) {
        meta.allocateFiles(filenameLines.size());
        // CHECKSTYLE:Indentation:OFF
        for (int i = 0; i < filenameLines.size(); i++) {
            FilenameLine line = filenameLines.get(i);
            meta.getFileName()[i] = line.fileName;
            meta.getFileMask()[i] = line.fileMask;
            meta.getFileRequired()[i] = line.fileRequired;
            meta.getExludeFileMask()[i] = line.excludeFileMask;
            meta.getIncludeSubFolders()[i] = line.includeSubFolders;
        }
    }
}
Also used : StepMetaInjectionEnumEntry(org.pentaho.di.trans.step.StepMetaInjectionEnumEntry) 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