Search in sources :

Example 1 with RepositoryElementMetaInterface

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

the class KettleFileRepository method getTransformationObjects.

@Override
public List<RepositoryElementMetaInterface> getTransformationObjects(ObjectId idDirectory, boolean includeDeleted) throws KettleException {
    try {
        List<RepositoryElementMetaInterface> list = new ArrayList<RepositoryElementMetaInterface>();
        RepositoryDirectoryInterface tree = loadRepositoryDirectoryTree();
        RepositoryDirectoryInterface directory = tree.findDirectory(idDirectory);
        String folderName = calcDirectoryName(directory);
        FileObject folder = KettleVFS.getFileObject(folderName);
        for (FileObject child : folder.getChildren()) {
            if (child.getType().equals(FileType.FILE)) {
                if (!child.isHidden() || !repositoryMeta.isHidingHiddenFiles()) {
                    String name = child.getName().getBaseName();
                    if (name.endsWith(EXT_TRANSFORMATION)) {
                        String transName = name.substring(0, name.length() - 4);
                        ObjectId id = new StringObjectId(calcObjectId(directory, transName, EXT_TRANSFORMATION));
                        Date date = new Date(child.getContent().getLastModifiedTime());
                        list.add(new RepositoryObject(id, transName, directory, "-", date, RepositoryObjectType.TRANSFORMATION, "", false));
                    }
                }
            }
        }
        return list;
    } catch (Exception e) {
        throw new KettleException("Unable to get list of transformations in folder with id : " + idDirectory, e);
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryObject(org.pentaho.di.repository.RepositoryObject) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) ArrayList(java.util.ArrayList) FileObject(org.apache.commons.vfs2.FileObject) StringObjectId(org.pentaho.di.repository.StringObjectId) Date(java.util.Date) KettleFileException(org.pentaho.di.core.exception.KettleFileException) FileSystemException(org.apache.commons.vfs2.FileSystemException) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Example 2 with RepositoryElementMetaInterface

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

the class KettleFileRepository method getJobObjects.

@Override
public List<RepositoryElementMetaInterface> getJobObjects(ObjectId id_directory, boolean includeDeleted) throws KettleException {
    try {
        List<RepositoryElementMetaInterface> list = new ArrayList<RepositoryElementMetaInterface>();
        RepositoryDirectoryInterface tree = loadRepositoryDirectoryTree();
        RepositoryDirectoryInterface directory = tree.findDirectory(id_directory);
        String folderName = calcDirectoryName(directory);
        FileObject folder = KettleVFS.getFileObject(folderName);
        for (FileObject child : folder.getChildren()) {
            if (child.getType().equals(FileType.FILE)) {
                if (!child.isHidden() || !repositoryMeta.isHidingHiddenFiles()) {
                    String name = child.getName().getBaseName();
                    if (name.endsWith(EXT_JOB)) {
                        String jobName = name.substring(0, name.length() - 4);
                        ObjectId id = new StringObjectId(calcObjectId(directory, jobName, EXT_JOB));
                        Date date = new Date(child.getContent().getLastModifiedTime());
                        list.add(new RepositoryObject(id, jobName, directory, "-", date, RepositoryObjectType.JOB, "", false));
                    }
                }
            }
        }
        return list;
    } catch (Exception e) {
        throw new KettleException("Unable to get list of jobs in folder with id : " + id_directory, e);
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryObject(org.pentaho.di.repository.RepositoryObject) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) ArrayList(java.util.ArrayList) FileObject(org.apache.commons.vfs2.FileObject) StringObjectId(org.pentaho.di.repository.StringObjectId) Date(java.util.Date) KettleFileException(org.pentaho.di.core.exception.KettleFileException) FileSystemException(org.apache.commons.vfs2.FileSystemException) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Example 3 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 4 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 5 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)

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)10 ObjectId (org.pentaho.di.repository.ObjectId)8 RepositoryDirectory (org.pentaho.di.repository.RepositoryDirectory)8 StringObjectId (org.pentaho.di.repository.StringObjectId)6 LongObjectId (org.pentaho.di.repository.LongObjectId)5 Repository (org.pentaho.di.repository.Repository)5 RepositoryObject (org.pentaho.di.repository.RepositoryObject)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 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 RepositoryObjectType (org.pentaho.di.repository.RepositoryObjectType)3 EERepositoryObject (org.pentaho.di.repository.pur.model.EERepositoryObject)3 URISyntaxException (java.net.URISyntaxException)2