/*!
* 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-2013 Pentaho Corporation.. All rights reserved.
*/
package org.pentaho.mantle.client.commands;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import org.pentaho.gwt.widgets.client.filechooser.RepositoryFile;
import org.pentaho.mantle.client.events.EventBusUtil;
import org.pentaho.mantle.client.events.SolutionFileActionEvent;
import org.pentaho.mantle.client.events.SolutionFileHandler;
import org.pentaho.mantle.client.solutionbrowser.SolutionBrowserPanel;
public class ExportFileCommand extends AbstractCommand {
private RepositoryFile repositoryFile;
public ExportFileCommand() {
}
public ExportFileCommand( RepositoryFile repositoryFile ) {
this.repositoryFile = repositoryFile;
}
private String solutionPath = null;
public String getSolutionPath() {
return solutionPath;
}
public void setSolutionPath( String solutionPath ) {
this.solutionPath = solutionPath;
}
protected void performOperation() {
final SolutionBrowserPanel sbp = SolutionBrowserPanel.getInstance();
if ( this.getSolutionPath() != null ) {
sbp.getFile( this.getSolutionPath(), new SolutionFileHandler() {
@Override
public void handle( RepositoryFile repositoryFile ) {
ExportFileCommand.this.setRepositoryFile( repositoryFile );
performOperation( true );
}
} );
} else {
performOperation( true );
}
}
protected void performOperation( boolean feedback ) {
String path = repositoryFile.getPath();
String moduleBaseURL = GWT.getModuleBaseURL();
String moduleName = GWT.getModuleName();
String contextURL = moduleBaseURL.substring( 0, moduleBaseURL.lastIndexOf( moduleName ) );
String exportURL =
contextURL + "api/repo/files/" + SolutionBrowserPanel.pathToId( path ) + "/download?withManifest=true";
Window.open( exportURL, "_new", "" );
final SolutionFileActionEvent event = new SolutionFileActionEvent();
event.setAction( this.getClass().getName() );
event.setMessage( "Success" );
EventBusUtil.EVENT_BUS.fireEvent( event );
}
public RepositoryFile getRepositoryFile() {
return repositoryFile;
}
public void setRepositoryFile( RepositoryFile repositoryFile ) {
this.repositoryFile = repositoryFile;
}
}