From 39071e5eed96947f0e369fbe4dc29b7c9d15c62d Mon Sep 17 00:00:00 2001 From: SindhujaAddagudi Date: Thu, 26 Dec 2024 19:43:16 +0530 Subject: [PATCH] [BACKLOG-42858]: Sequence dialog doAction changes --- .../trans/steps/addsequence/AddSequence.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/plugins/core/impl/src/main/java/org/pentaho/di/trans/steps/addsequence/AddSequence.java b/plugins/core/impl/src/main/java/org/pentaho/di/trans/steps/addsequence/AddSequence.java index 850b705fbadc..11246d15ed06 100644 --- a/plugins/core/impl/src/main/java/org/pentaho/di/trans/steps/addsequence/AddSequence.java +++ b/plugins/core/impl/src/main/java/org/pentaho/di/trans/steps/addsequence/AddSequence.java @@ -13,11 +13,18 @@ package org.pentaho.di.trans.steps.addsequence; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.pentaho.di.core.Const; import org.pentaho.di.core.Counter; import org.pentaho.di.core.database.Database; +import org.pentaho.di.core.database.DatabaseMeta; import org.pentaho.di.core.exception.KettleDatabaseException; import org.pentaho.di.core.exception.KettleException; import org.pentaho.di.core.exception.KettleStepException; +import org.pentaho.di.core.logging.LoggingObjectInterface; +import org.pentaho.di.core.logging.LoggingObjectType; +import org.pentaho.di.core.logging.SimpleLoggingObject; import org.pentaho.di.core.row.RowDataUtil; import org.pentaho.di.core.row.RowMetaInterface; import org.pentaho.di.core.util.Utils; @@ -30,6 +37,10 @@ import org.pentaho.di.trans.step.StepMeta; import org.pentaho.di.trans.step.StepMetaInterface; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Map; + /** * Adds a sequential number to a stream of rows. * @@ -252,4 +263,48 @@ public void dispose( StepMetaInterface smi, StepDataInterface sdi ) { super.dispose( smi, sdi ); } + @Override + public JSONObject doAction( String fieldName, StepMetaInterface stepMetaInterface, TransMeta transMeta, + Trans trans, Map queryParamToValues ) { + JSONObject response = new JSONObject(); + try { + Method actionMethod = AddSequence.class.getDeclaredMethod( fieldName + "Action", Map.class ); + this.setStepMetaInterface( stepMetaInterface ); + response = (JSONObject) actionMethod.invoke( this, queryParamToValues ); + + } catch ( NoSuchMethodException | InvocationTargetException | IllegalAccessException e ) { + log.logError( e.getMessage() ); + response.put( StepInterface.ACTION_STATUS, StepInterface.FAILURE_METHOD_NOT_RESPONSE ); + } + return response; + } + + @SuppressWarnings( "java:S1144" ) // Using reflection this method is being invoked + private JSONObject getSequenceAction( Map queryParams ) { + JSONObject response = new JSONObject(); + response.put( StepInterface.ACTION_STATUS, StepInterface.FAILURE_RESPONSE ); + DatabaseMeta databaseMeta = getTransMeta().findDatabase( queryParams.get( "connection" ) ); + if ( databaseMeta != null ) { + LoggingObjectInterface loggingObject = new SimpleLoggingObject( + "Add Sequence Step", LoggingObjectType.STEP, null ); + Database database = new Database( loggingObject, databaseMeta ); + try { + database.connect(); + String[] sequences = database.getSequences(); + if ( null != sequences && sequences.length > 0 ) { + sequences = Const.sortStrings( sequences ); + JSONArray sequenceNames = new JSONArray(); + for ( String schema : sequences ) { + sequenceNames.add( schema ); + } + response.put( "sequences", sequenceNames ); + response.put( StepInterface.ACTION_STATUS, StepInterface.SUCCESS_RESPONSE ); + } + } catch ( KettleDatabaseException e ) { + log.logError( e.getMessage() ); + } + } + return response; + } + }