Search in sources :

Example 11 with RepositoryElementMetaInterface

use of org.pentaho.di.repository.RepositoryElementMetaInterface in project pentaho-kettle by pentaho.

the class TrashBrowseController method undelete.

public void undelete() {
    // make a copy because the selected trash items changes as soon as trashService.undelete is called
    List<UIDeletedObject> selectedTrashFileItemsSnapshot = new ArrayList<UIDeletedObject>(selectedTrashFileItems);
    if (selectedTrashFileItemsSnapshot != null && selectedTrashFileItemsSnapshot.size() > 0) {
        List<ObjectId> ids = new ArrayList<ObjectId>();
        for (UIDeletedObject uiObj : selectedTrashFileItemsSnapshot) {
            ids.add(uiObj.getId());
        }
        try {
            trashService.undelete(ids);
            setTrash(trashService.getTrash());
            for (UIDeletedObject uiObj : selectedTrashFileItemsSnapshot) {
                // find the closest UIRepositoryDirectory that is in the dirMap
                RepositoryDirectoryInterface dir = repository.findDirectory(uiObj.getOriginalParentPath());
                while (dir != null && dirMap.get(dir.getObjectId()) == null) {
                    dir = dir.getParent();
                }
                // now refresh that UIRepositoryDirectory so that the file/folders deck instantly refreshes on undelete
                if (dir != null) {
                    dirMap.get(dir.getObjectId()).refresh();
                }
                // if transformation or directory with transformations call extension to restore data services references.
                if (RepositoryObjectType.TRANSFORMATION.name().equals(uiObj.getType())) {
                    TransMeta transMeta = repository.loadTransformation(uiObj.getId(), null);
                    ExtensionPointHandler.callExtensionPoint(LogChannel.GENERAL, KettleExtensionPoint.TransAfterOpen.id, transMeta);
                    transMeta.clearChanged();
                } else if (!RepositoryObjectType.JOB.name().equals(uiObj.getType())) {
                    // if not a transformation and not a job then is a Directory
                    RepositoryDirectoryInterface actualDir = repository.findDirectory(uiObj.getOriginalParentPath() + RepositoryDirectory.DIRECTORY_SEPARATOR + uiObj.getName());
                    if (actualDir != null) {
                        List<RepositoryElementMetaInterface> transformations = new ArrayList<>();
                        getAllTransformations(actualDir, transformations);
                        for (RepositoryElementMetaInterface repositoryElementMetaInterface : transformations) {
                            TransMeta transMeta = repository.loadTransformation(repositoryElementMetaInterface.getObjectId(), null);
                            ExtensionPointHandler.callExtensionPoint(LogChannel.GENERAL, KettleExtensionPoint.TransAfterOpen.id, transMeta);
                            transMeta.clearChanged();
                        }
                    } else {
                        displayExceptionMessage(BaseMessages.getString(PKG, "TrashBrowseController.UnableToRestoreDirectory", uiObj.getOriginalParentPath() + RepositoryDirectory.DIRECTORY_SEPARATOR + uiObj.getName()));
                    }
                }
            }
            deck.setSelectedIndex(1);
        } catch (Throwable th) {
            if (mainController == null || !mainController.handleLostRepository(th)) {
                displayExceptionMessage(BaseMessages.getString(PKG, "TrashBrowseController.UnableToRestoreFile", // $NON-NLS-1$
                th.getLocalizedMessage()));
            }
        }
    } else {
        // ui probably allowed the button to be enabled when it shouldn't have been enabled
        throw new RuntimeException();
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) ObjectId(org.pentaho.di.repository.ObjectId) ArrayList(java.util.ArrayList) TransMeta(org.pentaho.di.trans.TransMeta) ArrayList(java.util.ArrayList) List(java.util.List) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Example 12 with RepositoryElementMetaInterface

use of org.pentaho.di.repository.RepositoryElementMetaInterface in project pentaho-kettle by pentaho.

the class UIRepositoryDirectory method getRepositoryObjects.

// TODO: Abstract working model; should throw RepositoryException
// TODO: We will need a way to reset this cache when a directory or element changes
public UIRepositoryObjects getRepositoryObjects() throws KettleException {
    if (kidElementCache != null) {
        return kidElementCache;
    }
    if (kidElementCache == null) {
        kidElementCache = new UIRepositoryObjects() {

            private static final long serialVersionUID = 6901479331535375165L;

            public void onRemove(UIRepositoryObject child) {
                List<? extends RepositoryElementMetaInterface> dirRepoObjects = getDirectory().getRepositoryObjects();
                if (dirRepoObjects != null) {
                    Iterator<? extends RepositoryElementMetaInterface> iter = dirRepoObjects.iterator();
                    while (iter.hasNext()) {
                        RepositoryElementMetaInterface e = iter.next();
                        if (child.getObjectId().equals(e.getObjectId())) {
                            iter.remove();
                            return;
                        }
                    }
                }
            }
        };
    }
    for (UIRepositoryObject child : getChildren()) {
        kidElementCache.add(child);
    }
    List<RepositoryElementMetaInterface> jobsAndTransformations = getDirectory().getRepositoryObjects();
    if (jobsAndTransformations == null) {
        RepositoryDirectoryInterface dir = getDirectory();
        jobsAndTransformations = rep.getJobAndTransformationObjects(dir.getObjectId(), false);
        dir.setRepositoryObjects(jobsAndTransformations);
    }
    for (RepositoryElementMetaInterface child : jobsAndTransformations) {
        if (child.getObjectType().equals(RepositoryObjectType.TRANSFORMATION)) {
            try {
                kidElementCache.add(UIObjectRegistry.getInstance().constructUITransformation(child, this, rep));
            } catch (UIObjectCreationException e) {
                kidElementCache.add(new UITransformation(child, this, rep));
            }
        } else if (child.getObjectType().equals(RepositoryObjectType.JOB)) {
            try {
                kidElementCache.add(UIObjectRegistry.getInstance().constructUIJob(child, this, rep));
            } catch (UIObjectCreationException e) {
                kidElementCache.add(new UIJob(child, this, rep));
            }
        }
    }
    return kidElementCache;
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) Iterator(java.util.Iterator) List(java.util.List) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Example 13 with RepositoryElementMetaInterface

use of org.pentaho.di.repository.RepositoryElementMetaInterface in project pentaho-kettle by pentaho.

the class RepositoryDirectoryUI method loadRepositoryObjects.

protected static List<RepositoryElementMetaInterface> loadRepositoryObjects(RepositoryDirectoryInterface dir, boolean getTransformations, boolean getJobs, Repository rep) throws KettleDatabaseException {
    // Then show the transformations & jobs in that directory...
    List<RepositoryElementMetaInterface> repositoryObjects = new ArrayList<RepositoryElementMetaInterface>();
    if (dir.getRepositoryObjects() == null) {
        try {
            dir.setRepositoryObjects(rep.getJobAndTransformationObjects(dir.getObjectId(), false));
        } catch (KettleException e) {
            throw new KettleDatabaseException(e);
        }
    }
    List<RepositoryObjectType> allowedTypes = new ArrayList<>(2);
    if (getTransformations) {
        allowedTypes.add(RepositoryObjectType.TRANSFORMATION);
    }
    if (getJobs) {
        allowedTypes.add(RepositoryObjectType.JOB);
    }
    for (RepositoryElementMetaInterface repoObject : dir.getRepositoryObjects()) {
        if (allowedTypes.contains(repoObject.getObjectType())) {
            repositoryObjects.add(repoObject);
        }
    }
    return repositoryObjects;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) ArrayList(java.util.ArrayList) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Example 14 with RepositoryElementMetaInterface

use of org.pentaho.di.repository.RepositoryElementMetaInterface in project pentaho-kettle by pentaho.

the class RepositoryDirectoryUI method getTreeWithNames.

/**
 * Set the name of this directory on a TreeItem. Also, create children on this TreeItem to reflect the subdirectories.
 * In these sub-directories, fill in the available transformations from the repository.
 *
 * @param ti
 *          The TreeItem to set the name on and to create the subdirectories
 * @param rep
 *          The repository
 * @param objectMap
 *          The tree path to repository object mapping to populate.
 * @param dircolor
 *          The color in which the directories will be drawn.
 * @param sortPosition
 *          The sort position
 * @param ascending
 *          The ascending flag
 * @param getTransformations
 *          Include transformations in the tree or not
 * @param getJobs
 *          Include jobs in the tree or not
 * @throws KettleDatabaseException
 */
public static void getTreeWithNames(TreeItem ti, Repository rep, Color dircolor, int sortPosition, boolean includeDeleted, boolean ascending, boolean getTransformations, boolean getJobs, RepositoryDirectoryInterface dir, String filterString, Pattern pattern) throws KettleDatabaseException {
    ti.setText(dir.getName());
    ti.setData(dir);
    ti.setData("isFolder", true);
    // First, we draw the directories
    List<RepositoryDirectoryInterface> children = dir.getChildren();
    Collections.sort(children, new Comparator<RepositoryDirectoryInterface>() {

        @Override
        public int compare(RepositoryDirectoryInterface o1, RepositoryDirectoryInterface o2) {
            return o1.getName().compareToIgnoreCase(o2.getName());
        }
    });
    for (int i = 0; i < children.size(); i++) {
        RepositoryDirectory subdir = (RepositoryDirectory) children.get(i);
        TreeItem subti = new TreeItem(ti, SWT.NONE);
        subti.setImage(GUIResource.getInstance().getImageFolder());
        subti.setData("isFolder", true);
        getTreeWithNames(subti, rep, dircolor, sortPosition, includeDeleted, ascending, getTransformations, getJobs, subdir, filterString, pattern);
    }
    List<RepositoryElementMetaInterface> repositoryObjects = loadRepositoryObjects(dir, getTransformations, getJobs, rep);
    // Sort the directory list appropriately...
    RepositoryObject.sortRepositoryObjects(repositoryObjects, sortPosition, ascending);
    addToTree(ti, filterString, pattern, repositoryObjects);
    ti.setExpanded(dir.isRoot());
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) TreeItem(org.eclipse.swt.widgets.TreeItem) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Example 15 with RepositoryElementMetaInterface

use of org.pentaho.di.repository.RepositoryElementMetaInterface in project pentaho-kettle by pentaho.

the class RepositoryExplorerDialog method delSelectedObjects.

public boolean delSelectedObjects() {
    TreeItem[] items = wTree.getSelection();
    boolean error = false;
    MessageBox mb = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO);
    mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Delete.Confirm.Message1") + (items.length > 1 ? BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Delete.Confirm.Message2") + items.length + BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Delete.Confirm.Message3") : BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Delete.Confirm.Message4")));
    mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Delete.Confirm.Title"));
    int answer = mb.open();
    if (answer != SWT.YES) {
        return false;
    }
    for (int i = 0; i < items.length; i++) {
        final RepositoryElementMetaInterface repositoryObject = objectMap.get(ConstUI.getTreePath(items[i], 0));
        if (repositoryObject != null) {
            try {
                switch(repositoryObject.getObjectType()) {
                    case TRANSFORMATION:
                        rep.deleteTransformation(repositoryObject.getObjectId());
                        break;
                    case JOB:
                        rep.deleteJob(repositoryObject.getObjectId());
                        break;
                    default:
                        break;
                }
            } catch (Exception e) {
                new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Delete.ErrorRemoving.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Delete.ErrorRemoving.Message") + repositoryObject.getName() + "]", e);
                error = true;
            }
        }
    }
    refreshTree();
    return !error;
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) IOException(java.io.IOException) KettleException(org.pentaho.di.core.exception.KettleException) MessageBox(org.eclipse.swt.widgets.MessageBox) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Aggregations

RepositoryElementMetaInterface (org.pentaho.di.repository.RepositoryElementMetaInterface)33 Test (org.junit.Test)13 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)13 ArrayList (java.util.ArrayList)11 KettleException (org.pentaho.di.core.exception.KettleException)11 RepositoryDirectory (org.pentaho.di.repository.RepositoryDirectory)8 ObjectId (org.pentaho.di.repository.ObjectId)7 LongObjectId (org.pentaho.di.repository.LongObjectId)5 Repository (org.pentaho.di.repository.Repository)5 RepositoryObject (org.pentaho.di.repository.RepositoryObject)5 RepositoryObjectType (org.pentaho.di.repository.RepositoryObjectType)5 StringObjectId (org.pentaho.di.repository.StringObjectId)5 IOException (java.io.IOException)4 List (java.util.List)4 TreeItem (org.eclipse.swt.widgets.TreeItem)4 KettleFileException (org.pentaho.di.core.exception.KettleFileException)4 EERepositoryObject (org.pentaho.di.repository.pur.model.EERepositoryObject)4 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 RepositoryLock (org.pentaho.di.repository.pur.model.RepositoryLock)3