Search in sources :

Example 1 with IStepAnalyzer

use of org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzer in project pentaho-metaverse by pentaho.

the class StepAnalyzerProviderTest method TestAddAndSetAnalyzers.

@Test
public void TestAddAndSetAnalyzers() {
    final IStepAnalyzer analyzer1 = mock(IStepAnalyzer.class);
    final IStepAnalyzer analyzer2 = mock(IStepAnalyzer.class);
    List<IStepAnalyzer> analyzers = new ArrayList();
    analyzers.add(analyzer1);
    analyzers.add(analyzer2);
    provider.setStepAnalyzers(analyzers);
    assertEquals(2, provider.getAnalyzers().size());
    // verify that duplicate analyzers aren't added to the list
    provider.setStepAnalyzers(analyzers);
    assertEquals(2, provider.getAnalyzers().size());
    provider.setStepAnalyzers(null);
    assertNull(provider.getAnalyzers());
    // verify that "clonable" analyzers are added to the main analyzers list
    provider.setClonableStepAnalyzers(analyzers);
    assertEquals(2, provider.getAnalyzers().size());
    // and that duplicate clonable analyzers aren't added to the list
    provider.setClonableStepAnalyzers(analyzers);
    assertEquals(2, provider.getAnalyzers().size());
    provider.setClonableStepAnalyzers(null);
    assertNull(provider.getAnalyzers());
}
Also used : IStepAnalyzer(org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzer) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with IStepAnalyzer

use of org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzer in project pentaho-metaverse by pentaho.

the class TransformationAnalyzer method getStepAnalyzers.

protected Set<IStepAnalyzer> getStepAnalyzers(final StepMeta stepMeta) {
    Set<IStepAnalyzer> stepAnalyzers = new HashSet<IStepAnalyzer>();
    // Attempt to discover a BaseStepMeta from the given StepMeta
    BaseStepMeta baseStepMeta = getBaseStepMetaFromStepMeta(stepMeta);
    stepAnalyzerProvider = getStepAnalyzerProvider();
    if (stepAnalyzerProvider != null) {
        if (baseStepMeta == null) {
            stepAnalyzers.addAll(stepAnalyzerProvider.getAnalyzers());
        } else {
            Set<Class<?>> analyzerClassSet = new HashSet<Class<?>>(1);
            analyzerClassSet.add(baseStepMeta.getClass());
            stepAnalyzers.addAll(stepAnalyzerProvider.getAnalyzers(analyzerClassSet));
        }
    } else {
        stepAnalyzers.add(new GenericStepMetaAnalyzer());
    }
    return stepAnalyzers;
}
Also used : IStepAnalyzer(org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzer) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) HashSet(java.util.HashSet) GenericStepMetaAnalyzer(org.pentaho.metaverse.analyzer.kettle.step.GenericStepMetaAnalyzer)

Example 3 with IStepAnalyzer

use of org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzer in project pentaho-metaverse by pentaho.

the class AbstractStepMetaJsonSerializer method getFieldLineageMetadataProvider.

protected IFieldLineageMetadataProvider getFieldLineageMetadataProvider(T meta) {
    IStepAnalyzerProvider provider = getStepAnalyzerProvider();
    if (provider == null) {
        // try to get it from PentahoSystem
        provider = PentahoSystem.get(IStepAnalyzerProvider.class);
    }
    if (provider != null) {
        Set<Class<?>> types = new HashSet<Class<?>>();
        types.add(meta.getClass());
        List<IStepAnalyzer> analyzers = provider.getAnalyzers(types);
        if (analyzers != null) {
            for (IStepAnalyzer analyzer : analyzers) {
                // try to set up the analyzer with parent step & trans meta
                if (analyzer instanceof StepAnalyzer) {
                    StepAnalyzer bsa = (StepAnalyzer) analyzer;
                    try {
                        bsa.validateState(null, meta);
                        bsa.loadInputAndOutputStreamFields(meta);
                    } catch (MetaverseAnalyzerException e) {
                    // eat it
                    }
                }
                if (analyzer instanceof IFieldLineageMetadataProvider) {
                    return (IFieldLineageMetadataProvider) analyzer;
                }
            }
        }
    }
    return new GenericStepMetaAnalyzer();
}
Also used : IStepAnalyzer(org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzer) IFieldLineageMetadataProvider(org.pentaho.metaverse.api.analyzer.kettle.step.IFieldLineageMetadataProvider) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) StepAnalyzer(org.pentaho.metaverse.api.analyzer.kettle.step.StepAnalyzer) IStepAnalyzer(org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzer) IStepAnalyzerProvider(org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzerProvider) HashSet(java.util.HashSet) GenericStepMetaAnalyzer(org.pentaho.metaverse.analyzer.kettle.step.GenericStepMetaAnalyzer)

