Search in sources :

Example 1 with IAnalysisContext

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

the class MongoDbInputStepAnalyzerTest method testCreateOutputFieldNode.

@Test
public void testCreateOutputFieldNode() throws Exception {
    IAnalysisContext context = mock(IAnalysisContext.class);
    ValueMetaInterface vmi = new ValueMeta("field1");
    MongoField mongoField1 = new MongoField();
    mongoField1.m_fieldName = "field1";
    mongoField1.m_fieldPath = "$.field1";
    mongoField1.m_arrayIndexInfo = "range";
    mongoField1.m_occurenceFraction = "occurence";
    mongoField1.m_indexedVals = Arrays.asList(new String[] { "one", "two" });
    mongoField1.m_disparateTypes = true;
    mongoField1.m_kettleType = "ValueMetaString";
    mongoField1.m_outputIndex = 0;
    List<MongoField> mongoFields = Arrays.asList(mongoField1);
    when(meta.getMongoFields()).thenReturn(mongoFields);
    doReturn("thisStepName").when(analyzer).getStepName();
    when(node.getLogicalId()).thenReturn("logical id");
    IMetaverseNode node = analyzer.createOutputFieldNode(context, vmi, ExternalResourceStepAnalyzer.RESOURCE, DictionaryConst.NODE_TYPE_TRANS_FIELD);
    assertNotNull(node);
    assertEquals("field1", node.getName());
    assertEquals(mongoField1.m_fieldPath, node.getProperty(MongoDbInputStepAnalyzer.JSON_PATH));
    assertEquals(mongoField1.m_arrayIndexInfo, node.getProperty(MongoDbInputStepAnalyzer.MINMAX_RANGE));
    assertEquals(mongoField1.m_occurenceFraction, node.getProperty(MongoDbInputStepAnalyzer.OCCUR_RATIO));
    assertEquals(mongoField1.m_indexedVals, node.getProperty(MongoDbInputStepAnalyzer.INDEXED_VALS));
    assertEquals(mongoField1.m_disparateTypes, node.getProperty(MongoDbInputStepAnalyzer.DISPARATE_TYPES));
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) IAnalysisContext(org.pentaho.metaverse.api.IAnalysisContext) ValueMeta(org.pentaho.di.core.row.ValueMeta) MongoField(org.pentaho.mongo.wrapper.field.MongoField) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 2 with IAnalysisContext

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

the class ExternalResourceStepAnalyzerTest method testCreateInputFieldNode_resource.

@Test
public void testCreateInputFieldNode_resource() throws Exception {
    IAnalysisContext context = mock(IAnalysisContext.class);
    doReturn("thisStepName").when(analyzer).getStepName();
    analyzer.rootNode = node;
    when(node.getLogicalId()).thenReturn("logical id");
    ValueMetaInterface vmi = new ValueMeta("name", 1);
    IMetaverseNode inputFieldNode = analyzer.createInputFieldNode(context, vmi, ExternalResourceStepAnalyzer.RESOURCE, DictionaryConst.NODE_TYPE_TRANS_FIELD);
    assertNotNull(inputFieldNode);
    assertNotNull(inputFieldNode.getProperty(DictionaryConst.PROPERTY_KETTLE_TYPE));
    assertEquals("thisStepName", inputFieldNode.getProperty(DictionaryConst.PROPERTY_TARGET_STEP));
    assertEquals("INPUT_TYPE", inputFieldNode.getType());
    // the input node should be added by this step
    verify(builder).addNode(inputFieldNode);
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) IAnalysisContext(org.pentaho.metaverse.api.IAnalysisContext) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 3 with IAnalysisContext

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

the class MongoDbInputStepAnalyzerTest method testCreateOutputFieldNode_noFields.

