private void getInfo( ScriptMeta meta ) { int nrfields = wFields.nrNonEmpty(); meta.allocate( nrfields ); meta.getFieldname()[i] = item.getText( 1 ); meta.getRename()[i] = item.getText( 2 ); if ( meta.getRename()[i] == null || meta.getRename()[i].length() == 0 || meta.getRename()[i].equalsIgnoreCase( meta.getFieldname()[i] ) ) { meta.getRename()[i] = meta.getFieldname()[i]; meta.getType()[i] = ValueMetaFactory.getIdForValueMeta( item.getText( 3 ) ); String slen = item.getText( 4 ); String sprc = item.getText( 5 ); meta.getLength()[i] = Const.toInt( slen, -1 ); meta.getPrecision()[i] = Const.toInt( sprc, -1 ); meta.getReplace()[i] = YES_NO_COMBO[1].equalsIgnoreCase( item.getText( 6 ) ); meta.setJSScripts( jsScripts );
for ( int i = 0; i < input.getFieldname().length; i++ ) { if ( input.getFieldname()[i] != null && input.getFieldname()[i].length() > 0 ) { TableItem item = wFields.table.getItem( i ); item.setText( 1, input.getFieldname()[i] ); if ( input.getRename()[i] != null && !input.getFieldname()[i].equals( input.getRename()[i] ) ) { item.setText( 2, input.getRename()[i] ); item.setText( 3, ValueMetaFactory.getValueMetaName( input.getType()[i] ) ); if ( input.getLength()[i] >= 0 ) { item.setText( 4, "" + input.getLength()[i] ); if ( input.getPrecision()[i] >= 0 ) { item.setText( 5, "" + input.getPrecision()[i] ); item.setText( 6, input.getReplace()[i] ? YES_NO_COMBO[1] : YES_NO_COMBO[0] ); org.pentaho.di.trans.steps.script.ScriptValuesScript[] jsScripts = input.getJSScripts(); if ( jsScripts.length > 0 ) { for ( int i = 0; i < jsScripts.length; i++ ) {
private void buildAddClassesListTree() { if ( wTreeClassesitem != null ) { wTreeClassesitem.dispose(); } if ( input.getAddClasses() != null ) { for ( int i = 0; i < input.getAddClasses().length; i++ ) { // System.out.println(input.getAddClasses().length); try { Method[] methods = input.getAddClasses()[i].getAddClass().getMethods(); String strClassType = input.getAddClasses()[i].getAddClass().toString(); String strParams; wTreeClassesitem = new TreeItem( wTree, SWT.NULL ); wTreeClassesitem.setText( input.getAddClasses()[i].getJSName() ); for ( int j = 0; j < methods.length; j++ ) { String strDeclaringClass = methods[j].getDeclaringClass().toString(); if ( strClassType.equals( strDeclaringClass ) ) { TreeItem item2 = new TreeItem( wTreeClassesitem, SWT.NULL ); strParams = buildAddClassFunctionName( methods[j] ); item2.setText( methods[j].getName() + "(" + strParams + ")" ); String strData = input.getAddClasses()[i].getJSName() + "." + methods[j].getName() + "(" + strParams + ")"; item2.setData( strData ); } } } catch ( Exception e ) { // Ignore errors } } } }
public Object getValueFromJScript( Object result, int i ) throws KettleValueException { String fieldName = meta.getFieldname()[ i ]; if ( !Utils.isEmpty( fieldName ) ) { // res.setName(meta.getRename()[i]); // res.setType(meta.getType()[i]); try { return ( result == null ) ? null : JavaScriptUtils.convertFromJs( result, meta.getType()[ i ], fieldName ); } catch ( Exception e ) { throw new KettleValueException( BaseMessages.getString( PKG, "Script.Log.JavascriptError" ), e ); } } else { throw new KettleValueException( "No name was specified for result value #" + ( i + 1 ) ); } }
meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore ); data.replaceIndex = new int[ meta.getFieldname().length ]; for ( int i = 0; i < meta.getFieldname().length; i++ ) { if ( meta.getReplace()[ i ] ) { data.replaceIndex[ i ] = rowMeta.indexOfValue( meta.getFieldname()[ i ] ); if ( data.replaceIndex[ i ] < 0 ) { if ( Utils.isEmpty( meta.getFieldname()[ i ] ) ) { throw new KettleStepException( BaseMessages.getString( PKG, "ScriptValuesMetaMod.Exception.FieldToReplaceNotFound", meta.getFieldname()[ i ] ) ); data.replaceIndex[ i ] = rowMeta.indexOfValue( meta.getRename()[ i ] ); if ( data.replaceIndex[ i ] < 0 ) { throw new KettleStepException( BaseMessages.getString( PKG, "ScriptValuesMetaMod.Exception.FieldToReplaceNotFound", meta.getRename()[ i ] ) ); data.cx = ScriptMeta.createNewScriptEngine( getStepname() ); data.scope = data.cx.getBindings( ScriptContext.ENGINE_SCOPE ); for ( int i = 0; i < meta.getNumberOfJSScripts(); i++ ) { data.scope.put( jsScripts[ i ].getScriptName(), jsScripts[ i ].getScript() ); if ( meta.getAddClasses() != null ) { for ( int i = 0; i < meta.getAddClasses().length; i++ ) { data.scope.put( meta.getAddClasses()[ i ].getJSName(), meta.getAddClasses()[ i ].getAddObject() ); for ( int i = 0; i < meta.getFieldname().length; i++ ) { Object result = data.scope.get( meta.getFieldname()[ i ] );
public void modify( StepMetaInterface someMeta ) { if ( someMeta instanceof ScriptMeta ) { ( (ScriptMeta) someMeta ).allocate( 5 ); } }
CompiledScript jsscript; jscx = createNewScriptEngine( stepMeta.getName() ); jsscope = jscx.getBindings( ScriptContext.ENGINE_SCOPE ); for ( int i = 0; i < getNumberOfJSScripts(); i++ ) { jsscope.put( jsScripts[i].getScriptName(), jsScripts[i].getScript() ); if ( getAddClasses() != null ) { for ( int i = 0; i < getAddClasses().length; i++ ) { jsscope.put( getAddClasses()[i].getJSName(), getAddClasses()[i].getAddObject() );
changed = input.hasChanged(); wlFields.setLayoutData( fdlFields ); final int FieldsRows = input.getFieldname().length; input.setChanged( changed );
@Before public void setUp() throws Exception { helper = new StepMockHelper<>( "test-script", ScriptMeta.class, ScriptData.class ); when( helper.logChannelInterfaceFactory.create( any(), any( LoggingObjectInterface.class ) ) ).thenReturn( helper.logChannelInterface ); when( helper.trans.isRunning() ).thenReturn( true ); when( helper.initStepMetaInterface.getJSScripts() ).thenReturn( new ScriptValuesScript[] { new ScriptValuesScript( ScriptValuesScript.NORMAL_SCRIPT, "", "var i = 0;" ) } ); }
public void parseXmlForAdditionalClasses() throws KettleException { try { Properties sysprops = System.getProperties(); String strActPath = sysprops.getProperty( "user.dir" ); Document dom = XMLHandler.loadXMLFile( strActPath + "/plugins/steps/ScriptValues_mod/plugin.xml" ); Node stepnode = dom.getDocumentElement(); Node libraries = XMLHandler.getSubNode( stepnode, "js_libraries" ); int nbOfLibs = XMLHandler.countNodes( libraries, "js_lib" ); additionalClasses = new ScriptAddClasses[nbOfLibs]; for ( int i = 0; i < nbOfLibs; i++ ) { Node fnode = XMLHandler.getSubNodeByNr( libraries, "js_lib", i ); String strJarName = XMLHandler.getTagAttribute( fnode, "name" ); String strClassName = XMLHandler.getTagAttribute( fnode, "classname" ); String strJSName = XMLHandler.getTagAttribute( fnode, "js_name" ); Class<?> addClass = LoadAdditionalClass( strActPath + "/plugins/steps/ScriptValues_mod/" + strJarName, strClassName ); Object addObject = addClass.newInstance(); additionalClasses[i] = new ScriptAddClasses( addClass, addObject, strJSName ); } } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "ScriptMeta.Exception.UnableToParseXMLforAdditionalClasses" ), e ); } }
ScriptMeta scriptMeta = new ScriptMeta(); getInfo( scriptMeta ); StepMeta scriptStep =
public Object clone() { ScriptMeta retval = (ScriptMeta) super.clone(); int nrfields = fieldname.length; retval.allocate( nrfields ); System.arraycopy( fieldname, 0, retval.fieldname, 0, nrfields ); System.arraycopy( rename, 0, retval.rename, 0, nrfields ); System.arraycopy( type, 0, retval.type, 0, nrfields ); System.arraycopy( length, 0, retval.length, 0, nrfields ); System.arraycopy( precision, 0, retval.precision, 0, nrfields ); System.arraycopy( replace, 0, retval.replace, 0, nrfields ); return retval; }
public boolean init( StepMetaInterface smi, StepDataInterface sdi ) { meta = (ScriptMeta) smi; data = (ScriptData) sdi; if ( super.init( smi, sdi ) ) { // Add init code here. // Get the actual Scripts from our MetaData jsScripts = meta.getJSScripts(); for ( int j = 0; j < jsScripts.length; j++ ) { switch ( jsScripts[ j ].getScriptType() ) { case ScriptValuesScript.TRANSFORM_SCRIPT: strTransformScript = jsScripts[ j ].getScript(); break; case ScriptValuesScript.START_SCRIPT: strStartScript = jsScripts[ j ].getScript(); break; case ScriptValuesScript.END_SCRIPT: strEndScript = jsScripts[ j ].getScript(); break; default: break; } } return true; } return false; }
public void setDefault() { jsScripts = new ScriptValuesScript[1]; jsScripts[0] = new ScriptValuesScript( ScriptValuesScript.TRANSFORM_SCRIPT, BaseMessages .getString( PKG, "Script.Script1" ), "//" + BaseMessages.getString( PKG, "Script.ScriptHere" ) + Const.CR + Const.CR ); int nrfields = 0; allocate( nrfields ); for ( int i = 0; i < nrfields; i++ ) { fieldname[i] = "newvalue"; rename[i] = "newvalue"; type[i] = ValueMetaInterface.TYPE_NUMBER; length[i] = -1; precision[i] = -1; replace[i] = false; } }
if ( input.getAddClasses() != null ) { for ( int i = 0; i < input.getAddClasses().length; i++ ) { Object jsOut = Context.javaToJS( input.getAddClasses()[i].getAddObject(), jsscope ); ScriptableObject.putProperty( jsscope, input.getAddClasses()[i].getJSName(), jsOut );
int nrfields = XMLHandler.countNodes( fields, "field" ); allocate( nrfields );
allocate( nrfields );