use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.
the class MetaInjectMeta method exportResources.
@Override
public String exportResources(VariableSpace space, Map<String, ResourceDefinition> definitions, ResourceNamingInterface resourceNamingInterface, Repository repository, IMetaStore metaStore) throws KettleException {
try {
// Try to load the transformation from repository or file.
// Modify this recursively too...
//
// NOTE: there is no need to clone this step because the caller is
// responsible for this.
//
// First load the executor transformation metadata...
//
TransMeta executorTransMeta = loadTransformationMeta(repository, space);
// Also go down into the mapping transformation and export the files
// there. (mapping recursively down)
//
String proposedNewFilename = executorTransMeta.exportResources(executorTransMeta, definitions, resourceNamingInterface, repository, metaStore);
// To get a relative path to it, we inject
// ${Internal.Entry.Current.Directory}
//
String newFilename = "${" + Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY + "}/" + proposedNewFilename;
// Set the correct filename inside the XML.
//
executorTransMeta.setFilename(newFilename);
// exports always reside in the root directory, in case we want to turn
// this into a file repository...
//
executorTransMeta.setRepositoryDirectory(new RepositoryDirectory());
// change it in the entry
//
fileName = newFilename;
setSpecificationMethod(ObjectLocationSpecificationMethod.FILENAME);
return proposedNewFilename;
} catch (Exception e) {
throw new KettleException(BaseMessages.getString(PKG, "MetaInjectMeta.Exception.UnableToLoadTrans", fileName));
}
}
use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.
the class MetaInjectTest method testWriteInjectedKtrToRepoDifferentDir.
@Test
public void testWriteInjectedKtrToRepoDifferentDir() throws Exception {
RepositoryDirectory rootDir = PowerMockito.spy(new RepositoryDirectory(null, "/"));
RepositoryDirectory adminDir = PowerMockito.spy(new RepositoryDirectory(new RepositoryDirectory(new RepositoryDirectory(null, "/"), "home"), "admin"));
TransMeta cloneMeta = PowerMockito.spy((TransMeta) data.transMeta.clone());
PowerMockito.doReturn(cloneMeta).when(data.transMeta).clone();
PowerMockito.doReturn(adminDir).when(repository).createRepositoryDirectory(rootDir, "/home/admin");
PowerMockito.doReturn(adminDir).when(data.transMeta).getRepositoryDirectory();
PowerMockito.whenNew(RepositoryDirectory.class).withArguments(null, "/").thenReturn(rootDir);
metaInject.setRepository(repository);
Whitebox.<String>invokeMethod(metaInject, "writeInjectedKtrToRepo", "injected_trans");
verify(repository, times(0)).findDirectory(anyString());
verify(repository, times(0)).createRepositoryDirectory(any(), any());
verify(cloneMeta, times(1)).setRepositoryDirectory(adminDir);
verify(cloneMeta, times(1)).setObjectId(any(ObjectId.class));
verify(repository, times(1)).save(cloneMeta, null, null, true);
}
use of org.pentaho.di.repository.RepositoryDirectory 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.RepositoryDirectory in project pentaho-kettle by pentaho.
the class PurRepository method fillRepositoryDirectoryFromTree.
private void fillRepositoryDirectoryFromTree(final RepositoryDirectoryInterface parentDir, final RepositoryFileTree treeNode) throws KettleException {
try {
List<RepositoryElementMetaInterface> fileChildren = new ArrayList<RepositoryElementMetaInterface>();
List<RepositoryFileTree> children = treeNode.getChildren();
if (children != null) {
for (RepositoryFileTree child : children) {
if (child.getFile().isFolder()) {
RepositoryDirectory dir = new RepositoryDirectory(parentDir, child.getFile().getName());
dir.setObjectId(new StringObjectId(child.getFile().getId().toString()));
parentDir.addSubdirectory(dir);
fillRepositoryDirectoryFromTree(dir, child);
} else {
// a real file, like a Transformation or Job
RepositoryLock lock = unifiedRepositoryLockService.getLock(child.getFile());
RepositoryObjectType objectType = getObjectType(child.getFile().getName());
fileChildren.add(new EERepositoryObject(child, parentDir, null, objectType, null, lock, false));
}
}
parentDir.setRepositoryObjects(fileChildren);
}
} catch (Exception e) {
throw new KettleException("Unable to load directory structure from repository", e);
}
}
use of org.pentaho.di.repository.RepositoryDirectory 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);
}
Aggregations