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);
}
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);
}
}
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;
}
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);
}
}
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);
}
}
Aggregations