Search in sources :

Example 1 with ResourceExportInterface

use of org.pentaho.di.resource.ResourceExportInterface in project pentaho-kettle by pentaho.

the class Spoon method exportAllXMLFile.

/**
 * Export this job or transformation including all depending resources to a single zip file.
 */
public void exportAllXMLFile() {
    ResourceExportInterface resourceExportInterface = getActiveTransformation();
    if (resourceExportInterface == null) {
        resourceExportInterface = getActiveJob();
    }
    if (resourceExportInterface == null) {
        // nothing to do here, prevent an NPE
        return;
    }
    // 
    try {
        String zipFilename = null;
        while (Utils.isEmpty(zipFilename)) {
            FileDialog dialog = new FileDialog(shell, SWT.SAVE);
            dialog.setText(BaseMessages.getString(PKG, "Spoon.ExportResourceSelectZipFile"));
            dialog.setFilterExtensions(new String[] { "*.zip;*.ZIP", "*" });
            dialog.setFilterNames(new String[] { BaseMessages.getString(PKG, "System.FileType.ZIPFiles"), BaseMessages.getString(PKG, "System.FileType.AllFiles") });
            setFilterPath(dialog);
            if (dialog.open() != null) {
                lastDirOpened = dialog.getFilterPath();
                zipFilename = dialog.getFilterPath() + Const.FILE_SEPARATOR + dialog.getFileName();
                FileObject zipFileObject = KettleVFS.getFileObject(zipFilename);
                if (zipFileObject.exists()) {
                    MessageBox box = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL);
                    box.setMessage(BaseMessages.getString(PKG, "Spoon.ExportResourceZipFileExists.Message", zipFilename));
                    box.setText(BaseMessages.getString(PKG, "Spoon.ExportResourceZipFileExists.Title"));
                    int answer = box.open();
                    if (answer == SWT.CANCEL) {
                        return;
                    }
                    if (answer == SWT.NO) {
                        zipFilename = null;
                    }
                }
            } else {
                return;
            }
        }
        // Export the resources linked to the currently loaded file...
        // 
        TopLevelResource topLevelResource = ResourceUtil.serializeResourceExportInterface(zipFilename, resourceExportInterface, (VariableSpace) resourceExportInterface, rep, metaStore);
        String message = ResourceUtil.getExplanation(zipFilename, topLevelResource.getResourceName(), resourceExportInterface);
        /*
       * // Add the ZIP file as a repository to the repository list... // RepositoriesMeta repositoriesMeta = new
       * RepositoriesMeta(); repositoriesMeta.readData();
       *
       * KettleFileRepositoryMeta fileRepositoryMeta = new KettleFileRepositoryMeta(
       * KettleFileRepositoryMeta.REPOSITORY_TYPE_ID, "Export " + baseFileName, "Export to file : " + zipFilename,
       * "zip://" + zipFilename + "!"); fileRepositoryMeta.setReadOnly(true); // A ZIP file is read-only int nr = 2;
       * String baseName = fileRepositoryMeta.getName(); while
       * (repositoriesMeta.findRepository(fileRepositoryMeta.getName()) != null) { fileRepositoryMeta.setName(baseName +
       * " " + nr); nr++; }
       *
       * repositoriesMeta.addRepository(fileRepositoryMeta); repositoriesMeta.writeData();
       */
        // Show some information concerning all this work...
        EnterTextDialog enterTextDialog = new EnterTextDialog(shell, BaseMessages.getString(PKG, "Spoon.Dialog.ResourceSerialized"), BaseMessages.getString(PKG, "Spoon.Dialog.ResourceSerializedSuccesfully"), message);
        enterTextDialog.setReadOnly();
        enterTextDialog.open();
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "Spoon.Error"), BaseMessages.getString(PKG, "Spoon.ErrorExportingFile"), e);
    }
}
Also used : TopLevelResource(org.pentaho.di.resource.TopLevelResource) ResourceExportInterface(org.pentaho.di.resource.ResourceExportInterface) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) FileObject(org.apache.commons.vfs2.FileObject) KettlePropertiesFileDialog(org.pentaho.di.ui.core.dialog.KettlePropertiesFileDialog) FileDialog(org.eclipse.swt.widgets.FileDialog) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) SWTException(org.eclipse.swt.SWTException) KettleRowException(org.pentaho.di.core.exception.KettleRowException) FileSystemException(org.apache.commons.vfs2.FileSystemException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleAuthException(org.pentaho.di.core.exception.KettleAuthException) KettleRepositoryLostException(org.pentaho.di.repository.KettleRepositoryLostException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) LifecycleException(org.pentaho.di.core.lifecycle.LifecycleException) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) KettleException(org.pentaho.di.core.exception.KettleException) MalformedURLException(java.net.MalformedURLException) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 2 with ResourceExportInterface

use of org.pentaho.di.resource.ResourceExportInterface in project pentaho-kettle by pentaho.

the class Spoon method exportAllFileRepository.

/**
 * Export this job or transformation including all depending resources to a single ZIP file containing a file
 * repository.
 */
