Search in sources :

Example 1 with BeanInjectionInfo

use of org.pentaho.di.core.injection.bean.BeanInjectionInfo in project pentaho-kettle by pentaho.

the class StepMetaProps method from.

/**
 * Retuns an instance of this class with stepMeta properties mapped
 * to a list of {@link PropGroup}
 */
public static StepMetaProps from(StepMetaInterface stepMeta) {
    StepMetaProps propMap = new StepMetaProps(stepMeta);
    // use metadata injection to extract properties
    BeanInjectionInfo info = new BeanInjectionInfo(stepMeta.getClass());
    BeanInjector injector = new BeanInjector(info);
    propMap.populateGroups(stepMeta, info, injector);
    return propMap;
}
Also used : BeanInjector(org.pentaho.di.core.injection.bean.BeanInjector) BeanInjectionInfo(org.pentaho.di.core.injection.bean.BeanInjectionInfo)

Example 2 with BeanInjectionInfo

use of org.pentaho.di.core.injection.bean.BeanInjectionInfo in project pentaho-kettle by pentaho.

the class StepMetaProps method to.

/**
 * Sets the properties of this StepMetaProps on {@param stepMetaInterface}
 * <p>
 * This method mutates the stepMeta, as opposed to returning a new instance, to match
 * more cleanly to Kettle's {@link StepMetaInterface#loadXML} design, which loads props into
 * an instance.
 */
public void to(StepMetaInterface stepMetaInterface) {
    BeanInjectionInfo info = new BeanInjectionInfo(stepMetaInterface.getClass());
    BeanInjector injector = new BeanInjector(info);
    info.getProperties().values().forEach(property -> assignValueForProp(property, stepMetaInterface, injector));
}
Also used : BeanInjector(org.pentaho.di.core.injection.bean.BeanInjector) BeanInjectionInfo(org.pentaho.di.core.injection.bean.BeanInjectionInfo)

Example 3 with BeanInjectionInfo

use of org.pentaho.di.core.injection.bean.BeanInjectionInfo in project pentaho-kettle by pentaho.

the class MetaInject method newInjection.

/**
 * Inject values from steps.
 */
private void newInjection(String targetStep, StepMetaInterface targetStepMeta) throws KettleException {
    if (log.isDetailed()) {
        logDetailed("Handing step '" + targetStep + "' injection!");
    }
    BeanInjectionInfo injectionInfo = new BeanInjectionInfo(targetStepMeta.getClass());
    BeanInjector injector = new BeanInjector(injectionInfo);
    // Collect all the metadata for this target step...
    // 
    Map<TargetStepAttribute, SourceStepField> targetMap = meta.getTargetSourceMapping();
    boolean wasInjection = false;
    for (TargetStepAttribute target : targetMap.keySet()) {
        SourceStepField source = targetMap.get(target);
        if (target.getStepname().equalsIgnoreCase(targetStep)) {
            // 
            if (source.getStepname() != null) {
                // from specified steo
                List<RowMetaAndData> rows = data.rowMap.get(source.getStepname());
                if (rows != null && !rows.isEmpty()) {
                    // 
                    if (injector.hasProperty(targetStepMeta, target.getAttributeKey())) {
                        // target step has specified key
                        boolean skip = false;
                        for (RowMetaAndData r : rows) {
                            if (r.getRowMeta().indexOfValue(source.getField()) < 0) {
                                logError(BaseMessages.getString(PKG, "MetaInject.SourceFieldIsNotDefined.Message", source.getField(), getTransMeta().getName()));
                                // source step doesn't contain specified field
                                skip = true;
                            }
                        }
                        if (!skip) {
                            // specified field exist - need to inject
                            injector.setProperty(targetStepMeta, target.getAttributeKey(), rows, source.getField());
                            wasInjection = true;
                        }
                    } else {
                        // target step doesn't have specified key - just report but don't fail like in 6.0 (BACKLOG-6753)
                        logError(BaseMessages.getString(PKG, "MetaInject.TargetKeyIsNotDefined.Message", target.getAttributeKey(), getTransMeta().getName()));
                    }
                }
            }
        }
    }
    if (wasInjection) {
        injector.runPostInjectionProcessing(targetStepMeta);
    }
}
Also used : BeanInjector(org.pentaho.di.core.injection.bean.BeanInjector) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) BeanInjectionInfo(org.pentaho.di.core.injection.bean.BeanInjectionInfo)

Example 4 with BeanInjectionInfo

use of org.pentaho.di.core.injection.bean.BeanInjectionInfo in project pentaho-kettle by pentaho.

the class MetaInject method getUnavailableTargetKeys.

public static Set<TargetStepAttribute> getUnavailableTargetKeys(Map<TargetStepAttribute, SourceStepField> targetMap, TransMeta injectedTransMeta, Set<TargetStepAttribute> unavailableTargetSteps) {
    Set<TargetStepAttribute> missingKeys = new HashSet<>();
    Map<String, BeanInjectionInfo> beanInfos = getUsedStepBeanInfos(injectedTransMeta);
    for (TargetStepAttribute key : targetMap.keySet()) {
        if (!unavailableTargetSteps.contains(key)) {
            BeanInjectionInfo info = beanInfos.get(key.getStepname().toUpperCase());
            if (info != null && !info.getProperties().containsKey(key.getAttributeKey())) {
                missingKeys.add(key);
            }
        }
    }
    return missingKeys;
}
Also used : BeanInjectionInfo(org.pentaho.di.core.injection.bean.BeanInjectionInfo) HashSet(java.util.HashSet)

Example 5 with BeanInjectionInfo

use of org.pentaho.di.core.injection.bean.BeanInjectionInfo in project pentaho-kettle by pentaho.

the class MetaInject method newInjectionConstants.

/**
 * Inject constant values.
 */
private void newInjectionConstants(String targetStep, StepMetaInterface targetStepMeta) throws KettleException {
    if (log.isDetailed()) {
        logDetailed("Handing step '" + targetStep + "' constants injection!");
    }
    BeanInjectionInfo injectionInfo = new BeanInjectionInfo(targetStepMeta.getClass());
    BeanInjector injector = new BeanInjector(injectionInfo);
    // 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)) {
            // 
            if (source.getStepname() == null) {
                // inject constant
                if (injector.hasProperty(targetStepMeta, target.getAttributeKey())) {
                    // target step has specified key
                    injector.setProperty(targetStepMeta, target.getAttributeKey(), null, source.getField());
                } else {
                    // target step doesn't have specified key - just report but don't fail like in 6.0 (BACKLOG-6753)
                    logError(BaseMessages.getString(PKG, "MetaInject.TargetKeyIsNotDefined.Message", target.getAttributeKey(), getTransMeta().getName()));
                }
            }
        }
    }
}
Also used : BeanInjector(org.pentaho.di.core.injection.bean.BeanInjector) BeanInjectionInfo(org.pentaho.di.core.injection.bean.BeanInjectionInfo)

Aggregations

BeanInjectionInfo (org.pentaho.di.core.injection.bean.BeanInjectionInfo)9 BeanInjector (org.pentaho.di.core.injection.bean.BeanInjector)5 Test (org.junit.Test)2 HashSet (java.util.HashSet)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)1 SourceStepField (org.pentaho.di.trans.steps.metainject.SourceStepField)1 TargetStepAttribute (org.pentaho.di.trans.steps.metainject.TargetStepAttribute)1