Search in sources :

Example 11 with SharedObjectInterface

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

the class PurRepository method loadAndCacheSharedObjects.

protected Map<RepositoryObjectType, List<? extends SharedObjectInterface>> loadAndCacheSharedObjects(final boolean deepCopy) throws KettleException {
    if (sharedObjectsByType == null) {
        try {
            sharedObjectsByType = new EnumMap<RepositoryObjectType, List<? extends SharedObjectInterface>>(RepositoryObjectType.class);
            // Slave Servers are referenced by Cluster Schemas so they must be loaded first
            readSharedObjects(sharedObjectsByType, RepositoryObjectType.DATABASE, RepositoryObjectType.PARTITION_SCHEMA, RepositoryObjectType.SLAVE_SERVER, RepositoryObjectType.CLUSTER_SCHEMA);
        } catch (Exception e) {
            sharedObjectsByType = null;
            // $NON-NLS-1$
            throw new KettleException("Unable to read shared objects from repository", e);
        }
    }
    return deepCopy ? deepCopy(sharedObjectsByType) : sharedObjectsByType;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) List(java.util.List) ArrayList(java.util.ArrayList) SharedObjectInterface(org.pentaho.di.shared.SharedObjectInterface) MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) UnifiedRepositoryCreateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryCreateFileException) UnifiedRepositoryUpdateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryUpdateFileException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) KettleException(org.pentaho.di.core.exception.KettleException) IdNotFoundException(org.pentaho.di.core.exception.IdNotFoundException) KettleSecurityException(org.pentaho.di.core.exception.KettleSecurityException)

Example 12 with SharedObjectInterface

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

the class PrivateDatabasesTestTemplate method createInjectingAnswer.

protected Answer<SharedObjects> createInjectingAnswer(final T meta, final SharedObjects fakeSharedObjects) throws Exception {
    return new Answer<SharedObjects>() {

        @Override
        public SharedObjects answer(InvocationOnMock invocation) throws Throwable {
            for (SharedObjectInterface value : fakeSharedObjects.getObjectsMap().values()) {
                DatabaseMeta db = (DatabaseMeta) value;
                meta.addOrReplaceDatabase(db);
            }
            return fakeSharedObjects;
        }
    };
}
Also used : Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SharedObjectInterface(org.pentaho.di.shared.SharedObjectInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta)

Example 13 with SharedObjectInterface

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

the class AbstractMeta method saveSharedObjects.

public void saveSharedObjects() throws KettleException {
    try {
        // Load all the shared objects...
        String soFile = environmentSubstitute(sharedObjectsFile);
        SharedObjects sharedObjects = new SharedObjects(soFile);
        // in-memory shared objects are supposed to be in sync, discard those on file to allow edit/delete
        sharedObjects.setObjectsMap(new Hashtable<>());
        for (SharedObjectInterface sharedObject : getAllSharedObjects()) {
            if (sharedObject.isShared()) {
                sharedObjects.storeObject(sharedObject);
            }
        }
        sharedObjects.saveToFile();
    } catch (Exception e) {
        throw new KettleException("Unable to save shared ojects", e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) SharedObjectInterface(org.pentaho.di.shared.SharedObjectInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) SharedObjects(org.pentaho.di.shared.SharedObjects) DuplicateParamException(org.pentaho.di.core.parameters.DuplicateParamException) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleException(org.pentaho.di.core.exception.KettleException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException)

Example 14 with SharedObjectInterface

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

the class AbstractMeta method readSharedObjects.

/**
 * Read shared objects.
 *
 * @return the shared objects
 * @throws KettleException the kettle exception
 */
public SharedObjects readSharedObjects() throws KettleException {
    // Extract the shared steps, connections, etc. using the SharedObjects
    // class
    // 
    String soFile = environmentSubstitute(sharedObjectsFile);
    SharedObjects sharedObjects = new SharedObjects(soFile);
    Map<?, SharedObjectInterface> objectsMap = sharedObjects.getObjectsMap();
    // 
    for (SharedObjectInterface object : objectsMap.values()) {
        loadSharedObject(object);
    }
    return sharedObjects;
}
Also used : SharedObjectInterface(org.pentaho.di.shared.SharedObjectInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) SharedObjects(org.pentaho.di.shared.SharedObjects)

Example 15 with SharedObjectInterface

use of org.pentaho.di.shared.SharedObjectInterface 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)

Aggregations

SharedObjectInterface (org.pentaho.di.shared.SharedObjectInterface)18 List (java.util.List)7 RepositoryObjectType (org.pentaho.di.repository.RepositoryObjectType)7 ArrayList (java.util.ArrayList)6 KettleException (org.pentaho.di.core.exception.KettleException)6 Test (org.junit.Test)5 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)5 SlaveServer (org.pentaho.di.cluster.SlaveServer)4 PartitionSchema (org.pentaho.di.partition.PartitionSchema)4 KettleFileException (org.pentaho.di.core.exception.KettleFileException)3 SharedObjects (org.pentaho.di.shared.SharedObjects)3 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)3 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)2 ClusterSchema (org.pentaho.di.cluster.ClusterSchema)2 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)2 KettleSecurityException (org.pentaho.di.core.exception.KettleSecurityException)2 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)2 ObjectId (org.pentaho.di.repository.ObjectId)2 RepositoryElementInterface (org.pentaho.di.repository.RepositoryElementInterface)2 StringObjectId (org.pentaho.di.repository.StringObjectId)2