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;
}
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;
}
}
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);
}
}
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));
}
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();
}
}
}
Aggregations