/** * 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 StepMetaInterface to( StepMetaInterface stepMetaInterface ) { BeanInjectionInfo info = new BeanInjectionInfo( stepMetaInterface.getClass() ); BeanInjector injector = new BeanInjector( info ); info.getProperties().values().forEach( property -> assignValueForProp( property, stepMetaInterface, injector ) ); return stepMetaInterface; }
private void populateGroups( StepMetaInterface stepMeta, BeanInjectionInfo info, BeanInjector injector ) { groups = info.getGroups().stream() // get metadata injection groups .flatMap( group -> group.getGroupProperties().stream() ) // expand to all properties .map( getProp( stepMeta, injector ) ) // map to property/value .collect( groupingBy( Prop::getGroup ) ).entrySet().stream() // group by group name .map( entry -> new PropGroup( entry.getKey(), entry.getValue() ) ) // map the set of properties to a group .collect( Collectors.toList() ); }
public String getDescription() { return BeanInjectionInfo.this.getDescription( name ); } }
private static Map<String, BeanInjectionInfo> getUsedStepBeanInfos( TransMeta transMeta ) { Map<String, BeanInjectionInfo> res = new HashMap<>(); for ( StepMeta step : transMeta.getUsedSteps() ) { Class<? extends StepMetaInterface> stepMetaClass = step.getStepMetaInterface().getClass(); if ( BeanInjectionInfo.isInjectionSupported( stepMetaClass ) ) { res.put( step.getName().toUpperCase(), new BeanInjectionInfo( stepMetaClass ) ); } } return res; }
@Test public void testInjectionDescription() throws Exception { BeanInjectionInfo ri = new BeanInjectionInfo( MetaBeanLevel1.class ); assertEquals( 3, ri.getGroups().size() ); assertEquals( "", ri.getGroups().get( 0 ).getName() ); assertEquals( "FILENAME_LINES", ri.getGroups().get( 1 ).getName() ); assertEquals( "FILENAME_LINES2", ri.getGroups().get( 2 ).getName() ); assertTrue( ri.getProperties().containsKey( "SEPARATOR" ) ); assertTrue( ri.getProperties().containsKey( "FILENAME" ) ); assertTrue( ri.getProperties().containsKey( "BASE" ) ); assertTrue( ri.getProperties().containsKey( "FIRST" ) ); assertEquals( "FILENAME_LINES", ri.getProperties().get( "FILENAME" ).getGroupName() ); assertEquals( "!DESCRIPTION!", ri.getDescription( "DESCRIPTION" ) ); }
public boolean hasProperty( Object root, String propName ) { BeanInjectionInfo.Property prop = info.getProperties().get( propName ); return prop != null; }
/** * 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 ); propMap.stepMeta = 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; }
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(), "" ) ); } } } }
StepMetaInterface meta = stepMeta.getStepMetaInterface(); if ( meta.getStepMetaInjectionInterface() != null || BeanInjectionInfo .isInjectionSupported( meta.getClass() ) ) { injectSteps.add( stepMeta ); if ( BeanInjectionInfo.isInjectionSupported( metaInterface.getClass() ) ) { processNewMDIDescription( stepMeta, stepItem, metaInterface ); } else {
protected void addInjectionProperty( Injection metaInj, BeanLevelInfo leaf ) { if ( StringUtils.isBlank( metaInj.name() ) ) { throw new RuntimeException( "Property name shouldn't be blank in the " + clazz ); } String propertyName = calcPropertyName( metaInj, leaf ); if ( properties.containsKey( propertyName ) ) { throw new RuntimeException( "Property '" + propertyName + "' already defined for " + clazz ); } // probably hided if ( hideProperties.contains( propertyName ) ) { return; } Property prop = new Property( propertyName, metaInj.group(), leaf.createCallStack() ); properties.put( prop.name, prop ); Group gr = groupsMap.get( metaInj.group() ); if ( gr == null ) { throw new RuntimeException( "Group '" + metaInj.group() + "' for property '" + metaInj.name() + "' is not defined " + clazz ); } gr.groupProperties.add( prop ); }
info.addInjectionProperty( annotationInjection, leaf ); } else if ( annotationInjectionDeep != null ) { info.addInjectionProperty( annotationInjection, leaf );
public Object getObject( Object root, String propName ) throws Exception { BeanInjectionInfo.Property prop = info.getProperties().get( propName ); if ( prop == null ) { throw new RuntimeException( "Property not found" ); } BeanLevelInfo beanLevelInfo = prop.path.get( 1 ); return beanLevelInfo.field.get( root ); }
private static BeanInjector buildBeanInjectorFor( Class<?> clazz ) { BeanInjectionInfo metaBeanInfo = new BeanInjectionInfo( clazz ); return new BeanInjector( metaBeanInfo ); }
for ( StepMeta stepMeta : data.transMeta.getUsedSteps() ) { StepMetaInterface meta = stepMeta.getStepMetaInterface(); if ( BeanInjectionInfo.isInjectionSupported( meta.getClass() ) ) { data.stepInjectionMetasMap.put( stepMeta.getName(), meta );
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() ); }
/** * Retrieves the raw prop value from root object. * <p> * The similar {@link #getProperty(Object, String)} method (also in this class )should be * revisited and possibly eliminated. That version attempts to retrieve indexed prop * vals from lists/arrays, but doesn't provide a way to retrieve the list or array objects * themselves. */ public Object getPropVal( Object root, String propName ) { Queue<BeanLevelInfo> beanInfos = newLinkedList( Optional.ofNullable( info.getProperties().get( propName ) ) .orElseThrow( () -> new IllegalArgumentException( "Property not found: " + propName ) ) .path ); beanInfos.remove(); // pop off root return getPropVal( root, propName, beanInfos ); }
@Test public void testWrongDeclarations() throws Exception { try { new BeanInjectionInfo( MetaBeanWrong1.class ); fail(); } catch ( Exception ex ) { new BeanInjectionInfo( MetaBeanWrong2.class ); fail(); } catch ( Exception ex ) { new BeanInjectionInfo( MetaBeanWrong3.class ); fail(); } catch ( Exception ex ) { new BeanInjectionInfo( MetaBeanWrong4.class ); fail(); } catch ( Exception ex ) { new BeanInjectionInfo( MetaBeanWrong5.class ); fail(); } catch ( Exception ex ) { new BeanInjectionInfo( MetaBeanWrong6.class ); fail(); } catch ( Exception ex ) { new BeanInjectionInfo( MetaBeanWrong7.class ); fail(); } catch ( Exception ex ) {
stepMetaInterface.getStepMetaInjectionInterface() != null || BeanInjectionInfo.isInjectionSupported( stepMetaInterface.getClass() );
public String getDescription() { return BeanInjectionInfo.this.getDescription( name ); }
@Test public void testGenerics() throws Exception { BeanInjectionInfo ri = new BeanInjectionInfo( MetaBeanChild.class ); assertTrue( ri.getProperties().size() == 7 ); assertTrue( ri.getProperties().containsKey( "BASE_ITEM_NAME" ) ); assertTrue( ri.getProperties().containsKey( "ITEM_CHILD_NAME" ) ); assertTrue( ri.getProperties().containsKey( "A" ) ); assertTrue( ri.getProperties().containsKey( "ITEM.BASE_ITEM_NAME" ) ); assertTrue( ri.getProperties().containsKey( "ITEM.ITEM_CHILD_NAME" ) ); assertTrue( ri.getProperties().containsKey( "SUB.BASE_ITEM_NAME" ) ); assertTrue( ri.getProperties().containsKey( "SUB.ITEM_CHILD_NAME" ) ); assertEquals( String.class, ri.getProperties().get( "A" ).getPropertyClass() ); }