Search in sources :

Example 1 with StepDefinition

use of org.pentaho.di.trans.steps.userdefinedjavaclass.StepDefinition in project pentaho-kettle by pentaho.

the class TransMetaTest method testGetPrevInfoFields.

@Test
public void testGetPrevInfoFields() throws KettleStepException {
    DataGridMeta dgm1 = new DataGridMeta();
    dgm1.setFieldName(new String[] { "id", "colA" });
    dgm1.allocate(2);
    dgm1.setFieldType(new String[] { ValueMetaFactory.getValueMetaName(ValueMetaInterface.TYPE_INTEGER), ValueMetaFactory.getValueMetaName(ValueMetaInterface.TYPE_STRING) });
    List<List<String>> dgm1Data = new ArrayList<>();
    dgm1Data.add(Arrays.asList("1", "A"));
    dgm1Data.add(Arrays.asList("2", "B"));
    dgm1.setDataLines(dgm1Data);
    DataGridMeta dgm2 = new DataGridMeta();
    dgm2.allocate(1);
    dgm2.setFieldName(new String[] { "moreData" });
    dgm2.setFieldType(new String[] { ValueMetaFactory.getValueMetaName(ValueMetaInterface.TYPE_STRING) });
    List<List<String>> dgm2Data = new ArrayList<>();
    dgm2Data.add(Arrays.asList("Some Informational Data"));
    dgm2.setDataLines(dgm2Data);
    StepMeta dg1 = new StepMeta("input1", dgm1);
    StepMeta dg2 = new StepMeta("input2", dgm2);
    final String UDJC_METHOD = "public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException { return false; }";
    UserDefinedJavaClassMeta udjcMeta = new UserDefinedJavaClassMeta();
    udjcMeta.getInfoStepDefinitions().add(new StepDefinition(dg2.getName(), dg2.getName(), dg2, "info_data"));
    udjcMeta.replaceDefinitions(Collections.singletonList(new UserDefinedJavaClassDef(UserDefinedJavaClassDef.ClassType.TRANSFORM_CLASS, "MainClass", UDJC_METHOD)));
    StepMeta udjc = new StepMeta("PDI-14910", udjcMeta);
    TransHopMeta hop1 = new TransHopMeta(dg1, udjc, true);
    TransHopMeta hop2 = new TransHopMeta(dg2, udjc, true);
    transMeta.addStep(dg1);
    transMeta.addStep(dg2);
    transMeta.addStep(udjc);
    transMeta.addTransHop(hop1);
    transMeta.addTransHop(hop2);
    RowMetaInterface row = null;
    row = transMeta.getPrevInfoFields(udjc);
    assertNotNull(row);
    assertEquals(1, row.size());
    assertEquals("moreData", row.getValueMeta(0).getName());
    assertEquals(ValueMetaInterface.TYPE_STRING, row.getValueMeta(0).getType());
}
Also used : ArrayList(java.util.ArrayList) StepDefinition(org.pentaho.di.trans.steps.userdefinedjavaclass.StepDefinition) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) UserDefinedJavaClassMeta(org.pentaho.di.trans.steps.userdefinedjavaclass.UserDefinedJavaClassMeta) UserDefinedJavaClassDef(org.pentaho.di.trans.steps.userdefinedjavaclass.UserDefinedJavaClassDef) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) DataGridMeta(org.pentaho.di.trans.steps.datagrid.DataGridMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Test(org.junit.Test)

Example 2 with StepDefinition

use of org.pentaho.di.trans.steps.userdefinedjavaclass.StepDefinition in project pentaho-kettle by pentaho.

the class UserDefinedJavaClassDialog method getInfo.

private void getInfo(UserDefinedJavaClassMeta meta) {
    int nrfields = wFields.nrNonEmpty();
    List<FieldInfo> newFields = new ArrayList<FieldInfo>(nrfields);
    for (int i = 0; i < nrfields; i++) {
        TableItem item = wFields.getNonEmpty(i);
        newFields.add(new FieldInfo(item.getText(1), ValueMetaFactory.getIdForValueMeta(item.getText(2)), Const.toInt(item.getText(3), -1), Const.toInt(item.getText(4), -1)));
    }
    meta.replaceFields(newFields);
    CTabItem[] cTabs = folder.getItems();
    if (cTabs.length > 0) {
        List<UserDefinedJavaClassDef> definitions = new ArrayList<UserDefinedJavaClassDef>(cTabs.length);
        for (int i = 0; i < cTabs.length; i++) {
            UserDefinedJavaClassDef def = new UserDefinedJavaClassDef(ClassType.NORMAL_CLASS, cTabs[i].getText(), getStyledTextComp(cTabs[i]).getText());
            if (cTabs[i].getImage().equals(imageActiveScript)) {
                def.setClassType(ClassType.TRANSFORM_CLASS);
            }
            definitions.add(def);
        }
        meta.replaceDefinitions(definitions);
    }
    meta.setClearingResultFields(wClearResultFields.getSelection());
    int nrInfos = wInfoSteps.nrNonEmpty();
    meta.getInfoStepDefinitions().clear();
    for (int i = 0; i < nrInfos; i++) {
        TableItem item = wInfoSteps.getNonEmpty(i);
        StepDefinition stepDefinition = new StepDefinition();
        int colNr = 1;
        stepDefinition.tag = item.getText(colNr++);
        stepDefinition.stepMeta = transMeta.findStep(item.getText(colNr++));
        stepDefinition.description = item.getText(colNr++);
        meta.getInfoStepDefinitions().add(stepDefinition);
    }
    int nrTargets = wTargetSteps.nrNonEmpty();
    meta.getTargetStepDefinitions().clear();
    for (int i = 0; i < nrTargets; i++) {
        TableItem item = wTargetSteps.getNonEmpty(i);
        StepDefinition stepDefinition = new StepDefinition();
        int colNr = 1;
        stepDefinition.tag = item.getText(colNr++);
        stepDefinition.stepMeta = transMeta.findStep(item.getText(colNr++));
        stepDefinition.description = item.getText(colNr++);
        meta.getTargetStepDefinitions().add(stepDefinition);
    }
    int nrParameters = wParameters.nrNonEmpty();
    meta.getUsageParameters().clear();
    for (int i = 0; i < nrParameters; i++) {
        TableItem item = wParameters.getNonEmpty(i);
        UsageParameter usageParameter = new UsageParameter();
        int colNr = 1;
        usageParameter.tag = item.getText(colNr++);
        usageParameter.value = item.getText(colNr++);
        usageParameter.description = item.getText(colNr++);
        meta.getUsageParameters().add(usageParameter);
    }
}
Also used : UsageParameter(org.pentaho.di.trans.steps.userdefinedjavaclass.UsageParameter) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) StepDefinition(org.pentaho.di.trans.steps.userdefinedjavaclass.StepDefinition) UserDefinedJavaClassDef(org.pentaho.di.trans.steps.userdefinedjavaclass.UserDefinedJavaClassDef) CTabItem(org.eclipse.swt.custom.CTabItem) Point(org.eclipse.swt.graphics.Point) FieldInfo(org.pentaho.di.trans.steps.userdefinedjavaclass.UserDefinedJavaClassMeta.FieldInfo)

