List of usage examples for org.apache.commons.vfs FileObject toString
public String toString()
From source file:com.panet.imeta.job.entries.addresultfilenames.JobEntryAddResultFilenames.java
private boolean ProcessFile(String filename, String wildcard, Job parentJob, Result result) { LogWriter log = LogWriter.getInstance(); boolean rcode = false; FileObject filefolder = null; String realFilefoldername = environmentSubstitute(filename); String realwildcard = environmentSubstitute(wildcard); try {/*from w ww.ja va2 s. c o m*/ filefolder = KettleVFS.getFileObject(realFilefoldername); // Here gc() is explicitly called if e.g. createfile is used in the // same // job for the same file. The problem is that after creating the // file the // file object is not properly garbaged collected and thus the file // cannot // be deleted anymore. This is a known problem in the JVM. System.gc(); if (filefolder.exists()) { // the file or folder exists if (filefolder.getType() == FileType.FILE) { // Add filename to Resultfilenames ... if (log.isDetailed()) log.logDetailed(toString(), Messages .getString("JobEntryAddResultFilenames.AddingFileToResult", filefolder.toString())); ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, KettleVFS.getFileObject(filefolder.toString()), parentJob.getJobname(), toString()); result.getResultFiles().put(resultFile.getFile().toString(), resultFile); } else { FileObject list[] = filefolder .findFiles(new TextFileSelector(filefolder.toString(), realwildcard)); for (int i = 0; i < list.length && !parentJob.isStopped(); i++) { // Add filename to Resultfilenames ... if (log.isDetailed()) log.logDetailed(toString(), Messages.getString( "JobEntryAddResultFilenames.AddingFileToResult", list[i].toString())); ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, KettleVFS.getFileObject(list[i].toString()), parentJob.getJobname(), toString()); result.getResultFiles().put(resultFile.getFile().toString(), resultFile); } } } else { // File can not be found if (log.isBasic()) log.logBasic(toString(), Messages.getString("JobEntryAddResultFilenames.FileCanNotbeFound", realFilefoldername)); //$NON-NLS-1$ rcode = true; } } catch (IOException e) { log.logError(toString(), Messages.getString("JobEntryAddResultFilenames.CouldNotProcess", //$NON-NLS-1$ realFilefoldername, e.getMessage())); } finally { if (filefolder != null) { try { filefolder.close(); } catch (IOException ex) { } ; } } return rcode; }
From source file:com.panet.imeta.job.entries.ssh2put.JobEntrySSH2PUT.java
private boolean deleteOrMoveFiles(FileObject file, String destinationFolder) throws KettleException { try {/*from w ww . j a v a 2 s. co m*/ boolean retval = false; // Delete the file if this is needed! // if (afterFtpPut.equals("delete_file")) { file.delete(); retval = true; if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobSSH2PUT.Log.DeletedFile", file.toString())); } else if (afterFtpPut.equals("move_file")) { // Move File FileObject destination = null; FileObject source = null; try { destination = KettleVFS .getFileObject(destinationFolder + Const.FILE_SEPARATOR + file.getName().getBaseName()); file.moveTo(destination); retval = true; } catch (Exception e) { log.logError(toString(), Messages.getString("JobSSH2PUT.Cant_Move_File.Label", file.toString(), destinationFolder, e.getMessage())); } finally { if (destination != null) { try { destination.close(); } catch (Exception ex) { } ; } if (source != null) { try { source.close(); } catch (Exception ex) { } ; } } if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobSSH2PUT.Log.MovedFile", file.toString(), ftpDirectory)); } return retval; } catch (Exception e) { throw new KettleException(e); } }
From source file:com.panet.imeta.job.entries.xmlwellformed.JobEntryXMLWellFormed.java
private boolean ProcessFileFolder(String sourcefilefoldername, String wildcard, Job parentJob, Result result) { LogWriter log = LogWriter.getInstance(); boolean entrystatus = false; FileObject sourcefilefolder = null; FileObject CurrentFile = null; // Get real source file and wilcard String realSourceFilefoldername = environmentSubstitute(sourcefilefoldername); if (Const.isEmpty(realSourceFilefoldername)) { log.logError(toString(),//w ww. j av a 2 s.co m Messages.getString("JobXMLWellFormed.log.FileFolderEmpty", sourcefilefoldername)); // Update Errors updateErrors(); return entrystatus; } String realWildcard = environmentSubstitute(wildcard); try { sourcefilefolder = KettleVFS.getFileObject(realSourceFilefoldername); if (sourcefilefolder.exists()) { if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobXMLWellFormed.Log.FileExists", sourcefilefolder.toString())); if (sourcefilefolder.getType() == FileType.FILE) { entrystatus = checkOneFile(sourcefilefolder, log, result, parentJob); } else if (sourcefilefolder.getType() == FileType.FOLDER) { FileObject[] fileObjects = sourcefilefolder.findFiles(new AllFileSelector() { public boolean traverseDescendents(FileSelectInfo info) { return true; } public boolean includeFile(FileSelectInfo info) { FileObject fileObject = info.getFile(); try { if (fileObject == null) return false; if (fileObject.getType() != FileType.FILE) return false; } catch (Exception ex) { // Upon error don't process the file. return false; } finally { if (fileObject != null) { try { fileObject.close(); } catch (IOException ex) { } ; } } return true; } }); if (fileObjects != null) { for (int j = 0; j < fileObjects.length && !parentJob.isStopped(); j++) { if (successConditionBroken) { if (!successConditionBrokenExit) { log.logError(toString(), Messages.getString( "JobXMLWellFormed.Error.SuccessConditionbroken", "" + NrAllErrors)); successConditionBrokenExit = true; } return false; } // Fetch files in list one after one ... CurrentFile = fileObjects[j]; if (!CurrentFile.getParent().toString().equals(sourcefilefolder.toString())) { // Not in the Base Folder..Only if include sub folders if (include_subfolders) { if (GetFileWildcard(CurrentFile.toString(), realWildcard)) { checkOneFile(CurrentFile, log, result, parentJob); } } } else { // In the base folder if (GetFileWildcard(CurrentFile.toString(), realWildcard)) { checkOneFile(CurrentFile, log, result, parentJob); } } } } } else { log.logError(toString(), Messages.getString("JobXMLWellFormed.Error.UnknowFileFormat", sourcefilefolder.toString())); // Update Errors updateErrors(); } } else { log.logError(toString(), Messages.getString("JobXMLWellFormed.Error.SourceFileNotExists", realSourceFilefoldername)); // Update Errors updateErrors(); } } // end try catch (IOException e) { log.logError(toString(), Messages.getString("JobXMLWellFormed.Error.Exception.Processing", realSourceFilefoldername.toString(), e.getMessage())); // Update Errors updateErrors(); } finally { if (sourcefilefolder != null) { try { sourcefilefolder.close(); } catch (IOException ex) { } ; } if (CurrentFile != null) { try { CurrentFile.close(); } catch (IOException ex) { } ; } } return entrystatus; }
From source file:com.panet.imeta.job.entries.ssh2get.JobEntrySSH2GET.java
private boolean CreateFolder(String filefolder) { FileObject folder = null; try {//from w w w. ja v a 2 s . co m folder = KettleVFS.getFileObject(filefolder); if (!folder.exists()) { if (createtargetfolder) { folder.createFolder(); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobSSH2GET.Log.FolderCreated", folder.toString())); } else return false; } return true; } catch (Exception e) { log.logError(toString(), Messages.getString("JobSSH2GET.Log.CanNotCreateFolder", folder.toString())); } finally { if (folder != null) { try { folder.close(); } catch (Exception ex) { } ; } } return false; }
From source file:com.panet.imeta.job.entries.deletefiles.JobEntryDeleteFiles.java
private boolean ProcessFile(String filename, String wildcard, Job parentJob) { LogWriter log = LogWriter.getInstance(); boolean rcode = false; FileObject filefolder = null; String realFilefoldername = environmentSubstitute(filename); String realwildcard = environmentSubstitute(wildcard); try {/*from ww w .ja v a2 s .c om*/ filefolder = KettleVFS.getFileObject(realFilefoldername); // Here gc() is explicitly called if e.g. createfile is used in the // same // job for the same file. The problem is that after creating the // file the // file object is not properly garbaged collected and thus the file // cannot // be deleted anymore. This is a known problem in the JVM. System.gc(); if (filefolder.exists()) { // the file or folder exists if (filefolder.getType() == FileType.FOLDER) { // It's a folder if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobEntryDeleteFiles.ProcessingFolder", realFilefoldername)); //$NON-NLS-1$ // Delete Files int Nr = filefolder .delete(new TextFileSelector(filefolder.toString(), realwildcard, parentJob)); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobEntryDeleteFiles.TotalDeleted", String.valueOf(Nr))); //$NON-NLS-1$ rcode = true; } else { // It's a file if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobEntryDeleteFiles.ProcessingFile", realFilefoldername)); //$NON-NLS-1$ boolean deleted = filefolder.delete(); if (!deleted) { log.logError(toString(), Messages.getString("JobEntryDeleteFiles.CouldNotDeleteFile", realFilefoldername)); //$NON-NLS-1$ } else { if (log.isBasic()) log.logBasic(toString(), Messages.getString("JobEntryDeleteFiles.FileDeleted", filename)); //$NON-NLS-1$ rcode = true; } } } else { // File already deleted, no reason to try to delete it if (log.isBasic()) log.logBasic(toString(), Messages.getString("JobEntryDeleteFiles.FileAlreadyDeleted", realFilefoldername)); //$NON-NLS-1$ rcode = true; } } catch (IOException e) { log.logError(toString(), Messages.getString("JobEntryDeleteFiles.CouldNotProcess", realFilefoldername, e.getMessage())); //$NON-NLS-1$ } finally { if (filefolder != null) { try { filefolder.close(); } catch (IOException ex) { } ; } } return rcode; }
From source file:com.panet.imeta.job.entries.movefiles.JobEntryMoveFiles.java
private boolean MoveOneFile(FileObject Currentfile, FileObject sourcefilefolder, String realDestinationFilefoldername, String realWildcard, LogWriter log, Job parentJob, Result result, FileObject movetofolderfolder) { boolean entrystatus = false; FileObject file_name = null;/*from w ww . j a v a2s. c o m*/ try { if (!Currentfile.toString().equals(sourcefilefolder.toString())) { // Pass over the Base folder itself // return destination short filename String sourceshortfilename = Currentfile.getName().getBaseName(); String shortfilename = sourceshortfilename; try { shortfilename = getDestinationFilename(sourceshortfilename); } catch (Exception e) { log.logError(toString(), Messages.getString(Messages.getString("JobMoveFiles.Error.GettingFilename", Currentfile.getName().getBaseName(), e.toString()))); return entrystatus; } int lenCurrent = sourceshortfilename.length(); String short_filename_from_basefolder = shortfilename; if (!isDoNotKeepFolderStructure()) short_filename_from_basefolder = Currentfile.toString() .substring(sourcefilefolder.toString().length(), Currentfile.toString().length()); short_filename_from_basefolder = short_filename_from_basefolder.substring(0, short_filename_from_basefolder.length() - lenCurrent) + shortfilename; // Built destination filename file_name = KettleVFS.getFileObject( realDestinationFilefoldername + Const.FILE_SEPARATOR + short_filename_from_basefolder); if (!Currentfile.getParent().toString().equals(sourcefilefolder.toString())) { // Not in the Base Folder..Only if include sub folders if (include_subfolders) { // Folders..only if include subfolders if (Currentfile.getType() == FileType.FOLDER) { if (include_subfolders && move_empty_folders && Const.isEmpty(wildcard)) { entrystatus = MoveFile(shortfilename, Currentfile, file_name, movetofolderfolder, log, parentJob, result); } } else { if (GetFileWildcard(sourceshortfilename, realWildcard)) { entrystatus = MoveFile(shortfilename, Currentfile, file_name, movetofolderfolder, log, parentJob, result); } } } } else { // In the Base Folder... // Folders..only if include subfolders if (Currentfile.getType() == FileType.FOLDER) { if (include_subfolders && move_empty_folders && Const.isEmpty(wildcard)) { entrystatus = MoveFile(shortfilename, Currentfile, file_name, movetofolderfolder, log, parentJob, result); } } else { // file...Check if exists if (GetFileWildcard(sourceshortfilename, realWildcard)) { entrystatus = MoveFile(shortfilename, Currentfile, file_name, movetofolderfolder, log, parentJob, result); } } } } entrystatus = true; } catch (Exception e) { log.logError(toString(), Messages.getString("JobMoveFiles.Log.Error", e.toString())); } finally { if (file_name != null) { try { file_name.close(); } catch (IOException ex) { } ; } } return entrystatus; }
From source file:com.panet.imeta.trans.steps.sort.SortRows.java
private Object[] getBuffer() throws KettleValueException { Object[] retval;//from w w w. j a v a2s . c o m // Open all files at once and read one row from each file... if (data.files.size() > 0 && (data.dis.size() == 0 || data.fis.size() == 0)) { if (log.isBasic()) logBasic("Opening " + data.files.size() + " tmp-files..."); try { for (int f = 0; f < data.files.size() && !isStopped(); f++) { FileObject fileObject = (FileObject) data.files.get(f); String filename = KettleVFS.getFilename(fileObject); if (log.isDetailed()) logDetailed("Opening tmp-file: [" + filename + "]"); InputStream fi = KettleVFS.getInputStream(fileObject); DataInputStream di; data.fis.add(fi); if (data.compressFiles) { GZIPInputStream gzfi = new GZIPInputStream(new BufferedInputStream(fi)); di = new DataInputStream(gzfi); data.gzis.add(gzfi); } else { di = new DataInputStream(new BufferedInputStream(fi, 50000)); } data.dis.add(di); // How long is the buffer? int buffersize = data.bufferSizes.get(f); if (log.isDetailed()) logDetailed("[" + filename + "] expecting " + buffersize + " rows..."); if (buffersize > 0) { Object[] row = (Object[]) data.outputRowMeta.readData(di); data.rowbuffer.add(row); // new row from input stream data.tempRows.add(new RowTempFile(row, f)); } } // Sort the data row buffer Collections.sort(data.tempRows, data.comparator); } catch (Exception e) { logError("Error reading back tmp-files : " + e.toString()); logError(Const.getStackTracker(e)); } } if (data.files.size() == 0) { if (data.getBufferIndex < data.buffer.size()) { retval = (Object[]) data.buffer.get(data.getBufferIndex); data.getBufferIndex++; } else { retval = null; } } else { if (data.rowbuffer.size() == 0) { retval = null; } else { // We now have "filenr" rows waiting: which one is the smallest? // if (log.isRowLevel()) { for (int i = 0; i < data.rowbuffer.size() && !isStopped(); i++) { Object[] b = (Object[]) data.rowbuffer.get(i); logRowlevel("--BR#" + i + ": " + data.outputRowMeta.getString(b)); } } RowTempFile rowTempFile = data.tempRows.remove(0); retval = rowTempFile.row; int smallest = rowTempFile.fileNumber; // now get another Row for position smallest FileObject file = (FileObject) data.files.get(smallest); DataInputStream di = (DataInputStream) data.dis.get(smallest); InputStream fi = (InputStream) data.fis.get(smallest); GZIPInputStream gzfi = (data.compressFiles) ? (GZIPInputStream) data.gzis.get(smallest) : null; try { Object[] row2 = (Object[]) data.outputRowMeta.readData(di); RowTempFile extra = new RowTempFile(row2, smallest); int index = Collections.binarySearch(data.tempRows, extra, data.comparator); if (index < 0) { data.tempRows.add(index * (-1) - 1, extra); } else { data.tempRows.add(index, extra); } } catch (KettleFileException fe) // empty file or EOF mostly { try { di.close(); fi.close(); if (gzfi != null) gzfi.close(); file.delete(); } catch (IOException e) { logError("Unable to close/delete file #" + smallest + " --> " + file.toString()); setErrors(1); stopAll(); return null; } data.files.remove(smallest); data.dis.remove(smallest); data.fis.remove(smallest); if (gzfi != null) data.gzis.remove(smallest); // Also update all file numbers in in data.tempRows if they are larger than smallest. // for (RowTempFile rtf : data.tempRows) { if (rtf.fileNumber > smallest) rtf.fileNumber--; } } catch (SocketTimeoutException e) { throw new KettleValueException(e); // should never happen on local files } } } return retval; }
From source file:com.panet.imeta.job.entries.unzip.JobEntryUnZip.java
private boolean unzipFile(LogWriter log, FileObject sourceFileObject, String realTargetdirectory, String realWildcard, String realWildcardExclude, Result result, Job parentJob, FileObject fileObject, FileObject movetodir, String realMovetodirectory) { boolean retval = false; try {//from w ww.j a va2s . c o m if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobUnZip.Log.ProcessingFile", sourceFileObject.toString())); // Do you create a root folder? // if (rootzip) { String shortSourceFilename = sourceFileObject.getName().getBaseName(); int lenstring = shortSourceFilename.length(); int lastindexOfDot = shortSourceFilename.lastIndexOf('.'); if (lastindexOfDot == -1) lastindexOfDot = lenstring; String foldername = realTargetdirectory + "/" + shortSourceFilename.substring(0, lastindexOfDot); FileObject rootfolder = KettleVFS.getFileObject(foldername); if (!rootfolder.exists()) { try { rootfolder.createFolder(); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobUnZip.Log.RootFolderCreated", foldername)); } catch (Exception e) { throw new Exception(Messages.getString("JobUnZip.Error.CanNotCreateRootFolder", foldername), e); } } } // Try to read the entries from the VFS object... // String zipFilename = "zip:" + sourceFileObject.getName().getFriendlyURI(); FileObject zipFile = KettleVFS.getFileObject(zipFilename); FileObject[] items = zipFile.findFiles(new AllFileSelector() { public boolean traverseDescendents(FileSelectInfo info) { return true; } public boolean includeFile(FileSelectInfo info) { // Never return the parent directory of a file list. if (info.getDepth() == 0) { return false; } FileObject fileObject = info.getFile(); return fileObject != null; } }); Pattern pattern = null; if (!Const.isEmpty(realWildcard)) { pattern = Pattern.compile(realWildcard); } Pattern patternexclude = null; if (!Const.isEmpty(realWildcardExclude)) { patternexclude = Pattern.compile(realWildcardExclude); } for (FileObject item : items) { if (successConditionBroken) { if (!successConditionBrokenExit) { log.logError(toString(), Messages.getString("JobUnZip.Error.SuccessConditionbroken", "" + NrErrors)); successConditionBrokenExit = true; } return false; } try { if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobUnZip.Log.ProcessingZipEntry", item.getName().getURI(), sourceFileObject.toString())); // get real destination filename // String newFileName = realTargetdirectory + Const.FILE_SEPARATOR + getTargetFilename(item.getName().getPath()); FileObject newFileObject = KettleVFS.getFileObject(newFileName); if (item.getType().equals(FileType.FOLDER)) { // Directory // if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobUnZip.CreatingDirectory.Label", newFileName)); // Create Directory if necessary ... // if (!newFileObject.exists()) newFileObject.createFolder(); } else { // File // boolean getIt = true; boolean getItexclude = false; // First see if the file matches the regular expression! // if (pattern != null) { Matcher matcher = pattern.matcher(item.getName().getURI()); getIt = matcher.matches(); } if (patternexclude != null) { Matcher matcherexclude = patternexclude.matcher(item.getName().getURI()); getItexclude = matcherexclude.matches(); } boolean take = takeThisFile(log, item, newFileName); if (getIt && !getItexclude && take) { if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobUnZip.ExtractingEntry.Label", item.getName().getURI(), newFileName)); if (iffileexist == IF_FILE_EXISTS_UNIQ) { // Create file with unique name int lenstring = newFileName.length(); int lastindexOfDot = newFileName.lastIndexOf('.'); if (lastindexOfDot == -1) lastindexOfDot = lenstring; newFileName = newFileName.substring(0, lastindexOfDot) + StringUtil.getFormattedDateTimeNow(true) + newFileName.substring(lastindexOfDot, lenstring); if (log.isDebug()) log.logDebug(toString(), Messages.getString("JobUnZip.Log.CreatingUniqFile", newFileName)); } // See if the folder to the target file exists... // if (!newFileObject.getParent().exists()) { newFileObject.getParent().createFolder(); // creates // the // whole // path. } InputStream is = null; OutputStream os = null; try { is = KettleVFS.getInputStream(item); os = KettleVFS.getOutputStream(newFileObject, false); if (is != null) { byte[] buff = new byte[2048]; int len; while ((len = is.read(buff)) > 0) { os.write(buff, 0, len); } // Add filename to result filenames addFilenameToResultFilenames(result, parentJob, newFileName); } } finally { if (is != null) is.close(); if (os != null) os.close(); } } // end if take } } catch (Exception e) { updateErrors(); log.logError(toString(), Messages.getString("JobUnZip.Error.CanNotProcessZipEntry", item.getName().getURI(), sourceFileObject.toString()), e); } } // End while // Here gc() is explicitly called if e.g. createfile is used in the // same // job for the same file. The problem is that after creating the // file the // file object is not properly garbaged collected and thus the file // cannot // be deleted anymore. This is a known problem in the JVM. // System.gc(); // Unzip done... if (afterunzip == 1) { // delete zip file boolean deleted = fileObject.delete(); if (!deleted) { updateErrors(); log.logError(toString(), Messages.getString("JobUnZip.Cant_Delete_File.Label", sourceFileObject.toString())); } // File deleted if (log.isDebug()) log.logDebug(toString(), Messages.getString("JobUnZip.File_Deleted.Label", sourceFileObject.toString())); } else if (afterunzip == 2) { FileObject destFile = null; // Move File try { String destinationFilename = movetodir + Const.FILE_SEPARATOR + fileObject.getName().getBaseName(); destFile = KettleVFS.getFileObject(destinationFilename); fileObject.moveTo(destFile); // File moved if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobUnZip.Log.FileMovedTo", sourceFileObject.toString(), realMovetodirectory)); } catch (Exception e) { updateErrors(); log.logError(toString(), Messages.getString("JobUnZip.Cant_Move_File.Label", sourceFileObject.toString(), realMovetodirectory, e.getMessage())); } finally { if (destFile != null) { try { destFile.close(); } catch (IOException ex) { } ; } } } retval = true; } catch (Exception e) { updateErrors(); log.logError(Messages.getString("JobUnZip.Error.Label"), Messages.getString("JobUnZip.ErrorUnzip.Label", sourceFileObject.toString(), e.getMessage()), e); } return retval; }
From source file:com.panet.imeta.job.entries.copymoveresultfilenames.JobEntryCopyMoveResultFilenames.java
private boolean ProcessFile(FileObject sourcefile, String destinationFolder, LogWriter log, Result result, Job parentJob) {/* ww w .j a va2 s.c om*/ boolean retval = false; boolean filexists = false; try { // return destination short filename String shortfilename = getDestinationFilename(sourcefile.getName().getBaseName()); // build full destination filename String destinationFilename = destinationFolder + Const.FILE_SEPARATOR + shortfilename; FileObject destinationfile = KettleVFS.getFileObject(destinationFilename); filexists = destinationfile.exists(); if (filexists) { if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobEntryCopyMoveResultFilenames.Log.FileExists", destinationFilename)); } if ((!filexists) || (filexists && isOverwriteFile())) { if (getAction().equals("copy")) { // Copy file FileUtil.copyContent(sourcefile, destinationfile); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobEntryCopyMoveResultFilenames.log.CopiedFile", sourcefile.toString(), destinationFolder)); } else { // Move file sourcefile.moveTo(destinationfile); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobEntryCopyMoveResultFilenames.log.MovedFile", sourcefile.toString(), destinationFolder)); } if (isRemovedSourceFilename()) { // Remove source file from result files list result.getResultFiles().remove(sourcefile.toString()); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString( "JobEntryCopyMoveResultFilenames.RemovedFileFromResult", sourcefile.toString())); } if (isAddDestinationFilename()) { // Add destination filename to Resultfilenames ... ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, KettleVFS.getFileObject(destinationfile.toString()), parentJob.getJobname(), toString()); result.getResultFiles().put(resultFile.getFile().toString(), resultFile); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString( "JobEntryCopyMoveResultFilenames.AddedFileToResult", destinationfile.toString())); } } retval = true; } catch (Exception e) { log.logError(toString(), Messages.getString("JobEntryCopyMoveResultFilenames.Log.ErrorProcessing", e.toString())); } return retval; }
From source file:com.panet.imeta.job.entries.movefiles.JobEntryMoveFiles.java
private boolean MoveFile(String shortfilename, FileObject sourcefilename, FileObject destinationfilename, FileObject movetofolderfolder, LogWriter log, Job parentJob, Result result) { FileObject destinationfile = null; boolean retval = false; try {// w w w . j av a 2s . c om if (!destinationfilename.exists()) { if (!simulate) sourcefilename.moveTo(destinationfilename); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobMoveFiles.Log.FileMoved", sourcefilename.getName().toString(), destinationfilename.getName().toString())); // add filename to result filename if (add_result_filesname && !iffileexists.equals("fail") && !iffileexists.equals("do_nothing")) addFileToResultFilenames(destinationfilename.toString(), log, result, parentJob); updateSuccess(); } else { if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobMoveFiles.Log.FileExists", destinationfilename.toString())); if (iffileexists.equals("overwrite_file")) { if (!simulate) sourcefilename.moveTo(destinationfilename); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobMoveFiles.Log.FileOverwrite", destinationfilename.getName().toString())); // add filename to result filename if (add_result_filesname && !iffileexists.equals("fail") && !iffileexists.equals("do_nothing")) addFileToResultFilenames(destinationfilename.toString(), log, result, parentJob); updateSuccess(); } else if (iffileexists.equals("unique_name")) { String short_filename = shortfilename; // return destination short filename try { short_filename = getMoveDestinationFilename(short_filename, "ddMMyyyy_HHmmssSSS"); } catch (Exception e) { log.logError(toString(), Messages.getString( Messages.getString("JobMoveFiles.Error.GettingFilename", short_filename))); return retval; } String movetofilenamefull = destinationfilename.getParent().toString() + Const.FILE_SEPARATOR + short_filename; destinationfile = KettleVFS.getFileObject(movetofilenamefull); if (!simulate) sourcefilename.moveTo(destinationfile); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobMoveFiles.Log.FileMoved", sourcefilename.getName().toString(), destinationfile.getName().toString())); // add filename to result filename if (add_result_filesname && !iffileexists.equals("fail") && !iffileexists.equals("do_nothing")) addFileToResultFilenames(destinationfile.toString(), log, result, parentJob); updateSuccess(); } else if (iffileexists.equals("delete_file")) { if (!simulate) destinationfilename.delete(); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobMoveFiles.Log.FileDeleted", destinationfilename.getName().toString())); } else if (iffileexists.equals("move_file")) { String short_filename = shortfilename; // return destination short filename try { short_filename = getMoveDestinationFilename(short_filename, null); } catch (Exception e) { log.logError(toString(), Messages.getString( Messages.getString("JobMoveFiles.Error.GettingFilename", short_filename))); return retval; } String movetofilenamefull = movetofolderfolder.toString() + Const.FILE_SEPARATOR + short_filename; destinationfile = KettleVFS.getFileObject(movetofilenamefull); if (!destinationfile.exists()) { if (!simulate) sourcefilename.moveTo(destinationfile); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobMoveFiles.Log.FileMoved", sourcefilename.getName().toString(), destinationfile.getName().toString())); // add filename to result filename if (add_result_filesname && !iffileexists.equals("fail") && !iffileexists.equals("do_nothing")) addFileToResultFilenames(destinationfile.toString(), log, result, parentJob); } else { if (ifmovedfileexists.equals("overwrite_file")) { if (!simulate) sourcefilename.moveTo(destinationfile); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobMoveFiles.Log.FileOverwrite", destinationfile.getName().toString())); // add filename to result filename if (add_result_filesname && !iffileexists.equals("fail") && !iffileexists.equals("do_nothing")) addFileToResultFilenames(destinationfile.toString(), log, result, parentJob); updateSuccess(); } else if (ifmovedfileexists.equals("unique_name")) { SimpleDateFormat daf = new SimpleDateFormat(); Date now = new Date(); daf.applyPattern("ddMMyyyy_HHmmssSSS"); String dt = daf.format(now); short_filename += "_" + dt; String destinationfilenamefull = movetofolderfolder.toString() + Const.FILE_SEPARATOR + short_filename; destinationfile = KettleVFS.getFileObject(destinationfilenamefull); if (!simulate) sourcefilename.moveTo(destinationfile); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobMoveFiles.Log.FileMoved", destinationfile.getName().toString())); // add filename to result filename if (add_result_filesname && !iffileexists.equals("fail") && !iffileexists.equals("do_nothing")) addFileToResultFilenames(destinationfile.toString(), log, result, parentJob); updateSuccess(); } else if (ifmovedfileexists.equals("fail")) { // Update Errors updateErrors(); } } } else if (iffileexists.equals("fail")) { // Update Errors updateErrors(); } } } catch (Exception e) { log.logError(toString(), Messages.getString("JobMoveFiles.Error.Exception.MoveProcessError", sourcefilename.toString(), destinationfilename.toString(), e.getMessage())); } finally { if (destinationfile != null) { try { destinationfile.close(); } catch (IOException ex) { } ; } } return retval; }