Search in sources :

Example 6 with MetaverseComponentDescriptor

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());
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) Repository(org.pentaho.di.repository.Repository) IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) 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) KettleStepException(org.pentaho.di.core.exception.KettleStepException) MetaverseComponentDescriptor(org.pentaho.metaverse.api.MetaverseComponentDescriptor)

Example 7 with MetaverseComponentDescriptor

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);
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) JobMeta(org.pentaho.di.job.JobMeta) Repository(org.pentaho.di.repository.Repository) IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) KettleException(org.pentaho.di.core.exception.KettleException) FileNotFoundException(java.io.FileNotFoundException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) MetaverseComponentDescriptor(org.pentaho.metaverse.api.MetaverseComponentDescriptor)

Example 8 with MetaverseComponentDescriptor

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);
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) JobMeta(org.pentaho.di.job.JobMeta) Repository(org.pentaho.di.repository.Repository) IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) 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) FileNotFoundException(java.io.FileNotFoundException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) MetaverseComponentDescriptor(org.pentaho.metaverse.api.MetaverseComponentDescriptor)

Example 9 with MetaverseComponentDescriptor

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);
            }
        }
    };
}
Also used : MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) MetaverseComponentDescriptor(org.pentaho.metaverse.api.MetaverseComponentDescriptor)

Example 10 with MetaverseComponentDescriptor

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);
}
Also used : INamespace(org.pentaho.metaverse.api.INamespace) IMetaverseObjectFactory(org.pentaho.metaverse.api.IMetaverseObjectFactory) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) IDocument(org.pentaho.metaverse.api.IDocument) MetaverseComponentDescriptor(org.pentaho.metaverse.api.MetaverseComponentDescriptor) Before(org.junit.Before)

Aggregations

MetaverseComponentDescriptor (org.pentaho.metaverse.api.MetaverseComponentDescriptor)36 Before (org.junit.Before)19 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)16 IComponentDescriptor (org.pentaho.metaverse.api.IComponentDescriptor)9 MetaverseAnalyzerException (org.pentaho.metaverse.api.MetaverseAnalyzerException)8 IMetaverseObjectFactory (org.pentaho.metaverse.api.IMetaverseObjectFactory)6 KettleException (org.pentaho.di.core.exception.KettleException)5 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)5 INamespace (org.pentaho.metaverse.api.INamespace)5 FileNotFoundException (java.io.FileNotFoundException)4 Matchers.anyString (org.mockito.Matchers.anyString)4 KettleMissingPluginsException (org.pentaho.di.core.exception.KettleMissingPluginsException)4 KettleStepException (org.pentaho.di.core.exception.KettleStepException)4 JobMeta (org.pentaho.di.job.JobMeta)4 Repository (org.pentaho.di.repository.Repository)4 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)4 Namespace (org.pentaho.metaverse.api.Namespace)4 TransMeta (org.pentaho.di.trans.TransMeta)3 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)3 StepMeta (org.pentaho.di.trans.step.StepMeta)3