use of org.apache.hop.core.ResultFile in project hop by apache.
the class AbstractFileErrorHandler method getWriter.
/**
* returns the OutputWiter if exists. Otherwhise it will create a new one.
*
* @return
* @throws HopException
*/
Writer getWriter(Object source) throws HopException {
try {
Writer outputStreamWriter = writers.get(source);
if (outputStreamWriter != null) {
return outputStreamWriter;
}
FileObject file = getReplayFilename(destinationDirectory, processingFilename, dateString, fileExtension, source);
ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, file, baseTransform.getPipelineMeta().getName(), baseTransform.getTransformName());
baseTransform.addResultFile(resultFile);
try {
if (encoding == null) {
outputStreamWriter = new OutputStreamWriter(HopVfs.getOutputStream(file, false));
} else {
outputStreamWriter = new OutputStreamWriter(HopVfs.getOutputStream(file, false), encoding);
}
} catch (Exception e) {
throw new HopException(BaseMessages.getString(PKG, "AbstractFileErrorHandler.Exception.CouldNotCreateFileErrorHandlerForFile") + file.getName().getURI(), e);
}
writers.put(source, outputStreamWriter);
return outputStreamWriter;
} catch (HopFileException e) {
throw new HopException(BaseMessages.getString(PKG, "AbstractFileErrorHandler.Exception.CouldNotCreateFileErrorHandlerForFile"), e);
}
}
use of org.apache.hop.core.ResultFile in project hop by apache.
the class BaseFileInputTransform method init.
/**
* Initialize transform before execute.
*/
@Override
public boolean init() {
initErrorHandling();
meta.additionalOutputFields.normalize();
data.files = meta.getFileInputList(this);
data.currentFileIndex = 0;
// If there are missing files,
// fail if we don't ignore errors
//
Result previousResult = getPipeline().getPreviousResult();
Map<String, ResultFile> resultFiles = (previousResult != null) ? previousResult.getResultFiles() : null;
if ((previousResult == null || resultFiles == null || resultFiles.size() == 0) && data.files.nrOfMissingFiles() > 0 && !meta.inputFiles.acceptingFilenames && !meta.errorHandling.errorIgnored) {
logError(BaseMessages.getString(PKG, "BaseFileInputTransform.Log.Error.NoFilesSpecified"));
return false;
}
return super.init();
}
use of org.apache.hop.core.ResultFile in project hop by apache.
the class ActionFileCompare method execute.
@Override
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) {
file1 = HopVfs.getFileObject(realFilename1);
file2 = HopVfs.getFileObject(realFilename2);
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, parentWorkflow.getWorkflowName(), toString());
resultFile.setComment(BaseMessages.getString(PKG, "ActionWaitForFile.FilenameAdded"));
result.getResultFiles().put(resultFile.getFile().toString(), resultFile);
resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, file2, parentWorkflow.getWorkflowName(), toString());
resultFile.setComment(BaseMessages.getString(PKG, "ActionWaitForFile.FilenameAdded"));
result.getResultFiles().put(resultFile.getFile().toString(), resultFile);
}
} else {
if (!file1.exists()) {
logError(BaseMessages.getString(PKG, "ActionFileCompare.ERROR_0004_File1_Does_Not_Exist", realFilename1));
}
if (!file2.exists()) {
logError(BaseMessages.getString(PKG, "ActionFileCompare.ERROR_0005_File2_Does_Not_Exist", realFilename2));
}
result.setResult(false);
result.setNrErrors(1);
}
} else {
logError(BaseMessages.getString(PKG, "ActionFileCompare.ERROR_0006_Need_Two_Filenames"));
}
} catch (Exception e) {
result.setResult(false);
result.setNrErrors(1);
logError(BaseMessages.getString(PKG, "ActionFileCompare.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.apache.hop.core.ResultFile in project hop by apache.
the class ActionFtp method addFilenameToResultFilenames.
private void addFilenameToResultFilenames(Result result, IWorkflowEngine<WorkflowMeta> parentWorkflow, String filename) throws HopException {
if (isAddResult) {
FileObject targetFile = null;
try {
targetFile = HopVfs.getFileObject(filename);
// Add to the result files...
ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, targetFile, parentWorkflow.getWorkflowName(), toString());
resultFile.setComment(BaseMessages.getString(PKG, "ActionFTP.Downloaded", serverName));
result.getResultFiles().put(resultFile.getFile().toString(), resultFile);
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "ActionFTP.FileAddedToResult", filename));
}
} catch (Exception e) {
throw new HopException(e);
} finally {
try {
targetFile.close();
targetFile = null;
} catch (Exception e) {
// Ignore close errors
}
}
}
}
use of org.apache.hop.core.ResultFile in project hop by apache.
the class PropertyInput method openNextFile.
private boolean openNextFile() {
InputStream fis = null;
try {
if (!meta.isFileField()) {
if (data.filenr >= data.files.nrOfFiles()) {
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "PropertyInput.Log.FinishedProcessing"));
}
return false;
}
// Is this the last file?
data.last_file = (data.filenr == data.files.nrOfFiles() - 1);
data.file = data.files.getFile(data.filenr);
// Move file pointer ahead!
data.filenr++;
} else {
// Get row from input rowset & set row busy!
data.readrow = getRow();
if (data.readrow == null) {
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "PropertyInput.Log.FinishedProcessing"));
}
return false;
}
if (first) {
first = false;
data.inputRowMeta = getInputRowMeta();
data.outputRowMeta = data.inputRowMeta.clone();
meta.getFields(data.outputRowMeta, getTransformName(), null, null, this, metadataProvider);
// Get total previous fields
data.totalpreviousfields = data.inputRowMeta.size();
// Create convert meta-data objects that will contain Date & Number formatters
data.convertRowMeta = data.outputRowMeta.cloneToType(IValueMeta.TYPE_STRING);
// Check is filename field is provided
if (Utils.isEmpty(meta.getDynamicFilenameField())) {
logError(BaseMessages.getString(PKG, "PropertyInput.Log.NoField"));
throw new HopException(BaseMessages.getString(PKG, "PropertyInput.Log.NoField"));
}
// cache the position of the field
if (data.indexOfFilenameField < 0) {
data.indexOfFilenameField = getInputRowMeta().indexOfValue(meta.getDynamicFilenameField());
if (data.indexOfFilenameField < 0) {
// The field is unreachable !
logError(BaseMessages.getString(PKG, "PropertyInput.Log.ErrorFindingField") + "[" + meta.getDynamicFilenameField() + "]");
throw new HopException(BaseMessages.getString(PKG, "PropertyInput.Exception.CouldnotFindField", meta.getDynamicFilenameField()));
}
}
}
// End if first
String filename = getInputRowMeta().getString(data.readrow, data.indexOfFilenameField);
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "PropertyInput.Log.FilenameInStream", meta.getDynamicFilenameField(), filename));
}
data.file = HopVfs.getFileObject(filename);
// Check if file exists!
}
// Check if file is empty
data.filename = HopVfs.getFilename(data.file);
// Add additional fields?
if (meta.getShortFileNameField() != null && meta.getShortFileNameField().length() > 0) {
data.shortFilename = data.file.getName().getBaseName();
}
if (meta.getPathField() != null && meta.getPathField().length() > 0) {
data.path = HopVfs.getFilename(data.file.getParent());
}
if (meta.isHiddenField() != null && meta.isHiddenField().length() > 0) {
data.hidden = data.file.isHidden();
}
if (meta.getExtensionField() != null && meta.getExtensionField().length() > 0) {
data.extension = data.file.getName().getExtension();
}
if (meta.getLastModificationDateField() != null && meta.getLastModificationDateField().length() > 0) {
data.lastModificationDateTime = new Date(data.file.getContent().getLastModifiedTime());
}
if (meta.getUriField() != null && meta.getUriField().length() > 0) {
data.uriName = data.file.getName().getURI();
}
if (meta.getRootUriField() != null && meta.getRootUriField().length() > 0) {
data.rootUriName = data.file.getName().getRootURI();
}
if (meta.getSizeField() != null && meta.getSizeField().length() > 0) {
data.size = data.file.getContent().getSize();
}
if (meta.resetRowNumber()) {
data.rownr = 0;
}
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "PropertyInput.Log.OpeningFile", data.file.toString()));
}
if (meta.isAddResultFile()) {
// Add this to the result file names...
ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, data.file, getPipelineMeta().getName(), getTransformName());
resultFile.setComment(BaseMessages.getString(PKG, "PropertyInput.Log.FileAddedResult"));
addResultFile(resultFile);
}
fis = data.file.getContent().getInputStream();
if (data.propfiles) {
// load properties file
data.pro = new Properties();
data.pro.load(fis);
data.it = data.pro.keySet().iterator();
} else {
// create wini object
data.wini = new Wini();
if (!Utils.isEmpty(data.realEncoding)) {
data.wini.getConfig().setFileEncoding(Charset.forName(data.realEncoding));
}
// load INI file
data.wini.load(fis);
if (data.realSection != null) {
// just one section
data.iniSection = data.wini.get(data.realSection);
if (data.iniSection == null) {
throw new HopException(BaseMessages.getString(PKG, "PropertyInput.Error.CanNotFindSection", data.realSection, "" + data.file.getName()));
}
} else {
// We need to fetch all sections
data.itSection = data.wini.keySet().iterator();
data.iniSection = data.wini.get(data.itSection.next().toString());
}
data.iniIt = data.iniSection.keySet().iterator();
}
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "PropertyInput.Log.FileOpened", data.file.toString()));
logDetailed(BaseMessages.getString(PKG, "PropertyInput.log.TotalKey", "" + (data.propfiles ? data.pro.size() : data.iniSection.size()), HopVfs.getFilename(data.file)));
}
} catch (Exception e) {
logError(BaseMessages.getString(PKG, "PropertyInput.Log.UnableToOpenFile", "" + data.filenr, data.file.toString(), e.toString()));
stopAll();
setErrors(1);
return false;
} finally {
BaseTransform.closeQuietly(fis);
}
return true;
}
Aggregations