Search in sources :

Example 6 with KettleValueException

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

the class XMLJoinMeta method getFields.

public void getFields(RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    ValueMetaInterface v = new ValueMeta(this.getValueXMLfield(), ValueMetaInterface.TYPE_STRING);
    v.setOrigin(name);
    TransMeta transMeta = (TransMeta) space;
    try {
        // source fields.
        for (String fieldName : transMeta.getStepFields(transMeta.findStep(getSourceXMLstep()), null, null).getFieldNames()) {
            row.removeValueMeta(fieldName);
        }
    } catch (KettleValueException e) {
    // Pass
    }
    row.addValueMeta(v);
}
Also used : TransMeta(org.pentaho.di.trans.TransMeta) KettleValueException(org.pentaho.di.core.exception.KettleValueException) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 7 with KettleValueException

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

the class JavaScriptUtils method jsToDate.

public static Date jsToDate(Object value, String classType) throws KettleValueException {
    double dbl;
    if (classType.equalsIgnoreCase("org.mozilla.javascript.Undefined")) {
        return null;
    } else {
        if (classType.equalsIgnoreCase("org.mozilla.javascript.NativeDate")) {
            dbl = Context.toNumber(value);
        } else if (classType.equalsIgnoreCase("org.mozilla.javascript.NativeJavaObject") || classType.equalsIgnoreCase("java.util.Date")) {
            // Is it a java Date() class ?
            try {
                Date dat = (Date) Context.jsToJava(value, java.util.Date.class);
                dbl = dat.getTime();
            } catch (Exception e) {
                // 
                try {
                    Value v = (Value) Context.jsToJava(value, Value.class);
                    return v.getDate();
                } catch (Exception e2) {
                    try {
                        String string = Context.toString(value);
                        return XMLHandler.stringToDate(string);
                    } catch (Exception e3) {
                        throw new KettleValueException("Can't convert a string to a date");
                    }
                }
            }
        } else if (classType.equalsIgnoreCase("java.lang.Double")) {
            dbl = (Double) value;
        } else {
            String string = (String) Context.jsToJava(value, String.class);
            dbl = Double.parseDouble(string);
        }
        long lng = Math.round(dbl);
        return new Date(lng);
    }
}
Also used : Value(org.pentaho.di.compatibility.Value) KettleValueException(org.pentaho.di.core.exception.KettleValueException) Date(java.util.Date) KettleValueException(org.pentaho.di.core.exception.KettleValueException)

Example 8 with KettleValueException

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

the class Job method beginProcessing.

/**
 * Handle logging at start
 *
 * @return true if it went OK.
 *
 * @throws KettleException
 */
