Search in sources :

Example 46 with RepositoryDirectoryInterface

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

the class RepositoryExplorerDialog method renameJob.

public void renameJob(TreeItem treeitem, String jobname, RepositoryDirectoryInterface repositorydir) {
    final TreeItem ti = treeitem;
    final String name = jobname;
    final RepositoryDirectoryInterface repdir = repositorydir;
    TreeEditor editor = new TreeEditor(wTree);
    editor.setItem(ti);
    final Text text = new Text(wTree, SWT.NONE);
    props.setLook(text);
    text.setText(name);
    text.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent arg0) {
            // Focus is lost: apply changes
            String newname = text.getText();
            if (renameJob(name, repdir, newname)) {
                ti.setText(newname);
            }
            text.dispose();
        }
    });
    text.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            // ESC --> Don't change tree item...
            if (e.keyCode == SWT.ESC) {
                text.dispose();
            }
            // ENTER --> Save changes...
            if (e.character == SWT.CR) {
                String newname = text.getText();
                if (renameJob(name, repdir, newname)) {
                    ti.setText(newname);
                }
                text.dispose();
            }
        }
    });
    editor.horizontalAlignment = SWT.LEFT;
    editor.grabHorizontal = true;
    editor.grabVertical = true;
    editor.minimumWidth = 50;
    text.selectAll();
    text.setFocus();
    editor.layout();
    editor.setEditor(text);
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) FocusAdapter(org.eclipse.swt.events.FocusAdapter) TreeEditor(org.eclipse.swt.custom.TreeEditor) TreeItem(org.eclipse.swt.widgets.TreeItem) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Text(org.eclipse.swt.widgets.Text) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 47 with RepositoryDirectoryInterface

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

the class RepositoryExplorerDialog method renameJob.

public boolean renameJob(String name, RepositoryDirectoryInterface repdir) {
    boolean retval = false;
    final TreeItem ti = wTree.getSelection()[0];
    if (ti.getItemCount() == 0) {
        final String fname = name;
        final RepositoryDirectoryInterface frepdir = repdir;
        TreeEditor editor = new TreeEditor(wTree);
        editor.setItem(ti);
        final Text text = new Text(wTree, SWT.NONE);
        props.setLook(text);
        text.setText(name);
        text.addFocusListener(new FocusAdapter() {

            @Override
            public void focusLost(FocusEvent arg0) {
                // Focus is lost: apply changes
                String newname = text.getText();
                if (renameJob(fname, newname, frepdir)) {
                    ti.setText(newname);
                }
                text.dispose();
            }
        });
        text.addKeyListener(new KeyAdapter() {

            @Override
            public void keyPressed(KeyEvent e) {
                // ESC --> Don't change tree item...
                if (e.keyCode == SWT.ESC) {
                    text.dispose();
                }
                // ENTER --> Save changes...
                if (e.character == SWT.CR) {
                    String newname = text.getText();
                    if (renameJob(fname, newname, frepdir)) {
                        ti.setText(newname);
                    }
                    text.dispose();
                }
            }
        });
        editor.horizontalAlignment = SWT.LEFT;
        editor.grabHorizontal = true;
        editor.grabVertical = true;
        editor.minimumWidth = 50;
        text.selectAll();
        text.setFocus();
        editor.layout();
        editor.setEditor(text);
    }
    return retval;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) FocusAdapter(org.eclipse.swt.events.FocusAdapter) TreeEditor(org.eclipse.swt.custom.TreeEditor) TreeItem(org.eclipse.swt.widgets.TreeItem) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Text(org.eclipse.swt.widgets.Text) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 48 with RepositoryDirectoryInterface

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

the class RepositoryExplorerDialog method renameDirectory.

