Search in sources :

Example 1 with TransformationAnalyzer

use of org.pentaho.metaverse.analyzer.kettle.TransformationAnalyzer 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;
    MetaverseAnalyzerException exception = null;
    switch(entry.getSpecificationMethod()) {
        case FILENAME:
            try {
                transPath = parentJobMeta.environmentSubstitute(entry.getFilename());
                String normalized = KettleAnalyzerUtil.normalizeFilePath(transPath);
                subTransMeta = getSubTransMeta(normalized);
                entry.copyVariablesFrom(subTransMeta);
                transPath = normalized;
            } catch (Exception e) {
                exception = new MetaverseAnalyzerException(Messages.getString("ERROR.SubTransNotFoundInParentJob", transPath, parentJobMeta.toString()), 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) {
                    exception = new MetaverseAnalyzerException(Messages.getString("ERROR.SubTransNotFoundInParentJob", file, parentJobMeta.toString()), e);
                }
            } else {
                exception = new MetaverseAnalyzerException(Messages.getString("ERROR.MissingConnectionForJobSubTrans", parentJobMeta.toString()));
            }
            break;
        case REPOSITORY_BY_REFERENCE:
            if (repo != null) {
                try {
                    subTransMeta = repo.loadTransformation(entry.getTransObjectId(), null);
                    transPath = subTransMeta.getPathAndName() + "." + subTransMeta.getDefaultExtension();
                } catch (KettleException e) {
                    exception = new MetaverseAnalyzerException(Messages.getString("ERROR.SubTransNotFoundInParentJob", (entry.getTransObjectId() == null ? "N/A" : entry.getTransObjectId().toString()), parentJobMeta.toString()), e);
                }
            } else {
                exception = new MetaverseAnalyzerException(Messages.getString("ERROR.MissingConnectionForJobSubTrans", parentJobMeta.toString()));
            }
            break;
    }
    rootNode.setProperty(DictionaryConst.PROPERTY_PATH, transPath);
    if (exception != null) {
        throw exception;
    }
    subTransMeta.copyVariablesFrom(parentJobMeta);
    subTransMeta.setFilename(transPath);
    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);
    // pull in the sub-job lineage only if the consolidateSubGraphs flag is set to true
    if (MetaverseConfig.consolidateSubGraphs()) {
        final IDocument subTransDocument = KettleAnalyzerUtil.buildDocument(getMetaverseBuilder(), subTransMeta, transPath, getDocumentDescriptor().getNamespace());
        if (subTransDocument != null) {
            final IComponentDescriptor subtransDocumentDescriptor = new MetaverseComponentDescriptor(subTransDocument.getStringID(), DictionaryConst.NODE_TYPE_TRANS, getDocumentDescriptor().getNamespace(), getDescriptor().getContext());
            // analyze the sub-transformation
            final TransformationAnalyzer transformationAnalyzer = new TransformationAnalyzer();
            transformationAnalyzer.setStepAnalyzerProvider(PentahoSystem.get(IStepAnalyzerProvider.class));
            transformationAnalyzer.setMetaverseBuilder(getMetaverseBuilder());
            transformationAnalyzer.analyze(subtransDocumentDescriptor, subTransMeta, transformationNode, transPath);
        }
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) JobMeta(org.pentaho.di.job.JobMeta) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) TransMeta(org.pentaho.di.trans.TransMeta) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) FileNotFoundException(java.io.FileNotFoundException) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) MetaverseComponentDescriptor(org.pentaho.metaverse.api.MetaverseComponentDescriptor) Repository(org.pentaho.di.repository.Repository) IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) TransformationAnalyzer(org.pentaho.metaverse.analyzer.kettle.TransformationAnalyzer) IStepAnalyzerProvider(org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzerProvider) IDocument(org.pentaho.metaverse.api.IDocument)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 KettleException (org.pentaho.di.core.exception.KettleException)1 KettleMissingPluginsException (org.pentaho.di.core.exception.KettleMissingPluginsException)1 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)1 JobMeta (org.pentaho.di.job.JobMeta)1 Repository (org.pentaho.di.repository.Repository)1 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)1 TransMeta (org.pentaho.di.trans.TransMeta)1 TransformationAnalyzer (org.pentaho.metaverse.analyzer.kettle.TransformationAnalyzer)1 IComponentDescriptor (org.pentaho.metaverse.api.IComponentDescriptor)1 IDocument (org.pentaho.metaverse.api.IDocument)1 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)1 MetaverseAnalyzerException (org.pentaho.metaverse.api.MetaverseAnalyzerException)1 MetaverseComponentDescriptor (org.pentaho.metaverse.api.MetaverseComponentDescriptor)1 IStepAnalyzerProvider (org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzerProvider)1