Search in sources :

Example 6 with AbstractMeta

use of org.pentaho.di.base.AbstractMeta in project pentaho-kettle by pentaho.

the class PurRepository_MoveAndRename_IT method moveAndRename_FailsIfANameConflictOccurs.

private void moveAndRename_FailsIfANameConflictOccurs(Assistant assistant) throws Exception {
    final String fileName = "moveAndRename_FailsIfANameConflictOccurs";
    final String renamed = fileName + "_renamed";
    AbstractMeta meta = assistant.createNew();
    AbstractMeta anotherMeta = assistant.createNew();
    RepositoryDirectoryInterface directory = getPublicDir();
    assistant.save(meta, fileName, directory);
    RepositoryDirectoryInterface destFolder = getDirInsidePublic(fileName);
    assistant.save(anotherMeta, renamed, destFolder);
    assistant.rename(meta, destFolder, renamed);
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) AbstractMeta(org.pentaho.di.base.AbstractMeta)

Example 7 with AbstractMeta

use of org.pentaho.di.base.AbstractMeta in project pentaho-kettle by pentaho.

the class PurRepository_MoveAndRename_IT method rename_CreatesNewRevision.

private void rename_CreatesNewRevision(Assistant assistant) throws Exception {
    final String initial = "rename_CreatesNewRevision";
    final String renamed = initial + "_renamed";
    AbstractMeta meta = assistant.createNew();
    assistant.save(meta, initial, getPublicDir());
    List<VersionSummary> historyBefore = unifiedRepository.getVersionSummaries(meta.getObjectId().getId());
    long before = System.currentTimeMillis();
    assistant.rename(meta, renamed);
    long after = System.currentTimeMillis();
    List<VersionSummary> historyAfter = unifiedRepository.getVersionSummaries(meta.getObjectId().getId());
    assertEquals(historyBefore.size() + 1, historyAfter.size());
    long newRevisionTs = historyAfter.get(historyAfter.size() - 1).getDate().getTime();
    assertTrue(String.format("%d <= %d <= %d", before, newRevisionTs, after), (before <= newRevisionTs) && (newRevisionTs <= after));
}
Also used : AbstractMeta(org.pentaho.di.base.AbstractMeta) VersionSummary(org.pentaho.platform.api.repository2.unified.VersionSummary)

Example 8 with AbstractMeta

use of org.pentaho.di.base.AbstractMeta in project pentaho-kettle by pentaho.

the class SpoonTabsDelegate method renameTabs.

/**
 * Rename the tabs
 */
public void renameTabs() {
    List<TabMapEntry> list = new ArrayList<TabMapEntry>(tabMap);
    for (TabMapEntry entry : list) {
        if (entry.getTabItem().isDisposed()) {
            // this should not be in the map, get rid of it.
            tabMap.remove(entry.getObjectName());
            continue;
        }
        // TabItem before = entry.getTabItem();
        // PDI-1683: need to get the String here, otherwise using only the "before" instance below, the reference gets
        // changed and result is always the same
        // String beforeText=before.getText();
        // 
        Object managedObject = entry.getObject().getManagedObject();
        if (managedObject != null) {
            if (entry.getObject() instanceof AbstractGraph) {
                AbstractMeta meta = (AbstractMeta) managedObject;
                String tabText = makeTabName(meta, entry.isShowingLocation());
                entry.getTabItem().setText(tabText);
                String toolTipText = BaseMessages.getString(PKG, "Spoon.TabTrans.Tooltip", tabText);
                if (entry.getObject() instanceof JobGraph) {
                    toolTipText = BaseMessages.getString(PKG, "Spoon.TabJob.Tooltip", tabText);
                }
                if (Const.isWindows() && !Utils.isEmpty(meta.getFilename())) {
                    toolTipText += Const.CR + Const.CR + meta.getFilename();
                }
                entry.getTabItem().setToolTipText(toolTipText);
            }
        }
    }
    spoon.setShellText();
}
Also used : AbstractGraph(org.pentaho.di.ui.spoon.AbstractGraph) JobGraph(org.pentaho.di.ui.spoon.job.JobGraph) AbstractMeta(org.pentaho.di.base.AbstractMeta) ArrayList(java.util.ArrayList) FileObject(org.apache.commons.vfs2.FileObject) TabMapEntry(org.pentaho.di.ui.spoon.TabMapEntry)

Example 9 with AbstractMeta

use of org.pentaho.di.base.AbstractMeta in project pentaho-kettle by pentaho.

the class SpoonTabsDelegate method tabClose.

