use of org.pentaho.di.repository.RepositoryExtended in project pentaho-kettle by pentaho.
the class RepositoryBrowserController method search.
public List<org.pentaho.repo.model.RepositoryObject> search(String path, String filter) {
RepositoryDirectoryInterface repositoryDirectoryInterface = findDirectory(path);
List<org.pentaho.repo.model.RepositoryObject> repositoryObjects = new ArrayList<>();
List<RepositoryObjectInterface> repositoryObjects1 = ((RepositoryExtended) getRepository()).getChildren(repositoryDirectoryInterface.getObjectId().getId(), filter);
for (RepositoryObjectInterface repositoryObject : repositoryObjects1) {
if (repositoryObject instanceof RepositoryDirectoryInterface) {
RepositoryDirectory repositoryDirectory = new RepositoryDirectory();
repositoryDirectory.setPath(path + "/" + repositoryObject.getName());
repositoryDirectory.setName(repositoryObject.getName());
repositoryDirectory.setObjectId(repositoryObject.getObjectId());
repositoryObjects.add(repositoryDirectory);
} else {
RepositoryFile repositoryFile = new RepositoryFile();
repositoryFile.setPath(path + "/" + repositoryObject.getName());
repositoryFile.setName(repositoryObject.getName());
repositoryFile.setType(((RepositoryObject) repositoryObject).getObjectType() == RepositoryObjectType.TRANSFORMATION ? TRANSFORMATION : JOB);
repositoryFile.setObjectId(repositoryObject.getObjectId());
repositoryObjects.add(repositoryFile);
}
}
return repositoryObjects;
}
use of org.pentaho.di.repository.RepositoryExtended in project pentaho-kettle by pentaho.
the class RepositoryBrowserController method loadDirectoryTree.
public RepositoryTree loadDirectoryTree(String filter) {
if (getRepository() != null) {
try {
if (getRepository() instanceof RepositoryExtended) {
rootDirectory = ((RepositoryExtended) getRepository()).loadRepositoryDirectoryTree(false);
} else {
rootDirectory = getRepository().loadRepositoryDirectoryTree();
}
RepositoryTree repositoryTree = new RepositoryTree();
RepositoryDirectory repositoryDirectory = RepositoryDirectory.build(null, rootDirectory);
populateFolders(repositoryDirectory, rootDirectory);
boolean isPentahoRepository = getRepository().getRepositoryMeta().getId().equals(PENTAHO_ENTERPRISE_REPOSITORY);
repositoryTree.setIncludeRoot(!isPentahoRepository);
repositoryTree.addChild(repositoryDirectory);
return repositoryTree;
} catch (Exception e) {
return null;
}
}
return null;
}
use of org.pentaho.di.repository.RepositoryExtended 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);
}
}
use of org.pentaho.di.repository.RepositoryExtended in project pentaho-kettle by pentaho.
the class BrowseControllerTest method testInit.
// PDI-16258
@Test
public void testInit() throws Exception {
RepositoryExtended repository = Mockito.mock(RepositoryExtended.class);
UserInfo userInfo = new UserInfo("user", "password", "user", "test user", true);
userInfo.setAdmin(true);
Mockito.doReturn(userInfo).when(repository).getUserInfo();
Mockito.doReturn(Mockito.mock(RepositoryDirectoryInterface.class)).when(repository).loadRepositoryDirectoryTree(anyString(), anyString(), anyInt(), anyBoolean(), anyBoolean(), anyBoolean());
BrowseController browseController = Mockito.spy(controller);
doNothing().when(browseController).createBindings();
browseController.init(repository);
Mockito.verify(repository).loadRepositoryDirectoryTree("/", "*.ktr|*.kjb", -1, true, true, true);
userInfo.setAdmin(false);
browseController.init(repository);
Mockito.verify(repository).loadRepositoryDirectoryTree("/", "*.ktr|*.kjb", -1, false, true, true);
userInfo.setAdmin(null);
browseController.init(repository);
Mockito.verify(repository, Mockito.times(2)).loadRepositoryDirectoryTree("/", "*.ktr|*.kjb", -1, false, true, true);
}
use of org.pentaho.di.repository.RepositoryExtended in project pentaho-kettle by pentaho.
the class UIRepositoryDirectoryTest method testRefresh.
@Test
public void testRefresh() throws Exception {
RepositoryDirectory root = new RepositoryDirectory();
LongObjectId rootObjectId = new LongObjectId(0L);
root.setObjectId(rootObjectId);
RepositoryDirectory dir = new RepositoryDirectory();
dir.setObjectId(new LongObjectId(1L));
root.addSubdirectory(dir);
RepositoryExtended repo = mock(RepositoryExtended.class);
UserInfo userInfo = new UserInfo();
userInfo.setAdmin(true);
Mockito.when(repo.getUserInfo()).thenReturn(userInfo);
RepositoryDirectory rd = Mockito.mock(RepositoryDirectory.class);
Mockito.when(rd.findDirectory(Mockito.eq(rootObjectId))).thenReturn(Mockito.mock(RepositoryDirectory.class));
Mockito.when(repo.loadRepositoryDirectoryTree("/", "*.ktr|*.kjb", -1, true, true, true)).thenReturn(rd);
UIRepositoryDirectory uiDir = new UIRepositoryDirectory(root, null, repo);
uiDir.refresh();
Mockito.verify(repo).loadRepositoryDirectoryTree("/", "*.ktr|*.kjb", -1, true, true, true);
}
Aggregations