Search in sources :

Example 51 with RepositoryDirectory

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

the class PurRepository method initRepositoryDirectoryTree.

private RepositoryDirectoryInterface initRepositoryDirectoryTree(RepositoryFileTree repoTree) throws KettleException {
    RepositoryFile rootFolder = repoTree.getFile();
    RepositoryDirectory rootDir = new RepositoryDirectory();
    rootDir.setObjectId(new StringObjectId(rootFolder.getId().toString()));
    fillRepositoryDirectoryFromTree(rootDir, repoTree);
    // Example: /etc
    RepositoryDirectory etcDir = rootDir.findDirectory(ClientRepositoryPaths.getEtcFolderPath());
    RepositoryDirectory newRoot = new RepositoryDirectory();
    newRoot.setObjectId(rootDir.getObjectId());
    newRoot.setVisible(false);
    for (int i = 0; i < rootDir.getNrSubdirectories(); i++) {
        RepositoryDirectory childDir = rootDir.getSubdirectory(i);
        // Don't show /etc
        boolean isEtcChild = childDir.equals(etcDir);
        if (isEtcChild) {
            continue;
        }
        newRoot.addSubdirectory(childDir);
    }
    return newRoot;
}
Also used : RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) StringObjectId(org.pentaho.di.repository.StringObjectId) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint)

Example 52 with RepositoryDirectory

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

the class PurRepository method loadRepositoryDirectoryTree.

