Search in sources :

Example 1 with TargetStepAttribute

use of org.pentaho.di.trans.steps.metainject.TargetStepAttribute in project pentaho-kettle by pentaho.

the class MetaInjectAnalyzer method getUsedFields.

@Override
protected Set<StepField> getUsedFields(MetaInjectMeta meta) {
    final Set<StepField> usedFields = new HashSet();
    final Iterator<Map.Entry<TargetStepAttribute, SourceStepField>> fieldMappingsIter = meta.getTargetSourceMapping().entrySet().iterator();
    while (fieldMappingsIter.hasNext()) {
        final Map.Entry<TargetStepAttribute, SourceStepField> entry = fieldMappingsIter.next();
        final SourceStepField value = entry.getValue();
        final Iterator<StepField> stepFields = createStepFields(value.getField(), getInputs()).iterator();
        while (stepFields.hasNext()) {
            final StepField stepField = stepFields.next();
            usedFields.add(stepField);
        }
    }
    return usedFields;
}
Also used : StepField(org.pentaho.metaverse.api.StepField) SourceStepField(org.pentaho.di.trans.steps.metainject.SourceStepField) TargetStepAttribute(org.pentaho.di.trans.steps.metainject.TargetStepAttribute) Map(java.util.Map) SourceStepField(org.pentaho.di.trans.steps.metainject.SourceStepField) HashSet(java.util.HashSet)

Example 2 with TargetStepAttribute

use of org.pentaho.di.trans.steps.metainject.TargetStepAttribute in project pentaho-kettle by pentaho.

the class MetaInjectAnalyzer method postAnalyze.

