Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BACKLOG-42858]: Sequence dialog doAction changes #9778

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*
Expand Down Expand Up @@ -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<String, String> 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<String, String> 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;
}

}