use of org.pentaho.di.core.CheckResult in project pentaho-kettle by pentaho.
the class RandomCCNumberGeneratorMeta method check.
public void check(List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository, IMetaStore metaStore) {
// See if we have input streams leading to this step!
int nrRemarks = remarks.size();
for (int i = 0; i < fieldCCType.length; i++) {
int len = Const.toInt(transMeta.environmentSubstitute(getFieldCCLength()[i]), -1);
if (len < 0) {
CheckResult cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "RandomCCNumberGeneratorMeta.CheckResult.WrongLen", String.valueOf(i)), stepMeta);
remarks.add(cr);
}
int size = Const.toInt(transMeta.environmentSubstitute(getFieldCCSize()[i]), -1);
if (size < 0) {
CheckResult cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "RandomCCNumberGeneratorMeta.CheckResult.WrongSize", String.valueOf(i)), stepMeta);
remarks.add(cr);
}
}
if (remarks.size() == nrRemarks) {
CheckResult cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "RandomCCNumberGeneratorMeta.CheckResult.AllTypesSpecified"), stepMeta);
remarks.add(cr);
}
if (Utils.isEmpty(getCardNumberFieldName())) {
CheckResult cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "RandomCCNumberGeneratorMeta.CheckResult.CardNumberFieldMissing"), stepMeta);
remarks.add(cr);
}
}
use of org.pentaho.di.core.CheckResult in project pentaho-kettle by pentaho.
the class ReplaceStringMeta method check.
public void check(List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepinfo, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository, IMetaStore metaStore) {
CheckResult cr;
String error_message = "";
boolean first = true;
boolean error_found = false;
if (prev == null) {
error_message += BaseMessages.getString(PKG, "ReplaceStringMeta.CheckResult.NoInputReceived") + Const.CR;
cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, error_message, stepinfo);
remarks.add(cr);
} else {
for (int i = 0; i < fieldInStream.length; i++) {
String field = fieldInStream[i];
ValueMetaInterface v = prev.searchValueMeta(field);
if (v == null) {
if (first) {
first = false;
error_message += BaseMessages.getString(PKG, "ReplaceStringMeta.CheckResult.MissingInStreamFields") + Const.CR;
}
error_found = true;
error_message += "\t\t" + field + Const.CR;
}
}
if (error_found) {
cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, error_message, stepinfo);
} else {
cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "ReplaceStringMeta.CheckResult.FoundInStreamFields"), stepinfo);
}
remarks.add(cr);
// Check whether all are strings
first = true;
error_found = false;
for (int i = 0; i < fieldInStream.length; i++) {
String field = fieldInStream[i];
ValueMetaInterface v = prev.searchValueMeta(field);
if (v != null) {
if (v.getType() != ValueMetaInterface.TYPE_STRING) {
if (first) {
first = false;
error_message += BaseMessages.getString(PKG, "ReplaceStringMeta.CheckResult.OperationOnNonStringFields") + Const.CR;
}
error_found = true;
error_message += "\t\t" + field + Const.CR;
}
}
}
if (error_found) {
cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, error_message, stepinfo);
} else {
cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "ReplaceStringMeta.CheckResult.AllOperationsOnStringFields"), stepinfo);
}
remarks.add(cr);
if (fieldInStream.length > 0) {
for (int idx = 0; idx < fieldInStream.length; idx++) {
if (Utils.isEmpty(fieldInStream[idx])) {
cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "ReplaceStringMeta.CheckResult.InStreamFieldMissing", new Integer(idx + 1).toString()), stepinfo);
remarks.add(cr);
}
}
}
// Check if all input fields are distinct.
for (int idx = 0; idx < fieldInStream.length; idx++) {
for (int jdx = 0; jdx < fieldInStream.length; jdx++) {
if (fieldInStream[idx].equals(fieldInStream[jdx]) && idx != jdx && idx < jdx) {
error_message = BaseMessages.getString(PKG, "ReplaceStringMeta.CheckResult.FieldInputError", fieldInStream[idx]);
cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, error_message, stepinfo);
remarks.add(cr);
}
}
}
}
}
use of org.pentaho.di.core.CheckResult in project pentaho-kettle by pentaho.
the class RowGenerator method buildRow.
public static final RowMetaAndData buildRow(RowGeneratorMeta meta, List<CheckResultInterface> remarks, String origin) throws KettlePluginException {
RowMetaInterface rowMeta = new RowMeta();
Object[] rowData = RowDataUtil.allocateRowData(meta.getFieldName().length + 2);
int index = 0;
if (meta.isNeverEnding()) {
if (!Utils.isEmpty(meta.getRowTimeField())) {
rowMeta.addValueMeta(new ValueMetaDate(meta.getRowTimeField()));
rowData[index++] = null;
}
if (!Utils.isEmpty(meta.getLastTimeField())) {
rowMeta.addValueMeta(new ValueMetaDate(meta.getLastTimeField()));
rowData[index++] = null;
}
}
for (int i = 0; i < meta.getFieldName().length; i++) {
int valtype = ValueMetaFactory.getIdForValueMeta(meta.getFieldType()[i]);
if (meta.getFieldName()[i] != null) {
// build a
ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta(meta.getFieldName()[i], valtype);
// value!
valueMeta.setLength(meta.getFieldLength()[i]);
valueMeta.setPrecision(meta.getFieldPrecision()[i]);
valueMeta.setConversionMask(meta.getFieldFormat()[i]);
valueMeta.setCurrencySymbol(meta.getCurrency()[i]);
valueMeta.setGroupingSymbol(meta.getGroup()[i]);
valueMeta.setDecimalSymbol(meta.getDecimal()[i]);
valueMeta.setOrigin(origin);
ValueMetaInterface stringMeta = ValueMetaFactory.cloneValueMeta(valueMeta, ValueMetaInterface.TYPE_STRING);
if (meta.isSetEmptyString() != null && meta.isSetEmptyString()[i]) {
// Set empty string
rowData[index] = StringUtil.EMPTY_STRING;
} else {
String stringValue = meta.getValue()[i];
// If the value is empty: consider it to be NULL.
if (Utils.isEmpty(stringValue)) {
rowData[index] = null;
if (valueMeta.getType() == ValueMetaInterface.TYPE_NONE) {
String message = BaseMessages.getString(PKG, "RowGenerator.CheckResult.SpecifyTypeError", valueMeta.getName(), stringValue);
remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
}
} else {
//
try {
rowData[index] = valueMeta.convertData(stringMeta, stringValue);
} catch (KettleValueException e) {
switch(valueMeta.getType()) {
case ValueMetaInterface.TYPE_NUMBER:
String message = BaseMessages.getString(PKG, "RowGenerator.BuildRow.Error.Parsing.Number", valueMeta.getName(), stringValue, e.toString());
remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
break;
case ValueMetaInterface.TYPE_DATE:
message = BaseMessages.getString(PKG, "RowGenerator.BuildRow.Error.Parsing.Date", valueMeta.getName(), stringValue, e.toString());
remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
break;
case ValueMetaInterface.TYPE_INTEGER:
message = BaseMessages.getString(PKG, "RowGenerator.BuildRow.Error.Parsing.Integer", valueMeta.getName(), stringValue, e.toString());
remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
break;
case ValueMetaInterface.TYPE_BIGNUMBER:
message = BaseMessages.getString(PKG, "RowGenerator.BuildRow.Error.Parsing.BigNumber", valueMeta.getName(), stringValue, e.toString());
remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
break;
case ValueMetaInterface.TYPE_TIMESTAMP:
message = BaseMessages.getString(PKG, "RowGenerator.BuildRow.Error.Parsing.Timestamp", valueMeta.getName(), stringValue, e.toString());
remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
break;
default:
// Boolean and binary don't throw errors normally, so it's probably an unspecified error problem...
message = BaseMessages.getString(PKG, "RowGenerator.CheckResult.SpecifyTypeError", valueMeta.getName(), stringValue);
remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
break;
}
}
}
}
// Now add value to the row!
// This is in fact a copy from the fields row, but now with data.
rowMeta.addValueMeta(valueMeta);
index++;
}
}
return new RowMetaAndData(rowMeta, rowData);
}
use of org.pentaho.di.core.CheckResult in project pentaho-kettle by pentaho.
the class RowGenerator method init.
@Override
public boolean init(StepMetaInterface smi, StepDataInterface sdi) {
try {
meta = (RowGeneratorMeta) smi;
data = (RowGeneratorData) sdi;
if (super.init(smi, sdi)) {
// Determine the number of rows to generate...
data.rowLimit = Const.toLong(environmentSubstitute(meta.getRowLimit()), -1L);
data.rowsWritten = 0L;
data.delay = Const.toLong(environmentSubstitute(meta.getIntervalInMs()), -1L);
if (data.rowLimit < 0L) {
// Unable to parse
logError(BaseMessages.getString(PKG, "RowGenerator.Wrong.RowLimit.Number"));
// fail
return false;
}
// Create a row (constants) with all the values in it...
// stores the errors...
List<CheckResultInterface> remarks = new ArrayList<CheckResultInterface>();
RowMetaAndData outputRow = buildRow(meta, remarks, getStepname());
if (!remarks.isEmpty()) {
for (int i = 0; i < remarks.size(); i++) {
CheckResult cr = (CheckResult) remarks.get(i);
logError(cr.getText());
}
return false;
}
data.outputRowData = outputRow.getData();
data.outputRowMeta = outputRow.getRowMeta();
return true;
}
return false;
} catch (Exception e) {
setErrors(1L);
logError("Error initializing step", e);
return false;
}
}
use of org.pentaho.di.core.CheckResult in project pentaho-kettle by pentaho.
the class RowGeneratorMeta method check.
public void check(List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository, IMetaStore metaStore) {
CheckResult cr;
if (prev != null && prev.size() > 0) {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "RowGeneratorMeta.CheckResult.NoInputStreamsError"), stepMeta);
remarks.add(cr);
} else {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "RowGeneratorMeta.CheckResult.NoInputStreamOk"), stepMeta);
remarks.add(cr);
String strLimit = transMeta.environmentSubstitute(rowLimit);
if (Const.toLong(strLimit, -1L) <= 0) {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_WARNING, BaseMessages.getString(PKG, "RowGeneratorMeta.CheckResult.WarnNoRows"), stepMeta);
remarks.add(cr);
} else {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "RowGeneratorMeta.CheckResult.WillReturnRows", strLimit), stepMeta);
remarks.add(cr);
}
}
// See if we have input streams leading to this step!
if (input.length > 0) {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "RowGeneratorMeta.CheckResult.NoInputError"), stepMeta);
remarks.add(cr);
} else {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "RowGeneratorMeta.CheckResult.NoInputOk"), stepMeta);
remarks.add(cr);
}
}
Aggregations