use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-kettle by pentaho.
the class PurRepository method getChildren.
@Override
public List<RepositoryObjectInterface> getChildren(String path, String filter) {
RepositoryRequest repoRequest = new RepositoryRequest();
repoRequest.setDepth(-1);
repoRequest.setChildNodeFilter("*" + filter + "*");
repoRequest.setIncludeAcls(false);
repoRequest.setTypes(FILES_TYPE_FILTER.FILES_FOLDERS);
repoRequest.setPath(path);
repoRequest.setShowHidden(false);
List<RepositoryFile> repositoryFiles = pur.getChildren(repoRequest);
List<RepositoryObjectInterface> repositoryElementInterfaces = new ArrayList<>();
for (RepositoryFile repositoryFile : repositoryFiles) {
if (repositoryFile.isFolder()) {
RepositoryDirectoryInterface repositoryDirectory = new RepositoryDirectory();
repositoryDirectory.setName(repositoryFile.getName());
repositoryDirectory.setObjectId(() -> repositoryFile.getId().toString());
repositoryElementInterfaces.add(repositoryDirectory);
} else {
RepositoryObject repositoryObject = new RepositoryObject();
repositoryObject.setName(repositoryFile.getName());
repositoryObject.setObjectId(() -> repositoryFile.getId().toString());
RepositoryObjectType repositoryObjectType = RepositoryObjectType.UNKNOWN;
if (repositoryFile.getName().endsWith(".ktr")) {
repositoryObjectType = RepositoryObjectType.TRANSFORMATION;
}
if (repositoryFile.getName().endsWith(".kjb")) {
repositoryObjectType = RepositoryObjectType.JOB;
}
repositoryObject.setObjectType(repositoryObjectType);
repositoryElementInterfaces.add(repositoryObject);
}
}
return repositoryElementInterfaces;
}
use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-kettle by pentaho.
the class PurRepository method loadRepositoryDirectoryTree.
@Deprecated
@Override
public RepositoryDirectoryInterface loadRepositoryDirectoryTree(boolean eager) throws KettleException {
// this method forces a reload of the repository directory tree structure
// a new rootRef will be obtained - this is a SoftReference which will be used
// by any calls to getRootDir()
RepositoryDirectoryInterface rootDir;
if (eager) {
RepositoryFileTree rootFileTree = loadRepositoryFileTree(ClientRepositoryPaths.getRootFolderPath());
rootDir = initRepositoryDirectoryTree(rootFileTree);
} else {
RepositoryFile root = pur.getFile("/");
rootDir = new LazyUnifiedRepositoryDirectory(root, null, pur, purRepositoryServiceRegistry);
}
rootRef.setRef(rootDir);
return rootDir;
}
use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-kettle by pentaho.
the class PurRepository method findDirectory.
@Override
public RepositoryDirectoryInterface findDirectory(String directory) throws KettleException {
RepositoryDirectoryInterface repositoryDirectoryInterface = null;
// check if we have a rootRef cached
boolean usingRootDirCache = rootRef.getRef() != null;
repositoryDirectoryInterface = getRootDir().findDirectory(directory);
// if we are using a cached version of the repository interface, allow a reload if we do not find
if (repositoryDirectoryInterface == null && usingRootDirCache) {
repositoryDirectoryInterface = loadRepositoryDirectoryTree().findDirectory(directory);
}
return repositoryDirectoryInterface;
}
use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-kettle by pentaho.
the class KettleFileRepositoryTest method testCurrentDirJob.
@Test
public void testCurrentDirJob() throws Exception {
final String dirName = "dirName";
final String jobName = "job";
JobMeta setupJobMeta = new JobMeta();
setupJobMeta.setName(jobName);
RepositoryDirectoryInterface repoDir = repository.createRepositoryDirectory(new RepositoryDirectory(), dirName);
setupJobMeta.setRepositoryDirectory(repoDir);
repository.save(setupJobMeta, "");
JobMeta jobMeta = repository.loadJob(jobName, repoDir, null, "");
assertEquals(repository, jobMeta.getRepository());
assertEquals(repoDir.getPath(), jobMeta.getRepositoryDirectory().getPath());
jobMeta.setInternalKettleVariables();
String currentDir = jobMeta.getVariable(Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY);
assertEquals(repoDir.getPath(), currentDir);
}
use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-kettle by pentaho.
the class StepWithMappingMetaTest method loadMappingMeta.
@Test
public void loadMappingMeta() throws Exception {
String variablePath = "Internal.Entry.Current.Directory";
String virtualDir = "/testFolder/CDA-91";
String fileName = "testTrans.ktr";
VariableSpace variables = new Variables();
StepMeta stepMeta = new StepMeta();
TransMeta parentTransMeta = new TransMeta();
stepMeta.setParentTransMeta(parentTransMeta);
RepositoryDirectoryInterface repositoryDirectory = Mockito.mock(RepositoryDirectoryInterface.class);
when(repositoryDirectory.toString()).thenReturn(virtualDir);
stepMeta.getParentTransMeta().setRepositoryDirectory(repositoryDirectory);
StepWithMappingMeta mappingMetaMock = mock(StepWithMappingMeta.class);
when(mappingMetaMock.getSpecificationMethod()).thenReturn(ObjectLocationSpecificationMethod.FILENAME);
when(mappingMetaMock.getFileName()).thenReturn("${" + variablePath + "}/" + fileName);
when(mappingMetaMock.getParentStepMeta()).thenReturn(stepMeta);
// mock repo and answers
Repository rep = mock(Repository.class);
Mockito.doAnswer(new Answer<TransMeta>() {
@Override
public TransMeta answer(final InvocationOnMock invocation) throws Throwable {
final String originalArgument = (String) (invocation.getArguments())[0];
// be sure that the variable was replaced by real path
assertEquals(virtualDir, originalArgument);
return null;
}
}).when(rep).findDirectory(anyString());
Mockito.doAnswer(new Answer<TransMeta>() {
@Override
public TransMeta answer(final InvocationOnMock invocation) throws Throwable {
final String originalArgument = (String) (invocation.getArguments())[0];
// be sure that transformation name was resolved correctly
assertEquals(fileName, originalArgument);
return mock(TransMeta.class);
}
}).when(rep).loadTransformation(anyString(), any(RepositoryDirectoryInterface.class), any(ProgressMonitorListener.class), anyBoolean(), anyString());
StepWithMappingMeta.loadMappingMeta(mappingMetaMock, rep, null, variables, true);
}
Aggregations