Skip to content

Commit

Permalink
[PDI-13072]: REST doesn't support matrix parameters: Changes to do th…
Browse files Browse the repository at this point in the history
…is implementation workable.

What was done:
1)Added possibility to enter matrix parameters on UI (like for already existing Parameters);
2)Fixed checkstyle violations and typos, a minor change in unit test;
3)Deleted the unnecessary logging line introduced by @vladimirdolzhenko;
  • Loading branch information
TatsianaKasiankova committed Aug 31, 2015
1 parent d5953c6 commit 03f3797
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 36 deletions.
2 changes: 2 additions & 0 deletions build.xml
Expand Up @@ -819,6 +819,8 @@
haltonerror="false"/> haltonerror="false"/>
<test todir="${testreports.xml.dir}" name="org.pentaho.di.trans.steps.gpload.GPLoadTest" <test todir="${testreports.xml.dir}" name="org.pentaho.di.trans.steps.gpload.GPLoadTest"
haltonerror="false"/> haltonerror="false"/>
<test todir="${testreports.xml.dir}" name="org.pentaho.di.trans.steps.rest.RestInputTest"
haltonerror="false"/>
</junit> </junit>
<junitreport todir="${testreports.html.dir}"> <junitreport todir="${testreports.html.dir}">
<fileset dir="${testreports.xml.dir}"> <fileset dir="${testreports.xml.dir}">
Expand Down
40 changes: 20 additions & 20 deletions engine/src/org/pentaho/di/trans/steps/rest/Rest.java
Expand Up @@ -30,7 +30,6 @@
import java.security.KeyStoreException; import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
import java.util.Arrays;


import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
Expand Down Expand Up @@ -93,8 +92,6 @@ private Object[] callRest( Object[] rowData ) throws KettleException {
} }
} }




WebResource webResource = null; WebResource webResource = null;


Client client = null; Client client = null;
Expand Down Expand Up @@ -142,6 +139,10 @@ private Object[] callRest( Object[] rowData ) throws KettleException {
} }
} }


if ( isDebug() ) {
logDebug( BaseMessages.getString( PKG, "Rest.Log.ConnectingToURL", webResource.getURI() ) );
}

WebResource.Builder builder = webResource.getRequestBuilder(); WebResource.Builder builder = webResource.getRequestBuilder();
if ( data.useHeaders ) { if ( data.useHeaders ) {
// Add headers // Add headers
Expand Down Expand Up @@ -319,7 +320,6 @@ public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws


Object[] r = getRow(); // Get row from input rowset & set row busy! Object[] r = getRow(); // Get row from input rowset & set row busy!


logBasic( Arrays.toString( r ) );
if ( r == null ) { if ( r == null ) {
// no more input to be expected... // no more input to be expected...
setOutputDone(); setOutputDone();
Expand Down Expand Up @@ -410,25 +410,25 @@ public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws
} }
data.useParams = true; data.useParams = true;
} }
}


int nrmatrixmatrixparams = meta.getMatrixParameterField() == null ? 0 : meta.getMatrixParameterField().length; int nrmatrixparams = meta.getMatrixParameterField() == null ? 0 : meta.getMatrixParameterField().length;
if ( nrmatrixmatrixparams > 0 ) { if ( nrmatrixparams > 0 ) {
data.nrMatrixParams = nrmatrixmatrixparams; data.nrMatrixParams = nrmatrixparams;
data.matrixParamNames = new String[nrmatrixmatrixparams]; data.matrixParamNames = new String[nrmatrixparams];
data.indexOfMatrixParamFields = new int[nrmatrixmatrixparams]; data.indexOfMatrixParamFields = new int[nrmatrixparams];
for ( int i = 0; i < nrmatrixmatrixparams; i++ ) { for ( int i = 0; i < nrmatrixparams; i++ ) {
data.matrixParamNames[i] = environmentSubstitute( meta.getMatrixParameterName()[i] ); data.matrixParamNames[i] = environmentSubstitute( meta.getMatrixParameterName()[i] );
String field = environmentSubstitute( meta.getMatrixParameterField()[i] ); String field = environmentSubstitute( meta.getMatrixParameterField()[i] );
if ( Const.isEmpty( field ) ) { if ( Const.isEmpty( field ) ) {
throw new KettleException( BaseMessages.getString( PKG, "Rest.Exception.MatrixParamFieldEmpty" ) ); throw new KettleException( BaseMessages.getString( PKG, "Rest.Exception.MatrixParamFieldEmpty" ) );
} }
data.indexOfMatrixParamFields[i] = data.inputRowMeta.indexOfValue( field ); data.indexOfMatrixParamFields[i] = data.inputRowMeta.indexOfValue( field );
if ( data.indexOfMatrixParamFields[i] < 0 ) { if ( data.indexOfMatrixParamFields[i] < 0 ) {
throw new KettleException( BaseMessages.getString( PKG, "Rest.Exception.ErrorFindingField", field ) ); throw new KettleException( BaseMessages.getString( PKG, "Rest.Exception.ErrorFindingField", field ) );
}
} }
data.useMatrixParams = true;
} }
data.useMatrixParams = true;
} }