Example 3 with StepDefinition

use of org.pentaho.di.trans.steps.userdefinedjavaclass.StepDefinition in project pentaho-kettle by pentaho.

the class UserDefinedJavaClassDialog method getData.

/**
 * Copy information from the meta-data input to the dialog fields.
 */
public void getData() {
    int i = 0;
    for (FieldInfo fi : input.getFieldInfo()) {
        TableItem item = wFields.table.getItem(i);
        i++;
        item.setText(1, fi.name);
        item.setText(2, ValueMetaFactory.getValueMetaName(fi.type));
        if (fi.length >= 0) {
            item.setText(3, "" + fi.length);
        }
        if (fi.precision >= 0) {
            item.setText(4, "" + fi.precision);
        }
    }
    List<UserDefinedJavaClassDef> definitions = input.getDefinitions();
    if (definitions.size() == 0) {
        try {
            definitions = new ArrayList<UserDefinedJavaClassDef>();
            // Note the tab name isn't i18n because it is a Java Class name and i18n characters might make it choke.
            definitions.add(new UserDefinedJavaClassDef(UserDefinedJavaClassDef.ClassType.TRANSFORM_CLASS, "Processor", UserDefinedJavaClassCodeSnippits.getSnippitsHelper().getDefaultCode()));
            input.replaceDefinitions(definitions);
        } catch (KettleXMLException e) {
            e.printStackTrace();
            new ErrorDialog(shell, BaseMessages.getString(PKG, "UserDefinedJavaClassDialog.Plugin.CreateErrorTitle"), BaseMessages.getString(PKG, "UserDefinedJavaClassDialog.Plugin.CreateErrorMessage", stepname), e);
        }
    }
    for (UserDefinedJavaClassDef def : definitions) {
        if (def.isTransformClass()) {
            strActiveScript = def.getClassName();
        }
        addCtab(def.getClassName(), def.getSource(), TabAddActions.ADD_DEFAULT);
    }
    setActiveCtab(strActiveScript);
    refresh();
    wClearResultFields.setSelection(input.isClearingResultFields());
    wFields.setRowNums();
    wFields.optWidth(true);
    int rowNr = 0;
    for (StepDefinition stepDefinition : input.getInfoStepDefinitions()) {
        TableItem item = wInfoSteps.table.getItem(rowNr++);
        int colNr = 1;
        item.setText(colNr++, Const.NVL(stepDefinition.tag, ""));
        item.setText(colNr++, stepDefinition.stepMeta != null ? stepDefinition.stepMeta.getName() : "");
        item.setText(colNr++, Const.NVL(stepDefinition.description, ""));
    }
    wInfoSteps.setRowNums();
    wInfoSteps.optWidth(true);
    rowNr = 0;
    for (StepDefinition stepDefinition : input.getTargetStepDefinitions()) {
        TableItem item = wTargetSteps.table.getItem(rowNr++);
        int colNr = 1;
        item.setText(colNr++, Const.NVL(stepDefinition.tag, ""));
        item.setText(colNr++, stepDefinition.stepMeta != null ? stepDefinition.stepMeta.getName() : "");
        item.setText(colNr++, Const.NVL(stepDefinition.description, ""));
    }
    wTargetSteps.setRowNums();
    wTargetSteps.optWidth(true);
    rowNr = 0;
    for (UsageParameter usageParameter : input.getUsageParameters()) {
        TableItem item = wParameters.table.getItem(rowNr++);
        int colNr = 1;
        item.setText(colNr++, Const.NVL(usageParameter.tag, ""));
        item.setText(colNr++, Const.NVL(usageParameter.value, ""));
        item.setText(colNr++, Const.NVL(usageParameter.description, ""));
    }
    wParameters.setRowNums();
    wParameters.optWidth(true);
    wStepname.selectAll();
    wStepname.setFocus();
}
Also used : UsageParameter(org.pentaho.di.trans.steps.userdefinedjavaclass.UsageParameter) TableItem(org.eclipse.swt.widgets.TableItem) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) StepDefinition(org.pentaho.di.trans.steps.userdefinedjavaclass.StepDefinition) UserDefinedJavaClassDef(org.pentaho.di.trans.steps.userdefinedjavaclass.UserDefinedJavaClassDef) Point(org.eclipse.swt.graphics.Point) FieldInfo(org.pentaho.di.trans.steps.userdefinedjavaclass.UserDefinedJavaClassMeta.FieldInfo)

Aggregations

StepDefinition (org.pentaho.di.trans.steps.userdefinedjavaclass.StepDefinition)3 UserDefinedJavaClassDef (org.pentaho.di.trans.steps.userdefinedjavaclass.UserDefinedJavaClassDef)3 ArrayList (java.util.ArrayList)2 Point (org.eclipse.swt.graphics.Point)2 TableItem (org.eclipse.swt.widgets.TableItem)2 UsageParameter (org.pentaho.di.trans.steps.userdefinedjavaclass.UsageParameter)2 FieldInfo (org.pentaho.di.trans.steps.userdefinedjavaclass.UserDefinedJavaClassMeta.FieldInfo)2 List (java.util.List)1 CTabItem (org.eclipse.swt.custom.CTabItem)1 Test (org.junit.Test)1 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)1 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)1 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)1 StepMeta (org.pentaho.di.trans.step.StepMeta)1 DataGridMeta (org.pentaho.di.trans.steps.datagrid.DataGridMeta)1 UserDefinedJavaClassMeta (org.pentaho.di.trans.steps.userdefinedjavaclass.UserDefinedJavaClassMeta)1 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)1 NodeList (org.w3c.dom.NodeList)1