@Test
public void testCreateOutputFieldNode_noFields() throws Exception {
    ValueMetaInterface vmi = new ValueMeta("field1");
    IAnalysisContext context = mock(IAnalysisContext.class);
    when(meta.getMongoFields()).thenReturn(null);
    doReturn("thisStepName").when(analyzer).getStepName();
    when(node.getLogicalId()).thenReturn("logical id");
    IMetaverseNode node = analyzer.createOutputFieldNode(context, vmi, ExternalResourceStepAnalyzer.RESOURCE, DictionaryConst.NODE_TYPE_TRANS_FIELD);
    assertEquals("field1", node.getName());
    assertNull(node.getProperty(MongoDbInputStepAnalyzer.JSON_PATH));
    assertNull(node.getProperty(MongoDbInputStepAnalyzer.MINMAX_RANGE));
    assertNull(node.getProperty(MongoDbInputStepAnalyzer.OCCUR_RATIO));
    assertNull(node.getProperty(MongoDbInputStepAnalyzer.INDEXED_VALS));
    assertNull(node.getProperty(MongoDbInputStepAnalyzer.DISPARATE_TYPES));
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) IAnalysisContext(org.pentaho.metaverse.api.IAnalysisContext) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 4 with IAnalysisContext

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

the class ExternalResourceStepAnalyzer method customAnalyze.

@Override
protected void customAnalyze(T meta, IMetaverseNode node) throws MetaverseAnalyzerException {
    // handle all of the external resources
    if (getExternalResourceConsumer() != null) {
        IAnalysisContext context = getDescriptor().getContext();
        Collection<IExternalResourceInfo> resources = getExternalResourceConsumer().getResources(meta, context);
        for (IExternalResourceInfo resource : resources) {
            try {
                if (resource.isInput()) {
                    String label = DictionaryConst.LINK_READBY;
                    IMetaverseNode resourceNode = createResourceNode(resource);
                    getMetaverseBuilder().addNode(resourceNode);
                    getMetaverseBuilder().addLink(resourceNode, label, node);
                }
                if (resource.isOutput()) {
                    String label = DictionaryConst.LINK_WRITESTO;
                    IMetaverseNode resourceNode = createResourceNode(resource);
                    getMetaverseBuilder().addNode(resourceNode);
                    getMetaverseBuilder().addLink(node, label, resourceNode);
                }
            } catch (MetaverseException e) {
                LOGGER.warn(e.getLocalizedMessage());
                LOGGER.debug(Messages.getString("ERROR.ErrorDuringAnalysisStackTrace"), e);
            }
        }
    }
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) IAnalysisContext(org.pentaho.metaverse.api.IAnalysisContext) MetaverseException(org.pentaho.metaverse.api.MetaverseException)

Example 5 with IAnalysisContext

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

the class ExternalResourceStepAnalyzerTest method testCreateOutputFieldNode_resource.

@Test
public void testCreateOutputFieldNode_resource() throws Exception {
    IAnalysisContext context = mock(IAnalysisContext.class);
    doReturn("thisStepName").when(analyzer).getStepName();
    analyzer.rootNode = node;
    when(node.getLogicalId()).thenReturn("logical id");
    ValueMetaInterface vmi = new ValueMeta("name", 1);
    IMetaverseNode outputFieldNode = analyzer.createOutputFieldNode(context, vmi, ExternalResourceStepAnalyzer.RESOURCE, DictionaryConst.NODE_TYPE_TRANS_FIELD);
    assertNotNull(outputFieldNode);
    assertNotNull(outputFieldNode.getProperty(DictionaryConst.PROPERTY_KETTLE_TYPE));
    assertEquals(ExternalResourceStepAnalyzer.RESOURCE, outputFieldNode.getProperty(DictionaryConst.PROPERTY_TARGET_STEP));
    assertEquals("OUTPUT_TYPE", outputFieldNode.getType());
    // the input node should be added by this step
    verify(builder).addNode(outputFieldNode);
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) IAnalysisContext(org.pentaho.metaverse.api.IAnalysisContext) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Aggregations

IAnalysisContext (org.pentaho.metaverse.api.IAnalysisContext)7 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)7 Test (org.junit.Test)6 ValueMeta (org.pentaho.di.core.row.ValueMeta)6 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)6 MetaverseException (org.pentaho.metaverse.api.MetaverseException)1 IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)1 MongoField (org.pentaho.mongo.wrapper.field.MongoField)1