Example 4 with IStepAnalyzer

use of org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzer in project pentaho-metaverse by pentaho.

the class AbstractStepMetaJsonSerializerTest method testGetStepFieldMapper.

@Test
public void testGetStepFieldMapper() throws Exception {
    IStepAnalyzerProvider provider = mock(IStepAnalyzerProvider.class);
    IStepAnalyzer<DummyTransMeta> analyzer = mock(IStepAnalyzer.class, withSettings().extraInterfaces(IFieldLineageMetadataProvider.class));
    List<IStepAnalyzer> analyzers = new ArrayList<IStepAnalyzer>(1);
    analyzers.add(analyzer);
    when(provider.getAnalyzers(any(Set.class))).thenReturn(analyzers);
    serializer.setStepAnalyzerProvider(provider);
    IFieldLineageMetadataProvider handler = serializer.getFieldLineageMetadataProvider(spyMeta);
    assertFalse(handler instanceof GenericStepMetaAnalyzer);
}
Also used : IStepAnalyzer(org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzer) IFieldLineageMetadataProvider(org.pentaho.metaverse.api.analyzer.kettle.step.IFieldLineageMetadataProvider) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) IStepAnalyzerProvider(org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzerProvider) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) GenericStepMetaAnalyzer(org.pentaho.metaverse.analyzer.kettle.step.GenericStepMetaAnalyzer) Test(org.junit.Test)

Example 5 with IStepAnalyzer

use of org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzer in project pentaho-metaverse by pentaho.

the class AnalyzerInfoService method getSupportedSteps.

/**
 * Gets a list of all implementations of {@link BaseStepMeta} with a custom {@link IStepAnalyzer}
 * that produces lineage. Any step not found in this list will fall back to using
 * {@link org.pentaho.metaverse.analyzer.kettle.step.GenericStepMetaAnalyzer}.
 *
 * <p><b>Example Request:</b><br />
 *    GET pentaho-di/osgi/cxf/lineage/info/steps
 * </p>
 *
 * @return List of {@link AnalyzerInfo}
 *
 * <p><b>Example Response:</b></p>
 *    <pre function="syntax.js">
 *      [ { meta: "CalculatorMeta" }, { meta: "CsvInputMeta" }, { meta: "ExcelInputMeta" } ]
 *    </pre>
 */
@GET
@Path("/steps")
@Produces({ MediaType.APPLICATION_JSON })
@StatusCodes({ @ResponseCode(code = OK, condition = "Successfully listed the supported steps"), @ResponseCode(code = SERVER_ERROR, condition = "Server Error.") })
public Response getSupportedSteps() {
    List<AnalyzerInfo> analyzers = new ArrayList<>();
    for (IStepAnalyzer analyzer : getStepAnalyzerProvider().getAnalyzers()) {
        Set<Class<? extends BaseStepMeta>> supportedSteps = analyzer.getSupportedSteps();
        for (Class<? extends BaseStepMeta> supportedStep : supportedSteps) {
            AnalyzerInfo info = new AnalyzerInfo(supportedStep.getSimpleName());
            analyzers.add(info);
        }
    }
    Collections.sort(analyzers, new AnalyzerInfoComparator());
    return Response.ok(analyzers).build();
}
Also used : IStepAnalyzer(org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzer) ArrayList(java.util.ArrayList) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) StatusCodes(org.codehaus.enunciate.jaxrs.StatusCodes)

Aggregations

IStepAnalyzer (org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzer)11 Test (org.junit.Test)7 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)4 TableOutputMeta (org.pentaho.di.trans.steps.tableoutput.TableOutputMeta)4 GenericStepMetaAnalyzer (org.pentaho.metaverse.analyzer.kettle.step.GenericStepMetaAnalyzer)4 MetaverseAnalyzerException (org.pentaho.metaverse.api.MetaverseAnalyzerException)2 IFieldLineageMetadataProvider (org.pentaho.metaverse.api.analyzer.kettle.step.IFieldLineageMetadataProvider)2 IStepAnalyzerProvider (org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzerProvider)2 Date (java.util.Date)1 List (java.util.List)1 Set (java.util.Set)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Response (javax.ws.rs.core.Response)1 StatusCodes (org.codehaus.enunciate.jaxrs.StatusCodes)1 UnknownParamException (org.pentaho.di.core.parameters.UnknownParamException)1 Trans (org.pentaho.di.trans.Trans)1