public void renameDirectory(TreeItem treeitem, RepositoryDirectoryInterface rd) {
    final TreeItem ti = treeitem;
    final RepositoryDirectoryInterface repdir = rd;
    final String name = ti.getText();
    TreeEditor editor = new TreeEditor(wTree);
    editor.setItem(ti);
    final Text text = new Text(wTree, SWT.NONE);
    props.setLook(text);
    text.setText(name);
    text.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent arg0) {
            // Focus is lost: apply changes
            String newname = text.getText();
            if (renameDirectory(repdir, name, newname)) {
                ti.setText(newname);
            }
            text.dispose();
        }
    });
    text.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            // ESC --> Don't change tree item...
            if (e.keyCode == SWT.ESC) {
                text.dispose();
            }
            // ENTER --> Save changes...
            if (e.character == SWT.CR) {
                String newname = text.getText();
                if (renameDirectory(repdir, name, newname)) {
                    ti.setText(newname);
                }
                text.dispose();
            }
        }
    });
    editor.horizontalAlignment = SWT.LEFT;
    editor.grabHorizontal = true;
    editor.grabVertical = true;
    editor.minimumWidth = 50;
    text.selectAll();
    text.setFocus();
    editor.layout();
    editor.setEditor(text);
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) FocusAdapter(org.eclipse.swt.events.FocusAdapter) TreeEditor(org.eclipse.swt.custom.TreeEditor) TreeItem(org.eclipse.swt.widgets.TreeItem) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Text(org.eclipse.swt.widgets.Text) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 49 with RepositoryDirectoryInterface

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

the class MetaInjectMeta method loadTransformationMeta.

public static final synchronized TransMeta loadTransformationMeta(MetaInjectMeta injectMeta, Repository rep, IMetaStore metaStore, VariableSpace space) throws KettleException {
    TransMeta mappingTransMeta = null;
    CurrentDirectoryResolver resolver = new CurrentDirectoryResolver();
    VariableSpace tmpSpace = resolver.resolveCurrentDirectory(injectMeta.getSpecificationMethod(), space, rep, injectMeta.getParentStepMeta(), injectMeta.getFileName());
    switch(injectMeta.getSpecificationMethod()) {
        case FILENAME:
            String realFilename = tmpSpace.environmentSubstitute(injectMeta.getFileName());
            try {
                // 
                if (rep != null) {
                    // need to try to load from the repository
                    realFilename = resolver.normalizeSlashes(realFilename);
                    try {
                        String dirStr = realFilename.substring(0, realFilename.lastIndexOf("/"));
                        String tmpFilename = realFilename.substring(realFilename.lastIndexOf("/") + 1);
                        RepositoryDirectoryInterface dir = rep.findDirectory(dirStr);
                        mappingTransMeta = rep.loadTransformation(tmpFilename, dir, null, true, null);
                    } catch (KettleException ke) {
                        // try without extension
                        if (realFilename.endsWith(Const.STRING_TRANS_DEFAULT_EXT)) {
                            try {
                                String tmpFilename = realFilename.substring(realFilename.lastIndexOf("/") + 1, realFilename.indexOf("." + Const.STRING_TRANS_DEFAULT_EXT));
                                String dirStr = realFilename.substring(0, realFilename.lastIndexOf("/"));
                                RepositoryDirectoryInterface dir = rep.findDirectory(dirStr);
                                mappingTransMeta = rep.loadTransformation(tmpFilename, dir, null, true, null);
                            } catch (KettleException ke2) {
                            // fall back to try loading from file system (transMeta is going to be null)
                            }
                        }
                    }
                }
                if (mappingTransMeta == null) {
                    mappingTransMeta = new TransMeta(realFilename, metaStore, rep, false, tmpSpace, null);
                    mappingTransMeta.getLogChannel().logDetailed("Loading Mapping from repository", "Mapping transformation was loaded from XML file [" + realFilename + "]");
                }
            } catch (Exception e) {
                throw new KettleException(BaseMessages.getString(PKG, "MetaInjectMeta.Exception.UnableToLoadTransformationFromFile", realFilename), e);
            }
            break;
        case REPOSITORY_BY_NAME:
            String realTransname = tmpSpace.environmentSubstitute(injectMeta.getTransName());
            String realDirectory = tmpSpace.environmentSubstitute(injectMeta.getDirectoryPath());
            if (rep != null) {
                if (!Utils.isEmpty(realTransname) && !Utils.isEmpty(realDirectory) && rep != null) {
                    RepositoryDirectoryInterface repdir = rep.findDirectory(realDirectory);
                    if (repdir != null) {
                        try {
                            // reads the last revision in the repository...
                            // 
                            // TODO: FIXME: see if we need to pass external MetaStore references to the repository?
                            // 
                            mappingTransMeta = rep.loadTransformation(realTransname, repdir, null, true, null);
                            mappingTransMeta.getLogChannel().logDetailed("Loading Mapping from repository", "Mapping transformation [" + realTransname + "] was loaded from the repository");
                        } catch (Exception e) {
                            throw new KettleException("Unable to load transformation [" + realTransname + "]", e);
                        }
                    } else {
                        throw new KettleException(BaseMessages.getString(PKG, "MetaInjectMeta.Exception.UnableToLoadTransformationFromRepository", realTransname, realDirectory));
                    }
                }
            } else {
                try {
                    mappingTransMeta = new TransMeta(realDirectory + "/" + realTransname, metaStore, rep, true, tmpSpace, null);
                } catch (KettleException ke) {
                    try {
                        // add .ktr extension and try again
                        mappingTransMeta = new TransMeta(realDirectory + "/" + realTransname + "." + Const.STRING_TRANS_DEFAULT_EXT, metaStore, rep, true, tmpSpace, null);
                    } catch (KettleException ke2) {
                        throw new KettleException(BaseMessages.getString(PKG, "StepWithMappingMeta.Exception.UnableToLoadTrans", realTransname) + realDirectory);
                    }
                }
            }
            break;
        case REPOSITORY_BY_REFERENCE:
            // Read the last revision by reference...
            mappingTransMeta = rep.loadTransformation(injectMeta.getTransObjectId(), null);
            break;
        default:
            break;
    }
    // Pass some important information to the mapping transformation metadata:
    // 
    mappingTransMeta.copyVariablesFrom(space);
    mappingTransMeta.setRepository(rep);
    mappingTransMeta.setFilename(mappingTransMeta.getFilename());
    return mappingTransMeta;
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) VariableSpace(org.pentaho.di.core.variables.VariableSpace) TransMeta(org.pentaho.di.trans.TransMeta) CurrentDirectoryResolver(org.pentaho.di.core.util.CurrentDirectoryResolver) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) KettleStepException(org.pentaho.di.core.exception.KettleStepException)

