Search in sources :

Example 11 with BaseStepMeta

use of org.pentaho.di.trans.step.BaseStepMeta in project pentaho-metaverse by pentaho.

the class AbstractStepMetaJsonSerializerTest method testWriteExternalResources.

@Test
public void testWriteExternalResources() throws Exception {
    StepExternalResourceConsumerProvider mockConsumerMap = mock(StepExternalResourceConsumerProvider.class);
    List<IStepExternalResourceConsumer> consumers = new ArrayList<IStepExternalResourceConsumer>();
    Set<IExternalResourceInfo> externalResources = new HashSet<IExternalResourceInfo>();
    IExternalResourceInfo info = mock(IExternalResourceInfo.class);
    externalResources.add(info);
    IStepExternalResourceConsumer consumer = mock(IStepExternalResourceConsumer.class);
    when(consumer.getResourcesFromMeta(anyObject())).thenReturn(externalResources);
    consumers.add(consumer);
    Class<? extends BaseStepMeta> stepMetaClass = BaseStepMeta.class;
    when(mockConsumerMap.getExternalResourceConsumers(any(Collection.class))).thenReturn(consumers);
    serializer.setStepExternalResourceConsumerProvider(mockConsumerMap);
    serializer.writeExternalResources(spyMeta, json, provider);
    verify(mockConsumerMap).getExternalResourceConsumers(any(Collection.class));
    verify(json).writeArrayFieldStart(AbstractStepMetaJsonSerializer.JSON_PROPERTY_EXTERNAL_RESOURCES);
    verify(consumer).getResourcesFromMeta(anyObject());
    verify(json, times(externalResources.size())).writeObject(any(IExternalResourceInfo.class));
    verify(json).writeEndArray();
}
Also used : StepExternalResourceConsumerProvider(org.pentaho.metaverse.analyzer.kettle.step.StepExternalResourceConsumerProvider) IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) ArrayList(java.util.ArrayList) Collection(java.util.Collection) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) IStepExternalResourceConsumer(org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with BaseStepMeta

use of org.pentaho.di.trans.step.BaseStepMeta in project pentaho-metaverse by pentaho.

the class ConnectionExternalResourceStepAnalyzerTest method setUp.

@Before
public void setUp() throws Exception {
    analyzer = spy(new ConnectionExternalResourceStepAnalyzer<BaseStepMeta>() {

        @Override
        protected IMetaverseNode createTableNode(IExternalResourceInfo resource) throws MetaverseAnalyzerException {
            return tableNode;
        }

        @Override
        public String getResourceInputNodeType() {
            return "INPUT_TYPE";
        }

        @Override
        public String getResourceOutputNodeType() {
            return "OUTPUT_TYPE";
        }

        @Override
        public boolean isOutput() {
            return false;
        }

        @Override
        public boolean isInput() {
            return true;
        }

        @Override
        protected Set<StepField> getUsedFields(BaseStepMeta meta) {
            Set<StepField> stepFields = new HashSet<>();
            stepFields.add(new StepField("prevStep", "filename"));
            return stepFields;
        }

        @Override
        public Set<Class<? extends BaseStepMeta>> getSupportedSteps() {
            return null;
        }
    });
    when(analyzer.getMetaverseBuilder()).thenReturn(builder);
    analyzer.descriptor = descriptor;
    when(descriptor.getContext()).thenReturn(context);
    analyzer.parentTransMeta = parentTransMeta;
    analyzer.parentStepMeta = parentStepMeta;
    analyzer.setMetaverseObjectFactory(new MetaverseObjectFactory());
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) MetaverseObjectFactory(org.pentaho.metaverse.api.MetaverseObjectFactory) StepField(org.pentaho.metaverse.api.StepField) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 13 with BaseStepMeta

use of org.pentaho.di.trans.step.BaseStepMeta 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)

Example 14 with BaseStepMeta

use of org.pentaho.di.trans.step.BaseStepMeta in project pentaho-metaverse by pentaho.

the class StepAnalyzerTest method setUp.

@Before
public void setUp() throws Exception {
    StepAnalyzer stepAnalyzer = new StepAnalyzer() {

        @Override
        protected Set<StepField> getUsedFields(BaseStepMeta meta) {
            return null;
        }

        @Override
        protected void customAnalyze(BaseStepMeta meta, IMetaverseNode rootNode) throws MetaverseAnalyzerException {
        }

        @Override
        public Set<Class<? extends BaseStepMeta>> getSupportedSteps() {
            return null;
        }
    };
    analyzer = spy(stepAnalyzer);
    analyzer.rootNode = rootNode;
    analyzer.baseStepMeta = baseStepMeta;
    analyzer.descriptor = descriptor;
    analyzer.parentTransMeta = parentTransMeta;
    analyzer.parentStepMeta = parentStepMeta;
    usedFields = new HashSet<>();
    inputs = new StepNodes();
    inputs.addNode("prevStep", "name", fieldNode);
    inputs.addNode("prevStep", "address", fieldNode);
    inputs.addNode("prevStep", "email", fieldNode);
    inputs.addNode("prevStep", "birthday", fieldNode);
    inputs.addNode("prevStep2", "employeeNumber", fieldNode);
    inputs.addNode("prevStep2", "occupation", fieldNode);
    outputs = new StepNodes();
    outputs.addNode("nextStep", "full name", fieldNode);
    outputs.addNode("nextStep", "address", fieldNode);
    outputs.addNode("nextStep", "email", fieldNode);
    outputs.addNode("nextStep", "date of birth", fieldNode);
    outputs.addNode("nextStep", "ID", fieldNode);
    outputs.addNode("nextStep", "occupation", fieldNode);
    doReturn(builder).when(analyzer).getMetaverseBuilder();
    MetaverseObjectFactory factory = new MetaverseObjectFactory();
    doReturn(factory).when(analyzer).getMetaverseObjectFactory();
    when(descriptor.getContext()).thenReturn(context);
    when(parentStepMeta.getName()).thenReturn("STEP NAME");
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) MetaverseObjectFactory(org.pentaho.metaverse.api.MetaverseObjectFactory) StepField(org.pentaho.metaverse.api.StepField) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Before(org.junit.Before)

Example 15 with BaseStepMeta

use of org.pentaho.di.trans.step.BaseStepMeta 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

BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)22 Test (org.junit.Test)8 HashSet (java.util.HashSet)7 StepMeta (org.pentaho.di.trans.step.StepMeta)7 StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)6 Before (org.junit.Before)4 ArrayList (java.util.ArrayList)3 KettleException (org.pentaho.di.core.exception.KettleException)3 TransMeta (org.pentaho.di.trans.TransMeta)3 StepInterface (org.pentaho.di.trans.step.StepInterface)3 MetaverseObjectFactory (org.pentaho.metaverse.api.MetaverseObjectFactory)3 StepField (org.pentaho.metaverse.api.StepField)3 IStepAnalyzer (org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzer)3 IStepExternalResourceConsumer (org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer)3 IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)3 Set (java.util.Set)2 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)2 ObjectId (org.pentaho.di.repository.ObjectId)2 StringObjectId (org.pentaho.di.repository.StringObjectId)2 Trans (org.pentaho.di.trans.Trans)2