Search in sources :

Example 16 with RepositoryElementMetaInterface

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

the class RepositoryExplorerDialog method setTreeMenu.

public void setTreeMenu() {
    Menu mTree = new Menu(shell, SWT.POP_UP);
    final TreeItem[] tisel = wTree.getSelection();
    if (tisel.length == 1 || sameCategory(tisel)) {
        final TreeItem ti = tisel[0];
        final int level = ConstUI.getTreeLevel(ti);
        final String[] path = ConstUI.getTreeStrings(ti);
        final String fullPath = ConstUI.getTreePath(ti, 0);
        final String item = ti.getText();
        final RepositoryElementMetaInterface repositoryObject = objectMap.get(fullPath);
        int cat = getItemCategory(ti);
        switch(cat) {
            case ITEM_CATEGORY_ROOT:
                // Export all
                MenuItem miExp = new MenuItem(mTree, SWT.PUSH);
                miExp.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Objects.ExportAll"));
                SelectionAdapter lsExp = new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        exportAll(directoryTree);
                    }
                };
                miExp.addSelectionListener(lsExp);
                // Import all
                MenuItem miImp = new MenuItem(mTree, SWT.PUSH);
                miImp.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Objects.ImportAll"));
                SelectionAdapter lsImp = new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        importAll();
                    }
                };
                miImp.addSelectionListener(lsImp);
                miImp.setEnabled(!readonly);
                // Export transMeta
                MenuItem miTrans = new MenuItem(mTree, SWT.PUSH);
                miTrans.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Objects.ExportTrans"));
                SelectionAdapter lsTrans = new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        exportTransformations(directoryTree);
                    }
                };
                miTrans.addSelectionListener(lsTrans);
                // Export jobs
                MenuItem miJobs = new MenuItem(mTree, SWT.PUSH);
                miJobs.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Objects.ExportJob"));
                SelectionAdapter lsJobs = new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        exportJobs(directoryTree);
                    }
                };
                miJobs.addSelectionListener(lsJobs);
                break;
            case ITEM_CATEGORY_DATABASES_ROOT:
                // New database
                MenuItem miNew = new MenuItem(mTree, SWT.PUSH);
                miNew.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.ConnectionsRoot.New"));
                SelectionAdapter lsNew = new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        newDatabase();
                    }
                };
                miNew.addSelectionListener(lsNew);
                miNew.setEnabled(!readonly);
                break;
            case ITEM_CATEGORY_DATABASE:
                // New database
                miNew = new MenuItem(mTree, SWT.PUSH);
                miNew.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Connections.New"));
                lsNew = new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        newDatabase();
                    }
                };
                miNew.addSelectionListener(lsNew);
                miNew.setEnabled(!readonly);
                // Edit database info
                MenuItem miEdit = new MenuItem(mTree, SWT.PUSH);
                miEdit.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Connections.Edit"));
                SelectionAdapter lsEdit = new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        editDatabase(item);
                    }
                };
                miEdit.addSelectionListener(lsEdit);
                miEdit.setEnabled(!readonly);
                // Delete database info
                MenuItem miDel = new MenuItem(mTree, SWT.PUSH);
                miDel.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Connections.Delete"));
                SelectionAdapter lsDel = new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        delDatabase(item);
                    }
                };
                miDel.addSelectionListener(lsDel);
                miDel.setEnabled(!readonly);
                break;
            case ITEM_CATEGORY_SLAVES_ROOT:
                // New slave
                miNew = new MenuItem(mTree, SWT.PUSH);
                miNew.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Slave.New"));
                lsNew = new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        newSlaveServer();
                    }
                };
                miNew.addSelectionListener(lsNew);
                miNew.setEnabled(!readonly);
                break;
            case ITEM_CATEGORY_SLAVE:
                // New slave
                miNew = new MenuItem(mTree, SWT.PUSH);
                miNew.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Slave.New"));
                lsNew = new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        newSlaveServer();
                    }
                };
                miNew.addSelectionListener(lsNew);
                miNew.setEnabled(!readonly);
                // Edit slave
                miEdit = new MenuItem(mTree, SWT.PUSH);
                miEdit.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Slave.Edit"));
                lsEdit = new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        editSlaveServer(item);
                    }
                };
                miEdit.addSelectionListener(lsEdit);
                miEdit.setEnabled(!readonly);
                // Delete slave
                miDel = new MenuItem(mTree, SWT.PUSH);
                miDel.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Slave.Delete"));
                lsDel = new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        delSlaveServer(item);
                    }
                };
                miDel.addSelectionListener(lsDel);
                miDel.setEnabled(!readonly);
                break;
            case ITEM_CATEGORY_PARTITIONS_ROOT:
                // New partition schema
                miNew = new MenuItem(mTree, SWT.PUSH);
                miNew.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.PartitionSchema.New"));
                lsNew = new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        newPartitionSchema();
                    }
                };
                miNew.addSelectionListener(lsNew);
                miNew.setEnabled(!readonly);
                break;
            case ITEM_CATEGORY_PARTITION:
                // New partition schema
                miNew = new MenuItem(mTree, SWT.PUSH);
                miNew.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.PartitionSchema.New"));
                lsNew = new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        newPartitionSchema();
                    }
                };
                miNew.addSelectionListener(lsNew);
                miNew.setEnabled(!readonly);
                // Edit partition schema
                miEdit = new MenuItem(mTree, SWT.PUSH);
                miEdit.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.PartitionSchema.Edit"));
                lsEdit = new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        editPartitionSchema(item);
                    }
                };
                miEdit.addSelectionListener(lsEdit);
                miEdit.setEnabled(!readonly);
                // Delete partition schema
                miDel = new MenuItem(mTree, SWT.PUSH);
                miDel.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.PartitionSchema.Delete"));
                lsDel = new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        delPartitionSchema(item);
                    }
                };
                miDel.addSelectionListener(lsDel);
                miDel.setEnabled(!readonly);
                break;
            case ITEM_CATEGORY_CLUSTERS_ROOT:
                // New cluster
                miNew = new MenuItem(mTree, SWT.PUSH);
                miNew.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Cluster.New"));
                lsNew = new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        newCluster();
                    }
                };
                miNew.addSelectionListener(lsNew);
                miNew.setEnabled(!readonly);
                break;
            case ITEM_CATEGORY_CLUSTER:
                // New cluster
                miNew = new MenuItem(mTree, SWT.PUSH);
                miNew.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Cluster.New"));
                lsNew = new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        newCluster();
                    }
                };
                miNew.addSelectionListener(lsNew);
                miNew.setEnabled(!readonly);
                // Edit cluster
                miEdit = new MenuItem(mTree, SWT.PUSH);
                miEdit.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Cluster.Edit"));
                lsEdit = new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        editCluster(item);
                    }
                };
                miEdit.addSelectionListener(lsEdit);
                miEdit.setEnabled(!readonly);
                // Delete cluster
                miDel = new MenuItem(mTree, SWT.PUSH);
                miDel.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Cluster.Delete"));
                lsDel = new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        delCluster(item);
                    }
                };
                miDel.addSelectionListener(lsDel);
                miDel.setEnabled(!readonly);
                break;
            case ITEM_CATEGORY_TRANSFORMATIONS_ROOT:
                break;
            case ITEM_CATEGORY_TRANSFORMATION:
                if (level >= 2 && repositoryObject != null) {
                    final RepositoryDirectoryInterface repdir = repositoryObject.getRepositoryDirectory();
                    if (tisel.length == 1) {
                        if (!repositoryObject.isDeleted()) {
                            // Open transformation...
                            MenuItem miOpen = new MenuItem(mTree, SWT.PUSH);
                            miOpen.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Transformations.Open"));
                            miOpen.addSelectionListener(new SelectionAdapter() {

                                @Override
                                public void widgetSelected(SelectionEvent e) {
                                    openTransformation(item, repdir);
                                }
                            });
                            // Rename transformation
                            MenuItem miRen = new MenuItem(mTree, SWT.PUSH);
                            miRen.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Transformations.Rename"));
                            miRen.addSelectionListener(new SelectionAdapter() {

                                @Override
                                public void widgetSelected(SelectionEvent e) {
                                    renameTransformation(item, repdir);
                                }
                            });
                            miRen.setEnabled(!readonly);
                        }
                    }
                    if (repositoryObject.isDeleted()) {
                        if (capabilities.supportsRevisions()) {
                            // Restore transformation
                            MenuItem miRestore = new MenuItem(mTree, SWT.PUSH);
                            miRestore.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Transformations.Restore"));
                            miRestore.addSelectionListener(new SelectionAdapter() {

                                @Override
                                public void widgetSelected(SelectionEvent e) {
                                    restoreSelectedObjects();
                                }
                            });
                        }
                    } else {
                        // Delete transformation
                        miDel = new MenuItem(mTree, SWT.PUSH);
                        miDel.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Transformations.Delete"));
                        miDel.addSelectionListener(new SelectionAdapter() {

                            @Override
                            public void widgetSelected(SelectionEvent e) {
                                delSelectedObjects();
                            }
                        });
                        miDel.setEnabled(!readonly);
                    }
                }
                break;
            case ITEM_CATEGORY_JOB_DIRECTORY:
            case ITEM_CATEGORY_TRANSFORMATION_DIRECTORY:
                if (level >= 2) {
                    // The first levels of path[] don't belong to the path to this directory!
                    String[] realpath = new String[level - 1];
                    for (int i = 0; i < realpath.length; i++) {
                        realpath[i] = path[i + 2];
                    }
                    // Find the directory in the directory tree...
                    final RepositoryDirectoryInterface repdir = directoryTree.findDirectory(realpath);
                    // Export xforms and jobs from directory
                    miExp = new MenuItem(mTree, SWT.PUSH);
                    miExp.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Objects.ExportAll"));
                    lsExp = new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            exportAll(repdir);
                        }
                    };
                    miExp.addSelectionListener(lsExp);
                    miExp.setEnabled(!readonly);
                    if (cat == ITEM_CATEGORY_TRANSFORMATION_DIRECTORY) {
                        // Export transMeta
                        miTrans = new MenuItem(mTree, SWT.PUSH);
                        miTrans.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Objects.ExportTrans"));
                        lsTrans = new SelectionAdapter() {

                            @Override
                            public void widgetSelected(SelectionEvent e) {
                                exportTransformations(repdir);
                            }
                        };
                        miTrans.addSelectionListener(lsTrans);
                    }
                    if (cat == ITEM_CATEGORY_JOB_DIRECTORY) {
                        // Export jobs
                        miJobs = new MenuItem(mTree, SWT.PUSH);
                        miJobs.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Objects.ExportJob"));
                        lsJobs = new SelectionAdapter() {

                            @Override
                            public void widgetSelected(SelectionEvent e) {
                                exportJobs(repdir);
                            }
                        };
                        miJobs.addSelectionListener(lsJobs);
                    }
                    // create directory...
                    MenuItem miCreate = new MenuItem(mTree, SWT.PUSH);
                    miCreate.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.TransDirectory.Create"));
                    miCreate.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            createDirectory(ti, repdir);
                        }
                    });
                    if (level > 2) {
                        // Can't rename or delete root directory...
                        // Rename directory
                        MenuItem miRename = new MenuItem(mTree, SWT.PUSH);
                        miRename.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.TransDirectory.Rename"));
                        miRename.addSelectionListener(new SelectionAdapter() {

                            @Override
                            public void widgetSelected(SelectionEvent e) {
                                renameDirectory(ti, repdir);
                            }
                        });
                        // Delete directory
                        MenuItem miDelete = new MenuItem(mTree, SWT.PUSH);
                        miDelete.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.TransDirectory.Delete"));
                        miDelete.addSelectionListener(new SelectionAdapter() {

                            @Override
                            public void widgetSelected(SelectionEvent e) {
                                delDirectory(ti, repdir);
                            }
                        });
                    }
                }
                break;
            case ITEM_CATEGORY_JOBS_ROOT:
                break;
            case ITEM_CATEGORY_JOB:
                if (level >= 2 && repositoryObject != null) {
                    final RepositoryDirectoryInterface repdir = repositoryObject.getRepositoryDirectory();
                    if (tisel.length == 1) {
                        if (!repositoryObject.isDeleted()) {
                            // Open job...
                            MenuItem miOpen = new MenuItem(mTree, SWT.PUSH);
                            miOpen.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Jobs.Open"));
                            miOpen.addSelectionListener(new SelectionAdapter() {

                                @Override
                                public void widgetSelected(SelectionEvent e) {
                                    openJob(item, repdir);
                                }
                            });
                            // Rename job
                            MenuItem miRen = new MenuItem(mTree, SWT.PUSH);
                            miRen.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Jobs.Rename"));
                            miRen.addSelectionListener(new SelectionAdapter() {

                                @Override
                                public void widgetSelected(SelectionEvent e) {
                                    renameJob(ti, item, repdir);
                                }
                            });
                            miRen.setEnabled(!readonly);
                        }
                    }
                    if (repositoryObject.isDeleted()) {
                        if (capabilities.supportsRevisions()) {
                            // Restore job
                            MenuItem miRestore = new MenuItem(mTree, SWT.PUSH);
                            miRestore.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Jobs.Restore"));
                            miRestore.addSelectionListener(new SelectionAdapter() {

                                @Override
                                public void widgetSelected(SelectionEvent e) {
                                    restoreSelectedObjects();
                                }
                            });
                        }
                    } else {
                        // Delete job
                        miDel = new MenuItem(mTree, SWT.PUSH);
                        miDel.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Jobs.Delete"));
                        miDel.addSelectionListener(new SelectionAdapter() {

                            @Override
                            public void widgetSelected(SelectionEvent e) {
                                delSelectedObjects();
                            }
                        });
                        miDel.setEnabled(!readonly);
                    }
                }
                break;
            case ITEM_CATEGORY_USERS_ROOT:
                mTree = new Menu(shell, SWT.POP_UP);
                // New user
                miNew = new MenuItem(mTree, SWT.PUSH);
                miNew.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.UsersRoot.New"));
                lsNew = new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        newUser();
                    }
                };
                miNew.addSelectionListener(lsNew);
                miNew.setEnabled(!readonly);
                break;
            case ITEM_CATEGORY_USER:
                // New user
                miNew = new MenuItem(mTree, SWT.PUSH);
                miNew.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Users.New"));
                lsNew = new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        newUser();
                    }
                };
                miNew.addSelectionListener(lsNew);
                miNew.setEnabled(!readonly);
                // Edit user info
                miEdit = new MenuItem(mTree, SWT.PUSH);
                miEdit.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Users.Edit"));
                lsEdit = new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        editUser(item);
                    }
                };
                miEdit.addSelectionListener(lsEdit);
                miEdit.setEnabled(!readonly);
                // Rename user
                MenuItem miRen = new MenuItem(mTree, SWT.PUSH);
                miRen.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Users.Rename"));
                SelectionAdapter lsRen = new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        renameUser();
                    }
                };
                miRen.addSelectionListener(lsRen);
                miRen.setEnabled(!readonly);
                // Delete user info
                miDel = new MenuItem(mTree, SWT.PUSH);
                miDel.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.PopupMenu.Users.Delete"));
                lsDel = new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        delUser(item);
                    }
                };
                miDel.addSelectionListener(lsDel);
                miDel.setEnabled(!readonly);
                break;
            default:
                mTree = null;
        }
    }
    ConstUI.displayMenu(mTree, wTree);
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) TreeItem(org.eclipse.swt.widgets.TreeItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Example 17 with RepositoryElementMetaInterface

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

the class RepositoryExplorerDialog method restoreSelectedObjects.

public boolean restoreSelectedObjects() {
    TreeItem[] items = wTree.getSelection();
    boolean error = false;
    for (int i = 0; i < items.length; i++) {
        final RepositoryElementMetaInterface repositoryObject = objectMap.get(ConstUI.getTreePath(items[i], 0));
        if (repositoryObject != null) {
            try {
                rep.undeleteObject(repositoryObject);
            } catch (Exception e) {
                new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Delete.ErrorRestoring.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Delete.ErrorRestoring.Message"), 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) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Example 18 with RepositoryElementMetaInterface

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

the class LazyUnifiedRepositoryDirectory method getRepositoryObjects.

@Override
public List<RepositoryElementMetaInterface> getRepositoryObjects() {
    if (fileChildren == null) {
        fileChildren = new ArrayList<RepositoryElementMetaInterface>();
        synchronized (fileChildren) {
            UnifiedRepositoryLockService lockService = (UnifiedRepositoryLockService) registry.getService(ILockService.class);
            RepositoryFileTree tree = repository.getTree(new RepositoryRequest(this.self.getPath(), true, 1, null));
            for (RepositoryFileTree tchild : tree.getChildren()) {
                RepositoryFile child = tchild.getFile();
                if (!child.isFolder()) {
                    RepositoryLock lock = null;
                    try {
                        lock = lockService.getLock(child);
                        RepositoryObjectType objectType = PurRepository.getObjectType(child.getName());
                        EERepositoryObject repositoryObject = new EERepositoryObject(child, this, null, objectType, null, lock, false);
                        repositoryObject.setVersioningEnabled(tchild.getVersioningEnabled());
                        repositoryObject.setVersionCommentEnabled(tchild.getVersionCommentEnabled());
                        fileChildren.add(repositoryObject);
                    } catch (KettleException e) {
                        logger.error("Error converting Unified Repository file to PDI RepositoryObject: " + child.getPath() + ". File will be skipped", e);
                    }
                }
            }
        }
    }
    return fileChildren;
}
Also used : EERepositoryObject(org.pentaho.di.repository.pur.model.EERepositoryObject) KettleException(org.pentaho.di.core.exception.KettleException) ILockService(org.pentaho.di.ui.repository.pur.services.ILockService) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryLock(org.pentaho.di.repository.pur.model.RepositoryLock) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Example 19 with RepositoryElementMetaInterface

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

the class PurRepository method fillRepositoryDirectoryFromTree.

private void fillRepositoryDirectoryFromTree(final RepositoryDirectoryInterface parentDir, final RepositoryFileTree treeNode) throws KettleException {
    try {
        List<RepositoryElementMetaInterface> fileChildren = new ArrayList<RepositoryElementMetaInterface>();
        List<RepositoryFileTree> children = treeNode.getChildren();
        if (children != null) {
            for (RepositoryFileTree child : children) {
                if (child.getFile().isFolder()) {
                    RepositoryDirectory dir = new RepositoryDirectory(parentDir, child.getFile().getName());
                    dir.setObjectId(new StringObjectId(child.getFile().getId().toString()));
                    parentDir.addSubdirectory(dir);
                    fillRepositoryDirectoryFromTree(dir, child);
                } else {
                    // a real file, like a Transformation or Job
                    RepositoryLock lock = unifiedRepositoryLockService.getLock(child.getFile());
                    RepositoryObjectType objectType = getObjectType(child.getFile().getName());
                    fileChildren.add(new EERepositoryObject(child, parentDir, null, objectType, null, lock, false));
                }
            }
            parentDir.setRepositoryObjects(fileChildren);
        }
    } catch (Exception e) {
        throw new KettleException("Unable to load directory structure from repository", e);
    }
}
Also used : EERepositoryObject(org.pentaho.di.repository.pur.model.EERepositoryObject) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) ArrayList(java.util.ArrayList) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) RepositoryLock(org.pentaho.di.repository.pur.model.RepositoryLock) StringObjectId(org.pentaho.di.repository.StringObjectId) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) 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) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Example 20 with RepositoryElementMetaInterface

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

the class GetRepositoryNames method getRepositoryObjects.

@SuppressWarnings("deprecation")
private List<RepositoryElementMetaInterface> getRepositoryObjects() throws KettleException {
    try {
        // The repository is available in the parent transformation metadata
        // 
        Repository repository = getTransMeta().getRepository();
        // Now populate the list...
        // 
        List<RepositoryElementMetaInterface> list = new ArrayList<RepositoryElementMetaInterface>();
        if (repository instanceof RepositoryExtended) {
            RepositoryExtended extendedRep = (RepositoryExtended) repository;
            for (int i = 0; i < meta.getDirectory().length; i++) {
                String directoryPath = environmentSubstitute(meta.getDirectory()[i]);
                String filter = null;
                // by default we look for current level
                int depth = 0;
                if (meta.getObjectTypeSelection().areTransformationsSelected()) {
                    filter = "*.ktr";
                }
                if (meta.getObjectTypeSelection().areJobsSelected()) {
                    // if we have selected the job and transformation than we have applied filter with both condition
                    filter = Utils.isEmpty(filter) ? "*.kjb" : filter + "|*.kjb";
                }
                // should include unlimited subfolder
                if (meta.getIncludeSubFolders()[i]) {
                    depth = -1;
                }
                RepositoryDirectoryInterface directory = extendedRep.loadRepositoryDirectoryTree(directoryPath, filter, depth, BooleanUtils.isTrue(repository.getUserInfo().isAdmin()), false, false);
                list.addAll(getRepositoryObjects(directory, environmentSubstitute(meta.getNameMask()[i]), environmentSubstitute(meta.getExcludeNameMask()[i])));
            }
        } else {
            // Get the repository directory tree.
            // 
            RepositoryDirectoryInterface tree = repository.loadRepositoryDirectoryTree();
            // 
            for (int i = 0; i < meta.getDirectory().length; i++) {
                RepositoryDirectoryInterface dir = tree.findDirectory(environmentSubstitute(meta.getDirectory()[i]));
                if (dir != null) {
                    List<RepositoryElementMetaInterface> objects = getRepositoryObjects(repository, dir, meta.getIncludeSubFolders()[i], environmentSubstitute(meta.getNameMask()[i]), environmentSubstitute(meta.getExcludeNameMask()[i]));
                    list.addAll(objects);
                }
            }
        }
        return list;
    } catch (Exception e) {
        throw new KettleException("Unable to get the list of repository objects from the repository", e);
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) Repository(org.pentaho.di.repository.Repository) ArrayList(java.util.ArrayList) RepositoryExtended(org.pentaho.di.repository.RepositoryExtended) KettleException(org.pentaho.di.core.exception.KettleException) 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