Commit d4c396e2 authored by pborate's avatar pborate

New scheduler for DWH_INV_SRET_SUM

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@212178 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 5ebae583
package ibase.webitm.dashboard.fin.ejb;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import ibase.scheduler.utility.interfaces.Schedule;
import ibase.system.config.ConnDriver;
import ibase.utility.BaseLogger;
import ibase.utility.E12GenericUtility;
import ibase.webitm.utility.ITMException;
public class UpdateDwhInvSretSum implements Schedule
{
//DWHCompleteEJB dwhCompleteEJB = new DWHCompleteEJB();
@SuppressWarnings({ "null", "unchecked" })
public String transComplete(String scheduleXml) throws Exception
{
System.out.println(" INSIDE UpdateDwhInvSretSum transComplete "+scheduleXml );
PreparedStatement pstmt = null;
Document dom = null;
Document domAll = null;
PreparedStatement pStmt = null;
Connection userDbConn = null;
String itemSer="";
String transDb = "";
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
Date date = new Date();
String sysdate= sdf.format(date);
Connection con = null;
Statement st = null;
PreparedStatement ps=null;
ResultSet rs =null;
String returnMsg=null;
try
{
JSONObject scheduleJson = xmlToJson("<Root>" + scheduleXml.toString()+ "</Root>");
JSONObject scheduleObject= scheduleJson.optJSONObject("SCHEDULE");
JSONObject userInfoXmlObject= scheduleObject.optJSONObject("SCHEDULE_OBJ");
JSONObject actualParameters= userInfoXmlObject.optJSONObject("ACTUALPARAMETERS");
JSONArray actualParameter= actualParameters.optJSONArray("ACTUALPARAMETER");
for(int i = 0, tansdata = actualParameter.length(); i < tansdata; i++)
{
JSONObject actualParObj = actualParameter.optJSONObject(i);
System.out.println("actualParObj "+actualParObj);
String temp =actualParObj.getString("name");
if(temp.equalsIgnoreCase("ITEM_SER") ){
itemSer=actualParObj.getString("value");
}
if(temp.equalsIgnoreCase("TRANS_DB") ){
transDb=actualParObj.getString("value");
}
}
//JSONObject userInfo= userInfoXmlObject.optJSONObject("UserInfo");
//transDb= userInfo.optString("transDB");
System.out.println("UpdateDwhInvSretSum Item ser "+itemSer +" sysdate "+sysdate +" transDb "+transDb);
ConnDriver connDriver = new ConnDriver();
con = connDriver.getConnectDB(transDb);
java.sql.CallableStatement cs = con.prepareCall("{CALL DWH_INV_SRET(?,?,?)}");
cs.setString(1,sysdate);
cs.setString(2,sysdate);
cs.setString(3,itemSer);
cs.execute();
con.commit();
pstmt = null;
rs = null;
}
finally
{
}
return "";
}
public JSONObject xmlToJson(String transData) throws JSONException
{
try
{
E12GenericUtility utility = new E12GenericUtility();
Document dashboardDom = utility.parseString(transData);
NodeList rootNodeList = dashboardDom.getElementsByTagName("Root");
Node rootNode = null;
if( rootNodeList != null && rootNodeList.getLength() > 0 ){
rootNode = rootNodeList.item(0);
return (JSONObject) xmlToJson(rootNode);
}
}
catch (ITMException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public Object xmlToJson(Node xmlObj) throws JSONException
{
// Create the return object
JSONObject jsonObj = new JSONObject();
// console.log('xmlObj.nodeType---', xmlObj.nodeType, xmlObj);
if (xmlObj.getNodeType() == Node.ELEMENT_NODE) { // element
// do attributes
if (xmlObj.hasAttributes()) {
NamedNodeMap attributes = xmlObj.getAttributes();
int attribLen = attributes.getLength();
for (int j = 0; j < attribLen; j++) {
Node attribute = attributes.item(j);
String name = attribute.getNodeName();
String value = attribute.getNodeValue();
jsonObj.put(name, value);
}
}
}
//System.out.println("jsonObj>>" + jsonObj);
// do children
if (xmlObj.hasChildNodes()) {
NodeList childNodes = xmlObj.getChildNodes();
int childNodeLen = childNodes.getLength();
for (int i = 0; i < childNodeLen; i++)
{
Node childNode = childNodes.item(i);
String childNodeName = childNode.getNodeName();
String childNodeValue = childNode.getNodeValue();
if("#cdata-section".equalsIgnoreCase(childNodeName) )
{
if (xmlObj.hasAttributes())
{
jsonObj.put("value", childNodeValue);
return jsonObj;
}
else
{
return childNodeValue;
}
}
else if( !"#text".equalsIgnoreCase(childNodeName) )
{
System.out.println(childNodeName + "<<childNodeValue>>" + childNodeValue);
if( jsonObj.optJSONObject(childNodeName) != null )
{
JSONObject old = jsonObj.optJSONObject(childNodeName);
jsonObj.put(childNodeName, new JSONArray());
jsonObj.optJSONArray(childNodeName).put(old);
jsonObj.optJSONArray(childNodeName).put(xmlToJson(childNode));
}
else if( jsonObj.optJSONArray(childNodeName) != null )
{
jsonObj.optJSONArray(childNodeName).put(xmlToJson(childNode));
}
else
{
jsonObj.put(childNodeName, xmlToJson(childNode));
}
}
}
}
//System.out.println(xmlObj.getNodeName() + ">>childNodeName>" + jsonObj);
return jsonObj;
}
@Override
public String schedule(HashMap map) throws Exception {
// TODO Auto-generated method stub
BaseLogger.log("3",null,null,"schedule hashMap::"+map);
return null;
}
@Override
public String schedule(String scheduleXml) throws Exception
{
BaseLogger.log("2",null,null,"schedule scheduleXml::"+scheduleXml);
transComplete(scheduleXml);
return "";
}
@Override
public String schedulePriority(String wrkflwPriority) throws Exception {
// TODO Auto-generated method stub
return null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment