Search in sources :

Example 11 with StepMetaInterface

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

the class TransMeta method addOrReplaceStep.

/**
 * Add a new step to the transformation if that step didn't exist yet. Otherwise, replace the step. This method also
 * marks that the transformation's steps have changed.
 *
 * @param stepMeta
 *          The meta-data for the step to be added.
 */
public void addOrReplaceStep(StepMeta stepMeta) {
    int index = steps.indexOf(stepMeta);
    if (index < 0) {
        index = steps.add(stepMeta) ? 0 : index;
    } else {
        StepMeta previous = getStep(index);
        previous.replaceMeta(stepMeta);
    }
    stepMeta.setParentTransMeta(this);
    StepMetaInterface iface = stepMeta.getStepMetaInterface();
    if (index != -1 && iface instanceof StepMetaChangeListenerInterface) {
        addStepChangeListener(index, (StepMetaChangeListenerInterface) iface);
    }
    changed_steps = true;
    clearCaches();
}
Also used : StepMetaChangeListenerInterface(org.pentaho.di.trans.step.StepMetaChangeListenerInterface) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint)

Example 12 with StepMetaInterface

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

the class TransMeta method addStep.

/**
 * Add a new step to the transformation. Also marks that the transformation's steps have changed.
 *
 * @param stepMeta
 *          The meta-data for the step to be added.
 */
public void addStep(StepMeta stepMeta) {
    steps.add(stepMeta);
    stepMeta.setParentTransMeta(this);
    StepMetaInterface iface = stepMeta.getStepMetaInterface();
    if (iface instanceof StepMetaChangeListenerInterface) {
        addStepChangeListener((StepMetaChangeListenerInterface) iface);
    }
    changed_steps = true;
    clearCaches();
}
Also used : StepMetaChangeListenerInterface(org.pentaho.di.trans.step.StepMetaChangeListenerInterface) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface)

Example 13 with StepMetaInterface

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

the class TransMeta method analyseImpact.

/**
 * Determines the impact of the different steps in a transformation on databases, tables and field.
 *
 * @param impact
 *          An ArrayList of DatabaseImpact objects.
 * @param monitor
 *          a progress monitor listener to be updated as the transformation is analyzed
 * @throws KettleStepException
 *           if any errors occur during analysis
 */
public void analyseImpact(List<DatabaseImpact> impact, ProgressMonitorListener monitor) throws KettleStepException {
    if (monitor != null) {
        monitor.beginTask(BaseMessages.getString(PKG, "TransMeta.Monitor.DeterminingImpactTask.Title"), nrSteps());
    }
    boolean stop = false;
    for (int i = 0; i < nrSteps() && !stop; i++) {
        if (monitor != null) {
            monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.LookingAtStepTask.Title") + (i + 1) + "/" + nrSteps());
        }
        StepMeta stepMeta = getStep(i);
        RowMetaInterface prev = getPrevStepFields(stepMeta);
        StepMetaInterface stepint = stepMeta.getStepMetaInterface();
        RowMetaInterface inform = null;
        StepMeta[] lu = getInfoStep(stepMeta);
        if (lu != null) {
            inform = getStepFields(lu);
        } else {
            inform = stepint.getTableFields();
        }
        compatibleAnalyseImpactStep(impact, stepint, this, stepMeta, prev, inform);
        stepint.analyseImpact(impact, this, stepMeta, prev, null, null, inform, repository, metaStore);
        if (monitor != null) {
            monitor.worked(1);
            stop = monitor.isCanceled();
        }
    }
    if (monitor != null) {
        monitor.done();
    }
}
Also used : StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint)

Example 14 with StepMetaInterface

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

