Search in sources :

Example 76 with KettleException

use of org.pentaho.di.core.exception.KettleException in project pentaho-kettle by pentaho.

the class TransFileListener method open.

public boolean open(Node transNode, String fname, boolean importfile) throws KettleMissingPluginsException {
    final Spoon spoon = Spoon.getInstance();
    final PropsUI props = PropsUI.getInstance();
    try {
        // Call extension point(s) before the file has been opened
        ExtensionPointHandler.callExtensionPoint(spoon.getLog(), KettleExtensionPoint.TransBeforeOpen.id, fname);
        TransMeta transMeta = new TransMeta();
        transMeta.loadXML(transNode, fname, spoon.getMetaStore(), spoon.getRepository(), true, new Variables(), new OverwritePrompter() {

            public boolean overwritePrompt(String message, String rememberText, String rememberPropertyName) {
                MessageDialogWithToggle.setDefaultImage(GUIResource.getInstance().getImageSpoon());
                Object[] res = spoon.messageDialogWithToggle(BaseMessages.getString(PKG, "System.Button.Yes"), null, message, Const.WARNING, new String[] { BaseMessages.getString(PKG, "System.Button.Yes"), BaseMessages.getString(PKG, "System.Button.No") }, 1, rememberText, !props.askAboutReplacingDatabaseConnections());
                int idx = ((Integer) res[0]).intValue();
                boolean toggleState = ((Boolean) res[1]).booleanValue();
                props.setAskAboutReplacingDatabaseConnections(!toggleState);
                // Yes means: overwrite
                return ((idx & 0xFF) == 0);
            }
        });
        if (transMeta.hasMissingPlugins()) {
            StepMeta stepMeta = transMeta.getStep(0);
            MissingTransDialog missingDialog = new MissingTransDialog(spoon.getShell(), transMeta.getMissingTrans(), stepMeta.getStepMetaInterface(), transMeta, stepMeta.getName());
            if (missingDialog.open() == null) {
                return true;
            }
        }
        transMeta.setRepositoryDirectory(spoon.getDefaultSaveLocation(transMeta));
        transMeta.setRepository(spoon.getRepository());
        transMeta.setMetaStore(spoon.getMetaStore());
        spoon.setTransMetaVariables(transMeta);
        spoon.getProperties().addLastFile(LastUsedFile.FILE_TYPE_TRANSFORMATION, fname, null, false, null);
        spoon.addMenuLast();
        // if any exist.
        if (importfile) {
            if (spoon.getRepository() != null) {
                transMeta = fixLinks(transMeta);
            }
        } else {
            transMeta.clearChanged();
        }
        transMeta.setFilename(fname);
        spoon.addTransGraph(transMeta);
        spoon.sharedObjectsFileMap.put(transMeta.getSharedObjects().getFilename(), transMeta.getSharedObjects());
        // Call extension point(s) now that the file has been opened
        ExtensionPointHandler.callExtensionPoint(spoon.getLog(), KettleExtensionPoint.TransAfterOpen.id, transMeta);
        SpoonPerspectiveManager.getInstance().activatePerspective(MainSpoonPerspective.class);
        spoon.refreshTree();
        return true;
    } catch (KettleMissingPluginsException e) {
        throw e;
    } catch (KettleException e) {
        new ErrorDialog(spoon.getShell(), BaseMessages.getString(PKG, "Spoon.Dialog.ErrorOpening.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.ErrorOpening.Message") + fname, e);
    }
    return false;
}
Also used : Variables(org.pentaho.di.core.variables.Variables) KettleException(org.pentaho.di.core.exception.KettleException) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) MissingTransDialog(org.pentaho.di.ui.trans.steps.missing.MissingTransDialog) TransMeta(org.pentaho.di.trans.TransMeta) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) OverwritePrompter(org.pentaho.di.core.gui.OverwritePrompter) StepMeta(org.pentaho.di.trans.step.StepMeta) PropsUI(org.pentaho.di.ui.core.PropsUI)

Example 77 with KettleException

use of org.pentaho.di.core.exception.KettleException in project pentaho-kettle by pentaho.

the class TransFileListener method save.

public boolean save(EngineMetaInterface meta, String fname, boolean export) {
    Spoon spoon = Spoon.getInstance();
    EngineMetaInterface lmeta;
    if (export) {
        lmeta = (TransMeta) ((TransMeta) meta).realClone(false);
    } else {
        lmeta = meta;
    }
    try {
        ExtensionPointHandler.callExtensionPoint(spoon.getLog(), KettleExtensionPoint.TransBeforeSave.id, lmeta);
    } catch (KettleException e) {
    // fails gracefully
    }
    boolean saveStatus = spoon.saveMeta(lmeta, fname);
    if (saveStatus) {
        try {
            ExtensionPointHandler.callExtensionPoint(spoon.getLog(), KettleExtensionPoint.TransAfterSave.id, lmeta);
        } catch (KettleException e) {
        // fails gracefully
        }
    }
    return saveStatus;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) TransMeta(org.pentaho.di.trans.TransMeta) EngineMetaInterface(org.pentaho.di.core.EngineMetaInterface)