Example 50 with RepositoryDirectoryInterface

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

the class PurRepository method getObjectInformation.

@Override
public RepositoryObject getObjectInformation(ObjectId objectId, RepositoryObjectType objectType) throws KettleException {
    try {
        RepositoryFile repositoryFile;
        try {
            repositoryFile = pur.getFileById(objectId.getId());
        } catch (Exception e) {
            // javax.jcr.Session throws exception, if a node with specified ID does not exist
            // see http://jira.pentaho.com/browse/BISERVER-12758
            log.logError("Error when trying to obtain a file by id: " + objectId.getId(), e);
            return null;
        }
        if (repositoryFile == null) {
            return null;
        }
        RepositoryFileAcl repositoryFileAcl = pur.getAcl(repositoryFile.getId());
        String parentPath = getParentPath(repositoryFile.getPath());
        String name = repositoryFile.getTitle();
        String description = repositoryFile.getDescription();
        Date modifiedDate = repositoryFile.getLastModifiedDate();
        // String creatorId = repositoryFile.getCreatorId();
        String ownerName = repositoryFileAcl != null ? repositoryFileAcl.getOwner().getName() : "";
        boolean deleted = isDeleted(repositoryFile);
        RepositoryDirectoryInterface directory = findDirectory(parentPath);
        return new RepositoryObject(objectId, name, directory, ownerName, modifiedDate, objectType, description, deleted);
    } catch (Exception e) {
        throw new KettleException("Unable to get object information for object with id=" + objectId, e);
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryObject(org.pentaho.di.repository.RepositoryObject) EERepositoryObject(org.pentaho.di.repository.pur.model.EERepositoryObject) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) 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) Date(java.util.Date)

Aggregations

RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)163 KettleException (org.pentaho.di.core.exception.KettleException)68 Test (org.junit.Test)32 TransMeta (org.pentaho.di.trans.TransMeta)30 ObjectId (org.pentaho.di.repository.ObjectId)27 JobMeta (org.pentaho.di.job.JobMeta)23 Repository (org.pentaho.di.repository.Repository)22 ArrayList (java.util.ArrayList)17 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)17 RepositoryDirectory (org.pentaho.di.repository.RepositoryDirectory)15 IOException (java.io.IOException)14 RepositoryElementMetaInterface (org.pentaho.di.repository.RepositoryElementMetaInterface)13 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)11 RepositoryObject (org.pentaho.di.repository.RepositoryObject)11 FileObject (org.apache.commons.vfs2.FileObject)10 List (java.util.List)8 TreeItem (org.eclipse.swt.widgets.TreeItem)8 KettleFileException (org.pentaho.di.core.exception.KettleFileException)8 Date (java.util.Date)7 FileSystemException (org.apache.commons.vfs2.FileSystemException)7