use of org.pentaho.metaverse.api.MetaverseComponentDescriptor in project pentaho-metaverse by pentaho.
the class TransExecutorStepAnalyzer method customAnalyze.
@Override
protected void customAnalyze(TransExecutorMeta meta, IMetaverseNode node) throws MetaverseAnalyzerException {
String transPath = meta.getFileName();
TransMeta subTransMeta = null;
Repository repo = parentTransMeta.getRepository();
switch(meta.getSpecificationMethod()) {
case FILENAME:
transPath = parentTransMeta.environmentSubstitute(meta.getFileName());
try {
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 = parentTransMeta.environmentSubstitute(meta.getDirectoryPath());
String file = parentTransMeta.environmentSubstitute(meta.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(meta.getTransObjectId(), null);
transPath = subTransMeta.getPathAndName() + "." + subTransMeta.getDefaultExtension();
} catch (KettleException e) {
throw new MetaverseAnalyzerException("Sub transformation can not be found by reference - " + meta.getTransObjectId(), e);
}
} else {
throw new MetaverseAnalyzerException("Not connected to a repository, can't get the transformation");
}
break;
}
// analyze the sub trans?
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(node, DictionaryConst.LINK_EXECUTES, transformationNode);
connectToSubTransInputFields(meta, subTransMeta, transformationNode, descriptor);
connectToSubTransOutputFields(meta, subTransMeta, transformationNode, descriptor);
node.setProperty(TRANSFORMATION_TO_EXECUTE, transPath);
if (StringUtils.isNotEmpty(meta.getExecutionResultTargetStep())) {
node.setProperty(EXECUTION_RESULTS_TARGET, meta.getExecutionResultTargetStep());
}
if (StringUtils.isNotEmpty(meta.getOutputRowsSourceStep())) {
node.setProperty(OUTPUT_ROWS_TARGET, meta.getOutputRowsSourceStep());
}
if (StringUtils.isNotEmpty(meta.getResultFilesTargetStep())) {
node.setProperty(RESULT_FILES_TARGET, meta.getResultFilesTargetStep());
}
}
use of org.pentaho.metaverse.api.MetaverseComponentDescriptor 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.metaverse.api.MetaverseComponentDescriptor 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.metaverse.api.MetaverseComponentDescriptor in project pentaho-metaverse by pentaho.
the class MetaverseUtil method getAnalyzerRunner.
public static Runnable getAnalyzerRunner(final IDocumentAnalyzer analyzer, final IDocument document) {
return new Runnable() {
@Override
public void run() {
try {
MetaverseComponentDescriptor docDescriptor = new MetaverseComponentDescriptor(document.getName(), DictionaryConst.NODE_TYPE_TRANS, document.getNamespace());
if (document.getContext() != null) {
docDescriptor.setContext(document.getContext());
}
analyzer.analyze(docDescriptor, document);
} catch (MetaverseAnalyzerException mae) {
throw new RuntimeException(Messages.getString("ERROR.AnalyzingDocument", document.getNamespaceId()), mae);
}
}
};
}
use of org.pentaho.metaverse.api.MetaverseComponentDescriptor in project pentaho-metaverse by pentaho.
the class MetaverseDocumentAnalyzerTest method setUp.
/**
* @throws Exception
*/
@Before
public void setUp() throws Exception {
builder = mock(IMetaverseBuilder.class);
transDoc = mock(IDocument.class);
namespace = mock(INamespace.class);
descriptor = new MetaverseComponentDescriptor("name", DictionaryConst.NODE_TYPE_TRANS, namespace);
IMetaverseObjectFactory factory = MetaverseTestUtils.getMetaverseObjectFactory();
when(builder.getMetaverseObjectFactory()).thenReturn(factory);
analyzer.setMetaverseBuilder(builder);
when(namespace.getParentNamespace()).thenReturn(namespace);
when(transDoc.getType()).thenReturn(type);
when(transDoc.getContent()).thenReturn(content);
when(transDoc.getNamespace()).thenReturn(namespace);
}
Aggregations