Example 78 with KettleException

use of org.pentaho.di.core.exception.KettleException in project pentaho-kettle by pentaho.

the class SpoonClustersDelegate method delClusterSchema.

public void delClusterSchema(TransMeta transMeta, ClusterSchema clusterSchema) {
    try {
        int idx = transMeta.getClusterSchemas().indexOf(clusterSchema);
        transMeta.getClusterSchemas().remove(idx);
        if (spoon.rep != null && clusterSchema.getObjectId() != null) {
            // remove the partition schema from the repository too...
            spoon.rep.deleteClusterSchema(clusterSchema.getObjectId());
            if (sharedObjectSyncUtil != null) {
                sharedObjectSyncUtil.deleteClusterSchema(clusterSchema);
            }
        }
        spoon.refreshTree();
    } catch (KettleException e) {
        new ErrorDialog(spoon.getShell(), BaseMessages.getString(PKG, "Spoon.Dialog.ErrorDeletingPartitionSchema.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.ErrorDeletingPartitionSchema.Message"), e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog)

Example 79 with KettleException

use of org.pentaho.di.core.exception.KettleException in project pentaho-kettle by pentaho.

the class SpoonDBDelegate method saveConnection.

public void saveConnection(DatabaseMeta db, String versionComment) {
    // Also add to repository?
    Repository rep = spoon.getRepository();
    if (rep != null) {
        if (!rep.getSecurityProvider().isReadOnly()) {
            try {
                if (Utils.isEmpty(versionComment)) {
                    rep.insertLogEntry("Saving database '" + db.getName() + "'");
                } else {
                    rep.insertLogEntry("Save database : " + versionComment);
                }
                rep.save(db, versionComment, null);
                spoon.getLog().logDetailed(BaseMessages.getString(PKG, "Spoon.Log.SavedDatabaseConnection", db.getDatabaseName()));
                db.setChanged(false);
            } catch (KettleException ke) {
                new ErrorDialog(spoon.getShell(), BaseMessages.getString(PKG, "Spoon.Dialog.ErrorSavingConnection.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.ErrorSavingConnection.Message", db.getDatabaseName()), ke);
            }
        } else {
            // This repository user is read-only!
            // 
            new ErrorDialog(spoon.getShell(), BaseMessages.getString(PKG, "Spoon.Dialog.UnableSave.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.ErrorSavingConnection.Message", db.getDatabaseName()), new KettleException(BaseMessages.getString(PKG, "Spoon.Dialog.Exception.ReadOnlyRepositoryUser")));
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) Repository(org.pentaho.di.repository.Repository) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog)

Example 80 with KettleException

use of org.pentaho.di.core.exception.KettleException in project pentaho-kettle by pentaho.

the class SpoonDBDelegate method copyTable.

public boolean copyTable(DatabaseMeta sourceDBInfo, DatabaseMeta targetDBInfo, String tablename) {
    try {
        // 
        // Create a new transformation...
        // 
        TransMeta meta = new TransMeta();
        meta.addDatabase(sourceDBInfo);
        meta.addDatabase(targetDBInfo);
        // 
        // Add a note
        // 
        String note = BaseMessages.getString(PKG, "Spoon.Message.Note.ReadInformationFromTableOnDB", tablename, sourceDBInfo.getDatabaseName()) + // "Reads information from table ["+tablename+"]
        Const.CR;
        // on database ["+sourceDBInfo+"]"
        note += BaseMessages.getString(PKG, "Spoon.Message.Note.WriteInformationToTableOnDB", tablename, targetDBInfo.getDatabaseName());
        // the information to table
        // ["+tablename+"] on
        // database
        // ["+targetDBInfo+"]"
        NotePadMeta ni = new NotePadMeta(note, 150, 10, -1, -1);
        meta.addNote(ni);
        // 
        // create the source step...
        // 
        // "read
        String fromstepname = BaseMessages.getString(PKG, "Spoon.Message.Note.ReadFromTable", tablename);
        // from
        // ["+tablename+"]";
        TableInputMeta tii = new TableInputMeta();
        tii.setDatabaseMeta(sourceDBInfo);
        tii.setSQL("SELECT * FROM " + tablename);
        PluginRegistry registry = PluginRegistry.getInstance();
        String fromstepid = registry.getPluginId(StepPluginType.class, tii);
        StepMeta fromstep = new StepMeta(fromstepid, fromstepname, tii);
        fromstep.setLocation(150, 100);
        fromstep.setDraw(true);
        fromstep.setDescription(BaseMessages.getString(PKG, "Spoon.Message.Note.ReadInformationFromTableOnDB", tablename, sourceDBInfo.getDatabaseName()));
        meta.addStep(fromstep);
        // 
        // add logic to rename fields in case any of the field names contain
        // reserved words...
        // Use metadata logic in SelectValues, use SelectValueInfo...
        // 
        Database sourceDB = new Database(loggingObject, sourceDBInfo);
        sourceDB.shareVariablesWith(meta);
        sourceDB.connect();
        try {
            // Get the fields for the input table...
            RowMetaInterface fields = sourceDB.getTableFields(tablename);
            // See if we need to deal with reserved words...
            int nrReserved = targetDBInfo.getNrReservedWords(fields);
            if (nrReserved > 0) {
                SelectValuesMeta svi = new SelectValuesMeta();
                svi.allocate(0, 0, nrReserved);
                int nr = 0;
                // CHECKSTYLE:Indentation:OFF
                for (int i = 0; i < fields.size(); i++) {
                    ValueMetaInterface v = fields.getValueMeta(i);
                    if (targetDBInfo.isReservedWord(v.getName())) {
                        if (svi.getMeta()[nr] == null) {
                            svi.getMeta()[nr] = new SelectMetadataChange(svi);
                        }
                        svi.getMeta()[nr].setName(v.getName());
                        svi.getMeta()[nr].setRename(targetDBInfo.quoteField(v.getName()));
                        nr++;
                    }
                }
                String selstepname = BaseMessages.getString(PKG, "Spoon.Message.Note.HandleReservedWords");
                String selstepid = registry.getPluginId(StepPluginType.class, svi);
                StepMeta selstep = new StepMeta(selstepid, selstepname, svi);
                selstep.setLocation(350, 100);
                selstep.setDraw(true);
                selstep.setDescription(BaseMessages.getString(PKG, "Spoon.Message.Note.RenamesReservedWords", // 
                targetDBInfo.getPluginId()));
                meta.addStep(selstep);
                TransHopMeta shi = new TransHopMeta(fromstep, selstep);
                meta.addTransHop(shi);
                fromstep = selstep;
            }
            // 
            // Create the target step...
            // 
            // 
            // Add the TableOutputMeta step...
            // 
            String tostepname = BaseMessages.getString(PKG, "Spoon.Message.Note.WriteToTable", tablename);
            TableOutputMeta toi = new TableOutputMeta();
            toi.setDatabaseMeta(targetDBInfo);
            toi.setTableName(tablename);
            toi.setCommitSize(200);
            toi.setTruncateTable(true);
            String tostepid = registry.getPluginId(StepPluginType.class, toi);
            StepMeta tostep = new StepMeta(tostepid, tostepname, toi);
            tostep.setLocation(550, 100);
            tostep.setDraw(true);
            tostep.setDescription(BaseMessages.getString(PKG, "Spoon.Message.Note.WriteInformationToTableOnDB2", tablename, targetDBInfo.getDatabaseName()));
            meta.addStep(tostep);
            // 
            // Add a hop between the two steps...
            // 
            TransHopMeta hi = new TransHopMeta(fromstep, tostep);
            meta.addTransHop(hi);
            // OK, if we're still here: overwrite the current transformation...
            // Set a name on this generated transformation
            // 
            String name = "Copy table from [" + sourceDBInfo.getName() + "] to [" + targetDBInfo.getName() + "]";
            String transName = name;
            int nr = 1;
            if (spoon.delegates.trans.getTransformation(transName) != null) {
                nr++;
                transName = name + " " + nr;
            }
            meta.setName(transName);
            spoon.delegates.trans.addTransGraph(meta);
            spoon.refreshGraph();
            spoon.refreshTree();
        } finally {
            sourceDB.disconnect();
        }
    } catch (Exception e) {
        new ErrorDialog(spoon.getShell(), BaseMessages.getString(PKG, "Spoon.Dialog.UnexpectedError.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.UnexpectedError.Message"), new KettleException(e.getMessage(), e));
        return false;
    }
    return true;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) TransMeta(org.pentaho.di.trans.TransMeta) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) TableOutputMeta(org.pentaho.di.trans.steps.tableoutput.TableOutputMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) TableInputMeta(org.pentaho.di.trans.steps.tableinput.TableInputMeta) KettleException(org.pentaho.di.core.exception.KettleException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) SelectValuesMeta(org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) Database(org.pentaho.di.core.database.Database) SelectMetadataChange(org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange) NotePadMeta(org.pentaho.di.core.NotePadMeta) TransHopMeta(org.pentaho.di.trans.TransHopMeta)

Aggregations

KettleException (org.pentaho.di.core.exception.KettleException)1977 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)449 KettleStepException (org.pentaho.di.core.exception.KettleStepException)438 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)317 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)316 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)233 IOException (java.io.IOException)208 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)195 FileObject (org.apache.commons.vfs2.FileObject)150 StepMeta (org.pentaho.di.trans.step.StepMeta)150 ArrayList (java.util.ArrayList)149 KettleFileException (org.pentaho.di.core.exception.KettleFileException)124 TransMeta (org.pentaho.di.trans.TransMeta)119 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)113 Test (org.junit.Test)111 KettleValueException (org.pentaho.di.core.exception.KettleValueException)100 Database (org.pentaho.di.core.database.Database)97 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)95 ObjectId (org.pentaho.di.repository.ObjectId)91 Shell (org.eclipse.swt.widgets.Shell)90