public void exportAllFileRepository() {
    ResourceExportInterface resourceExportInterface = getActiveTransformation();
    if (resourceExportInterface == null) {
        resourceExportInterface = getActiveJob();
    }
    if (resourceExportInterface == null) {
        // nothing to do here, prevent an NPE
        return;
    }
    // 
    try {
        String zipFilename = null;
        while (Utils.isEmpty(zipFilename)) {
            FileDialog dialog = new FileDialog(shell, SWT.SAVE);
            dialog.setText(BaseMessages.getString(PKG, "Spoon.ExportResourceSelectZipFile"));
            dialog.setFilterExtensions(new String[] { "*.zip;*.ZIP", "*" });
            dialog.setFilterNames(new String[] { BaseMessages.getString(PKG, "System.FileType.ZIPFiles"), BaseMessages.getString(PKG, "System.FileType.AllFiles") });
            setFilterPath(dialog);
            if (dialog.open() != null) {
                lastDirOpened = dialog.getFilterPath();
                zipFilename = dialog.getFilterPath() + Const.FILE_SEPARATOR + dialog.getFileName();
                FileObject zipFileObject = KettleVFS.getFileObject(zipFilename);
                if (zipFileObject.exists()) {
                    MessageBox box = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL);
                    box.setMessage(BaseMessages.getString(PKG, "Spoon.ExportResourceZipFileExists.Message", zipFilename));
                    box.setText(BaseMessages.getString(PKG, "Spoon.ExportResourceZipFileExists.Title"));
                    int answer = box.open();
                    if (answer == SWT.CANCEL) {
                        return;
                    }
                    if (answer == SWT.NO) {
                        zipFilename = null;
                    }
                }
            } else {
                return;
            }
        }
        // Export the resources linked to the currently loaded file...
        // 
        TopLevelResource topLevelResource = ResourceUtil.serializeResourceExportInterface(zipFilename, resourceExportInterface, (VariableSpace) resourceExportInterface, rep, metaStore);
        String message = ResourceUtil.getExplanation(zipFilename, topLevelResource.getResourceName(), resourceExportInterface);
        /*
       * // Add the ZIP file as a repository to the repository list... // RepositoriesMeta repositoriesMeta = new
       * RepositoriesMeta(); repositoriesMeta.readData();
       *
       * KettleFileRepositoryMeta fileRepositoryMeta = new KettleFileRepositoryMeta(
       * KettleFileRepositoryMeta.REPOSITORY_TYPE_ID, "Export " + baseFileName, "Export to file : " + zipFilename,
       * "zip://" + zipFilename + "!"); fileRepositoryMeta.setReadOnly(true); // A ZIP file is read-only int nr = 2;
       * String baseName = fileRepositoryMeta.getName(); while
       * (repositoriesMeta.findRepository(fileRepositoryMeta.getName()) != null) { fileRepositoryMeta.setName(baseName +
       * " " + nr); nr++; }
       *
       * repositoriesMeta.addRepository(fileRepositoryMeta); repositoriesMeta.writeData();
       */
        // Show some information concerning all this work...
        // 
        EnterTextDialog enterTextDialog = new EnterTextDialog(shell, BaseMessages.getString(PKG, "Spoon.Dialog.ResourceSerialized"), BaseMessages.getString(PKG, "Spoon.Dialog.ResourceSerializedSuccesfully"), message);
        enterTextDialog.setReadOnly();
        enterTextDialog.open();
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "Spoon.Error"), BaseMessages.getString(PKG, "Spoon.ErrorExportingFile"), e);
    }
}
Also used : TopLevelResource(org.pentaho.di.resource.TopLevelResource) ResourceExportInterface(org.pentaho.di.resource.ResourceExportInterface) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) FileObject(org.apache.commons.vfs2.FileObject) KettlePropertiesFileDialog(org.pentaho.di.ui.core.dialog.KettlePropertiesFileDialog) FileDialog(org.eclipse.swt.widgets.FileDialog) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) SWTException(org.eclipse.swt.SWTException) KettleRowException(org.pentaho.di.core.exception.KettleRowException) FileSystemException(org.apache.commons.vfs2.FileSystemException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleAuthException(org.pentaho.di.core.exception.KettleAuthException) KettleRepositoryLostException(org.pentaho.di.repository.KettleRepositoryLostException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) LifecycleException(org.pentaho.di.core.lifecycle.LifecycleException) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) KettleException(org.pentaho.di.core.exception.KettleException) MalformedURLException(java.net.MalformedURLException) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

MalformedURLException (java.net.MalformedURLException)2 FileObject (org.apache.commons.vfs2.FileObject)2 FileSystemException (org.apache.commons.vfs2.FileSystemException)2 SWTException (org.eclipse.swt.SWTException)2 FileDialog (org.eclipse.swt.widgets.FileDialog)2 MessageBox (org.eclipse.swt.widgets.MessageBox)2 KettleAuthException (org.pentaho.di.core.exception.KettleAuthException)2 KettleException (org.pentaho.di.core.exception.KettleException)2 KettleFileException (org.pentaho.di.core.exception.KettleFileException)2 KettleMissingPluginsException (org.pentaho.di.core.exception.KettleMissingPluginsException)2 KettleRowException (org.pentaho.di.core.exception.KettleRowException)2 KettleValueException (org.pentaho.di.core.exception.KettleValueException)2 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)2 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)2 Point (org.pentaho.di.core.gui.Point)2 LifecycleException (org.pentaho.di.core.lifecycle.LifecycleException)2 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)2 KettleRepositoryLostException (org.pentaho.di.repository.KettleRepositoryLostException)2 ResourceExportInterface (org.pentaho.di.resource.ResourceExportInterface)2 TopLevelResource (org.pentaho.di.resource.TopLevelResource)2