use of org.pentaho.di.core.RowMetaAndData in project pentaho-kettle by pentaho.
the class JobEntrySimpleEval method execute.
@Override
public Result execute(Result previousResult, int nr) throws KettleException {
Result result = previousResult;
result.setNrErrors(1);
result.setResult(false);
String sourcevalue = null;
switch(valuetype) {
case VALUE_TYPE_FIELD:
List<RowMetaAndData> rows = result.getRows();
RowMetaAndData resultRow = null;
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobEntrySimpleEval.Log.ArgFromPrevious.Found", (rows != null ? rows.size() : 0) + ""));
}
if (rows.size() == 0) {
rows = null;
logError(BaseMessages.getString(PKG, "JobEntrySimpleEval.Error.NoRows"));
return result;
}
// get first row
resultRow = rows.get(0);
String realfieldname = environmentSubstitute(fieldname);
int indexOfField = -1;
indexOfField = resultRow.getRowMeta().indexOfValue(realfieldname);
if (indexOfField == -1) {
logError(BaseMessages.getString(PKG, "JobEntrySimpleEval.Error.FieldNotExist", realfieldname));
resultRow = null;
rows = null;
return result;
}
sourcevalue = resultRow.getString(indexOfField, null);
if (sourcevalue == null) {
sourcevalue = "";
}
resultRow = null;
rows = null;
break;
case VALUE_TYPE_VARIABLE:
if (Utils.isEmpty(variablename)) {
logError(BaseMessages.getString(PKG, "JobEntrySimpleEval.Error.VariableMissing"));
return result;
}
if (isSuccessWhenVarSet()) {
// return variable name
// remove specifications if needed
String variableName = StringUtil.getVariableName(Const.NVL(getVariableName(), ""));
// Get value, if the variable is not set, Null will be returned
String value = getVariable(variableName);
if (value != null) {
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobEntrySimpleEval.VariableSet", variableName));
}
result.setResult(true);
result.setNrErrors(0);
return result;
} else {
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobEntrySimpleEval.VariableNotSet", variableName));
}
// PDI-6943: this job entry does not set errors upon evaluation, independently of the outcome of the check
result.setNrErrors(0);
return result;
}
}
sourcevalue = environmentSubstitute(getVariableWithSpec());
break;
default:
break;
}
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobSimpleEval.Log.ValueToevaluate", sourcevalue));
}
boolean success = false;
String realCompareValue = environmentSubstitute(comparevalue);
if (realCompareValue == null) {
realCompareValue = "";
}
String realMinValue = environmentSubstitute(minvalue);
String realMaxValue = environmentSubstitute(maxvalue);
switch(fieldtype) {
case FIELD_TYPE_STRING:
switch(successcondition) {
case // equal
SUCCESS_CONDITION_EQUAL:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
success = (sourcevalue.equals(realCompareValue));
if (valuetype == VALUE_TYPE_VARIABLE && !success) {
// make the empty value evaluate to true when compared to a not set variable
if (Utils.isEmpty(realCompareValue)) {
String variableName = StringUtil.getVariableName(variablename);
if (System.getProperty(variableName) == null) {
success = true;
}
}
}
break;
case // different
SUCCESS_CONDITION_DIFFERENT:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
success = (!sourcevalue.equals(realCompareValue));
break;
case // contains
SUCCESS_CONDITION_CONTAINS:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
success = (sourcevalue.contains(realCompareValue));
break;
case // not contains
SUCCESS_CONDITION_NOT_CONTAINS:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
success = (!sourcevalue.contains(realCompareValue));
break;
case // starts with
SUCCESS_CONDITION_START_WITH:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
success = (sourcevalue.startsWith(realCompareValue));
break;
case // not start with
SUCCESS_CONDITION_NOT_START_WITH:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
success = (!sourcevalue.startsWith(realCompareValue));
break;
case // ends with
SUCCESS_CONDITION_END_WITH:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
success = (sourcevalue.endsWith(realCompareValue));
break;
case // not ends with
SUCCESS_CONDITION_NOT_END_WITH:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
success = (!sourcevalue.endsWith(realCompareValue));
break;
case // regexp
SUCCESS_CONDITION_REGEX:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
success = (Pattern.compile(realCompareValue).matcher(sourcevalue).matches());
break;
case // in list
SUCCESS_CONDITION_IN_LIST:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
realCompareValue = Const.NVL(realCompareValue, "");
String[] parts = realCompareValue.split(",");
for (int i = 0; i < parts.length && !success; i++) {
success = (sourcevalue.equals(parts[i].trim()));
}
break;
case // not in list
SUCCESS_CONDITION_NOT_IN_LIST:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
realCompareValue = Const.NVL(realCompareValue, "");
parts = realCompareValue.split(",");
success = true;
for (int i = 0; i < parts.length && success; i++) {
success = !(sourcevalue.equals(parts[i].trim()));
}
break;
default:
break;
}
break;
case FIELD_TYPE_NUMBER:
double valuenumber;
try {
valuenumber = Double.parseDouble(sourcevalue);
} catch (Exception e) {
logError(BaseMessages.getString(PKG, "JobEntrySimpleEval.Error.UnparsableNumber", sourcevalue, e.getMessage()));
return result;
}
double valuecompare;
switch(successnumbercondition) {
case // equal
SUCCESS_NUMBER_CONDITION_EQUAL:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
try {
valuecompare = Double.parseDouble(realCompareValue);
} catch (Exception e) {
logError(BaseMessages.getString(PKG, "JobEntrySimpleEval.Error.UnparsableNumber", realCompareValue, e.getMessage()));
return result;
}
success = (valuenumber == valuecompare);
break;
case // different
SUCCESS_NUMBER_CONDITION_DIFFERENT:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
try {
valuecompare = Double.parseDouble(realCompareValue);
} catch (Exception e) {
logError(BaseMessages.getString(PKG, "JobEntrySimpleEval.Error.UnparsableNumber", realCompareValue, e.getMessage()));
return result;
}
success = (valuenumber != valuecompare);
break;
case // smaller
SUCCESS_NUMBER_CONDITION_SMALLER:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
try {
valuecompare = Double.parseDouble(realCompareValue);
} catch (Exception e) {
logError(BaseMessages.getString(PKG, "JobEntrySimpleEval.Error.UnparsableNumber", realCompareValue, e.getMessage()));
return result;
}
success = (valuenumber < valuecompare);
break;
case // smaller or equal
SUCCESS_NUMBER_CONDITION_SMALLER_EQUAL:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
try {
valuecompare = Double.parseDouble(realCompareValue);
} catch (Exception e) {
logError(BaseMessages.getString(PKG, "JobEntrySimpleEval.Error.UnparsableNumber", realCompareValue, e.getMessage()));
return result;
}
success = (valuenumber <= valuecompare);
break;
case // greater
SUCCESS_NUMBER_CONDITION_GREATER:
try {
valuecompare = Double.parseDouble(realCompareValue);
} catch (Exception e) {
logError(BaseMessages.getString(PKG, "JobEntrySimpleEval.Error.UnparsableNumber", realCompareValue, e.getMessage()));
return result;
}
success = (valuenumber > valuecompare);
break;
case // greater or equal
SUCCESS_NUMBER_CONDITION_GREATER_EQUAL:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
try {
valuecompare = Double.parseDouble(realCompareValue);
} catch (Exception e) {
logError(BaseMessages.getString(PKG, "JobEntrySimpleEval.Error.UnparsableNumber", realCompareValue, e.getMessage()));
return result;
}
success = (valuenumber >= valuecompare);
break;
case // between min and max
SUCCESS_NUMBER_CONDITION_BETWEEN:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValues", realMinValue, realMaxValue));
}
double valuemin;
try {
valuemin = Double.parseDouble(realMinValue);
} catch (Exception e) {
logError(BaseMessages.getString(PKG, "JobEntrySimpleEval.Error.UnparsableNumber", realMinValue, e.getMessage()));
return result;
}
double valuemax;
try {
valuemax = Double.parseDouble(realMaxValue);
} catch (Exception e) {
logError(BaseMessages.getString(PKG, "JobEntrySimpleEval.Error.UnparsableNumber", realMaxValue, e.getMessage()));
return result;
}
if (valuemin >= valuemax) {
logError(BaseMessages.getString(PKG, "JobEntrySimpleEval.Error.IncorrectNumbers", realMinValue, realMaxValue));
return result;
}
success = (valuenumber >= valuemin && valuenumber <= valuemax);
break;
case // in list
SUCCESS_NUMBER_CONDITION_IN_LIST:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
String[] parts = realCompareValue.split(",");
for (int i = 0; i < parts.length && !success; i++) {
try {
valuecompare = Double.parseDouble(parts[i]);
} catch (Exception e) {
logError(toString(), BaseMessages.getString(PKG, "JobEntrySimpleEval.Error.UnparsableNumber", parts[i], e.getMessage()));
return result;
}
success = (valuenumber == valuecompare);
}
break;
case // not in list
SUCCESS_NUMBER_CONDITION_NOT_IN_LIST:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
realCompareValue = Const.NVL(realCompareValue, "");
parts = realCompareValue.split(",");
success = true;
for (int i = 0; i < parts.length && success; i++) {
try {
valuecompare = Double.parseDouble(parts[i]);
} catch (Exception e) {
logError(toString(), BaseMessages.getString(PKG, "JobEntrySimpleEval.Error.UnparsableNumber", parts[i], e.getMessage()));
return result;
}
success = (valuenumber != valuecompare);
}
break;
default:
break;
}
break;
case FIELD_TYPE_DATE_TIME:
String realMask = environmentSubstitute(mask);
SimpleDateFormat df = new SimpleDateFormat();
if (!Utils.isEmpty(realMask)) {
df.applyPattern(realMask);
}
Date datevalue = null;
try {
datevalue = convertToDate(sourcevalue, realMask, df);
} catch (Exception e) {
logError(e.getMessage());
return result;
}
Date datecompare;
switch(successnumbercondition) {
case // equal
SUCCESS_NUMBER_CONDITION_EQUAL:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
try {
datecompare = convertToDate(realCompareValue, realMask, df);
} catch (Exception e) {
logError(e.getMessage());
return result;
}
success = (datevalue.equals(datecompare));
break;
case // different
SUCCESS_NUMBER_CONDITION_DIFFERENT:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
try {
datecompare = convertToDate(realCompareValue, realMask, df);
} catch (Exception e) {
logError(e.getMessage());
return result;
}
success = (!datevalue.equals(datecompare));
break;
case // smaller
SUCCESS_NUMBER_CONDITION_SMALLER:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
try {
datecompare = convertToDate(realCompareValue, realMask, df);
} catch (Exception e) {
logError(e.getMessage());
return result;
}
success = (datevalue.before(datecompare));
break;
case // smaller or equal
SUCCESS_NUMBER_CONDITION_SMALLER_EQUAL:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
try {
datecompare = convertToDate(realCompareValue, realMask, df);
} catch (Exception e) {
logError(e.getMessage());
return result;
}
success = (datevalue.before(datecompare) || datevalue.equals(datecompare));
break;
case // greater
SUCCESS_NUMBER_CONDITION_GREATER:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
try {
datecompare = convertToDate(realCompareValue, realMask, df);
} catch (Exception e) {
logError(e.getMessage());
return result;
}
success = (datevalue.after(datecompare));
break;
case // greater or equal
SUCCESS_NUMBER_CONDITION_GREATER_EQUAL:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
try {
datecompare = convertToDate(realCompareValue, realMask, df);
} catch (Exception e) {
logError(e.getMessage());
return result;
}
success = (datevalue.after(datecompare) || datevalue.equals(datecompare));
break;
case // between min and max
SUCCESS_NUMBER_CONDITION_BETWEEN:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValues", realMinValue, realMaxValue));
}
Date datemin;
try {
datemin = convertToDate(realMinValue, realMask, df);
} catch (Exception e) {
logError(e.getMessage());
return result;
}
Date datemax;
try {
datemax = convertToDate(realMaxValue, realMask, df);
} catch (Exception e) {
logError(e.getMessage());
return result;
}
if (datemin.after(datemax) || datemin.equals(datemax)) {
logError(BaseMessages.getString(PKG, "JobEntrySimpleEval.Error.IncorrectDates", realMinValue, realMaxValue));
return result;
}
success = ((datevalue.after(datemin) || datevalue.equals(datemin)) && (datevalue.before(datemax) || datevalue.equals(datemax)));
break;
case // in list
SUCCESS_NUMBER_CONDITION_IN_LIST:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
String[] parts = realCompareValue.split(",");
for (int i = 0; i < parts.length && !success; i++) {
try {
datecompare = convertToDate(realCompareValue, realMask, df);
} catch (Exception e) {
logError(toString(), e.getMessage());
return result;
}
success = (datevalue.equals(datecompare));
}
break;
case // not in list
SUCCESS_NUMBER_CONDITION_NOT_IN_LIST:
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobSimpleEval.Log.CompareWithValue", sourcevalue, realCompareValue));
}
realCompareValue = Const.NVL(realCompareValue, "");
parts = realCompareValue.split(",");
success = true;
for (int i = 0; i < parts.length && success; i++) {
try {
datecompare = convertToDate(realCompareValue, realMask, df);
} catch (Exception e) {
logError(toString(), e.getMessage());
return result;
}
success = (!datevalue.equals(datecompare));
}
break;
default:
break;
}
df = null;
break;
case FIELD_TYPE_BOOLEAN:
boolean valuebool;
try {
valuebool = ValueMetaString.convertStringToBoolean(sourcevalue);
} catch (Exception e) {
logError(BaseMessages.getString(PKG, "JobEntrySimpleEval.Error.UnparsableBoolean", sourcevalue, e.getMessage()));
return result;
}
switch(successbooleancondition) {
case // false
SUCCESS_BOOLEAN_CONDITION_FALSE:
success = (!valuebool);
break;
case // true
SUCCESS_BOOLEAN_CONDITION_TRUE:
success = (valuebool);
break;
default:
break;
}
break;
default:
break;
}
result.setResult(success);
// PDI-6943: this job entry does not set errors upon evaluation, independently of the outcome of the check
result.setNrErrors(0);
return result;
}
use of org.pentaho.di.core.RowMetaAndData in project pentaho-kettle by pentaho.
the class JobEntryEvalFilesMetrics method execute.
public Result execute(Result previousResult, int nr) throws KettleException {
Result result = previousResult;
result.setNrErrors(1);
result.setResult(false);
List<RowMetaAndData> rows = result.getRows();
RowMetaAndData resultRow = null;
// Set Embedded NamedCluter MetatStore Provider Key so that it can be passed to VFS
if (parentJobMeta.getNamedClusterEmbedManager() != null) {
parentJobMeta.getNamedClusterEmbedManager().passEmbeddedMetastoreKey(this, parentJobMeta.getEmbeddedMetastoreProviderKey());
}
try {
initMetrics();
} catch (Exception e) {
logError(BaseMessages.getString(PKG, "JobEvalFilesMetrics.Error.Init", e.toString()));
return result;
}
// Get source and destination files, also wildcard
String[] vsourcefilefolder = sourceFileFolder;
String[] vwildcard = sourceWildcard;
String[] vincludeSubFolders = sourceIncludeSubfolders;
switch(getSourceFiles()) {
case SOURCE_FILES_PREVIOUS_RESULT:
// Filenames are retrieved from previous result rows
String realResultFieldFile = environmentSubstitute(getResultFieldFile());
String realResultFieldWildcard = environmentSubstitute(getResultFieldWildcard());
String realResultFieldIncluseSubfolders = environmentSubstitute(getResultFieldIncludeSubfolders());
int indexOfResultFieldFile = -1;
if (Utils.isEmpty(realResultFieldFile)) {
logError(BaseMessages.getString(PKG, "JobEvalFilesMetrics.Error.ResultFieldsFileMissing"));
return result;
}
int indexOfResultFieldWildcard = -1;
int indexOfResultFieldIncludeSubfolders = -1;
// as such we must get rows
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobEvalFilesMetrics.Log.ArgFromPrevious.Found", (rows != null ? rows.size() : 0) + ""));
}
if (rows != null && rows.size() > 0) {
// We get rows
RowMetaAndData firstRow = rows.get(0);
indexOfResultFieldFile = firstRow.getRowMeta().indexOfValue(realResultFieldFile);
if (indexOfResultFieldFile == -1) {
logError(BaseMessages.getString(PKG, "JobEvalFilesMetrics.Error.CanNotFindField", realResultFieldFile));
return result;
}
if (!Utils.isEmpty(realResultFieldWildcard)) {
indexOfResultFieldWildcard = firstRow.getRowMeta().indexOfValue(realResultFieldWildcard);
if (indexOfResultFieldWildcard == -1) {
logError(BaseMessages.getString(PKG, "JobEvalFilesMetrics.Error.CanNotFindField", realResultFieldWildcard));
return result;
}
}
if (!Utils.isEmpty(realResultFieldIncluseSubfolders)) {
indexOfResultFieldIncludeSubfolders = firstRow.getRowMeta().indexOfValue(realResultFieldIncluseSubfolders);
if (indexOfResultFieldIncludeSubfolders == -1) {
logError(BaseMessages.getString(PKG, "JobEvalFilesMetrics.Error.CanNotFindField", realResultFieldIncluseSubfolders));
return result;
}
}
for (int iteration = 0; iteration < rows.size() && !parentJob.isStopped(); iteration++) {
resultRow = rows.get(iteration);
// Get source and destination file names, also wildcard
String vsourcefilefolder_previous = resultRow.getString(indexOfResultFieldFile, null);
String vwildcard_previous = null;
if (indexOfResultFieldWildcard > -1) {
vwildcard_previous = resultRow.getString(indexOfResultFieldWildcard, null);
}
String vincludeSubFolders_previous = NO;
if (indexOfResultFieldIncludeSubfolders > -1) {
vincludeSubFolders_previous = resultRow.getString(indexOfResultFieldIncludeSubfolders, NO);
}
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobEvalFilesMetrics.Log.ProcessingRow", vsourcefilefolder_previous, vwildcard_previous));
}
ProcessFileFolder(vsourcefilefolder_previous, vwildcard_previous, vincludeSubFolders_previous, parentJob, result);
}
}
break;
case SOURCE_FILES_FILENAMES_RESULT:
List<ResultFile> resultFiles = result.getResultFilesList();
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobEvalFilesMetrics.Log.ResultFilenames.Found", (resultFiles != null ? resultFiles.size() : 0) + ""));
}
if (resultFiles != null && resultFiles.size() > 0) {
// Let's check wildcard
Pattern pattern = null;
String realPattern = environmentSubstitute(getResultFilenamesWildcard());
if (!Utils.isEmpty(realPattern)) {
pattern = Pattern.compile(realPattern);
}
for (Iterator<ResultFile> it = resultFiles.iterator(); it.hasNext() && !parentJob.isStopped(); ) {
ResultFile resultFile = it.next();
FileObject file = resultFile.getFile();
try {
if (file != null && file.exists()) {
boolean getIt = true;
if (pattern != null) {
Matcher matcher = pattern.matcher(file.getName().getBaseName());
getIt = matcher.matches();
}
if (getIt) {
getFileSize(file, result, parentJob);
}
}
} catch (Exception e) {
incrementErrors();
logError(BaseMessages.getString(PKG, "JobEvalFilesMetrics.Error.GettingFileFromResultFilenames", file.toString(), e.toString()));
} finally {
if (file != null) {
try {
file.close();
} catch (Exception e) {
/* Ignore */
}
}
}
}
}
break;
default:
// from grid entered by user
if (vsourcefilefolder != null && vsourcefilefolder.length > 0) {
for (int i = 0; i < vsourcefilefolder.length && !parentJob.isStopped(); i++) {
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobEvalFilesMetrics.Log.ProcessingRow", vsourcefilefolder[i], vwildcard[i]));
}
ProcessFileFolder(vsourcefilefolder[i], vwildcard[i], vincludeSubFolders[i], parentJob, result);
}
} else {
logError(BaseMessages.getString(PKG, "JobEvalFilesMetrics.Error.FilesGridEmpty"));
return result;
}
break;
}
result.setResult(isSuccess());
result.setNrErrors(getNrError());
displayResults();
return result;
}
use of org.pentaho.di.core.RowMetaAndData in project pentaho-kettle by pentaho.
the class JobEntryMoveFiles method execute.
public Result execute(Result previousResult, int nr) throws KettleException {
Result result = previousResult;
List<RowMetaAndData> rows = result.getRows();
RowMetaAndData resultRow = null;
result.setNrErrors(1);
result.setResult(false);
NrErrors = 0;
NrSuccess = 0;
successConditionBroken = false;
successConditionBrokenExit = false;
limitFiles = Const.toInt(environmentSubstitute(getNrErrorsLessThan()), 10);
if (log.isDetailed()) {
if (simulate) {
logDetailed(BaseMessages.getString(PKG, "JobMoveFiles.Log.SimulationOn"));
}
if (include_subfolders) {
logDetailed(BaseMessages.getString(PKG, "JobMoveFiles.Log.IncludeSubFoldersOn"));
}
}
String MoveToFolder = environmentSubstitute(destinationFolder);
// Get source and destination files, also wildcard
String[] vsourcefilefolder = source_filefolder;
String[] vdestinationfilefolder = destination_filefolder;
String[] vwildcard = wildcard;
// Set Embedded NamedCluter MetatStore Provider Key so that it can be passed to VFS
if (parentJobMeta.getNamedClusterEmbedManager() != null) {
parentJobMeta.getNamedClusterEmbedManager().passEmbeddedMetastoreKey(this, parentJobMeta.getEmbeddedMetastoreProviderKey());
}
if (iffileexists.equals("move_file")) {
if (Utils.isEmpty(MoveToFolder)) {
logError(BaseMessages.getString(PKG, "JobMoveFiles.Log.Error.MoveToFolderMissing"));
return result;
}
FileObject folder = null;
try {
folder = KettleVFS.getFileObject(MoveToFolder, this);
if (!folder.exists()) {
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobMoveFiles.Log.Error.FolderMissing", MoveToFolder));
}
if (create_move_to_folder) {
folder.createFolder();
} else {
logError(BaseMessages.getString(PKG, "JobMoveFiles.Log.Error.FolderMissing", MoveToFolder));
return result;
}
}
if (!folder.getType().equals(FileType.FOLDER)) {
logError(BaseMessages.getString(PKG, "JobMoveFiles.Log.Error.NotFolder", MoveToFolder));
return result;
}
} catch (Exception e) {
logError(BaseMessages.getString(PKG, "JobMoveFiles.Log.Error.GettingMoveToFolder", MoveToFolder, e.getMessage()));
return result;
} finally {
if (folder != null) {
try {
folder.close();
} catch (IOException ex) {
/* Ignore */
}
}
}
}
if (arg_from_previous) {
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobMoveFiles.Log.ArgFromPrevious.Found", (rows != null ? rows.size() : 0) + ""));
}
}
if (arg_from_previous && rows != null) {
for (int iteration = 0; iteration < rows.size() && !parentJob.isStopped(); iteration++) {
// Success condition broken?
if (successConditionBroken) {
if (!successConditionBrokenExit) {
logError(BaseMessages.getString(PKG, "JobMoveFiles.Error.SuccessConditionbroken", "" + NrErrors));
successConditionBrokenExit = true;
}
result.setNrErrors(NrErrors);
displayResults();
return result;
}
resultRow = rows.get(iteration);
// Get source and destination file names, also wildcard
String vsourcefilefolder_previous = resultRow.getString(0, null);
String vdestinationfilefolder_previous = resultRow.getString(1, null);
String vwildcard_previous = resultRow.getString(2, null);
if (!Utils.isEmpty(vsourcefilefolder_previous) && !Utils.isEmpty(vdestinationfilefolder_previous)) {
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobMoveFiles.Log.ProcessingRow", vsourcefilefolder_previous, vdestinationfilefolder_previous, vwildcard_previous));
}
if (!ProcessFileFolder(vsourcefilefolder_previous, vdestinationfilefolder_previous, vwildcard_previous, parentJob, result, MoveToFolder)) {
// The move process fail
// Update Errors
updateErrors();
}
} else {
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobMoveFiles.Log.IgnoringRow", vsourcefilefolder[iteration], vdestinationfilefolder[iteration], vwildcard[iteration]));
}
}
}
} else if (vsourcefilefolder != null && vdestinationfilefolder != null) {
for (int i = 0; i < vsourcefilefolder.length && !parentJob.isStopped(); i++) {
// Success condition broken?
if (successConditionBroken) {
if (!successConditionBrokenExit) {
logError(BaseMessages.getString(PKG, "JobMoveFiles.Error.SuccessConditionbroken", "" + NrErrors));
successConditionBrokenExit = true;
}
result.setNrErrors(NrErrors);
displayResults();
return result;
}
if (!Utils.isEmpty(vsourcefilefolder[i]) && !Utils.isEmpty(vdestinationfilefolder[i])) {
// ok we can process this file/folder
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobMoveFiles.Log.ProcessingRow", vsourcefilefolder[i], vdestinationfilefolder[i], vwildcard[i]));
}
if (!ProcessFileFolder(vsourcefilefolder[i], vdestinationfilefolder[i], vwildcard[i], parentJob, result, MoveToFolder)) {
// Update Errors
updateErrors();
}
} else {
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobMoveFiles.Log.IgnoringRow", vsourcefilefolder[i], vdestinationfilefolder[i], vwildcard[i]));
}
}
}
}
// Success Condition
result.setNrErrors(NrErrors);
result.setNrLinesWritten(NrSuccess);
if (getSuccessStatus()) {
result.setResult(true);
}
displayResults();
return result;
}
use of org.pentaho.di.core.RowMetaAndData in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryMetaStoreDelegate method getNamespaces.
public Collection<RowMetaAndData> getNamespaces() throws KettleDatabaseException, KettleValueException {
List<RowMetaAndData> attrs = new ArrayList<RowMetaAndData>();
String sql = "SELECT * FROM " + quoteTable(KettleDatabaseRepository.TABLE_R_NAMESPACE);
List<Object[]> rows = repository.connectionDelegate.getRows(sql, 0);
for (Object[] row : rows) {
RowMetaAndData rowWithMeta = new RowMetaAndData(repository.connectionDelegate.getReturnRowMeta(), row);
long id = rowWithMeta.getInteger(quote(KettleDatabaseRepository.FIELD_NAMESPACE_ID_NAMESPACE), 0);
if (id > 0) {
attrs.add(rowWithMeta);
}
}
return attrs;
}
use of org.pentaho.di.core.RowMetaAndData in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryNotePadDelegate method loadNotePadMeta.
public NotePadMeta loadNotePadMeta(ObjectId id_note) throws KettleException {
NotePadMeta note = new NotePadMeta();
try {
note.setObjectId(id_note);
RowMetaAndData r = getNote(id_note);
if (r != null) {
note.setNote(r.getString("VALUE_STR", ""));
int x = (int) r.getInteger("GUI_LOCATION_X", 0L);
int y = (int) r.getInteger("GUI_LOCATION_Y", 0L);
note.setLocation(new Point(x, y));
note.setWidth((int) r.getInteger("GUI_LOCATION_WIDTH", 0L));
note.setHeight((int) r.getInteger("GUI_LOCATION_HEIGHT", 0L));
note.setSelected(false);
// Font
note.setFontName(r.getString("FONT_NAME", null));
note.setFontSize((int) r.getInteger("FONT_SIZE", -1));
note.setFontBold(r.getBoolean("FONT_BOLD", false));
note.setFontItalic(r.getBoolean("FONT_ITALIC", false));
// Font color
note.setFontColorRed((int) r.getInteger("FONT_COLOR_RED", NotePadMeta.COLOR_RGB_BLACK_BLUE));
note.setFontColorGreen((int) r.getInteger("FONT_COLOR_GREEN", NotePadMeta.COLOR_RGB_BLACK_GREEN));
note.setFontColorBlue((int) r.getInteger("FONT_COLOR_BLUE", NotePadMeta.COLOR_RGB_BLACK_BLUE));
// Background color
note.setBackGroundColorRed((int) r.getInteger("FONT_BACK_GROUND_COLOR_RED", NotePadMeta.COLOR_RGB_DEFAULT_BG_RED));
note.setBackGroundColorGreen((int) r.getInteger("FONT_BACK_GROUND_COLOR_GREEN", NotePadMeta.COLOR_RGB_DEFAULT_BG_GREEN));
note.setBackGroundColorBlue((int) r.getInteger("FONT_BACK_GROUND_COLOR_BLUE", NotePadMeta.COLOR_RGB_DEFAULT_BG_BLUE));
// Border color
note.setBorderColorRed((int) r.getInteger("FONT_BORDER_COLOR_RED", NotePadMeta.COLOR_RGB_DEFAULT_BORDER_RED));
note.setBorderColorGreen((int) r.getInteger("FONT_BORDER_COLOR_GREEN", NotePadMeta.COLOR_RGB_DEFAULT_BORDER_GREEN));
note.setBorderColorBlue((int) r.getInteger("FONT_BORDER_COLOR_BLUE", NotePadMeta.COLOR_RGB_DEFAULT_BORDER_BLUE));
note.setDrawShadow(r.getBoolean("DRAW_SHADOW", true));
// Done!
return note;
} else {
note.setObjectId(null);
throw new KettleException("I couldn't find Notepad with id_note=" + id_note + " in the repository.");
}
} catch (KettleDatabaseException dbe) {
note.setObjectId(null);
throw new KettleException("Unable to load Notepad from repository (id_note=" + id_note + ")", dbe);
}
}
Aggregations