the class LucidDBBulkLoaderDialog 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() {
    // Determine the source and target fields...
    // 
    RowMetaInterface sourceFields;
    RowMetaInterface targetFields;
    try {
        sourceFields = transMeta.getPrevStepFields(stepMeta);
    } catch (KettleException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "LucidDBBulkLoaderDialog.DoMapping.UnableToFindSourceFields.Title"), BaseMessages.getString(PKG, "LucidDBBulkLoaderDialog.DoMapping.UnableToFindSourceFields.Message"), e);
        return;
    }
    // refresh data
    input.setDatabaseMeta(transMeta.findDatabase(wConnection.getText()));
    input.setTableName(transMeta.environmentSubstitute(wTable.getText()));
    StepMetaInterface stepMetaInterface = stepMeta.getStepMetaInterface();
    try {
        targetFields = stepMetaInterface.getRequiredFields(transMeta);
    } catch (KettleException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "LucidDBBulkLoaderDialog.DoMapping.UnableToFindTargetFields.Title"), BaseMessages.getString(PKG, "LucidDBBulkLoaderDialog.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, "LucidDBBulkLoaderDialog.DoMapping.SomeSourceFieldsNotFound", missingSourceFields.toString()) + Const.CR;
        }
        if (missingTargetFields.length() > 0) {
            message += BaseMessages.getString(PKG, "LucidDBBulkLoaderDialog.DoMapping.SomeTargetFieldsNotFound", missingSourceFields.toString()) + Const.CR;
        }
        message += Const.CR;
        message += BaseMessages.getString(PKG, "LucidDBBulkLoaderDialog.DoMapping.SomeFieldsNotFoundContinue") + Const.CR;
        MessageDialog.setDefaultImage(GUIResource.getInstance().getImageSpoon());
        boolean goOn = MessageDialog.openConfirm(shell, BaseMessages.getString(PKG, "LucidDBBulkLoaderDialog.DoMapping.SomeFieldsNotFoundTitle"), message);
        if (!goOn) {
            return;
        }
    }
    EnterMappingDialog d = new EnterMappingDialog(LucidDBBulkLoaderDialog.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) EnterMappingDialog(org.pentaho.di.ui.core.dialog.EnterMappingDialog) TableItem(org.eclipse.swt.widgets.TableItem) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) ArrayList(java.util.ArrayList) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) SourceToTargetMapping(org.pentaho.di.core.SourceToTargetMapping)

Example 15 with StepMetaInterface

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

the class MetaInjectDialog method refreshTree.

private void refreshTree() {
    try {
        loadTransformation();
        treeItemTargetMap = new HashMap<>();
        wTree.removeAll();
        TreeItem transItem = new TreeItem(wTree, SWT.NONE);
        transItem.setExpanded(true);
        transItem.setText(injectTransMeta.getName());
        List<StepMeta> injectSteps = new ArrayList<>();
        for (StepMeta stepMeta : injectTransMeta.getUsedSteps()) {
            StepMetaInterface meta = stepMeta.getStepMetaInterface();
            if (meta.getStepMetaInjectionInterface() != null || BeanInjectionInfo.isInjectionSupported(meta.getClass())) {
                injectSteps.add(stepMeta);
            }
        }
        Collections.sort(injectSteps);
        for (StepMeta stepMeta : injectSteps) {
            TreeItem stepItem = new TreeItem(transItem, SWT.NONE);
            stepItem.setText(stepMeta.getName());
            stepItem.setExpanded(true);
            // For each step, add the keys
            // 
            StepMetaInterface metaInterface = stepMeta.getStepMetaInterface();
            if (BeanInjectionInfo.isInjectionSupported(metaInterface.getClass())) {
                processNewMDIDescription(stepMeta, stepItem, metaInterface);
            } else {
                processOldMDIDescription(stepMeta, stepItem, metaInterface.getStepMetaInjectionInterface());
            }
        }
    } catch (Throwable t) {
    // Ignore errors
    }
    for (TreeItem item : wTree.getItems()) {
        expandItemAndChildren(item);
    }
    // 
    if (injectTransMeta != null) {
        String[] sourceSteps = injectTransMeta.getStepNames();
        Arrays.sort(sourceSteps);
        wSourceStep.setItems(sourceSteps);
        wStreamingTargetStep.setItems(sourceSteps);
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) ArrayList(java.util.ArrayList) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta)

Aggregations

StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)77 StepMeta (org.pentaho.di.trans.step.StepMeta)40 KettleException (org.pentaho.di.core.exception.KettleException)31 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)21 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)20 TransMeta (org.pentaho.di.trans.TransMeta)16 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)16 TableItem (org.eclipse.swt.widgets.TableItem)15 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)15 SourceToTargetMapping (org.pentaho.di.core.SourceToTargetMapping)14 Trans (org.pentaho.di.trans.Trans)14 EnterMappingDialog (org.pentaho.di.ui.core.dialog.EnterMappingDialog)14 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)12 Point (org.pentaho.di.core.gui.Point)12 TransHopMeta (org.pentaho.di.trans.TransHopMeta)11 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)11 NotePadMeta (org.pentaho.di.core.NotePadMeta)8 KettleStepException (org.pentaho.di.core.exception.KettleStepException)8 JobEntryInterface (org.pentaho.di.job.entry.JobEntryInterface)8