Search in sources :

Example 21 with SharedObjects

use of org.pentaho.di.shared.SharedObjects in project pentaho-kettle by pentaho.

the class SharedDatabaseUtil method addSharedDatabase.

/**
 * Add a database to the list of shared databases in ~/.kettle/shared.xml
 *
 * @param databaseMeta
 * @throws KettleException in case there is an error
 * @throws KettleObjectExistsException if a database with the same name already exists
 */
public static void addSharedDatabase(DatabaseMeta databaseMeta) throws KettleObjectExistsException, KettleException {
    // First verify existence...
    // 
    List<DatabaseMeta> sharedDatabases = loadSharedDatabases();
    DatabaseMeta found = DatabaseMeta.findDatabase(sharedDatabases, databaseMeta.getName());
    if (found != null) {
        throw new KettleObjectExistsException("A database with name '" + databaseMeta.getName() + "' already exists in the shared databases list.");
    }
    try {
        SharedObjects sharedObjects = new SharedObjects();
        sharedObjects.storeObject(databaseMeta);
        sharedObjects.saveToFile();
    } catch (Exception e) {
        throw new KettleException("It was not possible to add database '" + databaseMeta.getName() + "' to the shared.xml file");
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleObjectExistsException(org.pentaho.di.core.exception.KettleObjectExistsException) SharedObjects(org.pentaho.di.shared.SharedObjects) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) KettleException(org.pentaho.di.core.exception.KettleException) KettleObjectExistsException(org.pentaho.di.core.exception.KettleObjectExistsException)

Example 22 with SharedObjects

use of org.pentaho.di.shared.SharedObjects in project pentaho-kettle by pentaho.

the class StarModelDialog method addDimensionsTab.

private void addDimensionsTab() {
    wDimensionsTab = new CTabItem(wTabFolder, SWT.NONE);
    wDimensionsTab.setText(BaseMessages.getString(PKG, "StarModelDialog.DimensionsTab.Label"));
    FormLayout dimensionsLayout = new FormLayout();
    dimensionsLayout.marginWidth = Const.MARGIN;
    dimensionsLayout.marginHeight = Const.MARGIN;
    Composite wDimensionsComp = new Composite(wTabFolder, SWT.NONE);
    props.setLook(wDimensionsComp);
    wDimensionsComp.setLayout(dimensionsLayout);
    Label wlTables = new Label(wDimensionsComp, SWT.RIGHT);
    wlTables.setText(BaseMessages.getString(PKG, "StarModelDialog.Tables.Label"));
    props.setLook(wlTables);
    FormData fdlAttributes = new FormData();
    fdlAttributes.left = new FormAttachment(0, 0);
    fdlAttributes.top = new FormAttachment(0, 0);
    wlTables.setLayoutData(fdlAttributes);
    // A few buttons to edit the list
    // 
    Button newTableButton = new Button(wDimensionsComp, SWT.PUSH);
    newTableButton.setText(BaseMessages.getString(PKG, "StarModelDialog.Button.NewTable"));
    newTableButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (newTable(shell, logicalModel)) {
                refreshTablesList();
            }
        }
    });
    Button copyTableButton = new Button(wDimensionsComp, SWT.PUSH);
    copyTableButton.setText(BaseMessages.getString(PKG, "StarModelDialog.Button.CopyTable"));
    copyTableButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (wTablesList.getSelectionIndex() < 0)
                return;
            TableItem item = wTablesList.table.getSelection()[0];
            String tableName = item.getText(1);
            if (copyTable(shell, logicalModel, tableName)) {
                refreshTablesList();
            }
        }
    });
    Button editTableButton = new Button(wDimensionsComp, SWT.PUSH);
    editTableButton.setText(BaseMessages.getString(PKG, "StarModelDialog.Button.EditTable"));
    editTableButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (wTablesList.getSelectionIndex() < 0)
                return;
            TableItem item = wTablesList.table.getSelection()[0];
            String tableName = item.getText(1);
            if (editTable(tableName)) {
                refreshTablesList();
            }
        }
    });
    Button delTableButton = new Button(wDimensionsComp, SWT.PUSH);
    delTableButton.setText(BaseMessages.getString(PKG, "StarModelDialog.Button.DeleteTable"));
    delTableButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (wTablesList.getSelectionIndex() < 0)
                return;
            TableItem item = wTablesList.table.getSelection()[0];
            String tableName = item.getText(1);
            if (deleteTable(tableName)) {
                refreshTablesList();
            }
        }
    });
    BaseStepDialog.positionBottomButtons(wDimensionsComp, new Button[] { newTableButton, copyTableButton, editTableButton, delTableButton }, margin, null);
    final int FieldsRows = logicalModel.getLogicalTables().size();
    List<DatabaseMeta> sharedDatabases = new ArrayList<DatabaseMeta>();
    try {
        SharedObjects sharedObjects = new SharedObjects();
        for (SharedObjectInterface sharedObject : sharedObjects.getObjectsMap().values()) {
            if (sharedObject instanceof DatabaseMeta) {
                sharedDatabases.add((DatabaseMeta) sharedObject);
            }
        }
    } catch (Exception e) {
        LogChannel.GENERAL.logError("Unable to load shared objects", e);
    }
    // The dimensions and fact of the model
    // 
    ColumnInfo[] colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "StarModelDialog.ColumnInfo.Name.Label"), ColumnInfo.COLUMN_TYPE_TEXT, false, true), new ColumnInfo(BaseMessages.getString(PKG, "StarModelDialog.ColumnInfo.Description.Label"), ColumnInfo.COLUMN_TYPE_TEXT, false, true), new ColumnInfo(BaseMessages.getString(PKG, "StarModelDialog.ColumnInfo.TableType.Label"), ColumnInfo.COLUMN_TYPE_TEXT, false, true) };
    wTablesList = new TableView(new Variables(), wDimensionsComp, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, colinf, FieldsRows, null, props);
    FormData fdTablesList = new FormData();
    fdTablesList.left = new FormAttachment(0, 0);
    fdTablesList.top = new FormAttachment(wlTables, margin);
    fdTablesList.right = new FormAttachment(100, 0);
    fdTablesList.bottom = new FormAttachment(newTableButton, -margin);
    wTablesList.setLayoutData(fdTablesList);
    wTablesList.setReadonly(true);
    wTablesList.table.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            if (wTablesList.getSelectionIndex() < 0)
                return;
            TableItem item = wTablesList.table.getSelection()[0];
            String tableName = item.getText(1);
            if (editTable(tableName)) {
                refreshTablesList();
            // refreshRelationshipsList();
            }
        }
    });
    FormData fdTablesComp = new FormData();
    fdTablesComp.left = new FormAttachment(0, 0);
    fdTablesComp.top = new FormAttachment(0, 0);
    fdTablesComp.right = new FormAttachment(100, 0);
    fdTablesComp.bottom = new FormAttachment(100, 0);
    wDimensionsComp.setLayoutData(fdTablesComp);
    wDimensionsComp.layout();
    wDimensionsTab.setControl(wDimensionsComp);
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) SharedObjects(org.pentaho.di.shared.SharedObjects) CTabItem(org.eclipse.swt.custom.CTabItem) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Variables(org.pentaho.di.core.variables.Variables) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SharedObjectInterface(org.pentaho.di.shared.SharedObjectInterface) FormAttachment(org.eclipse.swt.layout.FormAttachment) TableView(org.pentaho.di.ui.core.widget.TableView)

