diff --git a/core/src/main/java/org/pentaho/platform/engine/core/system/PentahoSystem.java b/core/src/main/java/org/pentaho/platform/engine/core/system/PentahoSystem.java index 2bf54741da2..66fb8d9882a 100644 --- a/core/src/main/java/org/pentaho/platform/engine/core/system/PentahoSystem.java +++ b/core/src/main/java/org/pentaho/platform/engine/core/system/PentahoSystem.java @@ -400,6 +400,7 @@ public static boolean init( final IApplicationContext pApplicationContext, final if ( debug ) { Logger.debug( PentahoSystem.class, "PentahoSystem Init Complete" ); //$NON-NLS-1$ } + return true; } diff --git a/user-console/src/main/java/org/pentaho/mantle/client/MantleUtils.java b/user-console/src/main/java/org/pentaho/mantle/client/MantleUtils.java index 182a66988dd..c5eb2e72679 100644 --- a/user-console/src/main/java/org/pentaho/mantle/client/MantleUtils.java +++ b/user-console/src/main/java/org/pentaho/mantle/client/MantleUtils.java @@ -14,7 +14,7 @@ * See the GNU Lesser General Public License for more details. * * - * Copyright (c) 2002-2023 Hitachi Vantara. All rights reserved. + * Copyright (c) 2002-2024 Hitachi Vantara. All rights reserved. * */ @@ -22,9 +22,12 @@ import com.google.gwt.http.client.RequestBuilder; import com.google.gwt.http.client.RequestException; +import org.pentaho.gwt.widgets.client.filechooser.RepositoryFile; import org.pentaho.mantle.client.events.EventBusUtil; import org.pentaho.mantle.client.events.GenericEvent; +import org.pentaho.mantle.client.events.SolutionFileHandler; import org.pentaho.mantle.client.solutionbrowser.SolutionBrowserPanel; +import org.pentaho.mantle.client.solutionbrowser.filelist.FileItem; import org.pentaho.mantle.client.ui.PerspectiveManager; public class MantleUtils { @@ -33,7 +36,6 @@ public class MantleUtils { setupNativeHooks( new MantleUtils() ); } - public void setSchedulesPerspective() { PerspectiveManager.getInstance().setPerspective( PerspectiveManager.SCHEDULES_PERSPECTIVE ); } @@ -61,6 +63,34 @@ public void fireRefreshFolderEvent( String outputLocation ) { EventBusUtil.EVENT_BUS.fireEvent( event ); } + public void handleRepositoryFileSelection( String solutionPath, Boolean isAdhoc) { + final SolutionBrowserPanel sbp = SolutionBrowserPanel.getInstance(); + sbp.getFile( solutionPath, new SolutionFileHandler() { + @Override + public void handle( RepositoryFile repositoryFile ) { + if( isAdhoc ) { + openAdhocDialog( true ); + } else { + FileItem fileItem = new FileItem( repositoryFile, null, null, false, null ); + checkSchedulePermissionAndDialog( fileItem.getRepositoryFile().getId(), fileItem.getPath() ); + } + } + } ); + } + + private native void openAdhocDialog( boolean feedback ) /*-{ + $wnd.pho.showDialog(feedback); + }-*/; + + private native void checkSchedulePermissionAndDialog( String repositoryFileId, String repositoryFilePath ) /*-{ + $wnd.pho.checkSchedulePermissionAndDialog(repositoryFileId, repositoryFilePath); + }-*/; + + public boolean checkSelectedPerspective() { + return !PerspectiveManager.getInstance().getActivePerspective().getId().equals( + PerspectiveManager.SCHEDULES_PERSPECTIVE ); + } + public static native String getSchedulerPluginContextURL()/*-{ if (typeof $wnd.pho.getSchedulerPluginContextURL !== "undefined" ) { return $wnd.pho.getSchedulerPluginContextURL(); @@ -93,5 +123,15 @@ private static native void setupNativeHooks( MantleUtils utils ) //CHECKSTYLE IGNORE LineLength FOR NEXT 1 LINES utils.@org.pentaho.mantle.client.MantleUtils::fireRefreshFolderEvent(Ljava/lang/String;)(outputLocation); } + + $wnd.mantle.handleRepositoryFileSelection = function(solutionPath, isAdhoc) { + //CHECKSTYLE IGNORE LineLength FOR NEXT 1 LINES + utils.@org.pentaho.mantle.client.MantleUtils::handleRepositoryFileSelection(Ljava/lang/String;Ljava/lang/Boolean;)(solutionPath, isAdhoc); + } + + $wnd.mantle.checkSelectedPerspective = function() { + //CHECKSTYLE IGNORE LineLength FOR NEXT 1 LINES + return utils.@org.pentaho.mantle.client.MantleUtils::checkSelectedPerspective()(); + } }-*/; } diff --git a/user-console/src/main/java/org/pentaho/mantle/client/commands/AdhocRunInBackgroundCommand.java b/user-console/src/main/java/org/pentaho/mantle/client/commands/AdhocRunInBackgroundCommand.java deleted file mode 100644 index 35742945aa4..00000000000 --- a/user-console/src/main/java/org/pentaho/mantle/client/commands/AdhocRunInBackgroundCommand.java +++ /dev/null @@ -1,220 +0,0 @@ -/*! - * - * This program is free software; you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software - * Foundation. - * - * You should have received a copy of the GNU Lesser General Public License along with this - * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html - * or from the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU Lesser General Public License for more details. - * - * - * Copyright (c) 2002-2018 Hitachi Vantara. All rights reserved. - * - */ - -package org.pentaho.mantle.client.commands; - -import com.google.gwt.http.client.Request; -import com.google.gwt.http.client.RequestBuilder; -import com.google.gwt.http.client.RequestCallback; -import com.google.gwt.http.client.RequestException; -import com.google.gwt.http.client.Response; -import com.google.gwt.json.client.JSONParser; -import com.google.gwt.xml.client.Document; -import com.google.gwt.xml.client.Element; -import com.google.gwt.xml.client.Node; -import com.google.gwt.xml.client.NodeList; -import com.google.gwt.xml.client.XMLParser; -import org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox; -import org.pentaho.gwt.widgets.client.filechooser.RepositoryFile; -import org.pentaho.gwt.widgets.client.utils.NameUtils; -import org.pentaho.mantle.client.events.SolutionFileHandler; -import org.pentaho.mantle.client.messages.Messages; -import org.pentaho.mantle.client.solutionbrowser.SolutionBrowserPanel; - -public class AdhocRunInBackgroundCommand extends RunInBackgroundCommand { - - - public AdhocRunInBackgroundCommand() { - } - - private String jobId = null; - - private String recalculateFinished = null; - - private String solutionPath = null; - - @Override - public String getSolutionPath() { - return solutionPath; - } - - @Override - public void setSolutionPath( String solutionPath ) { - this.solutionPath = solutionPath; - } - - public void setJobId( String jobId ) { - this.jobId = jobId; - } - - public String getJobId() { - return jobId; - } - - public String getRecalculateFinished() { - return recalculateFinished; - } - - public void setRecalculateFinished( String recalculateFinished ) { - this.recalculateFinished = recalculateFinished; - } - - @Override - protected void performOperation() { - final SolutionBrowserPanel sbp = SolutionBrowserPanel.getInstance(); - if ( this.getSolutionPath() != null ) { - sbp.getFile( this.getSolutionPath(), new SolutionFileHandler() { - @Override - public void handle( RepositoryFile repositoryFile ) { - showDialog( true ); - } - } ); - } else { - performOperation( true ); - } - } - - @Override - protected void showDialog( final boolean feedback ) { - createScheduleOutputLocationDialog( getSolutionPath(), getOutputLocationPath(), feedback ); - } - - public static native void onCancel() - /*-{ - $wnd.mantle_fireEvent('GenericEvent', {eventSubType: 'locationPromptCanceled'}); - }-*/; - - public static native void onOk( final String outputPath ) - /*-{ - $wnd.mantle_fireEvent('GenericEvent', {eventSubType: 'locationPromptOk', stringParam: outputPath}); - }-*/; - - public static native void onAttach() - /*-{ -git }-*/; - - private static native void onFinished( String uuid )/*-{ - $wnd.mantle_fireEvent('GenericEvent', {eventSubType: 'locationPromptFinish', stringParam: uuid}); - }-*/; - - private RequestBuilder createTreeRequest() { - RequestBuilder scheduleFileRequestBuilder = new RequestBuilder( RequestBuilder.GET, contextURL + "api/repo/files/" - + NameUtils.encodeRepositoryPath( getOutputLocationPath() ) + "/tree?depth=1" ); - scheduleFileRequestBuilder.setHeader( "If-Modified-Since", "01 Jan 1970 00:00:00 GMT" ); - return scheduleFileRequestBuilder; - } - - @Override - protected void performOperation( boolean feedback ) { - - RequestBuilder treeRequestBuilder = createTreeRequest(); - - try { - treeRequestBuilder.sendRequest( null, new RequestCallback() { - - public void onError( Request request, Throwable exception ) { - AdhocRunInBackgroundCommand.this.onError( exception ); - } - - public void onResponseReceived( Request request, Response response ) { - if ( response.getStatusCode() == Response.SC_OK ) { - RequestBuilder scheduleFileRequestBuilder = parseFolderId( response ); - - try { - scheduleFileRequestBuilder.sendRequest( "", new RequestCallback() { - - @Override - public void onError( Request request, Throwable exception ) { - new MessageDialogBox( - Messages.getString( "error" ), exception.toString(), false, false, true ); - } - - @Override - public void onResponseReceived( Request request, Response response ) { - if ( response.getStatusCode() != Response.SC_OK ) { - AdhocRunInBackgroundCommand.this.onError( response ); - } else { - try { - onFinished( JSONParser. - parseStrict( response.getText() ).isObject() - .get( "uuid" ).isString().stringValue() ); - } catch ( Exception e ) { - AdhocRunInBackgroundCommand.this.onError( e ); - } - } - } - - } ); - } catch ( RequestException e ) { - AdhocRunInBackgroundCommand.this.onError( e ); - } - } else { - AdhocRunInBackgroundCommand.this.onError( response ); - } - } - - } ); - } catch ( RequestException e ) { - AdhocRunInBackgroundCommand.this.onError( e ); - } - } - - private RequestBuilder parseFolderId( Response response ) { - String folderId = null; - Document repository = XMLParser.parse( response.getText() ); - NodeList fileNodeList = repository.getElementsByTagName( "file" ); - for ( int i = 0; i < fileNodeList.getLength(); i++ ) { - Element element = (Element) fileNodeList.item( i ); - Node pathNode = element.getElementsByTagName( "path" ).item( 0 ); - - if ( getOutputLocationPath().equals( pathNode.getFirstChild().getNodeValue() ) ) { - folderId = element.getElementsByTagName( "id" ).item( 0 ).getFirstChild().getNodeValue(); - } - } - - RequestBuilder scheduleFileRequestBuilder = - new RequestBuilder( RequestBuilder.POST, contextURL + "plugin/reporting/api/jobs/" - + jobId + "/schedule?confirm=true&folderId=" + folderId + "&newName=" + getOutputName() + "&recalculateFinished=" + getRecalculateFinished() ); - scheduleFileRequestBuilder.setHeader( "Content-Type", "application/json" ); - scheduleFileRequestBuilder.setHeader( "If-Modified-Since", "01 Jan 1970 00:00:00 GMT" ); - return scheduleFileRequestBuilder; - } - - private void onError( Response response ) { - MessageDialogBox dialogBox = - new MessageDialogBox( - Messages.getString( "error" ), - Messages.getString( "serverErrorColon" ) + " " + response.getStatusCode(), false, false, - true ); - dialogBox.center(); - } - - private void onError( Throwable exception ) { - MessageDialogBox dialogBox = - new MessageDialogBox( Messages.getString( "error" ), exception.toString(), false, false, - true ); - dialogBox.center(); - } - - public native void createScheduleOutputLocationDialog(String solutionPath, String outputLocationPath, Boolean feedback) /*-{ - $wnd.pho.createScheduleOutputLocationDialog(solutionPath, outputLocationPath, feedback); - }-*/; - -} diff --git a/user-console/src/main/java/org/pentaho/mantle/client/commands/RunInBackgroundCommand.java b/user-console/src/main/java/org/pentaho/mantle/client/commands/RunInBackgroundCommand.java deleted file mode 100644 index f52f9022bf3..00000000000 --- a/user-console/src/main/java/org/pentaho/mantle/client/commands/RunInBackgroundCommand.java +++ /dev/null @@ -1,500 +0,0 @@ -/*! - * - * This program is free software; you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software - * Foundation. - * - * You should have received a copy of the GNU Lesser General Public License along with this - * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html - * or from the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU Lesser General Public License for more details. - * - * - * Copyright (c) 2002-2021 Hitachi Vantara. All rights reserved. - * - */ - -package org.pentaho.mantle.client.commands; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.http.client.Request; -import com.google.gwt.http.client.RequestBuilder; -import com.google.gwt.http.client.RequestCallback; -import com.google.gwt.http.client.RequestException; -import com.google.gwt.http.client.Response; -import com.google.gwt.i18n.client.DateTimeFormat; -import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat; -import com.google.gwt.json.client.JSONBoolean; -import com.google.gwt.json.client.JSONNull; -import com.google.gwt.json.client.JSONNumber; -import com.google.gwt.json.client.JSONObject; -import com.google.gwt.json.client.JSONParser; -import com.google.gwt.json.client.JSONString; - -import com.google.gwt.json.client.JSONValue; -import org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox; -import org.pentaho.gwt.widgets.client.filechooser.RepositoryFile; -import org.pentaho.gwt.widgets.client.utils.NameUtils; -import org.pentaho.gwt.widgets.client.utils.string.StringUtils; -import org.pentaho.mantle.client.MantleUtils; -import org.pentaho.mantle.client.events.SolutionFileHandler; -import org.pentaho.mantle.client.messages.Messages; -import org.pentaho.mantle.client.solutionbrowser.SolutionBrowserPanel; -import org.pentaho.mantle.client.solutionbrowser.filelist.FileItem; -import org.pentaho.mantle.client.ui.PerspectiveManager; - -import java.util.Date; - -import static org.pentaho.mantle.client.environment.EnvironmentHelper.getFullyQualifiedURL; - -/** - * Run In Background Command - * - * Note that the run in background command functionality is similar to schedule functionality. While a lot of code is - * duplicated over the two commands, quite a bit of screen flow / controller logic is embedded in the view dialogs. - * Combining these would make more sense once the control flow is removed from the views and abstracted into controllers. - */ -public class RunInBackgroundCommand extends AbstractCommand { - String moduleBaseURL = GWT.getModuleBaseURL(); - - String moduleName = GWT.getModuleName(); - - String contextURL = moduleBaseURL.substring( 0, moduleBaseURL.lastIndexOf( moduleName ) ); - - private FileItem repositoryFile; - - public RunInBackgroundCommand() { - setupNativeHooks( this ); - } - - public RunInBackgroundCommand( FileItem fileItem ) { - this.repositoryFile = fileItem; - } - - private String solutionPath = null; - private String solutionTitle = null; - private String outputLocationPath = null; - private String outputName = null; - private String overwriteFile; - private String dateFormat; - - public String getSolutionTitle() { - return solutionTitle; - } - - public void setSolutionTitle( String solutionTitle ) { - this.solutionTitle = solutionTitle; - } - - public String getSolutionPath() { - return solutionPath; - } - - public void setSolutionPath( String solutionPath ) { - this.solutionPath = solutionPath; - } - - public String getOutputLocationPath() { - return outputLocationPath; - } - - public void setOutputLocationPath( String outputLocationPath ) { - this.outputLocationPath = outputLocationPath; - } - - public String getModuleBaseURL() { - return moduleBaseURL; - } - - public void setModuleBaseURL( String moduleBaseURL ) { - this.moduleBaseURL = moduleBaseURL; - } - - public String getOutputName() { - return outputName; - } - - public void setOutputName( String outputName ) { - this.outputName = outputName; - } - - /** - * Get Date Format - * - * @return a string representation of a date format - */ - public String getDateFormat() { - return dateFormat; - } - - /** - * Set Date Format - * - * @param dateFormat a string representation of a date format - */ - public void setDateFormat( String dateFormat ) { - this.dateFormat = dateFormat; - } - - /** - * Get Overwrite File - * - * @return the string "true" if the file should be overwritten, otherwise "false" - */ - public String getOverwriteFile() { - return overwriteFile; - } - - /** - * Set Overwrite File - * - * @param overwriteFile the string "true" if the file should be overwritten, otherwise "false" - */ - public void setOverwriteFile( String overwriteFile ) { - this.overwriteFile = overwriteFile; - } - - protected void performOperation() { - final SolutionBrowserPanel sbp = SolutionBrowserPanel.getInstance(); - if ( this.getSolutionPath() != null ) { - sbp.getFile( this.getSolutionPath(), new SolutionFileHandler() { - @Override - public void handle( RepositoryFile repositoryFile ) { - RunInBackgroundCommand.this.repositoryFile = new FileItem( repositoryFile, null, null, false, null ); - checkSchedulePermissionAndDialog(); - } - } ); - } else { - performOperation( true ); - } - } - - @SuppressWarnings ( "deprecation" ) - protected JSONObject getJsonSimpleTrigger( int repeatCount, int interval, Date startDate, Date endDate ) { - JSONObject trigger = new JSONObject(); - trigger.put( "repeatInterval", new JSONNumber( interval ) ); //$NON-NLS-1$ - trigger.put( "repeatCount", new JSONNumber( repeatCount ) ); //$NON-NLS-1$ - trigger - .put( - "startTime", startDate != null ? new JSONString( DateTimeFormat.getFormat( PredefinedFormat.ISO_8601 ).format( startDate ) ) : JSONNull.getInstance() ); //$NON-NLS-1$ - if ( endDate != null ) { - endDate.setHours( 23 ); - endDate.setMinutes( 59 ); - endDate.setSeconds( 59 ); - } - trigger - .put( - "endTime", endDate == null ? JSONNull.getInstance() : new JSONString( DateTimeFormat.getFormat( PredefinedFormat.ISO_8601 ).format( endDate ) ) ); //$NON-NLS-1$ - return trigger; - } - - protected void showDialog( final boolean feedback ) { - - createScheduleOutputLocationDialog( getSolutionPath(), feedback ); - - final String filePath = solutionPath; - String urlPath = NameUtils.URLEncode( NameUtils.encodeRepositoryPath( filePath ) ); - - RequestBuilder scheduleFileRequestBuilder = createParametersChecker( urlPath ); - final boolean isXAction = isXAction( urlPath ); - - try { - scheduleFileRequestBuilder.sendRequest( null, new RequestCallback() { - public void onError( Request request, Throwable exception ) { - MessageDialogBox dialogBox = - new MessageDialogBox( Messages.getString( "error" ), exception.toString(), false, false, true ); //$NON-NLS-1$ - dialogBox.center(); - } - - public void onResponseReceived( Request request, Response response ) { - if ( response.getStatusCode() == Response.SC_OK ) { - String responseMessage = response.getText(); - boolean hasParams = hasParameters( responseMessage, isXAction ); - if ( !hasParams ) { - setOkButtonText(); - } - centerScheduleOutputLocationDialog(); - } else { - MessageDialogBox dialogBox = - new MessageDialogBox( - Messages.getString( "error" ), Messages.getString( "serverErrorColon" ) + " " + response.getStatusCode(), false, false, true ); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ - dialogBox.center(); - } - } - } ); - } catch ( RequestException e ) { - MessageDialogBox dialogBox = - new MessageDialogBox( Messages.getString( "error" ), e.toString(), false, false, true ); //$NON-NLS-1$ - dialogBox.center(); - } - } - - private boolean hasParameters( String responseMessage, boolean isXAction ) { - if ( isXAction ) { - int numOfInputs = StringUtils.countMatches( responseMessage, " 0 ? true : false; - } else { - return Boolean.parseBoolean( responseMessage ); - } - } - - private boolean isXAction( String urlPath ) { - if ( ( urlPath != null ) && ( urlPath.endsWith( "xaction" ) ) ) { - return true; - } else { - return false; - } - } - - private RequestBuilder createParametersChecker( String urlPath ) { - RequestBuilder scheduleFileRequestBuilder = null; - if ( ( urlPath != null ) && ( urlPath.endsWith( "xaction" ) ) ) { - scheduleFileRequestBuilder = new RequestBuilder( RequestBuilder.GET, contextURL + "api/repos/" + urlPath - + "/parameterUi" ); - } else { - scheduleFileRequestBuilder = new RequestBuilder( RequestBuilder.GET, contextURL + "api/repo/files/" + urlPath - + "/parameterizable" ); - } - scheduleFileRequestBuilder.setHeader( "accept", "text/plain" ); //$NON-NLS-1$ //$NON-NLS-2$ - scheduleFileRequestBuilder.setHeader( "If-Modified-Since", "01 Jan 1970 00:00:00 GMT" ); - return scheduleFileRequestBuilder; - } - - protected void checkSchedulePermissionAndDialog() { - final String url = MantleUtils.getSchedulerPluginContextURL() + "api/scheduler/isScheduleAllowed?id=" + repositoryFile.getRepositoryFile().getId(); //$NON-NLS-1$ - RequestBuilder requestBuilder = new RequestBuilder( RequestBuilder.GET, url ); - requestBuilder.setHeader( "accept", "text/plain" ); - requestBuilder.setHeader( "If-Modified-Since", "01 Jan 1970 00:00:00 GMT" ); - final MessageDialogBox errorDialog = - new MessageDialogBox( - Messages.getString( "error" ), Messages.getString( "noSchedulePermission" ), false, false, true ); //$NON-NLS-1$ //$NON-NLS-2$ - try { - requestBuilder.sendRequest( null, new RequestCallback() { - - public void onError( Request request, Throwable caught ) { - errorDialog.center(); - } - - public void onResponseReceived( Request request, Response response ) { - if ( "true".equalsIgnoreCase( response.getText() ) ) { - showDialog( true ); - } else { - errorDialog.center(); - } - } - } ); - } catch ( RequestException re ) { - errorDialog.center(); - } - } - - protected void performOperation( boolean feedback ) { - - final String filePath = ( this.getSolutionPath() != null ) ? this.getSolutionPath() : repositoryFile.getPath(); - String urlPath = NameUtils.URLEncode( NameUtils.encodeRepositoryPath( filePath ) ); - - RequestBuilder scheduleFileRequestBuilder = createParametersChecker( urlPath ); - final boolean isXAction = isXAction( urlPath ); - - try { - scheduleFileRequestBuilder.sendRequest( null, new RequestCallback() { - - public void onError( Request request, Throwable exception ) { - MessageDialogBox dialogBox = - new MessageDialogBox( Messages.getString( "error" ), exception.toString(), false, false, true ); //$NON-NLS-1$ - dialogBox.center(); - } - - public void onResponseReceived( Request request, Response response ) { - if ( response.getStatusCode() == Response.SC_OK ) { - final JSONObject scheduleRequest = new JSONObject(); - scheduleRequest.put( "inputFile", new JSONString( filePath ) ); //$NON-NLS-1$ - - //Set date format to append to filename - if ( StringUtils.isEmpty( getDateFormat() ) ) { - scheduleRequest.put( "appendDateFormat", JSONNull.getInstance() ); //$NON-NLS-1$ - } else { - scheduleRequest.put( "appendDateFormat", new JSONString( getDateFormat() ) ); //$NON-NLS-1$ - } - - //Set whether to overwrite the file - if ( StringUtils.isEmpty( getOverwriteFile() ) ) { - scheduleRequest.put( "overwriteFile", JSONNull.getInstance() ); //$NON-NLS-1$ - } else { - scheduleRequest.put( "overwriteFile", new JSONString( getOverwriteFile() ) ); //$NON-NLS-1$ - } - - // Set job name - if ( StringUtils.isEmpty( getOutputName() ) ) { - scheduleRequest.put( "jobName", JSONNull.getInstance() ); //$NON-NLS-1$ - } else { - scheduleRequest.put( "jobName", new JSONString( getOutputName() ) ); //$NON-NLS-1$ - } - - // Set output path location - if ( StringUtils.isEmpty( getOutputLocationPath() ) ) { - scheduleRequest.put( "outputFile", JSONNull.getInstance() ); //$NON-NLS-1$ - } else { - scheduleRequest.put( "outputFile", new JSONString( getOutputLocationPath() ) ); //$NON-NLS-1$ - } - - // BISERVER-9321 - scheduleRequest.put( "runInBackground", JSONBoolean.getInstance( true ) ); - - String responseMessage = response.getText(); - final boolean hasParams = hasParameters( responseMessage, isXAction ); - - RequestBuilder emailValidRequest = - new RequestBuilder( RequestBuilder.GET, contextURL + "api/emailconfig/isValid" ); //$NON-NLS-1$ - emailValidRequest.setHeader( "accept", "text/plain" ); //$NON-NLS-1$ //$NON-NLS-2$ - emailValidRequest.setHeader( "If-Modified-Since", "01 Jan 1970 00:00:00 GMT" ); - try { - emailValidRequest.sendRequest( null, new RequestCallback() { - - public void onError( Request request, Throwable exception ) { - MessageDialogBox dialogBox = - new MessageDialogBox( Messages.getString( "error" ), exception.toString(), false, false, true ); //$NON-NLS-1$ - dialogBox.center(); - } - - public void onResponseReceived( Request request, Response response ) { - if ( response.getStatusCode() == Response.SC_OK ) { - // final boolean isEmailConfValid = Boolean.parseBoolean(response.getText()); - // force false for now, I have a feeling PM is going to want this, making it easy to turn back - // on - final boolean isEmailConfValid = false; - if ( hasParams ) { - boolean isSchedulesPerspectiveActive = !PerspectiveManager.getInstance().getActivePerspective().getId().equals(PerspectiveManager.SCHEDULES_PERSPECTIVE ); - createScheduleParamsDialog( filePath, scheduleRequest, isEmailConfValid, isSchedulesPerspectiveActive ); - } else if ( isEmailConfValid ) { - createScheduleEmailDialog( filePath, scheduleRequest ); - } else { - // Handle Schedule Parameters - String jsonStringScheduleParams = getScheduleParams( scheduleRequest ); - JSONValue scheduleParams = JSONParser.parseStrict( jsonStringScheduleParams ); - scheduleRequest.put( "jobParameters", scheduleParams.isArray() ); - - // just run it - RequestBuilder scheduleFileRequestBuilder = - new RequestBuilder( RequestBuilder.POST, MantleUtils.getSchedulerPluginContextURL() + "api/scheduler/job" ); //$NON-NLS-1$ - scheduleFileRequestBuilder.setHeader( "Content-Type", "application/json" ); //$NON-NLS-1$//$NON-NLS-2$ - scheduleFileRequestBuilder.setHeader( "If-Modified-Since", "01 Jan 1970 00:00:00 GMT" ); - - try { - scheduleFileRequestBuilder.sendRequest( scheduleRequest.toString(), new RequestCallback() { - - @Override - public void onError( Request request, Throwable exception ) { - MessageDialogBox dialogBox = - new MessageDialogBox( - Messages.getString( "error" ), exception.toString(), false, false, true ); //$NON-NLS-1$ - dialogBox.center(); - } - - @Override - public void onResponseReceived( Request request, Response response ) { - if ( response.getStatusCode() == 200 ) { - MessageDialogBox dialogBox = - new MessageDialogBox( - Messages.getString( "runInBackground" ), Messages.getString( "backgroundExecutionStarted" ), //$NON-NLS-1$ //$NON-NLS-2$ - false, false, true ); - dialogBox.center(); - } else { - MessageDialogBox dialogBox = - new MessageDialogBox( - Messages.getString( "error" ), Messages.getString( "serverErrorColon" ) + " " + response.getStatusCode(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-2$ //$NON-NLS-3$ - false, false, true ); - dialogBox.center(); - } - } - - } ); - } catch ( RequestException e ) { - MessageDialogBox dialogBox = new MessageDialogBox( Messages.getString( "error" ), e.toString(), //$NON-NLS-1$ - false, false, true ); - dialogBox.center(); - } - } - - } - } - } ); - } catch ( RequestException e ) { - MessageDialogBox dialogBox = - new MessageDialogBox( Messages.getString( "error" ), e.toString(), false, false, true ); //$NON-NLS-1$ - dialogBox.center(); - } - - } else { - MessageDialogBox dialogBox = - new MessageDialogBox( - Messages.getString( "error" ), Messages.getString( "serverErrorColon" ) + " " + response.getStatusCode(), false, false, true ); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ - dialogBox.center(); - } - } - - } ); - } catch ( RequestException e ) { - MessageDialogBox dialogBox = - new MessageDialogBox( Messages.getString( "error" ), e.toString(), false, false, true ); //$NON-NLS-1$ - dialogBox.center(); - } - } - - private static native void setupNativeHooks( RunInBackgroundCommand cmd ) - /*-{ - $wnd.mantle_runInBackgroundCommand_setOutputName = function(outputName) { - //CHECKSTYLE IGNORE LineLength FOR NEXT 1 LINES - cmd.@org.pentaho.mantle.client.commands.RunInBackgroundCommand::setOutputName(Ljava/lang/String;)(outputName); - } - - $wnd.mantle_runInBackgroundCommand_setOutputLocationPath = function(outputLocationPath) { - //CHECKSTYLE IGNORE LineLength FOR NEXT 1 LINES - cmd.@org.pentaho.mantle.client.commands.RunInBackgroundCommand::setOutputLocationPath(Ljava/lang/String;)(outputLocationPath); - } - - $wnd.mantle_runInBackgroundCommand_setOverwriteFile = function(overwriteFile) { - //CHECKSTYLE IGNORE LineLength FOR NEXT 1 LINES - cmd.@org.pentaho.mantle.client.commands.RunInBackgroundCommand::setOverwriteFile(Ljava/lang/String;)(overwriteFile); - } - - $wnd.mantle_runInBackgroundCommand_setDateFormat = function(dateFormat) { - //CHECKSTYLE IGNORE LineLength FOR NEXT 1 LINES - cmd.@org.pentaho.mantle.client.commands.RunInBackgroundCommand::setDateFormat(Ljava/lang/String;)(dateFormat); - } - - $wnd.mantle_runInBackgroundCommand_performOperation = function(feedback) { - //CHECKSTYLE IGNORE LineLength FOR NEXT 1 LINES - cmd.@org.pentaho.mantle.client.commands.RunInBackgroundCommand::performOperation(Z)(feedback); - } - }-*/; - - private native void createScheduleOutputLocationDialog(String solutionPath, Boolean feedback) /*-{ - $wnd.pho.createScheduleOutputLocationDialog(solutionPath, feedback); - }-*/; - - private native void setOkButtonText() /*-{ - $wnd.pho.setOkButtonText(); - }-*/; - - private native void centerScheduleOutputLocationDialog() /*-{ - $wnd.pho.centerScheduleOutputLocationDialog(); - }-*/; - - private native void createScheduleParamsDialog( String filePath, JSONObject scheduleRequest, Boolean isEmailConfigValid, Boolean isSchedulesPerspectiveActive ) /*-{ - $wnd.pho.createScheduleParamsDialog( filePath, scheduleRequest, isEmailConfigValid, isSchedulesPerspectiveActive ); - }-*/; - - private native void createScheduleEmailDialog( String filePath, JSONObject scheduleRequest ) /*-{ - $wnd.pho.createScheduleEmailDialog( filePath, scheduleRequest ); - }-*/; - - private native String getScheduleParams( JSONObject scheduleRequest) /*-{ - return $wnd.pho.getScheduleParams( scheduleRequest ); - }-*/; -} diff --git a/user-console/src/main/java/org/pentaho/mantle/client/solutionbrowser/filelist/FileCommand.java b/user-console/src/main/java/org/pentaho/mantle/client/solutionbrowser/filelist/FileCommand.java index 8c40da3454b..5eddf457c14 100644 --- a/user-console/src/main/java/org/pentaho/mantle/client/solutionbrowser/filelist/FileCommand.java +++ b/user-console/src/main/java/org/pentaho/mantle/client/solutionbrowser/filelist/FileCommand.java @@ -27,7 +27,6 @@ import org.pentaho.mantle.client.commands.FilePropertiesCommand; import org.pentaho.mantle.client.commands.ImportFileCommand; import org.pentaho.mantle.client.commands.NewFolderCommand; -import org.pentaho.mantle.client.commands.RunInBackgroundCommand; import org.pentaho.mantle.client.commands.ShareFileCommand; import org.pentaho.mantle.client.solutionbrowser.IRepositoryFileProvider; import org.pentaho.mantle.client.solutionbrowser.SolutionBrowserPanel; @@ -92,7 +91,7 @@ public void execute() { } else if ( mode == COMMAND.CREATE_FOLDER ) { new NewFolderCommand( fileSummary ).execute(); } else if ( mode == COMMAND.BACKGROUND ) { - new RunInBackgroundCommand( selectedItem ).execute( true ); + runInBackground( selectedItem.getRepositoryFile() ); } else if ( mode == COMMAND.SCHEDULE_NEW ) { createSchedule( selectedItem.getRepositoryFile() ); } else if ( mode == COMMAND.SHARE ) { @@ -116,8 +115,15 @@ private void createSchedule( final RepositoryFile repositoryFile ) { createSchedule( repositoryFile.getId(), repositoryFile.getPath() ); } + private void runInBackground( final RepositoryFile repositoryFile ) { + runInBackground( repositoryFile.getId(), repositoryFile.getPath() ); + } + private native void createSchedule( final String repositoryFileId, final String repositoryFilePath )/*-{ $wnd.pho.createSchedule( repositoryFileId, repositoryFilePath ); }-*/; + private native void runInBackground( final String repositoryFileId, final String repositoryFilePath )/*-{ + $wnd.pho.runInBackground( repositoryFileId, repositoryFilePath ); + }-*/; } diff --git a/user-console/src/main/resources/org/pentaho/mantle/public/browser/js/browser.fileButtons.js b/user-console/src/main/resources/org/pentaho/mantle/public/browser/js/browser.fileButtons.js index 979fe1f6a19..e1b05769c9d 100644 --- a/user-console/src/main/resources/org/pentaho/mantle/public/browser/js/browser.fileButtons.js +++ b/user-console/src/main/resources/org/pentaho/mantle/public/browser/js/browser.fileButtons.js @@ -296,8 +296,8 @@ define([ window.parent.mantle_setPerspective('browser.perspective'); }, - runInBackgroundHandler: function (path, title) { - window.parent.executeCommand("RunInBackgroundCommand", this.buildParameter(path, title)); + runInBackgroundHandler: function (path, title, id) { + window.parent.pho.runInBackground(id, path); }, editHandler: function (path) {