// Do we need to set body // Do we need to set body
Expand Down
Expand Up @@ -44,6 +44,7 @@ RestMeta.CheckResult.UrlOk=URL is specified.
RestMeta.CheckResult.MissingArguments=Missing arguments, not found in input from previous steps\: RestMeta.CheckResult.MissingArguments=Missing arguments, not found in input from previous steps\:
RestDialog.Shell.Title=REST Client RestDialog.Shell.Title=REST Client
RestDialog.Parameters.Title=Parameters RestDialog.Parameters.Title=Parameters
RestDialog.MatrixParameters.Title=Matrix Parameters
RestDialog.ColumnInfo.Value=Value RestDialog.ColumnInfo.Value=Value
RestDialog.SSL.Title=SSL RestDialog.SSL.Title=SSL
Rest.Error.FileNotFound=We can not find file [{0}] Rest.Error.FileNotFound=We can not find file [{0}]
Expand Down Expand Up @@ -101,7 +102,7 @@ RestDialog.FailedToGetFields.DialogMessage=Error getting fields from incoming st
Rest.Exception.HeaderFieldEmpty=Header field is missing\! Rest.Exception.HeaderFieldEmpty=Header field is missing\!
Rest.Log.BodyValue= Adding HTTP body value [{0}] Rest.Log.BodyValue= Adding HTTP body value [{0}]
Rest.Log.queryParameterValue=Query parameter [{0}]\=''{1}'' Rest.Log.queryParameterValue=Query parameter [{0}]\=''{1}''
Rest.Log.matrixParameterValue=Matrix arameter [{0}]\=''{1}'' Rest.Log.matrixParameterValue=Matrix parameter [{0}]\=''{1}''
Rest.Exception.CouldnotFindField=Couldn''t find field ''{0}'' in row\! Rest.Exception.CouldnotFindField=Couldn''t find field ''{0}'' in row\!
Rest.Log.HeaderValue=Header parameter [{0}]\=''{1}'' Rest.Log.HeaderValue=Header parameter [{0}]\=''{1}''
Rest.Log.DBException=An error occurred, processing will be stopped\: Rest.Log.DBException=An error occurred, processing will be stopped\:
Expand Down
5 changes: 4 additions & 1 deletion test/org/pentaho/di/trans/steps/rest/RestInputTest.java
Expand Up @@ -75,7 +75,9 @@ public static void setUp() throws Exception {


@AfterClass @AfterClass
public static void tearDown() throws Exception { public static void tearDown() throws Exception {
tester.stop(); if ( tester != null ) {
tester.stop();
}
} }


protected Trans createAndTestTrans( PluginRegistry registry, TransMeta transMeta, StepMeta inputStep, protected Trans createAndTestTrans( PluginRegistry registry, TransMeta transMeta, StepMeta inputStep,
Expand Down Expand Up @@ -122,6 +124,7 @@ public StepMeta createRestInputStep( TransMeta transMeta, PluginRegistry registr


meta.setDefault(); meta.setDefault();
meta.setUrl( tester.createSocketConnector( true ) + "/context/simple/join" ); meta.setUrl( tester.createSocketConnector( true ) + "/context/simple/join" );
meta.setMethod( "POST" );
meta.setMatrixParameterField( new String[] { "pageSize" } ); meta.setMatrixParameterField( new String[] { "pageSize" } );
meta.setMatrixParameterName( new String[] { "limit" } ); meta.setMatrixParameterName( new String[] { "limit" } );


Expand Down
4 changes: 2 additions & 2 deletions test/org/pentaho/di/trans/steps/rest/SimpleRestService.java
@@ -1,6 +1,6 @@
package org.pentaho.di.trans.steps.rest; package org.pentaho.di.trans.steps.rest;


import javax.ws.rs.GET; import javax.ws.rs.POST;
import javax.ws.rs.MatrixParam; import javax.ws.rs.MatrixParam;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
Expand All @@ -14,7 +14,7 @@
*/ */
@Path( "/simple" ) @Path( "/simple" )
public class SimpleRestService { public class SimpleRestService {
@GET @POST
@Path( "/join" ) @Path( "/join" )
@Produces( MediaType.TEXT_PLAIN ) @Produces( MediaType.TEXT_PLAIN )
public String join( @MatrixParam( "limit" ) String limit, @QueryParam( "name" ) String name ) { public String join( @MatrixParam( "limit" ) String limit, @QueryParam( "name" ) String name ) {
Expand Down
116 changes: 104 additions & 12 deletions ui/src/org/pentaho/di/ui/trans/steps/rest/RestDialog.java
Expand Up @@ -147,24 +147,24 @@ public class RestDialog extends BaseStepDialog implements StepDialogInterface {


private CTabFolder wTabFolder; private CTabFolder wTabFolder;


private CTabItem wGeneralTab, wAdditionalTab, wParametersTab, wAuthTab, wSSLTab; private CTabItem wGeneralTab, wAdditionalTab, wParametersTab, wMatrixParametersTab, wAuthTab, wSSLTab;
private FormData fdTabFolder; private FormData fdTabFolder;


private Composite wGeneralComp, wAdditionalComp; private Composite wGeneralComp, wAdditionalComp;
private FormData fdGeneralComp, fdAdditionalComp; private FormData fdGeneralComp, fdAdditionalComp;


private Composite wParametersComp; private Composite wParametersComp, wMatrixParametersComp;
private FormData fdParametersComp; private FormData fdParametersComp, fdMatrixParametersComp;


private Composite wAuthComp; private Composite wAuthComp;
private FormData fdAuthComp; private FormData fdAuthComp;


private Composite wSSLComp; private Composite wSSLComp;
private FormData fdSSLComp; private FormData fdSSLComp;


private Label wlParameters; private Label wlParameters, wlMatrixParameters;
private TableView wParameters; private TableView wParameters, wMatrixParameters;
private FormData fdlParameters, fdParameters; private FormData fdlParameters, fdlMatrixParameters, fdParameters, fdMatrixParameters;


private Label wlResponseTime; private Label wlResponseTime;
private TextVar wResponseTime; private TextVar wResponseTime;
Expand All @@ -182,6 +182,9 @@ public class RestDialog extends BaseStepDialog implements StepDialogInterface {


private boolean gotPreviousFields = false; private boolean gotPreviousFields = false;


private Button wMatrixGet;
private Listener lsMatrixGet;

public RestDialog( Shell parent, Object in, TransMeta transMeta, String sname ) { public RestDialog( Shell parent, Object in, TransMeta transMeta, String sname ) {
super( parent, (BaseStepMeta) in, transMeta, sname ); super( parent, (BaseStepMeta) in, transMeta, sname );
input = (RestMeta) in; input = (RestMeta) in;
Expand Down Expand Up @@ -901,7 +904,7 @@ public void widgetSelected( SelectionEvent e ) {
wAdditionalTab.setControl( wAdditionalComp ); wAdditionalTab.setControl( wAdditionalComp );
// ////// END of Additional Tab // ////// END of Additional Tab


// Parameters tab... // Query Parameters tab...
// //
wParametersTab = new CTabItem( wTabFolder, SWT.NONE ); wParametersTab = new CTabItem( wTabFolder, SWT.NONE );
wParametersTab.setText( BaseMessages.getString( PKG, "RestDialog.Parameters.Title" ) ); wParametersTab.setText( BaseMessages.getString( PKG, "RestDialog.Parameters.Title" ) );
Expand Down Expand Up @@ -961,7 +964,68 @@ public void widgetSelected( SelectionEvent e ) {


wParametersComp.layout(); wParametersComp.layout();
wParametersTab.setControl( wParametersComp ); wParametersTab.setControl( wParametersComp );
// ////// END of Parameters Tab // ////// END of Query Parameters Tab

// Matrix Parameters tab
wMatrixParametersTab = new CTabItem( wTabFolder, SWT.NONE );
wMatrixParametersTab.setText( BaseMessages.getString( PKG, "RestDialog.MatrixParameters.Title" ) );

FormLayout pl = new FormLayout();
pl.marginWidth = Const.FORM_MARGIN;
pl.marginHeight = Const.FORM_MARGIN;

wMatrixParametersComp = new Composite( wTabFolder, SWT.NONE );
wMatrixParametersComp.setLayout( pl );
props.setLook( wMatrixParametersComp );

wlMatrixParameters = new Label( wMatrixParametersComp, SWT.NONE );
wlMatrixParameters.setText( BaseMessages.getString( PKG, "RestDialog.Parameters.Label" ) );
props.setLook( wlMatrixParameters );
fdlMatrixParameters = new FormData();
fdlMatrixParameters.left = new FormAttachment( 0, 0 );
fdlMatrixParameters.top = new FormAttachment( wStepname, margin );
wlMatrixParameters.setLayoutData( fdlMatrixParameters );

wMatrixGet = new Button( wMatrixParametersComp, SWT.PUSH );
wMatrixGet.setText( BaseMessages.getString( PKG, "RestDialog.GetParameters.Button" ) );
FormData fdMatrixGet = new FormData();
fdMatrixGet.top = new FormAttachment( wlMatrixParameters, margin );
fdMatrixGet.right = new FormAttachment( 100, 0 );
wMatrixGet.setLayoutData( fdMatrixGet );

int matrixParametersRows = input.getMatrixParameterField().length;

colinfoparams =
new ColumnInfo[] {
new ColumnInfo(
BaseMessages.getString( PKG, "RestDialog.ColumnInfo.ParameterField" ),
ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false ),
new ColumnInfo(
BaseMessages.getString( PKG, "RestDialog.ColumnInfo.ParameterName" ), ColumnInfo.COLUMN_TYPE_TEXT,
false ), };

wMatrixParameters =
new TableView(
transMeta, wMatrixParametersComp, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, colinfoparams,
matrixParametersRows, lsMod, props );

fdMatrixParameters = new FormData();
fdMatrixParameters.left = new FormAttachment( 0, 0 );
fdMatrixParameters.top = new FormAttachment( wlMatrixParameters, margin );
fdMatrixParameters.right = new FormAttachment( wMatrixGet, -margin );
fdMatrixParameters.bottom = new FormAttachment( 100, -margin );
wMatrixParameters.setLayoutData( fdMatrixParameters );

fdMatrixParametersComp = new FormData();
fdMatrixParametersComp.left = new FormAttachment( 0, 0 );
fdMatrixParametersComp.top = new FormAttachment( wStepname, margin );
fdMatrixParametersComp.right = new FormAttachment( 100, 0 );
fdMatrixParametersComp.bottom = new FormAttachment( 100, 0 );
wMatrixParametersComp.setLayoutData( fdMatrixParametersComp );

wMatrixParametersComp.layout();
wMatrixParametersTab.setControl( wMatrixParametersComp );
//END of Matrix Parameters Tab


fdTabFolder = new FormData(); fdTabFolder = new FormData();
fdTabFolder.left = new FormAttachment( 0, 0 ); fdTabFolder.left = new FormAttachment( 0, 0 );
Expand Down Expand Up @@ -1016,7 +1080,12 @@ public void handleEvent( Event e ) {
}; };
lsGet = new Listener() { lsGet = new Listener() {
public void handleEvent( Event e ) { public void handleEvent( Event e ) {
getParametersFields(); getParametersFields( wParameters );
}
};
lsMatrixGet = new Listener() {
public void handleEvent( Event e ) {
getParametersFields( wMatrixParameters );
} }
}; };
Listener lsGetHeaders = new Listener() { Listener lsGetHeaders = new Listener() {
Expand All @@ -1027,6 +1096,7 @@ public void handleEvent( Event e ) {


wOK.addListener( SWT.Selection, lsOK ); wOK.addListener( SWT.Selection, lsOK );
wGet.addListener( SWT.Selection, lsGet ); wGet.addListener( SWT.Selection, lsGet );
wMatrixGet.addListener( SWT.Selection, lsMatrixGet );
wGetHeaders.addListener( SWT.Selection, lsGetHeaders ); wGetHeaders.addListener( SWT.Selection, lsGetHeaders );
wCancel.addListener( SWT.Selection, lsCancel ); wCancel.addListener( SWT.Selection, lsCancel );


Expand Down Expand Up @@ -1086,6 +1156,9 @@ private void setMethod() {
wlParameters.setEnabled( activateParams ); wlParameters.setEnabled( activateParams );
wParameters.setEnabled( activateParams ); wParameters.setEnabled( activateParams );
wGet.setEnabled( activateParams ); wGet.setEnabled( activateParams );
wlMatrixParameters.setEnabled( activateParams );
wMatrixParameters.setEnabled( activateParams );
wMatrixGet.setEnabled( activateParams );
} }


protected void setComboBoxes() { protected void setComboBoxes() {
Expand Down Expand Up @@ -1176,6 +1249,18 @@ public void getData() {
} }
} }


if ( input.getMatrixParameterField() != null ) {
for ( int i = 0; i < input.getMatrixParameterField().length; i++ ) {
TableItem item = wMatrixParameters.table.getItem( i );
if ( input.getMatrixParameterField()[i] != null ) {
item.setText( 1, input.getMatrixParameterField()[i] );
}
if ( input.getMatrixParameterField()[i] != null ) {
item.setText( 2, input.getMatrixParameterField()[i] );
}
}
}

wMethod.setText( Const.NVL( input.getMethod(), RestMeta.HTTP_METHOD_GET ) ); wMethod.setText( Const.NVL( input.getMethod(), RestMeta.HTTP_METHOD_GET ) );
wMethodInField.setSelection( input.isDynamicMethod() ); wMethodInField.setSelection( input.isDynamicMethod() );
if ( input.getBodyField() != null ) { if ( input.getBodyField() != null ) {
Expand Down Expand Up @@ -1244,7 +1329,7 @@ private void ok() {


int nrheaders = wFields.nrNonEmpty(); int nrheaders = wFields.nrNonEmpty();
int nrparams = wParameters.nrNonEmpty(); int nrparams = wParameters.nrNonEmpty();
int nrmatrixparams = 0; // TODO: it has to be added extra matrix parameters panel int nrmatrixparams = wMatrixParameters.nrNonEmpty();
input.allocate( nrheaders, nrparams, nrmatrixparams ); input.allocate( nrheaders, nrparams, nrmatrixparams );


if ( isDebug() ) { if ( isDebug() ) {
Expand All @@ -1263,6 +1348,13 @@ private void ok() {
input.getParameterName()[i] = item.getText( 2 ); input.getParameterName()[i] = item.getText( 2 );
} }


//CHECKSTYLE:Indentation:OFF
for ( int i = 0; i < nrmatrixparams; i++ ) {
TableItem item = wMatrixParameters.getNonEmpty( i );
input.getMatrixParameterField()[i] = item.getText( 1 );
input.getMatrixParameterName()[i] = item.getText( 2 );
}

input.setDynamicMethod( wMethodInField.getSelection() ); input.setDynamicMethod( wMethodInField.getSelection() );
input.setMethodFieldName( wMethodField.getText() ); input.setMethodFieldName( wMethodField.getText() );
input.setMethod( wMethod.getText() ); input.setMethod( wMethod.getText() );
Expand All @@ -1288,12 +1380,12 @@ private void ok() {
dispose(); dispose();
} }


private void getParametersFields() { private void getParametersFields( TableView tView ) {
try { try {
RowMetaInterface r = transMeta.getPrevStepFields( stepname ); RowMetaInterface r = transMeta.getPrevStepFields( stepname );
if ( r != null && !r.isEmpty() ) { if ( r != null && !r.isEmpty() ) {
BaseStepDialog BaseStepDialog
.getFieldsFromPrevious( r, wParameters, 1, new int[] { 1, 2 }, new int[] { 3 }, -1, -1, null ); .getFieldsFromPrevious( r, tView, 1, new int[] { 1, 2 }, new int[] { 3 }, -1, -1, null );
} }
} catch ( KettleException ke ) { } catch ( KettleException ke ) {
new ErrorDialog( new ErrorDialog(
Expand Down

0 comments on commit 03f3797

Please sign in to comment.