use of org.pentaho.di.job.entries.checkfilelocked.LockFile in project pentaho-kettle by pentaho.
the class FileLocked method processRow.
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
meta = (FileLockedMeta) smi;
data = (FileLockedData) sdi;
// Get row from input rowset & set row busy!
Object[] r = getRow();
if (r == null) {
// no more input to be expected...
setOutputDone();
return false;
}
boolean FileLocked = false;
if (first) {
first = false;
// get the RowMeta
data.previousRowMeta = getInputRowMeta().clone();
data.NrPrevFields = data.previousRowMeta.size();
data.outputRowMeta = data.previousRowMeta;
meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);
// Check is filename field is provided
if (Utils.isEmpty(meta.getDynamicFilenameField())) {
logError(BaseMessages.getString(PKG, "FileLocked.Error.FilenameFieldMissing"));
throw new KettleException(BaseMessages.getString(PKG, "FileLocked.Error.FilenameFieldMissing"));
}
// cache the position of the field
if (data.indexOfFileename < 0) {
data.indexOfFileename = data.previousRowMeta.indexOfValue(meta.getDynamicFilenameField());
if (data.indexOfFileename < 0) {
// The field is unreachable !
logError(BaseMessages.getString(PKG, "FileLocked.Exception.CouldnotFindField") + "[" + meta.getDynamicFilenameField() + "]");
throw new KettleException(BaseMessages.getString(PKG, "FileLocked.Exception.CouldnotFindField", meta.getDynamicFilenameField()));
}
}
}
try {
// get filename
String filename = data.previousRowMeta.getString(r, data.indexOfFileename);
if (!Utils.isEmpty(filename)) {
// Check if file
LockFile locked = new LockFile(filename);
FileLocked = locked.isLocked();
// add filename to result filenames?
if (meta.addResultFilenames()) {
// Add this to the result file names...
ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, KettleVFS.getFileObject(filename), getTransMeta().getName(), getStepname());
resultFile.setComment(BaseMessages.getString(PKG, "FileLocked.Log.FileAddedResult"));
addResultFile(resultFile);
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "FileLocked.Log.FilenameAddResult", filename));
}
}
}
// add file locked
// copy row to output
putRow(data.outputRowMeta, RowDataUtil.addValueData(r, data.NrPrevFields, FileLocked));
if (isRowLevel()) {
logRowlevel(BaseMessages.getString(PKG, "FileLocked.LineNumber", getLinesRead() + " : " + getInputRowMeta().getString(r)));
}
} catch (Exception e) {
boolean sendToErrorRow = false;
String errorMessage = null;
if (getStepMeta().isDoingErrorHandling()) {
sendToErrorRow = true;
errorMessage = e.toString();
} else {
logError(BaseMessages.getString(PKG, "FileLocked.ErrorInStepRunning") + e.getMessage());
setErrors(1);
stopAll();
// signal end to receiver(s)
setOutputDone();
return false;
}
if (sendToErrorRow) {
// Simply add this row to the error row
putError(getInputRowMeta(), r, 1, errorMessage, meta.getResultFieldName(), "FileLocked001");
}
}
return true;
}
Aggregations