public boolean tabClose(TabItem item, boolean force) throws KettleException {
    // Try to find the tab-item that's being closed.
    boolean createPerms = !RepositorySecurityUI.verifyOperations(Spoon.getInstance().getShell(), Spoon.getInstance().getRepository(), false, RepositoryOperation.MODIFY_TRANSFORMATION, RepositoryOperation.MODIFY_JOB);
    boolean close = true;
    boolean canSave = true;
    for (TabMapEntry entry : tabMap) {
        if (item.equals(entry.getTabItem())) {
            final TabItemInterface itemInterface = entry.getObject();
            final Object managedObject = itemInterface.getManagedObject();
            if (!force) {
                if (managedObject != null && AbstractMeta.class.isAssignableFrom(managedObject.getClass())) {
                    canSave = !((AbstractMeta) managedObject).hasMissingPlugins();
                }
                if (canSave) {
                    // Can we close this tab? Only allow users with create content perms to save
                    if (!itemInterface.canBeClosed() && createPerms) {
                        int reply = itemInterface.showChangedWarning();
                        if (reply == SWT.YES) {
                            close = itemInterface.applyChanges();
                        } else {
                            if (reply == SWT.CANCEL) {
                                close = false;
                            } else {
                                close = true;
                            }
                        }
                    }
                }
            }
            String beforeCloseId = null;
            String afterCloseId = null;
            if (itemInterface instanceof TransGraph) {
                beforeCloseId = KettleExtensionPoint.TransBeforeClose.id;
                afterCloseId = KettleExtensionPoint.TransAfterClose.id;
            } else if (itemInterface instanceof JobGraph) {
                beforeCloseId = KettleExtensionPoint.JobBeforeClose.id;
                afterCloseId = KettleExtensionPoint.JobAfterClose.id;
            }
            if (beforeCloseId != null) {
                try {
                    ExtensionPointHandler.callExtensionPoint(log, beforeCloseId, managedObject);
                } catch (KettleException e) {
                    // prevent tab close
                    close = false;
                }
            }
            // 
            if (close) {
                if (itemInterface instanceof TransGraph) {
                    TransMeta transMeta = (TransMeta) managedObject;
                    spoon.delegates.trans.closeTransformation(transMeta);
                    spoon.refreshTree();
                // spoon.refreshCoreObjects();
                } else if (itemInterface instanceof JobGraph) {
                    JobMeta jobMeta = (JobMeta) managedObject;
                    spoon.delegates.jobs.closeJob(jobMeta);
                    spoon.refreshTree();
                // spoon.refreshCoreObjects();
                } else if (itemInterface instanceof SpoonBrowser) {
                    this.removeTab(entry);
                    spoon.refreshTree();
                } else if (itemInterface instanceof Composite) {
                    Composite comp = (Composite) itemInterface;
                    if (comp != null && !comp.isDisposed()) {
                        comp.dispose();
                    }
                }
                if (afterCloseId != null) {
                    try {
                        ExtensionPointHandler.callExtensionPoint(log, afterCloseId, managedObject);
                    } catch (KettleException e) {
                    // fails gracefully... what else could we do?
                    }
                }
            }
            break;
        }
    }
    return close;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) JobMeta(org.pentaho.di.job.JobMeta) Composite(org.eclipse.swt.widgets.Composite) AbstractMeta(org.pentaho.di.base.AbstractMeta) TransMeta(org.pentaho.di.trans.TransMeta) TransGraph(org.pentaho.di.ui.spoon.trans.TransGraph) TabMapEntry(org.pentaho.di.ui.spoon.TabMapEntry) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) JobGraph(org.pentaho.di.ui.spoon.job.JobGraph) SpoonBrowser(org.pentaho.di.ui.spoon.SpoonBrowser) FileObject(org.apache.commons.vfs2.FileObject) TabItemInterface(org.pentaho.di.ui.spoon.TabItemInterface)

Example 10 with AbstractMeta

use of org.pentaho.di.base.AbstractMeta in project pentaho-kettle by pentaho.

the class DelegatesPrivateDatabasesTest method saveAndLoad_SetIsNotEmpty.

@Test
public void saveAndLoad_SetIsNotEmpty() throws Exception {
    meta.setPrivateDatabases(Collections.singleton(DB_NAME));
    AbstractMeta restored = (AbstractMeta) delegate.dataNodeToElement(delegate.elementToDataNode(meta));
    assertEquals(meta.getPrivateDatabases(), restored.getPrivateDatabases());
}
Also used : AbstractMeta(org.pentaho.di.base.AbstractMeta) Test(org.junit.Test)

Aggregations

AbstractMeta (org.pentaho.di.base.AbstractMeta)50 Test (org.junit.Test)18 KettleException (org.pentaho.di.core.exception.KettleException)10 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)7 LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)6 JobMeta (org.pentaho.di.job.JobMeta)6 TransMeta (org.pentaho.di.trans.TransMeta)6 FileObject (org.apache.commons.vfs2.FileObject)5 ExtensionPointWrapper (org.pentaho.di.ui.core.events.dialog.extension.ExtensionPointWrapper)5 SlaveServer (org.pentaho.di.cluster.SlaveServer)4 EngineMetaInterface (org.pentaho.di.core.EngineMetaInterface)4 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)4 RunConfiguration (org.pentaho.di.engine.configuration.api.RunConfiguration)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 EmbeddedMetaStore (org.pentaho.di.core.attributes.metastore.EmbeddedMetaStore)3 ExtensionPoint (org.pentaho.di.core.extension.ExtensionPoint)3 SimpleLoggingObject (org.pentaho.di.core.logging.SimpleLoggingObject)3 EmbeddedRunConfigurationManager (org.pentaho.di.engine.configuration.impl.EmbeddedRunConfigurationManager)3 RunConfigurationManager (org.pentaho.di.engine.configuration.impl.RunConfigurationManager)3 RepositoryObject (org.pentaho.di.repository.RepositoryObject)3