Example 23 with SharedObjects

use of org.pentaho.di.shared.SharedObjects in project pentaho-kettle by pentaho.

the class Spoon method unShareObject.

protected void unShareObject(SharedObjectInterface sharedObject) {
    MessageBox mb = new MessageBox(shell, SWT.YES | SWT.NO | SWT.ICON_WARNING);
    // "Are you sure you want to stop sharing?"
    mb.setMessage(BaseMessages.getString(PKG, "Spoon.Dialog.StopSharing.Message"));
    // Warning!
    mb.setText(BaseMessages.getString(PKG, "Spoon.Dialog.StopSharing.Title"));
    int answer = mb.open();
    if (answer == SWT.YES) {
        sharedObject.setShared(false);
        EngineMetaInterface meta = getActiveMeta();
        try {
            if (meta != null) {
                SharedObjects sharedObjects = null;
                if (meta instanceof TransMeta) {
                    sharedObjects = ((TransMeta) meta).getSharedObjects();
                }
                if (meta instanceof JobMeta) {
                    sharedObjects = ((JobMeta) meta).getSharedObjects();
                }
                if (sharedObjects != null) {
                    sharedObjects.removeObject(sharedObject);
                    sharedObjects.saveToFile();
                }
            }
        } catch (Exception e) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "Spoon.Dialog.ErrorWritingSharedObjects.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.ErrorWritingSharedObjects.Message"), e);
        }
        refreshTree();
    }
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) TransMeta(org.pentaho.di.trans.TransMeta) EngineMetaInterface(org.pentaho.di.core.EngineMetaInterface) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) SharedObjects(org.pentaho.di.shared.SharedObjects) 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 24 with SharedObjects

