Search in sources :

Example 81 with ResultFile

use of org.pentaho.di.core.ResultFile in project pentaho-kettle by pentaho.

the class JobEntryMSAccessBulkLoad method addFileToResultFilenames.

private void addFileToResultFilenames(String fileaddentry, Result result, Job parentJob) {
    try {
        ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, KettleVFS.getFileObject(fileaddentry, this), parentJob.getJobname(), toString());
        result.getResultFiles().put(resultFile.getFile().toString(), resultFile);
        if (log.isDebug()) {
            logDebug(" ------ ");
            logDebug(BaseMessages.getString(PKG, "JobEntryMSAccessBulkLoad.Log.FileAddedToResultFilesName", fileaddentry));
        }
    } catch (Exception e) {
        log.logError(BaseMessages.getString(PKG, "JobEntryMSAccessBulkLoad.Error.AddingToFilenameResult"), fileaddentry + "" + e.getMessage());
    }
}
Also used : ResultFile(org.pentaho.di.core.ResultFile) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException)

Example 82 with ResultFile

use of org.pentaho.di.core.ResultFile in project pentaho-kettle by pentaho.

the class AccessInput method openNextFile.

private boolean openNextFile() {
    try {
        if (!meta.isFileField()) {
            // finished processing!
            if (data.filenr >= data.files.nrOfFiles()) {
                if (log.isDetailed()) {
                    logDetailed(BaseMessages.getString(PKG, "AccessInput.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, "AccessInput.Log.FinishedProcessing"));
                }
                return false;
            }
            if (first) {
                first = false;
                data.inputRowMeta = getInputRowMeta();
                data.outputRowMeta = data.inputRowMeta.clone();
                meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);
                // Get total previous fields
                data.totalpreviousfields = data.inputRowMeta.size();
                // Create convert meta-data objects that will contain Date & Number formatters
                data.convertRowMeta = data.outputRowMeta.clone();
                // For String to <type> conversions, we allocate a conversion meta data row as well...
                // 
                data.convertRowMeta = data.outputRowMeta.clone();
                for (int i = 0; i < data.convertRowMeta.size(); i++) {
                    ValueMetaInterface valueMeta = data.convertRowMeta.getValueMeta(i);
                    data.convertRowMeta.setValueMeta(i, ValueMetaFactory.cloneValueMeta(valueMeta, ValueMetaInterface.TYPE_STRING));
                }
                // Check is filename field is provided
                if (Utils.isEmpty(meta.getDynamicFilenameField())) {
                    logError(BaseMessages.getString(PKG, "AccessInput.Log.NoField"));
                    throw new KettleException(BaseMessages.getString(PKG, "AccessInput.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, "AccessInput.Log.ErrorFindingField") + "[" + meta.getDynamicFilenameField() + "]");
                        throw new KettleException(BaseMessages.getString(PKG, "AccessInput.Exception.CouldnotFindField", meta.getDynamicFilenameField()));
                    }
                }
            }
            // End if first
            String filename = getInputRowMeta().getString(data.readrow, data.indexOfFilenameField);
            if (log.isDetailed()) {
                logDetailed(BaseMessages.getString(PKG, "AccessInput.Log.FilenameInStream", meta.getDynamicFilenameField(), filename));
            }
            data.file = KettleVFS.getFileObject(filename, getTransMeta());
        // Check if file exists!
        }
        // 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 = KettleVFS.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 = new Long(data.file.getContent().getSize());
        }
        if (meta.isResetRowNumber()) {
            data.rownr = 0;
        }
        if (log.isDetailed()) {
            logDetailed(BaseMessages.getString(PKG, "AccessInput.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, getTransMeta().getName(), getStepname());
            resultFile.setComment(BaseMessages.getString(PKG, "AccessInput.Log.FileAddedResult"));
            addResultFile(resultFile);
        }
        // Read mdb file
        data.file.getName().getPathDecoded();
        // Read-only
        data.d = Database.open(new File(AccessInputMeta.getFilename(data.file)), true);
        // Get table
        if (data.isTableSystem) {
            data.t = data.d.getSystemTable(data.tableName);
        } else {
            data.t = data.d.getTable(data.tableName);
        }
        if (log.isDetailed()) {
            logDetailed(BaseMessages.getString(PKG, "AccessInput.Log.FileOpened", data.file.toString()));
        }
    } catch (Exception e) {
        logError(BaseMessages.getString(PKG, "AccessInput.Log.UnableToOpenFile", "" + data.filenr, data.file.toString(), e.toString()));
        stopAll();
        setErrors(1);
        return false;
    }
    return true;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ResultFile(org.pentaho.di.core.ResultFile) File(java.io.File) ResultFile(org.pentaho.di.core.ResultFile) Date(java.util.Date) KettleException(org.pentaho.di.core.exception.KettleException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 83 with ResultFile

use of org.pentaho.di.core.ResultFile in project pentaho-kettle by pentaho.

the class AccessOutput method openFile.

boolean openFile() throws Exception {
    data.oneFileOpened = true;
    String realFilename = environmentSubstitute(meta.getFilename());
    if (log.isBasic()) {
        logBasic(BaseMessages.getString(PKG, "AccessOutput.log.WritingToFile", realFilename));
    }
    FileObject fileObject = KettleVFS.getFileObject(realFilename, getTransMeta());
    File file = FileUtils.toFile(fileObject.getURL());
    // First open or create the access file
    if (!file.exists()) {
        if (meta.isFileCreated()) {
            data.createDatabase(file);
        } else {
            logError(BaseMessages.getString(PKG, "AccessOutput.InitError.FileDoesNotExist", realFilename));
            return false;
        }
    } else {
        data.openDatabase(file);
    }
    // 
    if (meta.isAddToResultFiles()) {
        ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, fileObject, getTransMeta().getName(), toString());
        resultFile.setComment("This file was created with an access output step");
        addResultFile(resultFile);
    }
    return true;
}
Also used : FileObject(org.apache.commons.vfs2.FileObject) ResultFile(org.pentaho.di.core.ResultFile) File(java.io.File) ResultFile(org.pentaho.di.core.ResultFile)

Aggregations

ResultFile (org.pentaho.di.core.ResultFile)83 KettleException (org.pentaho.di.core.exception.KettleException)65 FileObject (org.apache.commons.vfs2.FileObject)32 IOException (java.io.IOException)29 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)29 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)28 Result (org.pentaho.di.core.Result)20 KettleFileException (org.pentaho.di.core.exception.KettleFileException)16 KettleStepException (org.pentaho.di.core.exception.KettleStepException)12 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)11 File (java.io.File)10 OutputStream (java.io.OutputStream)10 Date (java.util.Date)9 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)6 FileInputStream (java.io.FileInputStream)5 KettleValueException (org.pentaho.di.core.exception.KettleValueException)5 ArrayList (java.util.ArrayList)4 Matcher (java.util.regex.Matcher)4 Pattern (java.util.regex.Pattern)4 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)4