use of org.pentaho.di.core.Result in project pentaho-kettle by pentaho.
the class JobEntryFileCompare method execute.
public Result execute(Result previousResult, int nr) {
Result result = previousResult;
result.setResult(false);
String realFilename1 = getRealFilename1();
String realFilename2 = getRealFilename2();
FileObject file1 = null;
FileObject file2 = null;
try {
if (filename1 != null && filename2 != 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());
}
file1 = KettleVFS.getFileObject(realFilename1, this);
file2 = KettleVFS.getFileObject(realFilename2, this);
if (file1.exists() && file2.exists()) {
if (equalFileContents(file1, file2)) {
result.setResult(true);
} else {
result.setResult(false);
}
// add filename to result filenames
if (addFilenameToResult && file1.getType() == FileType.FILE && file2.getType() == FileType.FILE) {
ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, file1, parentJob.getJobname(), toString());
resultFile.setComment(BaseMessages.getString(PKG, "JobWaitForFile.FilenameAdded"));
result.getResultFiles().put(resultFile.getFile().toString(), resultFile);
resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, file2, parentJob.getJobname(), toString());
resultFile.setComment(BaseMessages.getString(PKG, "JobWaitForFile.FilenameAdded"));
result.getResultFiles().put(resultFile.getFile().toString(), resultFile);
}
} else {
if (!file1.exists()) {
logError(BaseMessages.getString(PKG, "JobEntryFileCompare.ERROR_0004_File1_Does_Not_Exist", realFilename1));
}
if (!file2.exists()) {
logError(BaseMessages.getString(PKG, "JobEntryFileCompare.ERROR_0005_File2_Does_Not_Exist", realFilename2));
}
result.setResult(false);
result.setNrErrors(1);
}
} else {
logError(BaseMessages.getString(PKG, "JobEntryFileCompare.ERROR_0006_Need_Two_Filenames"));
}
} catch (Exception e) {
result.setResult(false);
result.setNrErrors(1);
logError(BaseMessages.getString(PKG, "JobEntryFileCompare.ERROR_0007_Comparing_Files", realFilename2, realFilename2, e.getMessage()));
} finally {
try {
if (file1 != null) {
file1.close();
file1 = null;
}
if (file2 != null) {
file2.close();
file2 = null;
}
} catch (IOException e) {
// Ignore errors
}
}
return result;
}
use of org.pentaho.di.core.Result in project pentaho-kettle by pentaho.
the class JobEntryFileExists method execute.
public Result execute(Result previousResult, int nr) {
Result result = previousResult;
result.setResult(false);
result.setNrErrors(0);
if (filename != 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());
}
String realFilename = getRealFilename();
try {
FileObject file = KettleVFS.getFileObject(realFilename, this);
if (file.exists() && file.isReadable()) {
logDetailed(BaseMessages.getString(PKG, "JobEntryFileExists.File_Exists", realFilename));
result.setResult(true);
} else {
logDetailed(BaseMessages.getString(PKG, "JobEntryFileExists.File_Does_Not_Exist", realFilename));
}
} catch (Exception e) {
result.setNrErrors(1);
logError(BaseMessages.getString(PKG, "JobEntryFileExists.ERROR_0004_IO_Exception", e.getMessage()), e);
}
} else {
result.setNrErrors(1);
logError(BaseMessages.getString(PKG, "JobEntryFileExists.ERROR_0005_No_Filename_Defined"));
}
return result;
}
use of org.pentaho.di.core.Result in project pentaho-kettle by pentaho.
the class JobEntryMailValidator method execute.
/**
* Execute this job entry and return the result. In this case it means, just set the result boolean in the Result
* class.
*
* @param previousResult
* The result of the previous execution
* @return The Result of the execution.
*/
public Result execute(Result previousResult, int nr) {
Result result = previousResult;
result.setNrErrors(1);
result.setResult(false);
String realEmailAddress = environmentSubstitute(emailAddress);
if (Utils.isEmpty(realEmailAddress)) {
logError(BaseMessages.getString(PKG, "JobEntryMailValidator.Error.EmailEmpty"));
return result;
}
String realSender = environmentSubstitute(emailSender);
if (smtpCheck) {
// check sender
if (Utils.isEmpty(realSender)) {
logError(BaseMessages.getString(PKG, "JobEntryMailValidator.Error.EmailSenderEmpty"));
return result;
}
}
String realDefaultSMTP = environmentSubstitute(defaultSMTP);
int timeOut = Const.toInt(environmentSubstitute(timeout), 0);
// Split the mail-address: separated by space
String[] mailsCheck = realEmailAddress.split(" ");
boolean exitloop = false;
boolean mailIsValid = false;
String MailError = null;
for (int i = 0; i < mailsCheck.length && !exitloop; i++) {
String email = mailsCheck[i];
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobEntryMailValidator.CheckingMail", email));
}
// Check if address is valid
MailValidationResult resultValidator = MailValidation.isAddressValid(log, email, realSender, realDefaultSMTP, timeOut, smtpCheck);
mailIsValid = resultValidator.isValide();
MailError = resultValidator.getErrorMessage();
if (log.isDetailed()) {
if (mailIsValid) {
logDetailed(BaseMessages.getString(PKG, "JobEntryMailValidator.MailValid", email));
} else {
logDetailed(BaseMessages.getString(PKG, "JobEntryMailValidator.MailNotValid", email));
logDetailed(MailError);
}
}
// invalid mail? exit loop
if (!resultValidator.isValide()) {
exitloop = true;
}
}
result.setResult(mailIsValid);
if (mailIsValid) {
result.setNrErrors(0);
}
return result;
}
use of org.pentaho.di.core.Result 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.Result in project pentaho-kettle by pentaho.
the class JobEntryMysqlBulkFile method execute.
public Result execute(Result previousResult, int nr) {
String LimitNbrLignes = "";
String ListOfColumn = "*";
String strHighPriority = "";
String OutDumpText = "";
String OptionEnclosed = "";
String FieldSeparator = "";
String LinesTerminated = "";
Result result = previousResult;
result.setResult(false);
// Let's check the filename ...
if (filename != null) {
// User has specified a file, We can continue ...
String realFilename = getRealFilename();
File file = new File(realFilename);
if (file.exists() && iffileexists == 2) {
// the file exists and user want to Fail
result.setResult(false);
result.setNrErrors(1);
logError(BaseMessages.getString(PKG, "JobMysqlBulkFile.FileExists1.Label") + realFilename + BaseMessages.getString(PKG, "JobMysqlBulkFile.FileExists2.Label"));
} else if (file.exists() && iffileexists == 1) {
// the file exists and user want to do nothing
result.setResult(true);
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobMysqlBulkFile.FileExists1.Label") + realFilename + BaseMessages.getString(PKG, "JobMysqlBulkFile.FileExists2.Label"));
}
} else {
if (file.exists() && iffileexists == 0) {
// File exists and user want to renamme it with unique name
// Format Date
// Try to clean filename (without wildcard)
String wildcard = realFilename.substring(realFilename.length() - 4, realFilename.length());
if (wildcard.substring(0, 1).equals(".")) {
// Find wildcard
realFilename = realFilename.substring(0, realFilename.length() - 4) + "_" + StringUtil.getFormattedDateTimeNow(true) + wildcard;
} else {
// did not find wildcard
realFilename = realFilename + "_" + StringUtil.getFormattedDateTimeNow(true);
}
logDebug(BaseMessages.getString(PKG, "JobMysqlBulkFile.FileNameChange1.Label") + realFilename + BaseMessages.getString(PKG, "JobMysqlBulkFile.FileNameChange1.Label"));
}
// User has specified an existing file, We can continue ...
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobMysqlBulkFile.FileExists1.Label") + realFilename + BaseMessages.getString(PKG, "JobMysqlBulkFile.FileExists2.Label"));
}
if (connection != null) {
// User has specified a connection, We can continue ...
Database db = new Database(this, connection);
db.shareVariablesWith(this);
try {
db.connect(parentJob.getTransactionId(), null);
// Get schemaname
String realSchemaname = environmentSubstitute(schemaname);
// Get tablename
String realTablename = environmentSubstitute(tablename);
if (db.checkTableExists(realTablename)) {
// The table existe, We can continue ...
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobMysqlBulkFile.TableExists1.Label") + realTablename + BaseMessages.getString(PKG, "JobMysqlBulkFile.TableExists2.Label"));
}
// Add schemaname (Most the time Schemaname.Tablename)
if (schemaname != null) {
realTablename = realSchemaname + "." + realTablename;
}
// Set the Limit lines
if (Const.toInt(getRealLimitlines(), 0) > 0) {
LimitNbrLignes = "LIMIT " + getRealLimitlines();
}
// Set list of Column, if null get all columns (*)
if (getRealListColumn() != null) {
ListOfColumn = MysqlString(getRealListColumn());
}
// Fields separator
if (getRealSeparator() != null && outdumpvalue == 0) {
FieldSeparator = "FIELDS TERMINATED BY '" + Const.replace(getRealSeparator(), "'", "''") + "'";
}
// Lines Terminated by
if (getRealLineterminated() != null && outdumpvalue == 0) {
LinesTerminated = "LINES TERMINATED BY '" + Const.replace(getRealLineterminated(), "'", "''") + "'";
}
// High Priority ?
if (isHighPriority()) {
strHighPriority = "HIGH_PRIORITY";
}
if (getRealEnclosed() != null && outdumpvalue == 0) {
if (isOptionEnclosed()) {
OptionEnclosed = "OPTIONALLY ";
}
OptionEnclosed = OptionEnclosed + "ENCLOSED BY '" + Const.replace(getRealEnclosed(), "'", "''") + "'";
}
// OutFile or Dumpfile
if (outdumpvalue == 0) {
OutDumpText = "INTO OUTFILE";
} else {
OutDumpText = "INTO DUMPFILE";
}
String FILEBulkFile = "SELECT " + strHighPriority + " " + ListOfColumn + " " + OutDumpText + " '" + realFilename + "' " + FieldSeparator + " " + OptionEnclosed + " " + LinesTerminated + " FROM " + realTablename + " " + LimitNbrLignes + " LOCK IN SHARE MODE";
try {
if (log.isDetailed()) {
logDetailed(FILEBulkFile);
}
// Run the SQL
PreparedStatement ps = db.prepareSQL(FILEBulkFile);
ps.execute();
// Everything is OK...we can disconnect now
db.disconnect();
if (isAddFileToResult()) {
// Add filename to output files
ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, KettleVFS.getFileObject(realFilename, this), parentJob.getJobname(), toString());
result.getResultFiles().put(resultFile.getFile().toString(), resultFile);
}
result.setResult(true);
} catch (SQLException je) {
db.disconnect();
result.setNrErrors(1);
logError(BaseMessages.getString(PKG, "JobMysqlBulkFile.Error.Label") + " " + je.getMessage());
} catch (KettleFileException e) {
logError(BaseMessages.getString(PKG, "JobMysqlBulkFile.Error.Label") + e.getMessage());
result.setNrErrors(1);
}
} else {
// Of course, the table should have been created already before the bulk load operation
db.disconnect();
result.setNrErrors(1);
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobMysqlBulkFile.TableNotExists1.Label") + realTablename + BaseMessages.getString(PKG, "JobMysqlBulkFile.TableNotExists2.Label"));
}
}
} catch (KettleDatabaseException dbe) {
db.disconnect();
result.setNrErrors(1);
logError(BaseMessages.getString(PKG, "JobMysqlBulkFile.Error.Label") + " " + dbe.getMessage());
}
} else {
// No database connection is defined
result.setNrErrors(1);
logError(BaseMessages.getString(PKG, "JobMysqlBulkFile.Nodatabase.Label"));
}
}
} else {
// No file was specified
result.setNrErrors(1);
logError(BaseMessages.getString(PKG, "JobMysqlBulkFile.Nofilename.Label"));
}
return result;
}
Aggregations