use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-metaverse by pentaho.
the class JobJobEntryAnalyzer method customAnalyze.
@Override
protected void customAnalyze(JobEntryJob entry, IMetaverseNode rootNode) throws MetaverseAnalyzerException {
JobMeta subJobMeta = null;
JobMeta parentJobMeta = entry.getParentJob().getJobMeta();
// For some reason the JobMeta's variables have been reset by now, so re-activate them
parentJobMeta.activateParameters();
Repository repo = parentJobMeta.getRepository();
String jobPath = null;
switch(entry.getSpecificationMethod()) {
case FILENAME:
try {
jobPath = parentJobMeta.environmentSubstitute(entry.getFilename());
String normalized = KettleAnalyzerUtil.normalizeFilePath(jobPath);
subJobMeta = getSubJobMeta(normalized);
jobPath = normalized;
} catch (Exception e) {
throw new MetaverseAnalyzerException("Sub job can not be found - " + jobPath, e);
}
break;
case REPOSITORY_BY_NAME:
if (repo != null) {
String dir = parentJobMeta.environmentSubstitute(entry.getDirectory());
String file = parentJobMeta.environmentSubstitute(entry.getJobName());
try {
RepositoryDirectoryInterface rdi = repo.findDirectory(dir);
subJobMeta = repo.loadJob(file, rdi, null, null);
String filename = subJobMeta.getFilename() == null ? subJobMeta.toString() : subJobMeta.getFilename();
jobPath = filename + "." + subJobMeta.getDefaultExtension();
} catch (KettleException e) {
throw new MetaverseAnalyzerException("Sub job can not be found in repository - " + file, e);
}
} else {
throw new MetaverseAnalyzerException("Not connected to a repository, can't get the job");
}
break;
case REPOSITORY_BY_REFERENCE:
if (repo != null) {
try {
subJobMeta = repo.loadJob(entry.getJobObjectId(), null);
String filename = subJobMeta.getFilename() == null ? subJobMeta.toString() : subJobMeta.getFilename();
jobPath = filename + "." + subJobMeta.getDefaultExtension();
} catch (KettleException e) {
throw new MetaverseAnalyzerException("Sub job can not be found by reference - " + entry.getJobObjectId(), e);
}
} else {
throw new MetaverseAnalyzerException("Not connected to a repository, can't get the job");
}
break;
}
IComponentDescriptor ds = new MetaverseComponentDescriptor(subJobMeta.getName(), DictionaryConst.NODE_TYPE_JOB, descriptor.getNamespace().getParentNamespace());
IMetaverseNode jobNode = createNodeFromDescriptor(ds);
jobNode.setProperty(DictionaryConst.PROPERTY_NAMESPACE, ds.getNamespaceId());
jobNode.setProperty(DictionaryConst.PROPERTY_PATH, jobPath);
jobNode.setLogicalIdGenerator(DictionaryConst.LOGICAL_ID_GENERATOR_DOCUMENT);
metaverseBuilder.addLink(rootNode, DictionaryConst.LINK_EXECUTES, jobNode);
}
use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-metaverse by pentaho.
the class TransJobEntryAnalyzer method customAnalyze.
@Override
protected void customAnalyze(JobEntryTrans entry, IMetaverseNode rootNode) throws MetaverseAnalyzerException {
TransMeta subTransMeta = null;
JobMeta parentJobMeta = entry.getParentJob().getJobMeta();
// For some reason the JobMeta's variables have been reset by now, so re-activate them
parentJobMeta.activateParameters();
Repository repo = parentJobMeta.getRepository();
String transPath = null;
switch(entry.getSpecificationMethod()) {
case FILENAME:
try {
transPath = parentJobMeta.environmentSubstitute(entry.getFilename());
String normalized = KettleAnalyzerUtil.normalizeFilePath(transPath);
subTransMeta = getSubTransMeta(normalized);
transPath = normalized;
} catch (Exception e) {
throw new MetaverseAnalyzerException("Sub transformation can not be found - " + transPath, e);
}
break;
case REPOSITORY_BY_NAME:
if (repo != null) {
String dir = parentJobMeta.environmentSubstitute(entry.getDirectory());
String file = parentJobMeta.environmentSubstitute(entry.getTransname());
try {
RepositoryDirectoryInterface rdi = repo.findDirectory(dir);
subTransMeta = repo.loadTransformation(file, rdi, null, true, null);
transPath = subTransMeta.getPathAndName() + "." + subTransMeta.getDefaultExtension();
} catch (KettleException e) {
throw new MetaverseAnalyzerException("Sub transformation can not be found in repository - " + file, e);
}
} else {
throw new MetaverseAnalyzerException("Not connected to a repository, can't get the transformation");
}
break;
case REPOSITORY_BY_REFERENCE:
if (repo != null) {
try {
subTransMeta = repo.loadTransformation(entry.getTransObjectId(), null);
transPath = subTransMeta.getPathAndName() + "." + subTransMeta.getDefaultExtension();
} catch (KettleException e) {
throw new MetaverseAnalyzerException("Sub transformation can not be found by reference - " + entry.getTransObjectId(), e);
}
} else {
throw new MetaverseAnalyzerException("Not connected to a repository, can't get the transformation");
}
break;
}
IComponentDescriptor ds = new MetaverseComponentDescriptor(subTransMeta.getName(), DictionaryConst.NODE_TYPE_TRANS, descriptor.getNamespace().getParentNamespace());
IMetaverseNode transformationNode = createNodeFromDescriptor(ds);
transformationNode.setProperty(DictionaryConst.PROPERTY_NAMESPACE, ds.getNamespaceId());
transformationNode.setProperty(DictionaryConst.PROPERTY_PATH, transPath);
transformationNode.setLogicalIdGenerator(DictionaryConst.LOGICAL_ID_GENERATOR_DOCUMENT);
metaverseBuilder.addLink(rootNode, DictionaryConst.LINK_EXECUTES, transformationNode);
}
use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-metaverse by pentaho.
the class TransExecutorStepAnalyzerTest method testCustomAnalyze_repoRef.
@Test
public void testCustomAnalyze_repoRef() throws Exception {
when(meta.getTransObjectId()).thenReturn(mock(ObjectId.class));
Repository repo = mock(Repository.class);
RepositoryDirectoryInterface repoDir = mock(RepositoryDirectoryInterface.class);
when(repo.findDirectory(anyString())).thenReturn(repoDir);
when(repo.loadTransformation(any(ObjectId.class), anyString())).thenReturn(childTransMeta);
when(parentTransMeta.getRepository()).thenReturn(repo);
doReturn(childTransMeta).when(spyAnalyzer).getSubTransMeta(anyString());
when(childTransMeta.getPathAndName()).thenReturn("/home/admin/my");
when(childTransMeta.getDefaultExtension()).thenReturn("ktr");
when(meta.getSpecificationMethod()).thenReturn(ObjectLocationSpecificationMethod.REPOSITORY_BY_REFERENCE);
// don't bother running the connectX methods, we'll test those later
doNothing().when(spyAnalyzer).connectToSubTransInputFields(eq(meta), any(TransMeta.class), any(IMetaverseNode.class), any(IComponentDescriptor.class));
doNothing().when(spyAnalyzer).connectToSubTransOutputFields(eq(meta), any(TransMeta.class), any(IMetaverseNode.class), any(IComponentDescriptor.class));
spyAnalyzer.customAnalyze(meta, node);
verify(node).setProperty(eq(TransExecutorStepAnalyzer.TRANSFORMATION_TO_EXECUTE), Mockito.contains("/home/admin/my.ktr"));
// we should have one link created that "executes" the sub transformation
verify(builder, times(1)).addLink(eq(node), eq(DictionaryConst.LINK_EXECUTES), any(IMetaverseNode.class));
}
use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-platform by pentaho.
the class KettleComponent method loadTransformFromRepository.
private TransMeta loadTransformFromRepository(final String directoryName, final String transformationName, final Repository repository) {
if (ComponentBase.debug) {
// $NON-NLS-1$
debug(Messages.getInstance().getString("Kettle.DEBUG_DIRECTORY", directoryName));
}
if (ComponentBase.debug) {
// $NON-NLS-1$
debug(Messages.getInstance().getString("Kettle.DEBUG_TRANSFORMATION", transformationName));
}
TransMeta transMeta = null;
try {
if (ComponentBase.debug) {
// $NON-NLS-1$
debug(Messages.getInstance().getString("Kettle.DEBUG_FINDING_DIRECTORY"));
}
if (ComponentBase.debug) {
// $NON-NLS-1$
debug(Messages.getInstance().getString("Kettle.DEBUG_GETTING_TRANSFORMATION_METADATA"));
}
try {
// Load the transformation from the repository
RepositoryDirectoryInterface repositoryDirectory = repository.loadRepositoryDirectoryTree().findDirectory(directoryName);
transMeta = repository.loadTransformation(transformationName, repositoryDirectory, null, true, null);
} catch (Exception e) {
error(Messages.getInstance().getErrorString("Kettle.ERROR_0009_TRANSFROMATION_METADATA_NOT_FOUND", directoryName + "/" + transformationName), // $NON-NLS-1$ //$NON-NLS-2$
e);
return null;
}
if (transMeta == null) {
error(Messages.getInstance().getErrorString("Kettle.ERROR_0009_TRANSFROMATION_METADATA_NOT_FOUND", // $NON-NLS-1$ //$NON-NLS-2$
directoryName + "/" + transformationName));
debug(getKettleLog(true));
return null;
} else {
return transMeta;
}
} catch (Exception e) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("Kettle.ERROR_0008_ERROR_RUNNING", e.toString()), e);
}
return null;
}
use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pdi-dataservice-server-plugin by pentaho.
the class TransientResolver method loadFromRepository.
private static TransMeta loadFromRepository(Repository repository, String filePath) throws KettleException {
// this code assumes that filePath always begins with '/' or '\', and we use this as a file separator
char fileSeparator = filePath.charAt(0);
String name = filePath.substring(filePath.lastIndexOf(fileSeparator) + 1, filePath.length());
String path = filePath.substring(0, filePath.lastIndexOf(fileSeparator));
RepositoryDirectoryInterface root = repository.loadRepositoryDirectoryTree();
RepositoryDirectoryInterface rd = root.findDirectory(path);
if (rd == null) {
// root
rd = root;
}
return repository.loadTransformation(repository.getTransformationID(name, rd), null);
}
Aggregations