Skip to content

Commit

Permalink
[BACKLOG-25665] Improve error handling in Field Selection dialog of J…
Browse files Browse the repository at this point in the history
…SON Input Step (#5800)
  • Loading branch information
ddiroma authored and Ben Morrise committed Sep 24, 2018
1 parent 2866b5a commit ef2d060
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 46 deletions.
Expand Up @@ -22,6 +22,7 @@


package org.pentaho.getfields.endpoint; package org.pentaho.getfields.endpoint;


import org.pentaho.di.core.exception.KettleFileException;
import org.pentaho.getfields.types.json.JsonSampler; import org.pentaho.getfields.types.json.JsonSampler;
import org.pentaho.getfields.types.json.node.Node; import org.pentaho.getfields.types.json.node.Node;


Expand Down Expand Up @@ -57,8 +58,10 @@ private Response loadJson( String path ) {
Node node = null; Node node = null;
try { try {
node = jsonSampler.sample( path ); node = jsonSampler.sample( path );
} catch ( IOException e ) { } catch ( KettleFileException e ) { // Cannot find file OR no permissions
return Response.status( Response.Status.NOT_FOUND ).build(); return Response.status( Response.Status.NOT_FOUND ).build();
} catch ( IOException e ) { // Invalid JSON structure
return Response.status( Response.Status.NOT_ACCEPTABLE ).build();
} }


return Response.ok( node ).build(); return Response.ok( node ).build();
Expand Down
Expand Up @@ -22,6 +22,9 @@
import org.pentaho.di.ui.core.GetFieldsDialogOperation; import org.pentaho.di.ui.core.GetFieldsDialogOperation;
import org.pentaho.getfields.dialog.GetFieldsDialog; import org.pentaho.getfields.dialog.GetFieldsDialog;


import java.util.HashMap;
import java.util.Map;

/** /**
* Created by ddiroma on 08/13/18. * Created by ddiroma on 08/13/18.
*/ */
Expand All @@ -33,14 +36,23 @@
) )
public class GetFieldsExtensionPoint implements ExtensionPointInterface { public class GetFieldsExtensionPoint implements ExtensionPointInterface {


private static final Map<String, String> INPUT_TYPES;

static {
// The input types are the step id's of individual steps that map to the string used in the get fields dialog
// Add more input types as they are added to use get fields extension point
INPUT_TYPES = new HashMap<>();
INPUT_TYPES.put( "JSON Input", "JSON" );
}

@Override public void callExtensionPoint( LogChannelInterface logChannelInterface, Object o ) throws KettleException { @Override public void callExtensionPoint( LogChannelInterface logChannelInterface, Object o ) throws KettleException {
GetFieldsDialogOperation getFieldsDialogOperation = (GetFieldsDialogOperation) o; GetFieldsDialogOperation getFieldsDialogOperation = (GetFieldsDialogOperation) o;
GetFieldsDialog getFieldsDialog = new GetFieldsDialog( getFieldsDialogOperation.getShell(), GetFieldsDialog getFieldsDialog = new GetFieldsDialog( getFieldsDialogOperation.getShell(),
getFieldsDialogOperation.getWidth(), getFieldsDialogOperation.getHeight(), getFieldsDialogOperation getFieldsDialogOperation.getWidth(), getFieldsDialogOperation.getHeight(), getFieldsDialogOperation
.getFilename() ); .getFilename() );
String name = getFieldsDialogOperation.getStepMeta().getName(); String title = getFieldsDialogOperation.getTitle(); // this is for the dialog title AND the key for input type
getFieldsDialog.setTitle( name ); getFieldsDialog.setTitle( title );
getFieldsDialog.setType( name ); getFieldsDialog.setType( INPUT_TYPES.get( title ) );
getFieldsDialog.open(); getFieldsDialog.open();
getFieldsDialogOperation.setPaths( getFieldsDialog.getPaths() ); getFieldsDialogOperation.setPaths( getFieldsDialog.getPaths() );
} }
Expand Down
Expand Up @@ -107,11 +107,11 @@ public Node sample( InputStream inputStream ) throws IOException {
* @return The sampled Node * @return The sampled Node
* @throws IOException * @throws IOException
*/ */
public Node sample( String file ) throws IOException { public Node sample( String file ) throws IOException, KettleFileException {
try { try {
return sample( KettleVFS.getInputStream( file ) ); return sample( KettleVFS.getInputStream( file ) );
} catch ( KettleFileException kfe ) { } catch ( KettleFileException kfe ) {
return null; throw kfe;
} }
} }


Expand Down
34 changes: 22 additions & 12 deletions plugins/get-fields/core/src/main/javascript/app/app.component.js
Expand Up @@ -72,18 +72,28 @@ define([
function onInit() { function onInit() {
var path = $location.search().path; var path = $location.search().path;
vm.type = $location.search().type; vm.type = $location.search().type;
$timeout(function() { if (path === "") { // No file path specified in step
if (vm.showMessage) { _showMessage(i18n.get("get-fields-plugin.app.unable-to-view.label", {dataType: vm.type}),
vm.showMessageText = true; i18n.get("get-fields.plugin.app.unable-to-view.message", {dataType: vm.type}));
} } else {
}, 1000); $timeout(function() {
dt.sample(path).then(function(response) { if (vm.showMessage) {
vm.tree = response.data; vm.showMessageText = true;
vm.showMessage = false; }
}, function() { }, 1000);
_showMessage(i18n.get("get-fields-plugin.app.unable-to-access.label", {dataType: vm.type}), dt.sample(path).then(function(response) {
i18n.get("get-fields.plugin.app.unable-to-access.message")); vm.tree = response.data;
}); vm.showMessage = false;
}, function(response) {
if (response.status === 404) { // Cannot find file OR no permissions
_showMessage(i18n.get("get-fields-plugin.app.unable-to-access.label", {dataType: vm.type}),
i18n.get("get-fields.plugin.app.unable-to-access.message"));
} else { // Invalid JSON structure OR other issue
_showMessage(i18n.get("get-fields-plugin.app.unable-to-view.label", {dataType: vm.type}),
i18n.get("get-fields.plugin.app.unable-to-view.message", {dataType: vm.type}));
}
});
}
} }


function doSearch(value) { function doSearch(value) {
Expand Down
Expand Up @@ -50,7 +50,11 @@ message .message .title {
font-family: OpenSansLight; font-family: OpenSansLight;
} }


message .message .title.messageNoSpinner {
margin-bottom: 24px;
}

message .message .messageTxt { message .message .messageTxt {
line-height: 28px; line-height: 24px;
font-size: 14px; font-size: 14px;
} }
@@ -1,7 +1,7 @@
<div class="message"> <div class="message">
<div class="icon" ng-if="vm.showSpinner"></div> <div class="icon" ng-if="vm.showSpinner"></div>
<div class="text" ng-if="(vm.title || vm.message) && vm.showText"> <div class="text" ng-if="(vm.title || vm.message) && vm.showText">
<div class="title"> <div class="title" ng-class="{messageNoSpinner : !vm.showSpinner}">
{{vm.title}} {{vm.title}}
</div> </div>
<div class="messageTxt"> <div class="messageTxt">
Expand Down
Expand Up @@ -8,16 +8,15 @@ get-fields-plugin.app.cancel.button=Cancel
get-fields-plugin.app.help.link=Help get-fields-plugin.app.help.link=Help
get-fields-plugin.app.clear-selection.label=Clear Selection get-fields-plugin.app.clear-selection.label=Clear Selection
get-fields-plugin.app.resample.label=Resample get-fields-plugin.app.resample.label=Resample
## Error message 1 -- Cannot find search value
get-fields-plugin.app.unable-to-find.label=Unable to find "{searchField}" get-fields-plugin.app.unable-to-find.label=Unable to find "{searchField}"
get-fields.plugin.app.unable-to-find.message=Sorry, we were unable to find that field. Please try another search or increase your sample size. get-fields.plugin.app.unable-to-find.message=Sorry, we were unable to find that field. Please try another search or increase your sample size.
## Error message 2 -- Cannot find file OR no permissions
get-fields-plugin.app.unable-to-access.label=Unable to access your {dataType} data get-fields-plugin.app.unable-to-access.label=Unable to access your {dataType} data
get-fields.plugin.app.unable-to-access.message=It looks like the location you specified is either incorrect or you do not have access. Check your settings in the File tab and try again. get-fields.plugin.app.unable-to-access.message=It looks like the location you specified is either incorrect or you do not have access. Check your settings in the File tab and try again.

## Error message 3 -- No file path specified in step OR Invalid JSON structure OR other issue
## get-fields-error component get-fields-plugin.app.unable-to-view.label=Unable to view {dataType} fields
get-fields-plugin.error.unable-to-make-selection.header=Unable to make selection get-fields.plugin.app.unable-to-view.message=It looks like there is no input specified, so we are unable to display {dataType} fields. Please add an input in the "Field" tab and try again.
get-fields-plugin.error.unable-to-make-selection.message=The selection you are trying to make cannot be made with your current selection. You can use an additional {0} step or deselect the other fields.
get-fields-plugin.error.unable-to-resample.header=UX still needs to define this
get-fields-plugin.error.unable-to-resample.message=UX still needs to define this


## get-fields-message component ## get-fields-message component
get-fields-plugin.message.title=Just a moment get-fields-plugin.message.title=Just a moment
Expand Down
Expand Up @@ -8,16 +8,15 @@ get-fields-plugin.app.cancel.button=Cancel
get-fields-plugin.app.help.link=Help get-fields-plugin.app.help.link=Help
get-fields-plugin.app.clear-selection.label=Clear Selection get-fields-plugin.app.clear-selection.label=Clear Selection
get-fields-plugin.app.resample.label=Resample get-fields-plugin.app.resample.label=Resample
## Error message 1 -- Cannot find search value
get-fields-plugin.app.unable-to-find.label=Unable to find "{searchField}" get-fields-plugin.app.unable-to-find.label=Unable to find "{searchField}"
get-fields.plugin.app.unable-to-find.message=Sorry, we were unable to find that field. Please try another search or increase your sample size. get-fields.plugin.app.unable-to-find.message=Sorry, we were unable to find that field. Please try another search or increase your sample size.
## Error message 2 -- Cannot find file OR no permissions
get-fields-plugin.app.unable-to-access.label=Unable to access your {dataType} data get-fields-plugin.app.unable-to-access.label=Unable to access your {dataType} data
get-fields.plugin.app.unable-to-access.message=It looks like the location you specified is either incorrect or you do not have access. Check your settings in the File tab and try again. get-fields.plugin.app.unable-to-access.message=It looks like the location you specified is either incorrect or you do not have access. Check your settings in the File tab and try again.

## Error message 3 -- No file path specified in step OR Invalid JSON structure OR other issue
## get-fields-error component get-fields-plugin.app.unable-to-view.label=Unable to view {dataType} fields
get-fields-plugin.error.unable-to-make-selection.header=Unable to make selection get-fields.plugin.app.unable-to-view.message=It looks like there is no input specified, so we are unable to display {dataType} fields. Please add an input in the "Field" tab and try again.
get-fields-plugin.error.unable-to-make-selection.message=The selection you are trying to make cannot be made with your current selection. You can use an additional {0} step or deselect the other fields.
get-fields-plugin.error.unable-to-resample.header=UX still needs to define this
get-fields-plugin.error.unable-to-resample.message=UX still needs to define this


## get-fields-message component ## get-fields-message component
get-fields-plugin.message.title=Just a moment get-fields-plugin.message.title=Just a moment
Expand Down
Expand Up @@ -1480,8 +1480,8 @@ private void get() {
// Call new get fields dialog // Call new get fields dialog
if ( wFilenameList.getItemCount() > 0 ) { if ( wFilenameList.getItemCount() > 0 ) {
String filename = transMeta.environmentSubstitute( wFilenameList.getItem( 0 )[ 0 ] ); String filename = transMeta.environmentSubstitute( wFilenameList.getItem( 0 )[ 0 ] );
GetFieldsDialogOperation getFieldsDialogOperation = new GetFieldsDialogOperation( shell, stepMeta, 540, 588, GetFieldsDialogOperation getFieldsDialogOperation = new GetFieldsDialogOperation( shell, 540, 588, filename,
filename ); BaseMessages.getString( PKG, "JsonInput.GetFields.Dialog.Title" ) );
ExtensionPointHandler.callExtensionPoint( null, KettleExtensionPoint.GetFieldsExtension.id, ExtensionPointHandler.callExtensionPoint( null, KettleExtensionPoint.GetFieldsExtension.id,
getFieldsDialogOperation ); getFieldsDialogOperation );


Expand Down
Expand Up @@ -5,6 +5,7 @@
JsonInput.name=JSON input JsonInput.name=JSON input
JsonInput.description=Extract relevant portions out of JSON structures (file or incoming field) and output rows JsonInput.description=Extract relevant portions out of JSON structures (file or incoming field) and output rows
JsonInput.category=Input JsonInput.category=Input
JsonInput.GetFields.Dialog.Title=JSON Input


JsonInputDialog.Limit.Label=Limit JsonInputDialog.Limit.Label=Limit
JsonInputDialog.FilenameEdit.Button=&Edit JsonInputDialog.FilenameEdit.Button=&Edit
Expand Down
Expand Up @@ -16,7 +16,6 @@
package org.pentaho.di.ui.core; package org.pentaho.di.ui.core;


import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
import org.pentaho.di.trans.step.StepMeta;


import java.util.List; import java.util.List;


Expand All @@ -25,18 +24,18 @@
*/ */
public class GetFieldsDialogOperation { public class GetFieldsDialogOperation {
private Shell shell; private Shell shell;
private StepMeta stepMeta;
private int width; private int width;
private int height; private int height;
private String filename; private String filename;
private String title;
private List<String> paths; private List<String> paths;


public GetFieldsDialogOperation( Shell shell, StepMeta stepMeta, int width, int height, String filename ) { public GetFieldsDialogOperation( Shell shell, int width, int height, String filename, String title ) {
this.shell = shell; this.shell = shell;
this.stepMeta = stepMeta;
this.width = width; this.width = width;
this.height = height; this.height = height;
this.filename = filename; this.filename = filename;
this.title = title;
} }


public Shell getShell() { public Shell getShell() {
Expand All @@ -47,14 +46,6 @@ public void setShell( Shell shell ) {
this.shell = shell; this.shell = shell;
} }


public StepMeta getStepMeta() {
return stepMeta;
}

public void setStepMeta( StepMeta stepMeta ) {
this.stepMeta = stepMeta;
}

public int getWidth() { public int getWidth() {
return width; return width;
} }
Expand Down Expand Up @@ -86,4 +77,12 @@ public List<String> getPaths() {
public void setPaths( List<String> paths ) { public void setPaths( List<String> paths ) {
this.paths = paths; this.paths = paths;
} }

public String getTitle() {
return title;
}

public void setTitle( String title ) {
this.title = title;
}
} }

0 comments on commit ef2d060

Please sign in to comment.