use of org.pentaho.di.shared.SharedObjects in project pentaho-kettle by pentaho.

the class Spoon method loadRepositoryObjects.

/**
 * @deprecated is this ever used?
 * functionality seems covered in loadSessionInformation
 */
public void loadRepositoryObjects(TransMeta transMeta) {
    // Load common database info from active repository...
    if (rep != null) {
        try {
            SharedObjects sharedObjects = rep.readTransSharedObjects(transMeta);
            sharedObjectsFileMap.put(sharedObjects.getFilename(), sharedObjects);
        } catch (Exception e) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "Spoon.Error.UnableToLoadSharedObjects.Title"), BaseMessages.getString(PKG, "Spoon.Error.UnableToLoadSharedObjects.Message"), e);
        }
    }
}
Also used : ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) SharedObjects(org.pentaho.di.shared.SharedObjects) 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)

Example 25 with SharedObjects

use of org.pentaho.di.shared.SharedObjects in project pentaho-kettle by pentaho.

the class Spoon method loadSessionInformation.

private void loadSessionInformation(Repository repository, boolean saveOldDatabases) {
    JobMeta[] jobMetas = getLoadedJobs();
    for (JobMeta jobMeta : jobMetas) {
        for (int i = 0; i < jobMeta.nrDatabases(); i++) {
            jobMeta.getDatabase(i).setObjectId(null);
        }
        // Set for the existing job the ID at -1!
        jobMeta.setObjectId(null);
        // Keep track of the old databases for now.
        List<DatabaseMeta> oldDatabases = jobMeta.getDatabases();
        // In order to re-match the databases on name (not content), we
        // need to load the databases from the new repository.
        // NOTE: for purposes such as DEVELOP - TEST - PRODUCTION
        // cycles.
        // first clear the list of databases and slave servers
        jobMeta.setDatabases(new ArrayList<DatabaseMeta>());
        jobMeta.setSlaveServers(new ArrayList<SlaveServer>());
        // Read them from the new repository.
        try {
            SharedObjects sharedObjects = repository != null ? repository.readJobMetaSharedObjects(jobMeta) : jobMeta.readSharedObjects();
            sharedObjectsFileMap.put(sharedObjects.getFilename(), sharedObjects);
        } catch (KettleException e) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "Spoon.Dialog.ErrorReadingSharedObjects.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.ErrorReadingSharedObjects.Message", makeTabName(jobMeta, true)), e);
        }
        // Then we need to re-match the databases at save time...
        for (DatabaseMeta oldDatabase : oldDatabases) {
            DatabaseMeta newDatabase = DatabaseMeta.findDatabase(jobMeta.getDatabases(), oldDatabase.getName());
            // If it exists, change the settings...
            if (newDatabase != null) {
                // 
                // A database connection with the same name exists in
                // the new repository.
                // Change the old connections to reflect the settings in
                // the new repository
                // 
                oldDatabase.setDatabaseInterface(newDatabase.getDatabaseInterface());
            } else {
                if (saveOldDatabases) {
                    // 
                    // The old database is not present in the new
                    // repository: simply add it to the list.
                    // When the job gets saved, it will be added
                    // to the repository.
                    // 
                    jobMeta.addDatabase(oldDatabase);
                }
            }
        }
        if (repository != null) {
            try {
                // For the existing job, change the directory too:
                // Try to find the same directory in the new repository...
                RepositoryDirectoryInterface rdi = repository.findDirectory(jobMeta.getRepositoryDirectory().getPath());
                if (rdi != null && !rdi.getPath().equals("/")) {
                    jobMeta.setRepositoryDirectory(rdi);
                } else {
                    // the root is the default!
                    jobMeta.setRepositoryDirectory(repository.loadRepositoryDirectoryTree());
                }
            } catch (KettleException ke) {
                rep = null;
                new ErrorDialog(shell, BaseMessages.getString(PKG, "Spoon.Dialog.ErrorConnectingRepository.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.ErrorConnectingRepository.Message", Const.CR), ke);
            }
        }
    }
    TransMeta[] transMetas = getLoadedTransformations();
    for (TransMeta transMeta : transMetas) {
        for (int i = 0; i < transMeta.nrDatabases(); i++) {
            transMeta.getDatabase(i).setObjectId(null);
        }
        // Set for the existing transformation the ID at -1!
        transMeta.setObjectId(null);
        // Keep track of the old databases for now.
        List<DatabaseMeta> oldDatabases = transMeta.getDatabases();
        // In order to re-match the databases on name (not content), we
        // need to load the databases from the new repository.
        // NOTE: for purposes such as DEVELOP - TEST - PRODUCTION
        // cycles.
        // first clear the list of databases, partition schemas, slave
        // servers, clusters
        transMeta.setDatabases(new ArrayList<DatabaseMeta>());
        transMeta.setPartitionSchemas(new ArrayList<PartitionSchema>());
        transMeta.setSlaveServers(new ArrayList<SlaveServer>());
        transMeta.setClusterSchemas(new ArrayList<ClusterSchema>());
        // Read them from the new repository.
        try {
            SharedObjects sharedObjects = repository != null ? repository.readTransSharedObjects(transMeta) : transMeta.readSharedObjects();
            sharedObjectsFileMap.put(sharedObjects.getFilename(), sharedObjects);
        } catch (KettleException e) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "Spoon.Dialog.ErrorReadingSharedObjects.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.ErrorReadingSharedObjects.Message", makeTabName(transMeta, true)), e);
        }
        // Then we need to re-match the databases at save time...
        for (DatabaseMeta oldDatabase : oldDatabases) {
            DatabaseMeta newDatabase = DatabaseMeta.findDatabase(transMeta.getDatabases(), oldDatabase.getName());
            // If it exists, change the settings...
            if (newDatabase != null) {
                // 
                // A database connection with the same name exists in
                // the new repository.
                // Change the old connections to reflect the settings in
                // the new repository
                // 
                oldDatabase.setDatabaseInterface(newDatabase.getDatabaseInterface());
            } else {
                if (saveOldDatabases) {
                    // 
                    // The old database is not present in the new
                    // repository: simply add it to the list.
                    // When the transformation gets saved, it will be added
                    // to the repository.
                    // 
                    transMeta.addDatabase(oldDatabase);
                }
            }
        }
        if (repository != null) {
            try {
                // For the existing transformation, change the directory too:
                // Try to find the same directory in the new repository...
                RepositoryDirectoryInterface rdi = repository.findDirectory(transMeta.getRepositoryDirectory().getPath());
                if (rdi != null && !rdi.getPath().equals("/")) {
                    transMeta.setRepositoryDirectory(rdi);
                } else {
                    // the root is the default!
                    transMeta.setRepositoryDirectory(repository.loadRepositoryDirectoryTree());
                }
            } catch (KettleException ke) {
                rep = null;
                new ErrorDialog(shell, BaseMessages.getString(PKG, "Spoon.Dialog.ErrorConnectingRepository.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.ErrorConnectingRepository.Message", Const.CR), ke);
            }
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) JobMeta(org.pentaho.di.job.JobMeta) PartitionSchema(org.pentaho.di.partition.PartitionSchema) TransMeta(org.pentaho.di.trans.TransMeta) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) SharedObjects(org.pentaho.di.shared.SharedObjects) SlaveServer(org.pentaho.di.cluster.SlaveServer) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) ClusterSchema(org.pentaho.di.cluster.ClusterSchema)

Aggregations

SharedObjects (org.pentaho.di.shared.SharedObjects)25 KettleException (org.pentaho.di.core.exception.KettleException)13 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)10 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)8 KettleFileException (org.pentaho.di.core.exception.KettleFileException)6 KettleValueException (org.pentaho.di.core.exception.KettleValueException)6 KettleRepositoryLostException (org.pentaho.di.repository.KettleRepositoryLostException)6 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)6 MalformedURLException (java.net.MalformedURLException)5 FileSystemException (org.apache.commons.vfs2.FileSystemException)5 SWTException (org.eclipse.swt.SWTException)5 KettleAuthException (org.pentaho.di.core.exception.KettleAuthException)5 KettleMissingPluginsException (org.pentaho.di.core.exception.KettleMissingPluginsException)5 KettleRowException (org.pentaho.di.core.exception.KettleRowException)5 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)5 LifecycleException (org.pentaho.di.core.lifecycle.LifecycleException)5 JobMeta (org.pentaho.di.job.JobMeta)5 TransMeta (org.pentaho.di.trans.TransMeta)5 SlaveServer (org.pentaho.di.cluster.SlaveServer)4 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)4