public boolean beginProcessing() throws KettleException {
    currentDate = new Date();
    logDate = new Date();
    startDate = Const.MIN_DATE;
    endDate = currentDate;
    resetErrors();
    final JobLogTable jobLogTable = jobMeta.getJobLogTable();
    int intervalInSeconds = Const.toInt(environmentSubstitute(jobLogTable.getLogInterval()), -1);
    if (jobLogTable.isDefined()) {
        DatabaseMeta logcon = jobMeta.getJobLogTable().getDatabaseMeta();
        String schemaName = environmentSubstitute(jobMeta.getJobLogTable().getActualSchemaName());
        String tableName = environmentSubstitute(jobMeta.getJobLogTable().getActualTableName());
        String schemaAndTable = jobMeta.getJobLogTable().getDatabaseMeta().getQuotedSchemaTableCombination(schemaName, tableName);
        Database ldb = new Database(this, logcon);
        ldb.shareVariablesWith(this);
        ldb.connect();
        ldb.setCommit(logCommitSize);
        try {
            // See if we have to add a batch id...
            Long id_batch = new Long(1);
            if (jobMeta.getJobLogTable().isBatchIdUsed()) {
                id_batch = logcon.getNextBatchId(ldb, schemaName, tableName, jobLogTable.getKeyField().getFieldName());
                setBatchId(id_batch.longValue());
                if (getPassedBatchId() <= 0) {
                    setPassedBatchId(id_batch.longValue());
                }
            }
            Object[] lastr = ldb.getLastLogDate(schemaAndTable, jobMeta.getName(), true, LogStatus.END);
            if (!Utils.isEmpty(lastr)) {
                Date last;
                try {
                    last = ldb.getReturnRowMeta().getDate(lastr, 0);
                } catch (KettleValueException e) {
                    throw new KettleJobException(BaseMessages.getString(PKG, "Job.Log.ConversionError", "" + tableName), e);
                }
                if (last != null) {
                    startDate = last;
                }
            }
            depDate = currentDate;
            ldb.writeLogRecord(jobMeta.getJobLogTable(), LogStatus.START, this, null);
            if (!ldb.isAutoCommit()) {
                ldb.commitLog(true, jobMeta.getJobLogTable());
            }
            ldb.disconnect();
            // 
            if (intervalInSeconds > 0) {
                final Timer timer = new Timer(getName() + " - interval logging timer");
                TimerTask timerTask = new TimerTask() {

                    public void run() {
                        try {
                            endProcessing();
                        } catch (Exception e) {
                            log.logError(BaseMessages.getString(PKG, "Job.Exception.UnableToPerformIntervalLogging"), e);
                            // Also stop the show...
                            // 
                            errors.incrementAndGet();
                            stopAll();
                        }
                    }
                };
                timer.schedule(timerTask, intervalInSeconds * 1000, intervalInSeconds * 1000);
                addJobListener(new JobAdapter() {

                    public void jobFinished(Job job) {
                        timer.cancel();
                    }
                });
            }
            // Add a listener at the end of the job to take of writing the final job
            // log record...
            // 
            addJobListener(new JobAdapter() {

                public void jobFinished(Job job) throws KettleException {
                    try {
                        endProcessing();
                    } catch (KettleJobException e) {
                        log.logError(BaseMessages.getString(PKG, "Job.Exception.UnableToWriteToLoggingTable", jobLogTable.toString()), e);
                        // job is failed in case log database record is failed!
                        throw new KettleException(e);
                    }
                }
            });
        } catch (KettleDatabaseException dbe) {
            // This is even before actual execution
            addErrors(1);
            throw new KettleJobException(BaseMessages.getString(PKG, "Job.Log.UnableToProcessLoggingStart", "" + tableName), dbe);
        } finally {
            ldb.disconnect();
        }
    }
    // If we need to write out the job entry logging information, do so at the end of the job:
    // 
    JobEntryLogTable jobEntryLogTable = jobMeta.getJobEntryLogTable();
    if (jobEntryLogTable.isDefined()) {
        addJobListener(new JobAdapter() {

            public void jobFinished(Job job) throws KettleException {
                try {
                    writeJobEntryLogInformation();
                } catch (KettleException e) {
                    throw new KettleException(BaseMessages.getString(PKG, "Job.Exception.UnableToPerformJobEntryLoggingAtJobEnd"), e);
                }
            }
        });
    }
    // If we need to write the log channel hierarchy and lineage information,
    // add a listener for that too...
    // 
    ChannelLogTable channelLogTable = jobMeta.getChannelLogTable();
    if (channelLogTable.isDefined()) {
        addJobListener(new JobAdapter() {

            public void jobFinished(Job job) throws KettleException {
                try {
                    writeLogChannelInformation();
                } catch (KettleException e) {
                    throw new KettleException(BaseMessages.getString(PKG, "Job.Exception.UnableToPerformLoggingAtTransEnd"), e);
                }
            }
        });
    }
    JobExecutionExtension extension = new JobExecutionExtension(this, result, null, false);
    ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.JobBeginProcessing.id, extension);
    return true;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) JobLogTable(org.pentaho.di.core.logging.JobLogTable) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Date(java.util.Date) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) KettleJobException(org.pentaho.di.core.exception.KettleJobException) DuplicateParamException(org.pentaho.di.core.parameters.DuplicateParamException) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) KettleJobException(org.pentaho.di.core.exception.KettleJobException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) Timer(java.util.Timer) TimerTask(java.util.TimerTask) ChannelLogTable(org.pentaho.di.core.logging.ChannelLogTable) Database(org.pentaho.di.core.database.Database) FileObject(org.apache.commons.vfs2.FileObject) JobEntryLogTable(org.pentaho.di.core.logging.JobEntryLogTable) KettleValueException(org.pentaho.di.core.exception.KettleValueException) JobEntryJob(org.pentaho.di.job.entries.job.JobEntryJob)

