String pidParam = null;
Integer resourceIdParam = null;
logger.debug("IN");
Monitor monitor =MonitorFactory.start("SpagoBI_Console.NotifyStartAction.service");
conn = null;
stmt = null;
try {
super.service(request,response);
//check for mandatory parameters
user = getAttributeAsString( USER_ID );
logger.debug("Parameter [" + USER_ID + "] is equals to [" + user + "]");
Assert.assertTrue(!StringUtilities.isEmpty( user ), "Parameter [" + USER_ID + "] cannot be null or empty");
idService = this.getAttributeAsInteger( ID_SERVICE );
logger.debug("Parameter [" + ID_SERVICE + "] is equals to [" + idService + "]");
Assert.assertNotNull(idService, "Parameter [" + ID_SERVICE + "] cannot be null or empty");
pid = getAttributeAsString( PID );
logger.debug("Parameter [" + PID + "] is equals to [" + pid + "]");
Assert.assertTrue(!StringUtilities.isEmpty( pid ), "Parameter [" + PID + "] cannot be null or empty");
resourceName = getAttributeAsString( RESOURCE_NAME );
logger.debug("Parameter [" + RESOURCE_NAME + "] is equals to [" + resourceName + "]");
Assert.assertTrue(!StringUtilities.isEmpty( resourceName ), "Parameter [" + RESOURCE_NAME + "] cannot be null or empty");
formatDate = getAttributeAsString( FORMAT_DATE );
logger.debug("Parameter [" + FORMAT_DATE + "] is equals to [" + formatDate + "]");
dataSource = getConsoleEngineInstance().getDataSource();
conn = dataSource.getConnection();
conn.setAutoCommit(false);
sql = "INSERT INTO SERVICE_INSTANCE "
+ "(ID_SERVICE_INSTANCE, " + // 1
"ID_SERVICE, " + // 2
"ID_TARGET_SERVICE_INSTANCE, " + // 3
"MESSAGE_ID, " + // 4
"CORRELATION_ID, " + // 5
"STATE, " + // 6
"STARTDATE, " + // 7
"ENDDATE, " + // 8
"LABEL, " + // 9
"MARKER, " + // 10
"MONITOR_CHECK, " + // 11
"ERRORS_CHECK, " + // 12
"ALARMS_CHECK, " + // 13
"VIEWS_CHECK, " + // 14
"USER_ID, " + // 15
"TS_UPDATE, " + // 16
"RESOURCE_ID) " // 17
+ "VALUES "
+ " (?, ?, NULL, NULL, NULL, " +
"0, ?, to_date('12/12/9999','dd/MM/yyyy'), ?, 0, " +
"0, 0, 0, 0, NULL, ?, ?)";
if (formatDate != null){
//sets the format specified into template
String dateStr = new SimpleDateFormat(formatDate).format(new Timestamp(System.currentTimeMillis())); //HH --> hh24
sysDate = Timestamp.valueOf(dateStr);
}else{
sysDate = new Timestamp( System.currentTimeMillis() );
}
// sysDate = new Date( System.currentTimeMillis() );
logger.debug("Query parameter [sysDate] is equals to [" + sysDate + "]");
idServiceInstanceParam = getIdServiceInstance(conn);
logger.debug("Query parameter [idServiceInstanceParam] is equals to [" + idServiceInstanceParam + "]");
idServiceParam = idService;
logger.debug("Query parameter [idServiceParam] is equals to [" + idServiceParam + "]");
pidParam = pid;
logger.debug("Query parameter [pid] is equals to [" + pidParam + "]");
resourceIdParam = getResourceId(conn, resourceName);
logger.debug("Query parameter [resourceIdParam] is equals to [" + resourceIdParam + "]");
try {
stmt = conn.prepareStatement(sql);
} catch (SQLException e) {
throw new ConsoleEngineRuntimeException("Impossible to create a prepared statement for query [" + sql + "]", e);
}
try {
stmt.setDouble(1, idServiceInstanceParam);
stmt.setInt(2, idServiceParam);
//stmt.setDate(3, sysDate);
stmt.setTimestamp(3, sysDate);
stmt.setString(4, pidParam);
//stmt.setDate(5, sysDate);
stmt.setTimestamp(5, sysDate);
stmt.setInt(6, resourceIdParam.intValue());
} catch (SQLException e) {
throw new ConsoleEngineRuntimeException("Impossible to set the value of the parameter [resourceName] to [" + resourceName + "] in query [" + sql + "]", e);
}
logger.debug("Prameters has been succesfully replaced in statement [" + stmt.toString() + "]");
try {
stmt.executeUpdate();
} catch (SQLException e) {
logger.error("Query parameter [pid] is equals to [" + pidParam + "]");
logger.error("Query parameter [resourceIdParam] is equals to [" + resourceIdParam + "]");
logger.error("Query parameter [idServiceParam] is equals to [" + idServiceParam + "]");
logger.error("Query parameter [sysDate] is equals to [" + sysDate + "]");
logger.error("Query parameter [idServiceInstanceParam] is equals to [" + idServiceInstanceParam + "]");
throw new ConsoleEngineRuntimeException("Impossible to execute statement [" + stmt.toString() + "]", e);
}
logger.debug("Statement [" + stmt.toString() + "] has been succesfully executed");
conn.commit();
try {
writeBackToClient( new JSONAcknowledge() );
} catch (IOException e) {
String msg = "Impossible to write back the responce to the client";
throw new SpagoBIEngineServiceException(getActionName(), msg, e);
}
} catch (Throwable t) {
throw SpagoBIEngineServiceExceptionHandler.getInstance().getWrappedException(getActionName(), getEngineInstance(), t);
} finally {
releaseResources(conn, stmt, null);
monitor.stop();
logger.debug("OUT");
}
}