use of org.pentaho.di.core.Result in project pentaho-kettle by pentaho.
the class JobEntryCheckFilesLocked method execute.
public Result execute(Result previousResult, int nr) {
Result result = previousResult;
List<RowMetaAndData> rows = result.getRows();
RowMetaAndData resultRow = null;
oneFileLocked = false;
result.setResult(true);
try {
if (argFromPrevious) {
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobEntryCheckFilesLocked.FoundPreviousRows", String.valueOf((rows != null ? rows.size() : 0))));
}
}
if (argFromPrevious && rows != null) {
// Copy the input row to the (command line) arguments
for (int iteration = 0; iteration < rows.size() && !parentJob.isStopped(); iteration++) {
resultRow = rows.get(iteration);
// Get values from previous result
String filefolder_previous = resultRow.getString(0, "");
String fmasks_previous = resultRow.getString(1, "");
// ok we can process this file/folder
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobEntryCheckFilesLocked.ProcessingRow", filefolder_previous, fmasks_previous));
}
ProcessFile(filefolder_previous, fmasks_previous);
}
} else if (arguments != null) {
for (int i = 0; i < arguments.length && !parentJob.isStopped(); i++) {
// ok we can process this file/folder
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobEntryCheckFilesLocked.ProcessingArg", arguments[i], filemasks[i]));
}
ProcessFile(arguments[i], filemasks[i]);
}
}
if (oneFileLocked) {
result.setResult(false);
result.setNrErrors(1);
}
} catch (Exception e) {
logError(BaseMessages.getString(PKG, "JobEntryCheckFilesLocked.ErrorRunningJobEntry", e));
}
return result;
}
use of org.pentaho.di.core.Result in project pentaho-kettle by pentaho.
the class JobEntryConnectedToRepository 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);
if (rep == null) {
logError(BaseMessages.getString(PKG, "JobEntryConnectedToRepository.Log.NotConnected"));
return result;
}
if (isspecificrep) {
if (Utils.isEmpty(repname)) {
logError(BaseMessages.getString(PKG, "JobEntryConnectedToRepository.Error.NoRep"));
return result;
}
String Reponame = environmentSubstitute(repname);
if (!Reponame.equals(rep.getName())) {
logError(BaseMessages.getString(PKG, "JobEntryConnectedToRepository.Error.DiffRep", rep.getName(), Reponame));
return result;
}
}
if (isspecificuser) {
if (Utils.isEmpty(username)) {
logError(BaseMessages.getString(PKG, "JobEntryConnectedToRepository.Error.NoUser"));
return result;
}
String realUsername = environmentSubstitute(username);
if (rep.getSecurityProvider().getUserInfo() != null && !realUsername.equals(rep.getSecurityProvider().getUserInfo().getLogin())) {
logError(BaseMessages.getString(PKG, "JobEntryConnectedToRepository.Error.DiffUser", rep.getUserInfo().getLogin(), realUsername));
return result;
}
}
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobEntryConnectedToRepository.Log.Connected", rep.getName(), rep.getUserInfo() != null ? rep.getUserInfo().getLogin() : ""));
}
result.setResult(true);
result.setNrErrors(0);
return result;
}
use of org.pentaho.di.core.Result in project pentaho-kettle by pentaho.
the class JobEntryCopyFiles method execute.
public Result execute(Result previousResult, int nr) throws KettleException {
Result result = previousResult;
List<RowMetaAndData> rows = result.getRows();
RowMetaAndData resultRow = null;
int NbrFail = 0;
NbrFail = 0;
if (isBasic()) {
logBasic(BaseMessages.getString(PKG, "JobCopyFiles.Log.Starting"));
}
// 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 {
// Get source and destination files, also wildcard
String[] vsourcefilefolder = preprocessfilefilder(source_filefolder);
String[] vdestinationfilefolder = preprocessfilefilder(destination_filefolder);
String[] vwildcard = wildcard;
result.setResult(false);
result.setNrErrors(1);
if (arg_from_previous) {
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobCopyFiles.Log.ArgFromPrevious.Found", (rows != null ? rows.size() : 0) + ""));
}
}
if (arg_from_previous && rows != null) {
// Copy the input row to the (command line) arguments
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(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 (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobCopyFiles.Log.ProcessingRow", KettleVFS.getFriendlyURI(vsourcefilefolder_previous), KettleVFS.getFriendlyURI(vdestinationfilefolder_previous), vwildcard_previous));
}
if (!processFileFolder(vsourcefilefolder_previous, vdestinationfilefolder_previous, vwildcard_previous, parentJob, result)) {
// The copy process fail
NbrFail++;
}
} else {
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobCopyFiles.Log.IgnoringRow", KettleVFS.getFriendlyURI(vsourcefilefolder[iteration]), KettleVFS.getFriendlyURI(vdestinationfilefolder[iteration]), vwildcard[iteration]));
}
}
}
} else if (vsourcefilefolder != null && vdestinationfilefolder != null) {
for (int i = 0; i < vsourcefilefolder.length && !parentJob.isStopped(); i++) {
if (!Utils.isEmpty(vsourcefilefolder[i]) && !Utils.isEmpty(vdestinationfilefolder[i])) {
if (isBasic()) {
logBasic(BaseMessages.getString(PKG, "JobCopyFiles.Log.ProcessingRow", KettleVFS.getFriendlyURI(vsourcefilefolder[i]), KettleVFS.getFriendlyURI(vdestinationfilefolder[i]), vwildcard[i]));
}
if (!processFileFolder(vsourcefilefolder[i], vdestinationfilefolder[i], vwildcard[i], parentJob, result)) {
// The copy process fail
NbrFail++;
}
} else {
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobCopyFiles.Log.IgnoringRow", KettleVFS.getFriendlyURI(vsourcefilefolder[i]), KettleVFS.getFriendlyURI(vdestinationfilefolder[i]), vwildcard[i]));
}
}
}
}
} finally {
list_add_result = null;
list_files_remove = null;
}
// Check if all files was process with success
if (NbrFail == 0) {
result.setResult(true);
result.setNrErrors(0);
} else {
result.setNrErrors(NbrFail);
}
return result;
}
use of org.pentaho.di.core.Result in project pentaho-kettle by pentaho.
the class JobEntryCopyMoveResultFilenames method execute.
public Result execute(Result previousResult, int nr) {
Result result = previousResult;
result.setNrErrors(1);
result.setResult(false);
boolean deleteFile = getAction().equals("delete");
// 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 realdestinationFolder = null;
if (!deleteFile) {
realdestinationFolder = environmentSubstitute(getDestinationFolder());
if (!CreateDestinationFolder(realdestinationFolder)) {
return result;
}
}
if (!Utils.isEmpty(wildcard)) {
wildcardPattern = Pattern.compile(environmentSubstitute(wildcard));
}
if (!Utils.isEmpty(wildcardexclude)) {
wildcardExcludePattern = Pattern.compile(environmentSubstitute(wildcardexclude));
}
if (previousResult != null) {
NrErrors = 0;
limitFiles = Const.toInt(environmentSubstitute(getNrErrorsLessThan()), 10);
NrErrors = 0;
NrSuccess = 0;
successConditionBroken = false;
successConditionBrokenExit = false;
FileObject file = null;
try {
int size = result.getResultFiles().size();
if (log.isBasic()) {
logBasic(BaseMessages.getString(PKG, "JobEntryCopyMoveResultFilenames.log.FilesFound", "" + size));
}
List<ResultFile> resultFiles = result.getResultFilesList();
if (resultFiles != null && resultFiles.size() > 0) {
for (Iterator<ResultFile> it = resultFiles.iterator(); it.hasNext() && !parentJob.isStopped(); ) {
if (successConditionBroken) {
logError(BaseMessages.getString(PKG, "JobEntryCopyMoveResultFilenames.Error.SuccessConditionbroken", "" + NrErrors));
throw new Exception(BaseMessages.getString(PKG, "JobEntryCopyMoveResultFilenames.Error.SuccessConditionbroken", "" + NrErrors));
}
ResultFile resultFile = it.next();
file = resultFile.getFile();
if (file != null && file.exists()) {
if (!specifywildcard || (CheckFileWildcard(file.getName().getBaseName(), wildcardPattern, true) && !CheckFileWildcard(file.getName().getBaseName(), wildcardExcludePattern, false) && specifywildcard)) {
// Copy or Move file
if (!processFile(file, realdestinationFolder, result, parentJob, deleteFile)) {
// Update Errors
updateErrors();
}
}
} else {
logError(BaseMessages.getString(PKG, "JobEntryCopyMoveResultFilenames.log.ErrorCanNotFindFile", file.toString()));
// Update Errors
updateErrors();
}
}
// end for
}
} catch (Exception e) {
logError(BaseMessages.getString(PKG, "JobEntryCopyMoveResultFilenames.Error", e.toString()));
} finally {
if (file != null) {
try {
file.close();
file = null;
} catch (Exception ex) {
/* Ignore */
}
}
}
}
// Success Condition
result.setNrErrors(NrErrors);
result.setNrLinesWritten(NrSuccess);
if (getSuccessStatus()) {
result.setResult(true);
}
return result;
}
use of org.pentaho.di.core.Result in project pentaho-kettle by pentaho.
the class JobEntryDeleteResultFilenames method execute.
public Result execute(Result previousResult, int nr) {
Result result = previousResult;
result.setResult(false);
if (previousResult != null) {
try {
int size = previousResult.getResultFiles().size();
if (log.isBasic()) {
logBasic(BaseMessages.getString(PKG, "JobEntryDeleteResultFilenames.log.FilesFound", "" + size));
}
if (!specifywildcard) {
// Delete all files
previousResult.getResultFiles().clear();
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobEntryDeleteResultFilenames.log.DeletedFiles", "" + size));
}
} else {
List<ResultFile> resultFiles = result.getResultFilesList();
if (resultFiles != null && resultFiles.size() > 0) {
for (Iterator<ResultFile> it = resultFiles.iterator(); it.hasNext() && !parentJob.isStopped(); ) {
ResultFile resultFile = it.next();
FileObject file = resultFile.getFile();
if (file != null && file.exists()) {
if (CheckFileWildcard(file.getName().getBaseName(), environmentSubstitute(wildcard), true) && !CheckFileWildcard(file.getName().getBaseName(), environmentSubstitute(wildcardexclude), false)) {
// Remove file from result files list
result.getResultFiles().remove(resultFile.getFile().toString());
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobEntryDeleteResultFilenames.log.DeletedFile", file.toString()));
}
}
}
}
}
}
result.setResult(true);
} catch (Exception e) {
logError(BaseMessages.getString(PKG, "JobEntryDeleteResultFilenames.Error", e.toString()));
}
}
return result;
}
Aggregations