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());
}
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);
}
}
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();
}
Aggregations