Search in sources :

Example 6 with IComponentDescriptor

use of org.pentaho.metaverse.api.IComponentDescriptor 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 7 with IComponentDescriptor

use of org.pentaho.metaverse.api.IComponentDescriptor in project pentaho-metaverse by pentaho.

the class MongoDbConnectionAnalyzerTest method testBuildComponentDescriptor.

@Test
public void testBuildComponentDescriptor() throws Exception {
    IComponentDescriptor dbDesc = analyzer.buildComponentDescriptor(mockDescriptor, mongoDbMeta);
    assertNotNull(dbDesc);
    assertEquals("db", dbDesc.getName());
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) Test(org.junit.Test)

Example 8 with IComponentDescriptor

use of org.pentaho.metaverse.api.IComponentDescriptor in project pentaho-metaverse by pentaho.

the class BaseKettleMetaverseComponentTest method testCreateNodeFromDescriptor.

@Test
public void testCreateNodeFromDescriptor() throws Exception {
    String namespaceId = "{namespace: 'my namespace', name: 'my name', type: 'my type'}";
    ILogicalIdGenerator idGenerator = DictionaryConst.LOGICAL_ID_GENERATOR_DEFAULT;
    IComponentDescriptor descriptor = mock(IComponentDescriptor.class);
    INamespace ns = mock(INamespace.class);
    when(descriptor.getParentNamespace()).thenReturn(mock(INamespace.class));
    when(descriptor.getNamespace()).thenReturn(ns);
    when(ns.getNamespaceId()).thenReturn(namespaceId);
    component.metaverseObjectFactory = spy(new MetaverseObjectFactory());
    IMetaverseNode node = component.createNodeFromDescriptor(descriptor, idGenerator);
    assertNotNull(node);
    assertTrue(node.getLogicalId().contains(namespaceId));
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) ILogicalIdGenerator(org.pentaho.metaverse.api.ILogicalIdGenerator) INamespace(org.pentaho.metaverse.api.INamespace) MetaverseObjectFactory(org.pentaho.metaverse.api.MetaverseObjectFactory) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 9 with IComponentDescriptor

use of org.pentaho.metaverse.api.IComponentDescriptor in project pentaho-metaverse by pentaho.

the class DatabaseConnectionAnalyzerTest method testBuildComponentDescriptor.

@Test
public void testBuildComponentDescriptor() throws Exception {
    when(databaseMeta.getName()).thenReturn("connectionName");
    when(mockDescriptor.getNamespace()).thenReturn(mock(INamespace.class));
    when(mockDescriptor.getContext()).thenReturn(mock(IAnalysisContext.class));
    IComponentDescriptor dbDesc = dbConnectionAnalyzer.buildComponentDescriptor(mockDescriptor, databaseMeta);
    assertNotNull(dbDesc);
    assertEquals("connectionName", dbDesc.getName());
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) INamespace(org.pentaho.metaverse.api.INamespace) IAnalysisContext(org.pentaho.metaverse.api.IAnalysisContext) Test(org.junit.Test)

Example 10 with IComponentDescriptor

use of org.pentaho.metaverse.api.IComponentDescriptor in project pentaho-metaverse by pentaho.

the class StepAnalyzerTest method testGetInputFieldsWithException.

@Test
public void testGetInputFieldsWithException() {
    analyzer = new StepAnalyzer() {

        @Override
        public void validateState(IComponentDescriptor descriptor, BaseStepMeta object) throws MetaverseAnalyzerException {
            throw new MetaverseAnalyzerException("expected exception");
        }

        @Override
        public Set<Class<? extends BaseStepMeta>> getSupportedSteps() {
            return null;
        }

        @Override
        protected Set getUsedFields(BaseStepMeta meta) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        protected void customAnalyze(BaseStepMeta meta, IMetaverseNode rootNode) throws MetaverseAnalyzerException {
        // TODO Auto-generated method stub
        }
    };
    assertNull(analyzer.getInputFields(null));
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) HashSet(java.util.HashSet) Set(java.util.Set) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Test(org.junit.Test)

Aggregations

IComponentDescriptor (org.pentaho.metaverse.api.IComponentDescriptor)20 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)15 Test (org.junit.Test)10 MetaverseComponentDescriptor (org.pentaho.metaverse.api.MetaverseComponentDescriptor)9 MetaverseAnalyzerException (org.pentaho.metaverse.api.MetaverseAnalyzerException)8 INamespace (org.pentaho.metaverse.api.INamespace)6 KettleException (org.pentaho.di.core.exception.KettleException)5 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)5 FileNotFoundException (java.io.FileNotFoundException)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 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)4 ValueMeta (org.pentaho.di.core.row.ValueMeta)3 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)3 TransMeta (org.pentaho.di.trans.TransMeta)3 StepMeta (org.pentaho.di.trans.step.StepMeta)3 MetaverseTransientNode (org.pentaho.dictionary.MetaverseTransientNode)3