use of org.pentaho.di.trans.steps.getvariable.GetVariableMeta.FieldDefinition in project pentaho-kettle by pentaho.
the class ParameterSimpleTransIT method testParameterSimpleTrans6.
/**
* Test case for parameters using a simple transformation. Check whether parameters override variables.
*
* @throws Exception
* exception on any problem.
*/
public void testParameterSimpleTrans6() throws Exception {
KettleEnvironment.init();
//
// Create a new transformation...
//
TransMeta transMeta = new TransMeta();
transMeta.setName("parameter_simple_trans4");
PluginRegistry registry = PluginRegistry.getInstance();
//
// create a get variables step...
//
String getVariablesStepname = "get variables step";
GetVariableMeta gvm = new GetVariableMeta();
// Set the information of the get variables step.
String getVariablesPid = registry.getPluginId(StepPluginType.class, gvm);
StepMeta getVariablesStep = new StepMeta(getVariablesPid, getVariablesStepname, gvm);
transMeta.addStep(getVariablesStep);
//
// Generate 1 row
//
String[] fieldName = { "PARAM1", "PARAM2" };
String[] varName = { "${Param1}", "%%PARAM2%%" };
int[] fieldType = { ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING };
int[] length = { -1, -1 };
int[] precision = { -1, -1 };
String[] format = { "", "" };
String[] currency = { "", "" };
String[] decimal = { "", "" };
String[] grouping = { "", "" };
int[] trimType = { ValueMetaInterface.TRIM_TYPE_NONE, ValueMetaInterface.TRIM_TYPE_NONE };
FieldDefinition[] fields = new FieldDefinition[fieldName.length];
for (int i = 0; i < fields.length; i++) {
FieldDefinition field = new FieldDefinition();
field.setFieldName(fieldName[i]);
field.setVariableString(varName[i]);
field.setFieldType(fieldType[i]);
field.setFieldLength(length[i]);
field.setFieldPrecision(precision[i]);
field.setFieldFormat(format[i]);
field.setCurrency(currency[i]);
field.setDecimal(decimal[i]);
field.setGroup(grouping[i]);
field.setTrimType(trimType[i]);
fields[i] = field;
}
gvm.setFieldDefinitions(fields);
//
// Create a dummy step 1
//
String dummyStepname1 = "dummy step 1";
DummyTransMeta dm1 = new DummyTransMeta();
String dummyPid1 = registry.getPluginId(StepPluginType.class, dm1);
StepMeta dummyStep1 = new StepMeta(dummyPid1, dummyStepname1, dm1);
transMeta.addStep(dummyStep1);
TransHopMeta hi1 = new TransHopMeta(getVariablesStep, dummyStep1);
transMeta.addTransHop(hi1);
// Now execute the transformation...
Trans trans = new Trans(transMeta);
trans.addParameterDefinition("Param1", "", "Parameter 1");
trans.addParameterDefinition("PARAM2", "", "Parameter 2");
trans.setParameterValue("PARAM2", "PARAMVALUE2");
// See whether this variable overrides the parameter... it should NOT. Param1
// is defined but not set. And no default... so the variable will be set to "". not
// to "Variable1"
trans.setVariable("Param1", "Variable1");
trans.prepareExecution(null);
StepInterface si = trans.getStepInterface(dummyStepname1, 0);
RowStepCollector endRc = new RowStepCollector();
si.addRowListener(endRc);
trans.startThreads();
trans.waitUntilFinished();
// Now check whether the output is still as we expect.
List<RowMetaAndData> goldenImageRows = createResultData6();
List<RowMetaAndData> resultRows1 = endRc.getRowsWritten();
checkRows(resultRows1, goldenImageRows);
}
use of org.pentaho.di.trans.steps.getvariable.GetVariableMeta.FieldDefinition in project pentaho-kettle by pentaho.
the class ParameterSimpleTransIT method testParameterSimpleTrans1.
/**
* Test case for parameters using a simple transformation.
*
* @throws Exception
* exception on any problem.
*/
public void testParameterSimpleTrans1() throws Exception {
KettleEnvironment.init();
//
// Create a new transformation...
//
TransMeta transMeta = new TransMeta();
transMeta.setName("parameter_simple_trans1");
PluginRegistry registry = PluginRegistry.getInstance();
//
// create a get variables step...
//
String getVariablesStepname = "get variables step";
GetVariableMeta gvm = new GetVariableMeta();
// Set the information of the get variables step.
String getVariablesPid = registry.getPluginId(StepPluginType.class, gvm);
StepMeta getVariablesStep = new StepMeta(getVariablesPid, getVariablesStepname, gvm);
transMeta.addStep(getVariablesStep);
//
// Generate 1 row
//
String[] fieldName = { "PARAM1", "PARAM2" };
String[] varName = { "${Param1}", "%%PARAM2%%" };
int[] fieldType = { ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING };
int[] length = { -1, -1 };
int[] precision = { -1, -1 };
String[] format = { "", "" };
String[] currency = { "", "" };
String[] decimal = { "", "" };
String[] grouping = { "", "" };
int[] trimType = { ValueMetaInterface.TRIM_TYPE_NONE, ValueMetaInterface.TRIM_TYPE_NONE };
FieldDefinition[] fields = new FieldDefinition[fieldName.length];
for (int i = 0; i < fields.length; i++) {
FieldDefinition field = new FieldDefinition();
field.setFieldName(fieldName[i]);
field.setVariableString(varName[i]);
field.setFieldType(fieldType[i]);
field.setFieldLength(length[i]);
field.setFieldPrecision(precision[i]);
field.setFieldFormat(format[i]);
field.setCurrency(currency[i]);
field.setDecimal(decimal[i]);
field.setGroup(grouping[i]);
field.setTrimType(trimType[i]);
fields[i] = field;
}
gvm.setFieldDefinitions(fields);
//
// Create a dummy step 1
//
String dummyStepname1 = "dummy step 1";
DummyTransMeta dm1 = new DummyTransMeta();
String dummyPid1 = registry.getPluginId(StepPluginType.class, dm1);
StepMeta dummyStep1 = new StepMeta(dummyPid1, dummyStepname1, dm1);
transMeta.addStep(dummyStep1);
TransHopMeta hi1 = new TransHopMeta(getVariablesStep, dummyStep1);
transMeta.addTransHop(hi1);
// Now execute the transformation...
Trans trans = new Trans(transMeta);
trans.addParameterDefinition("Param1", "", "Parameter 1");
trans.addParameterDefinition("PARAM2", "", "Parameter 2");
trans.setParameterValue("Param1", "ParamValue1");
trans.setParameterValue("PARAM2", "PARAMVALUE2");
trans.prepareExecution(null);
StepInterface si = trans.getStepInterface(dummyStepname1, 0);
RowStepCollector endRc = new RowStepCollector();
si.addRowListener(endRc);
trans.startThreads();
trans.waitUntilFinished();
// Now check whether the output is still as we expect.
List<RowMetaAndData> goldenImageRows = createResultData1();
List<RowMetaAndData> resultRows1 = endRc.getRowsWritten();
checkRows(resultRows1, goldenImageRows);
}
use of org.pentaho.di.trans.steps.getvariable.GetVariableMeta.FieldDefinition in project pentaho-kettle by pentaho.
the class GetVariableMetaTest method setUpLoadSave.
@Before
public void setUpLoadSave() throws Exception {
List<String> attributes = Arrays.asList("fieldDefinitions");
Map<String, String> getterMap = new HashMap<String, String>();
getterMap.put("fieldDefinitions", "getFieldDefinitions");
Map<String, String> setterMap = new HashMap<String, String>();
setterMap.put("fieldDefinitions", "setFieldDefinitions");
FieldDefinition fieldDefinition = new FieldDefinition();
fieldDefinition.setFieldName("fieldName");
fieldDefinition.setFieldLength(4);
fieldDefinition.setCurrency(null);
fieldDefinition.setFieldPrecision(5);
fieldDefinition.setFieldType(ValueMetaInterface.TYPE_NUMBER);
fieldDefinition.setGroup("group");
fieldDefinition.setVariableString("variableString");
FieldLoadSaveValidator<FieldDefinition[]> fieldDefinitionLoadSaveValidator = new ArrayLoadSaveValidator<FieldDefinition>(new FieldDefinitionLoadSaveValidator(fieldDefinition), 5);
Map<String, FieldLoadSaveValidator<?>> attrValidatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();
attrValidatorMap.put("fieldName", fieldDefinitionLoadSaveValidator);
Map<String, FieldLoadSaveValidator<?>> typeValidatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();
typeValidatorMap.put(FieldDefinition[].class.getCanonicalName(), fieldDefinitionLoadSaveValidator);
loadSaveTester = new LoadSaveTester<>(testMetaClass, attributes, Collections.emptyList(), Collections.emptyList(), getterMap, setterMap, attrValidatorMap, typeValidatorMap, this);
}
use of org.pentaho.di.trans.steps.getvariable.GetVariableMeta.FieldDefinition in project pentaho-kettle by pentaho.
the class GetVariableDialog method getInfo.
private void getInfo(GetVariableMeta input) throws KettleException {
// return value
stepname = wStepname.getText();
// Table table = wFields.table;
int count = wFields.nrNonEmpty();
input.allocate(count);
// CHECKSTYLE:Indentation:OFF
for (int i = 0; i < count; i++) {
TableItem item = wFields.getNonEmpty(i);
FieldDefinition currentField = input.getFieldDefinitions()[i];
int index = 1;
currentField.setFieldName(item.getText(index++));
currentField.setVariableString(item.getText(index++));
currentField.setFieldType(ValueMetaFactory.getIdForValueMeta(item.getText(index++)));
currentField.setFieldFormat(item.getText(index++));
currentField.setFieldLength(Const.toInt(item.getText(index++), -1));
currentField.setFieldPrecision(Const.toInt(item.getText(index++), -1));
currentField.setCurrency(item.getText(index++));
currentField.setDecimal(item.getText(index++));
currentField.setGroup(item.getText(index++));
currentField.setTrimType(ValueMetaString.getTrimTypeByDesc(item.getText(index++)));
}
}
use of org.pentaho.di.trans.steps.getvariable.GetVariableMeta.FieldDefinition in project pentaho-kettle by pentaho.
the class ParameterSimpleTransIT method testParameterSimpleTrans5.
/**
* Test case for parameters using a simple transformation. Check whether parameters override variables.
*
* @throws Exception
* exception on any problem.
*/
public void testParameterSimpleTrans5() throws Exception {
KettleEnvironment.init();
//
// Create a new transformation...
//
TransMeta transMeta = new TransMeta();
transMeta.setName("parameter_simple_trans4");
PluginRegistry registry = PluginRegistry.getInstance();
//
// create a get variables step...
//
String getVariablesStepname = "get variables step";
GetVariableMeta gvm = new GetVariableMeta();
// Set the information of the get variables step.
String getVariablesPid = registry.getPluginId(StepPluginType.class, gvm);
StepMeta getVariablesStep = new StepMeta(getVariablesPid, getVariablesStepname, gvm);
transMeta.addStep(getVariablesStep);
//
// Generate 1 row
//
String[] fieldName = { "PARAM1", "PARAM2" };
String[] varName = { "${Param1}", "%%PARAM2%%" };
int[] fieldType = { ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING };
int[] length = { -1, -1 };
int[] precision = { -1, -1 };
String[] format = { "", "" };
String[] currency = { "", "" };
String[] decimal = { "", "" };
String[] grouping = { "", "" };
int[] trimType = { ValueMetaInterface.TRIM_TYPE_NONE, ValueMetaInterface.TRIM_TYPE_NONE };
FieldDefinition[] fields = new FieldDefinition[fieldName.length];
for (int i = 0; i < fields.length; i++) {
FieldDefinition field = new FieldDefinition();
field.setFieldName(fieldName[i]);
field.setVariableString(varName[i]);
field.setFieldType(fieldType[i]);
field.setFieldLength(length[i]);
field.setFieldPrecision(precision[i]);
field.setFieldFormat(format[i]);
field.setCurrency(currency[i]);
field.setDecimal(decimal[i]);
field.setGroup(grouping[i]);
field.setTrimType(trimType[i]);
fields[i] = field;
}
gvm.setFieldDefinitions(fields);
//
// Create a dummy step 1
//
String dummyStepname1 = "dummy step 1";
DummyTransMeta dm1 = new DummyTransMeta();
String dummyPid1 = registry.getPluginId(StepPluginType.class, dm1);
StepMeta dummyStep1 = new StepMeta(dummyPid1, dummyStepname1, dm1);
transMeta.addStep(dummyStep1);
TransHopMeta hi1 = new TransHopMeta(getVariablesStep, dummyStep1);
transMeta.addTransHop(hi1);
// Now execute the transformation...
Trans trans = new Trans(transMeta);
trans.addParameterDefinition("Param1", "default1", "Parameter 1");
trans.addParameterDefinition("PARAM2", "", "Parameter 2");
trans.setParameterValue("PARAM2", "PARAMVALUE2");
// See whether this variable overrides the parameter... it should NOT. Param1
// is defined but not set, so defaults should kick in.
trans.setVariable("Param1", "Variable1");
trans.prepareExecution(null);
StepInterface si = trans.getStepInterface(dummyStepname1, 0);
RowStepCollector endRc = new RowStepCollector();
si.addRowListener(endRc);
trans.startThreads();
trans.waitUntilFinished();
// Now check whether the output is still as we expect.
List<RowMetaAndData> goldenImageRows = createResultData5();
List<RowMetaAndData> resultRows1 = endRc.getRowsWritten();
checkRows(resultRows1, goldenImageRows);
}
Aggregations