Example 9 with KettleValueException

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

the class ValueMetaBase method convertStringToInteger.

protected synchronized Long convertStringToInteger(String string) throws KettleValueException {
    // see if trimming needs
    string = Const.trimToType(string, getTrimType());
    if (Utils.isEmpty(string)) {
        return null;
    }
    try {
        Number number;
        if (lenientStringToNumber) {
            number = new Long(getDecimalFormat(false).parse(string).longValue());
        } else {
            ParsePosition parsePosition = new ParsePosition(0);
            number = getDecimalFormat(false).parse(string, parsePosition);
            if (parsePosition.getIndex() < string.length()) {
                throw new KettleValueException(toString() + " : couldn't convert String to number : non-numeric character found at position " + (parsePosition.getIndex() + 1) + " for value [" + string + "]");
            }
        }
        return new Long(number.longValue());
    } catch (Exception e) {
        throw new KettleValueException(toString() + " : couldn't convert String to Integer", e);
    }
}
Also used : KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) ParseException(java.text.ParseException) KettleEOFException(org.pentaho.di.core.exception.KettleEOFException) EOFException(java.io.EOFException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) SQLException(java.sql.SQLException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) ParsePosition(java.text.ParsePosition)

Example 10 with KettleValueException

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

the class ValueMetaBase method convertStringToNumber.

protected synchronized Double convertStringToNumber(String string) throws KettleValueException {
    // see if trimming needs
    string = Const.trimToType(string, getTrimType());
    if (Utils.isEmpty(string)) {
        return null;
    }
    try {
        DecimalFormat format = getDecimalFormat(false);
        Number number;
        if (lenientStringToNumber) {
            number = format.parse(string);
        } else {
            ParsePosition parsePosition = new ParsePosition(0);
            number = format.parse(string, parsePosition);
            if (parsePosition.getIndex() < string.length()) {
                throw new KettleValueException(toString() + " : couldn't convert String to number : non-numeric character found at position " + (parsePosition.getIndex() + 1) + " for value [" + string + "]");
            }
        }
        return new Double(number.doubleValue());
    } catch (Exception e) {
        throw new KettleValueException(toString() + " : couldn't convert String to number ", e);
    }
}
Also used : DecimalFormat(java.text.DecimalFormat) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) ParseException(java.text.ParseException) KettleEOFException(org.pentaho.di.core.exception.KettleEOFException) EOFException(java.io.EOFException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) SQLException(java.sql.SQLException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) ParsePosition(java.text.ParsePosition)

Aggregations

KettleValueException (org.pentaho.di.core.exception.KettleValueException)127 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)35 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)35 KettleException (org.pentaho.di.core.exception.KettleException)25 KettleStepException (org.pentaho.di.core.exception.KettleStepException)17 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)16 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)13 IOException (java.io.IOException)12 Test (org.junit.Test)11 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)11 KettleFileException (org.pentaho.di.core.exception.KettleFileException)11 ParseException (java.text.ParseException)10 Date (java.util.Date)9 EOFException (java.io.EOFException)8 SQLException (java.sql.SQLException)8 ArrayList (java.util.ArrayList)8 Calendar (java.util.Calendar)8 KettleEOFException (org.pentaho.di.core.exception.KettleEOFException)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 BigDecimal (java.math.BigDecimal)6