@Override
public RepositoryDirectoryInterface loadRepositoryDirectoryTree(String path, String filter, int depth, boolean showHidden, boolean includeEmptyFolder, boolean includeAcls) throws KettleException {
    // First check for possibility of speedy algorithm
    if (filter == null && "/".equals(path) && includeEmptyFolder) {
        return initRepositoryDirectoryTree(loadRepositoryFileTreeFolders("/", -1, includeAcls, showHidden));
    }
    // load count levels from root to destination path to load folder tree
    int fromRootToDest = StringUtils.countMatches(path, "/");
    // create new root directory "/"
    RepositoryDirectory dir = new RepositoryDirectory();
    // fetch folder tree from root "/" to destination path for populate folder
    RepositoryFileTree rootDirTree = loadRepositoryFileTree("/", "*", fromRootToDest, showHidden, includeAcls, FILES_TYPE_FILTER.FOLDERS);
    // populate directory by folder tree
    fillRepositoryDirectoryFromTree(dir, rootDirTree);
    RepositoryDirectoryInterface destinationDir = dir.findDirectory(path);
    // search for goal path and filter
    RepositoryFileTree repoTree = loadRepositoryFileTree(path, filter, depth, showHidden, includeAcls, FILES_TYPE_FILTER.FILES_FOLDERS);
    // populate the directory with founded files and subdirectories with files
    fillRepositoryDirectoryFromTree(destinationDir, repoTree);
    if (includeEmptyFolder) {
        RepositoryDirectoryInterface folders = initRepositoryDirectoryTree(loadRepositoryFileTree(path, null, depth, showHidden, includeAcls, FILES_TYPE_FILTER.FOLDERS));
        return copyFrom(folders, destinationDir);
    } else {
        return destinationDir;
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Example 53 with RepositoryDirectory

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

the class PurRepository method createRepositoryDirectory.

@Override
public RepositoryDirectoryInterface createRepositoryDirectory(final RepositoryDirectoryInterface parentDirectory, final String directoryPath) throws KettleException {
    try {
        RepositoryDirectoryInterface refreshedParentDir = findDirectory(parentDirectory.getPath());
        // update the passed in repository directory with the children recently loaded from the repo
        parentDirectory.setChildren(refreshedParentDir.getChildren());
        String[] path = Const.splitPath(directoryPath, RepositoryDirectory.DIRECTORY_SEPARATOR);
        RepositoryDirectoryInterface follow = parentDirectory;
        for (int level = 0; level < path.length; level++) {
            RepositoryDirectoryInterface child = follow.findChild(path[level]);
            if (child == null) {
                // create this one
                child = new RepositoryDirectory(follow, path[level]);
                saveRepositoryDirectory(child);
                // link this with the parent directory
                follow.addSubdirectory(child);
            }
            follow = child;
        }
        return follow;
    } catch (Exception e) {
        throw new KettleException("Unable to create directory with path [" + directoryPath + "]", e);
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) 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)

Example 54 with RepositoryDirectory

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

the class JobMetaTest method testLoadXml.

@Test
public void testLoadXml() throws KettleException {
    String directory = "/home/admin";
    Node jobNode = Mockito.mock(Node.class);
    NodeList nodeList = new NodeList() {

        Node node = Mockito.mock(Node.class);

        {
            Mockito.when(node.getNodeName()).thenReturn("directory");
            Node child = Mockito.mock(Node.class);
            Mockito.when(node.getFirstChild()).thenReturn(child);
            Mockito.when(child.getNodeValue()).thenReturn(directory);
        }

        @Override
        public Node item(int index) {
            return node;
        }

        @Override
        public int getLength() {
            return 1;
        }
    };
    Mockito.when(jobNode.getChildNodes()).thenReturn(nodeList);
    Repository rep = Mockito.mock(Repository.class);
    RepositoryDirectory repDirectory = new RepositoryDirectory(new RepositoryDirectory(new RepositoryDirectory(), "home"), "admin");
    Mockito.when(rep.findDirectory(Mockito.eq(directory))).thenReturn(repDirectory);
    JobMeta meta = new JobMeta();
    meta.loadXML(jobNode, null, rep, Mockito.mock(IMetaStore.class), false, Mockito.mock(OverwritePrompter.class));
    Job job = new Job(rep, meta);
    job.setInternalKettleVariables(null);
    Assert.assertEquals(repDirectory.getPath(), job.getVariable(Const.INTERNAL_VARIABLE_JOB_REPOSITORY_DIRECTORY));
}
Also used : Repository(org.pentaho.di.repository.Repository) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) OverwritePrompter(org.pentaho.di.core.gui.OverwritePrompter) IMetaStore(org.pentaho.metastore.api.IMetaStore) Test(org.junit.Test)

Example 55 with RepositoryDirectory

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

the class RepositoryExplorerDialog method createDirectory.

public void createDirectory(TreeItem ti, RepositoryDirectoryInterface repdir) {
    EnterStringDialog esd = new EnterStringDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Directory.Create.AskName.Default"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Directory.Create.AskName.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Directory.Create.AskName.Message"));
    String newdir = esd.open();
    if (newdir != null) {
        RepositoryDirectoryInterface rd = new RepositoryDirectory(repdir, newdir);
        String[] path = rd.getPathArray();
        RepositoryDirectoryInterface exists = directoryTree.findDirectory(path);
        if (exists == null) {
            try {
                rep.saveRepositoryDirectory(rd);
            } catch (Exception exception) {
                new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Directory.Create.UnexpectedError.Message1") + newdir + BaseMessages.getString(PKG, "RepositoryExplorerDialog.Directory.Create.UnexpectedError.Message2") + repdir.getPath() + "]", BaseMessages.getString(PKG, "RepositoryExplorerDialog.Directory.Create.UnexpectedError.Title"), exception);
            }
        } else {
            MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
            mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Directory.Create.AlreadyExists.Message1") + newdir + BaseMessages.getString(PKG, "RepositoryExplorerDialog.Directory.Create.AlreadyExists.Message2") + repdir.getPath() + BaseMessages.getString(PKG, "RepositoryExplorerDialog.Directory.Create.AlreadyExists.Message3"));
            mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Directory.Create.AlreadyExists.Title"));
            mb.open();
        }
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) EnterStringDialog(org.pentaho.di.ui.core.dialog.EnterStringDialog) IOException(java.io.IOException) KettleException(org.pentaho.di.core.exception.KettleException) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

RepositoryDirectory (org.pentaho.di.repository.RepositoryDirectory)57 KettleException (org.pentaho.di.core.exception.KettleException)23 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)15 Test (org.junit.Test)14 TransMeta (org.pentaho.di.trans.TransMeta)11 LongObjectId (org.pentaho.di.repository.LongObjectId)10 ObjectId (org.pentaho.di.repository.ObjectId)9 KettleFileException (org.pentaho.di.core.exception.KettleFileException)8 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)8 Repository (org.pentaho.di.repository.Repository)8 RepositoryElementMetaInterface (org.pentaho.di.repository.RepositoryElementMetaInterface)8 ArrayList (java.util.ArrayList)7 StringObjectId (org.pentaho.di.repository.StringObjectId)7 FileSystemException (org.apache.commons.vfs2.FileSystemException)6 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)6 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)6 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)6 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)5 JobMeta (org.pentaho.di.job.JobMeta)5 TreeItem (org.eclipse.swt.widgets.TreeItem)4