@Override
public void postAnalyze(final MetaInjectMeta meta) throws MetaverseAnalyzerException {
    final String transformationPath = parentTransMeta.environmentSubstitute(meta.getFileName());
    final TransMeta subTransMeta = KettleAnalyzerUtil.getSubTransMeta(meta);
    subTransMeta.setFilename(transformationPath);
    // get the vertex corresponding to this step
    final Vertex stepVertex = findStepVertex(parentTransMeta, parentStepMeta.getName());
    // are we streaming data directly from an injector step to a template step?
    if (!StringUtil.isEmpty(meta.getStreamSourceStepname()) && !StringUtil.isEmpty(meta.getStreamTargetStepname())) {
        // get the field names flowing from the stream source step into the template ktr's streaming target
        // step directly and the output fields of the streamTargetStepVertex, and create "derives" links between the
        // pairs at each index - we look at the outputRowMeta rather than just finding the vertices in the graph,
        // because we need to preserve field order, and the gtraph might give us the field Vertices out of order;
        // the returned maps might contain multiple key-value pairs for multiple steps, but the values in all should be
        // the same, so we can graph the first value we encounter
        final List<String> sourceFieldNames = getOutputFieldNames(parentTransMeta, meta.getStreamSourceStepname());
        final List<String> targetFieldNames = getOutputFieldNames(subTransMeta, meta.getStreamTargetStepname());
        int index = 0;
        for (final String sourceFieldName : sourceFieldNames) {
            final Vertex streamSourceStepOutputField = findFieldVertex(parentTransMeta, meta.getStreamSourceStepname(), sourceFieldName);
            // get the target field at the same index, if it exists
            if (index < targetFieldNames.size()) {
                final Vertex streamTargetStepOutputField = findFieldVertex(subTransMeta, meta.getStreamTargetStepname(), targetFieldNames.get(index++));
                getMetaverseBuilder().addLink(streamSourceStepOutputField, DictionaryConst.LINK_DERIVES, streamTargetStepOutputField);
            } else {
                // we have mapped all the source fields we can, there are no more target steps to map to
                break;
            }
        }
    }
    final String sourceStepName = parentTransMeta.environmentSubstitute(meta.getSourceStepName());
    final Iterator<Map.Entry<TargetStepAttribute, SourceStepField>> fieldMappingsIter = meta.getTargetSourceMapping().entrySet().iterator();
    final List<String> verboseProperties = new ArrayList();
    int mappingCount = 1;
    int ignoredMappingCount = 1;
    // process the injection mappings
    while (fieldMappingsIter.hasNext()) {
        final Map.Entry<TargetStepAttribute, SourceStepField> entry = fieldMappingsIter.next();
        final TargetStepAttribute targetTemplateStepAttr = entry.getKey();
        final SourceStepField sourceInjectorStepField = entry.getValue();
        final String targetTemplateStepName = targetTemplateStepAttr.getStepname();
        // if the source step is set to stream data directly to a step in the template (target) transformation, the
        // mappings are ignored, and instead, data is sent directly
        final boolean ignoreMapping = sourceInjectorStepField.getStepname().equalsIgnoreCase(meta.getStreamSourceStepname());
        String mappingKey;
        if (!ignoreMapping) {
            mappingKey = "mapping [" + mappingCount++ + "]";
            // output fields from the target template step and pass them back (input) into the parent injector step
            if (targetTemplateStepName.equalsIgnoreCase(sourceStepName)) {
                final List<Vertex> targetTemplateFields = findFieldVertices(subTransMeta, targetTemplateStepName);
                for (final Vertex targetTemplateField : targetTemplateFields) {
                    getMetaverseBuilder().addLink(targetTemplateField, DictionaryConst.LINK_INPUTS, stepVertex);
                }
            }
            // create "pseudo" step property nodes - these are ANNOTATIONS assigned to step properties
            // Note, since the sub-transformation has already been analysed, this node will already exist, and therefore
            // we need to fetch the Vertex directly, as we currenlty have no way ot finding nodes in the graph
            final Vertex targetTemplateStepVertex = findStepVertex(subTransMeta, targetTemplateStepName);
            final IMetaverseNode subTransPropertyNode = getNode(targetTemplateStepAttr.getAttributeKey(), DictionaryConst.NODE_TYPE_STEP_PROPERTY, (String) targetTemplateStepVertex.getProperty(DictionaryConst.PROPERTY_LOGICAL_ID), targetTemplateStepName + ":" + targetTemplateStepAttr.getAttributeKey(), null);
            getMetaverseBuilder().addNode(subTransPropertyNode);
            // now that the property node has been added, find the corresponding vertex to add the "contains" link from
            // the target template step
            final Vertex subTransPropertyVertex = findVertexById(subTransPropertyNode.getStringID());
            if (subTransPropertyVertex != null) {
                getMetaverseBuilder().addLink(targetTemplateStepVertex, DictionaryConst.LINK_CONTAINS, subTransPropertyVertex);
            }
            final String injectorStepName = sourceInjectorStepField.getStepname();
            final String injectotFieldName = sourceInjectorStepField.getField();
            final IMetaverseNode matchingInjectorFieldNode = getInputs().findNode(injectorStepName, injectotFieldName);
            if (matchingInjectorFieldNode != null) {
                // add 'populates' links back to the real ETL meta output fields
                getMetaverseBuilder().addLink(matchingInjectorFieldNode, DictionaryConst.LINK_POPULATES, subTransPropertyNode);
            }
        } else {
            mappingKey = "ignored mapping [" + ignoredMappingCount++ + "]";
        }
        final StringBuilder mapping = new StringBuilder();
        mapping.append(sourceInjectorStepField.getStepname()).append(": ").append(sourceInjectorStepField.getField()).append(" > [").append(subTransMeta.getName()).append("] ").append(targetTemplateStepName).append(": ").append(targetTemplateStepAttr.getAttributeKey());
        verboseProperties.add(mappingKey);
        stepVertex.setProperty(mappingKey, mapping.toString());
    }
    // node and  "derives" links from those fields to the corresponding output fields of the root node
    if (StringUtils.isNotBlank(sourceStepName)) {
        // we created this node earlier, so we know it exists
        final List<Vertex> sourceStepFields = findFieldVertices(subTransMeta, sourceStepName);
        for (final Vertex sourceStepField : sourceStepFields) {
            getMetaverseBuilder().addLink(sourceStepField, DictionaryConst.LINK_INPUTS, stepVertex);
            // find a field in this step with the same name as the source step field
            final Vertex derivedField = findFieldVertex(parentTransMeta, stepVertex.getProperty(DictionaryConst.PROPERTY_NAME).toString(), sourceStepField.getProperty(DictionaryConst.PROPERTY_NAME).toString());
            if (derivedField != null) {
                getMetaverseBuilder().addLink(sourceStepField, DictionaryConst.LINK_DERIVES, derivedField);
            }
        }
    }
    stepVertex.setProperty(DictionaryConst.PROPERTY_VERBOSE_DETAILS, StringUtils.join(verboseProperties, ","));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) TransMeta(org.pentaho.di.trans.TransMeta) ArrayList(java.util.ArrayList) TargetStepAttribute(org.pentaho.di.trans.steps.metainject.TargetStepAttribute) Map(java.util.Map) SourceStepField(org.pentaho.di.trans.steps.metainject.SourceStepField)

