Search in sources :

Example 1 with InfoStepDefinition

use of org.pentaho.di.trans.steps.userdefinedjavaclass.InfoStepDefinition 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 (InfoStepDefinition 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 (TargetStepDefinition 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 : InfoStepDefinition(org.pentaho.di.trans.steps.userdefinedjavaclass.InfoStepDefinition) UsageParameter(org.pentaho.di.trans.steps.userdefinedjavaclass.UsageParameter) TableItem(org.eclipse.swt.widgets.TableItem) TargetStepDefinition(org.pentaho.di.trans.steps.userdefinedjavaclass.TargetStepDefinition) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) UserDefinedJavaClassDef(org.pentaho.di.trans.steps.userdefinedjavaclass.UserDefinedJavaClassDef) Point(org.eclipse.swt.graphics.Point) FieldInfo(org.pentaho.di.trans.steps.userdefinedjavaclass.UserDefinedJavaClassMeta.FieldInfo)

Example 2 with InfoStepDefinition

use of org.pentaho.di.trans.steps.userdefinedjavaclass.InfoStepDefinition 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);
        InfoStepDefinition stepDefinition = new InfoStepDefinition();
        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);
        TargetStepDefinition stepDefinition = new TargetStepDefinition();
        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 : InfoStepDefinition(org.pentaho.di.trans.steps.userdefinedjavaclass.InfoStepDefinition) UsageParameter(org.pentaho.di.trans.steps.userdefinedjavaclass.UsageParameter) TableItem(org.eclipse.swt.widgets.TableItem) TargetStepDefinition(org.pentaho.di.trans.steps.userdefinedjavaclass.TargetStepDefinition) ArrayList(java.util.ArrayList) 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 InfoStepDefinition

use of org.pentaho.di.trans.steps.userdefinedjavaclass.InfoStepDefinition 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(asList("1", "A"));
    dgm1Data.add(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(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 InfoStepDefinition(dg2.getName(), dg2.getName(), dg2, "info_data"));
    udjcMeta.replaceDefinitions(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 : InfoStepDefinition(org.pentaho.di.trans.steps.userdefinedjavaclass.InfoStepDefinition) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) 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) Mockito.anyString(org.mockito.Mockito.anyString) DataGridMeta(org.pentaho.di.trans.steps.datagrid.DataGridMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Test(org.junit.Test)

Aggregations

InfoStepDefinition (org.pentaho.di.trans.steps.userdefinedjavaclass.InfoStepDefinition)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 TargetStepDefinition (org.pentaho.di.trans.steps.userdefinedjavaclass.TargetStepDefinition)2 UsageParameter (org.pentaho.di.trans.steps.userdefinedjavaclass.UsageParameter)2 FieldInfo (org.pentaho.di.trans.steps.userdefinedjavaclass.UserDefinedJavaClassMeta.FieldInfo)2 Arrays.asList (java.util.Arrays.asList)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 CTabItem (org.eclipse.swt.custom.CTabItem)1 Test (org.junit.Test)1 Mockito.anyString (org.mockito.Mockito.anyString)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