use of org.pentaho.di.core.injection.bean.BeanInjector 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;
}
use of org.pentaho.di.core.injection.bean.BeanInjector 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));
}
use of org.pentaho.di.core.injection.bean.BeanInjector 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);
}
}
use of org.pentaho.di.core.injection.bean.BeanInjector 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()));
}
}
}
}
}
use of org.pentaho.di.core.injection.bean.BeanInjector in project pentaho-kettle by pentaho.
the class BaseMetadataInjectionTest method setup.
protected void setup(T meta) {
KettleLogStore.init();
this.meta = meta;
info = new BeanInjectionInfo(meta.getClass());
injector = new BeanInjector(info);
nonTestedProperties = new HashSet<>(info.getProperties().keySet());
}
Aggregations