Example 3 with TargetStepAttribute

use of org.pentaho.di.trans.steps.metainject.TargetStepAttribute 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 4 with TargetStepAttribute

use of org.pentaho.di.trans.steps.metainject.TargetStepAttribute in project pentaho-kettle by pentaho.

the class MetaInjectDialog method showInvalidMappingDialog.

private void showInvalidMappingDialog(Set<SourceStepField> unavailableSourceSteps, Set<TargetStepAttribute> unavailableTargetSteps, Set<TargetStepAttribute> missingTargetKeys) {
    MessageBox mb = new MessageBox(shell, SWT.YES | SWT.NO | SWT.ICON_QUESTION);
    mb.setMessage(BaseMessages.getString(PKG, "MetaInjectDialog.InvalidMapping.Question"));
    mb.setText(BaseMessages.getString(PKG, "MetaInjectDialog.InvalidMapping.Title"));
    int id = mb.open();
    if (id == SWT.YES) {
        MetaInject.removeUnavailableStepsFromMapping(targetSourceMapping, unavailableSourceSteps, unavailableTargetSteps);
        for (TargetStepAttribute target : missingTargetKeys) {
            targetSourceMapping.remove(target);
        }
    }
}
Also used : TargetStepAttribute(org.pentaho.di.trans.steps.metainject.TargetStepAttribute) Point(org.eclipse.swt.graphics.Point) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 5 with TargetStepAttribute

use of org.pentaho.di.trans.steps.metainject.TargetStepAttribute in project pentaho-kettle by pentaho.

the class MetaInjectDialog method processNewMDIDescription.

private void processNewMDIDescription(StepMeta stepMeta, TreeItem stepItem, StepMetaInterface metaInterface) {
    BeanInjectionInfo stepInjectionInfo = new BeanInjectionInfo(metaInterface.getClass());
    for (BeanInjectionInfo.Group gr : stepInjectionInfo.getGroups()) {
        boolean rootGroup = StringUtils.isEmpty(gr.getName());
        TreeItem groupItem;
        if (!rootGroup) {
            groupItem = new TreeItem(stepItem, SWT.NONE);
            groupItem.setText(gr.getName());
            groupItem.setText(1, gr.getDescription());
        } else {
            groupItem = null;
        }
        for (BeanInjectionInfo.Property property : gr.getGroupProperties()) {
            TreeItem treeItem = new TreeItem(rootGroup ? stepItem : groupItem, SWT.NONE);
            treeItem.setText(property.getName());
            treeItem.setText(1, property.getDescription());
            TargetStepAttribute target = new TargetStepAttribute(stepMeta.getName(), property.getName(), !rootGroup);
            treeItemTargetMap.put(treeItem, target);
            SourceStepField source = targetSourceMapping.get(target);
            if (source != null) {
                treeItem.setText(2, Const.NVL(source.getStepname() == null ? CONST_VALUE : source.getStepname(), ""));
                treeItem.setText(3, Const.NVL(source.getField(), ""));
            }
        }
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) BeanInjectionInfo(org.pentaho.di.core.injection.bean.BeanInjectionInfo) TargetStepAttribute(org.pentaho.di.trans.steps.metainject.TargetStepAttribute) SourceStepField(org.pentaho.di.trans.steps.metainject.SourceStepField)

Aggregations

TargetStepAttribute (org.pentaho.di.trans.steps.metainject.TargetStepAttribute)7 SourceStepField (org.pentaho.di.trans.steps.metainject.SourceStepField)6 Map (java.util.Map)3 TreeItem (org.eclipse.swt.widgets.TreeItem)3 HashMap (java.util.HashMap)2 FocusEvent (org.eclipse.swt.events.FocusEvent)2 ModifyEvent (org.eclipse.swt.events.ModifyEvent)2 ModifyListener (org.eclipse.swt.events.ModifyListener)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 ShellEvent (org.eclipse.swt.events.ShellEvent)2 Point (org.eclipse.swt.graphics.Point)2 Event (org.eclipse.swt.widgets.Event)2 Listener (org.eclipse.swt.widgets.Listener)2 Vertex (com.tinkerpop.blueprints.Vertex)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 CTabItem (org.eclipse.swt.custom.CTabItem)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1