Commit 5799e7ee authored by ngadkari's avatar ngadkari

new mrp verify component

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@213432 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 7c545471
package ibase.webitm.ejb.mfg;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import javax.ejb.Stateless;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
@Stateless
public class InvDemSuppSummVerifyIC extends ValidatorEJB{
E12GenericUtility genericUtility= new E12GenericUtility();
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
SimpleDateFormat simpleDateFormat = null;
public String wfValData() throws RemoteException,ITMException
{
System.out.println("wfValData()...");
return "";
}
// Item Change
public String itemChanged() throws RemoteException,ITMException
{
System.out.println("itemChanged Called...");
return "";
}
public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException
{
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String errString = null;
E12GenericUtility genericUtility= new E12GenericUtility();
try
{
if (xmlString != null && xmlString.trim().length()!=0)
{
dom = genericUtility.parseString(xmlString);
}
if (xmlString1 != null && xmlString1.trim().length()!=0)
{
dom1 = genericUtility.parseString(xmlString1);
}
if (xmlString2 != null && xmlString2.trim().length()!=0)
{
dom2 = genericUtility.parseString(xmlString2);
}
errString = itemChanged(dom, dom1, dom2, objContext, currentColumn, editFlag, xtraParams);
}
catch (Exception e)
{
System.out.println ("Exception :ProcessControlEJB :itemChanged(String,String):" + e.getMessage() + ":");
errString = genericUtility.createErrorString(e);
throw new ITMException(e);
}
System.out.println ("returning from ProcessControlEJB itemChanged");
return errString;
}
public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException
{
String returnValue="";
String returnValue1="";
String returnValue2="";
String itemCodeDom="";
String itemCodeDom1="";
String itemCodeDom2="";
ResultSet rs = null;
String sql = "";
String columnValue = "";
String userId = "";
String errString="";
Connection connectionObject = null;
Statement stmt = null;
StringBuffer valueXmlString = new StringBuffer();
int currentFormNo = 0;
E12GenericUtility genericUtility= new E12GenericUtility();
try
{
simpleDateFormat = new SimpleDateFormat(genericUtility.getApplDateFormat());
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode");
columnValue = genericUtility.getColumnValue(currentColumn,dom);
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext);
}
valueXmlString = new StringBuffer("<?xml version=\"1.0\"?><Root><Header><editFlag>");
valueXmlString.append(editFlag).append("</editFlag></Header>");
switch (currentFormNo)
{
case 1:
valueXmlString.append("<Detail1>");
if(currentColumn.trim().equals("itm_default"))
{
Calendar cal = Calendar.getInstance();
Date d = new Date();
String runDate = simpleDateFormat.format(d); // 01-10-2007 manoharan
cal.setTime(d);
cal.set(Calendar.DATE,1);
d = cal.getTime();
String fromDate = simpleDateFormat.format(d);
cal.setTime(d);
cal.add(Calendar.MONTH,3);
cal.set(Calendar.DATE,0);
d = cal.getTime();
String toDate = simpleDateFormat.format(d);
System.out.println("From Date :" + fromDate + " To Date :" + toDate);
valueXmlString.append("<date_from>").append(fromDate).append("</date_from>");
valueXmlString.append("<date_to>").append(toDate).append("</date_to>");
valueXmlString.append("<site_code__from>").append("0").append("</site_code__from>");
valueXmlString.append("<site_code__to>").append("ZZ").append("</site_code__to>");
valueXmlString.append("<item_code__from>").append("0").append("</item_code__from>");
valueXmlString.append("<item_code__to>").append("ZZ").append("</item_code__to>");
valueXmlString.append("<item_ser__from>").append("0").append("</item_ser__from>");
valueXmlString.append("<item_ser__to>").append("ZZ").append("</item_ser__to>");
}
valueXmlString.append("</Detail1>");
break;
}
valueXmlString.append("</Root>");
}
catch(Exception e)
{
System.out.println("Exception :[RunMRP][itemChanged::case 1:] :==>\n"+e.getMessage());
e.printStackTrace();
throw new ITMException(e);
}
return valueXmlString.toString();
}
// Validation
public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String errString = "";
System.out.println("wfValData(String)>>>");
try
{
dom = parseString(xmlString);
System.out.println("RunMRP : wfValData(String xmlString) : ==>\n" + xmlString );
System.out.println("RunMRP : wfValData(String xmlString1) : ==>\n" + xmlString1 );
dom1 = parseString(xmlString1);
if (xmlString2.trim().length() > 0 )
{
dom2 = parseString("<Root>" + xmlString2+ "</Root>");
}
errString = wfValData(dom,dom1,dom2,objContext,editFlag,xtraParams);
}
catch(Exception e)
{
System.out.println("Exception : RunMRP : wfValData(String xmlString) : ==>\n"+e.getMessage());
e.printStackTrace();
throw new ITMException(e);
}
return (errString);
}
public String wfValData(Document dom, Document dom1, Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException, ITMException
{
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
String childNodeName = "";
String errString = "";
int ctr,currentFormNo=0;
int childNodeListLength;
int count = 0;
String siteCodeFrom = "";
String siteCodeTo = "";
String itemCodeFrom = "";
String itemCodeTo = "";
String itemSerFrom = "";
String itemSerTo = "";
String errCode = "";
String userId = "";
String sql = "";
String itemcodeTo = "";
//String itemSerTo = "";
//String itemSerFrom = "";
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
simpleDateFormat = new SimpleDateFormat(genericUtility.getApplDateFormat());
conn = getConnection();
userId = getValueFromXTRA_PARAMS(xtraParams,"userId");
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext);
}
switch(currentFormNo)
{
case 1:
{
parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for(ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
int cnt;
System.out.println("childNodeName 0. : " + childNodeName);
if (childNodeName.equals("date_to"))
{
if (childNode.getFirstChild() == null || genericUtility.getColumnValue("date_from",dom) == null)
{
errCode = "VMRPDATE1";
errString = getErrorString("date_to",errCode,userId);
break;
}
String df = genericUtility.getColumnValue("date_from",dom);
String dt = genericUtility.getColumnValue("date_to",dom);
System.out.println("date From -->" + df );
System.out.println("date To -->" + dt );
System.out.println("Parsed " + simpleDateFormat.parse(df));
java.util.Date fromDate = new Date(simpleDateFormat.parse(genericUtility.getColumnValue("date_from",dom)).getTime());
java.util.Date toDate = new Date(simpleDateFormat.parse(genericUtility.getColumnValue("date_to",dom)).getTime());
if(fromDate.after(toDate))
{
System.out.println("Error...");
errCode = "VMRPDATE1";
errString = getErrorString("date_to",errCode,userId);
break;
}
else
System.out.println("No Error...");
}
if (childNodeName.equals("site_code__to"))
{
if (childNode.getFirstChild() == null || genericUtility.getColumnValue("site_code__from",dom) == null)
{
errCode = "VMRPSITE1";
errString = getErrorString("site_code__to",errCode,userId);
break;
}
siteCodeFrom = genericUtility.getColumnValue("site_code__from",dom);
siteCodeTo = genericUtility.getColumnValue("site_code__to",dom);
if(siteCodeTo.compareTo(siteCodeFrom)<0)
{
errCode = "VMRPSITE1";
errString = getErrorString("site_code__to",errCode,userId);
break;
}
count = 0;
}
if (childNodeName.equals("item_code__to"))
{
if (childNode.getFirstChild() == null || genericUtility.getColumnValue("item_code__from",dom) == null)
{
errCode = "VMRPSITE1";
errString = getErrorString("item_code__to",errCode,userId);
break;
}
itemCodeFrom = genericUtility.getColumnValue("item_code__from",dom);
itemCodeTo = genericUtility.getColumnValue("item_code__to",dom);
if(itemCodeTo.compareTo(itemCodeFrom)<0)
{
errCode = "VMRPITEMS1";
errString = getErrorString("item_code__to",errCode,userId);
break;
}
count = 0;
}
if (childNodeName.equals("item_ser__to"))
{
if (childNode.getFirstChild() == null || genericUtility.getColumnValue("item_ser__from",dom) == null)
{
errCode = "VMRPSITE1";
errString = getErrorString("item_ser__to",errCode,userId);
break;
}
itemSerFrom = genericUtility.getColumnValue("item_ser__from",dom);
itemSerTo = genericUtility.getColumnValue("item_ser__to",dom);
if(itemSerTo.compareTo(itemSerFrom)<0)
{
errCode = "VMRPITEMS1";
errString = getErrorString("item_ser__to",errCode,userId);
break;
}
count = 0;
}
if (childNodeName.equals("process_cycle"))
{
if (childNode.getFirstChild() == null || Integer.parseInt(genericUtility.getColumnValue("process_cycle",dom)) < 0)
{
errCode = "VMRPCYCL1";
errString = getErrorString("process_cycle",errCode,userId);
break;
}
}
if (childNodeName.equals("gen_ind"))
{
if (childNode.getFirstChild() == null || genericUtility.getColumnValue("gen_ind",dom) == null)
{
errCode = "VMRPGIND";
errString = getErrorString("gen_ind",errCode,userId);
break;
}
}
}
}
}
}
catch(Exception e)
{
System.out.println("Exception ::"+e);
e.printStackTrace();
errString = e.getMessage();
throw new ITMException(e);
}
finally
{
try
{
//System.out.println("Closing Connection.....");
conn.close();
conn = null;
}catch(Exception se){}
}
return errString;
}
}
package ibase.webitm.ejb.mfg;
import java.sql.*;
import java.util.*;
import org.w3c.dom.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.rmi.RemoteException;
import ibase.webitm.ejb.*;
import ibase.utility.BaseLogger;
import ibase.utility.CommonConstants;
import ibase.utility.E12GenericUtility;
import ibase.webitm.utility.ITMException;
import javax.ejb.Stateless;
@Stateless
public class InvDemSuppSummVerifyPrc extends ProcessEJB
{
E12GenericUtility genericUtility = new E12GenericUtility();
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
CommonConstants commonConstants = new CommonConstants();
Connection conn = null;
long startTime = 0;
public String process(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException
{
String rtrStr = "";
Document headerDom = null;
Document detailDom = null;
try
{
if(xmlString != null && xmlString.trim().length()!=0 )
{
System.out.println("XML String *.....*:"+xmlString);
headerDom = genericUtility.parseString(xmlString);
}
if(xmlString2 != null && xmlString2.trim().length()!=0)
{
detailDom = genericUtility.parseString(xmlString2);
}
rtrStr = process(headerDom, detailDom, windowName, xtraParams);
}
catch (Exception e)
{
System.out.println("Exception :InvDemSuppSummVerifyPrc :process(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
throw new ITMException(e);
}
return rtrStr;
}
public String process(Document headerDom, Document detailDom, String windowName, String xtraParams) throws RemoteException,ITMException
{
String errString = "";
String preview = "";
PreparedStatement pstmt = null,pstmt1 = null;
ResultSet rs = null,rs1=null;
double demand = 0.0,currentDemand= 0;
double supply = 0.0,currentSupply= 0;
int currentRec = 0;
String chgUser = "";
String chgTerm = "";
String itemCode = "";
String tranId = "";
String lineNo = "";
String tranSer = "";
String siteCode = "";
String adpQuery = "";
String siteCodeFrom = "";
String siteCodeTo = "";
String itemCodeFrom= "";
String itemCodeTo = "";
String sDateFrom = "";
String sDateTo = "";
String itemSerFrom = "";
String itemSerTo = "";
String dbDateFrom = "";
String dbDateTo = "";
String standingOrdTypes = "";
Timestamp dueDate = null;
Timestamp chgDate = null;
ArrayList arrStdOrdType = null;
HashMap demandSupplyMap = null;
HashMap<String, String> externalSqlMap = null;
String sqlFileName = "",sql="";
try
{
if(conn==null)
{
conn = getConnection();
}
genericUtility= new E12GenericUtility();
chgDate = new Timestamp(System.currentTimeMillis());
chgUser = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode");
chgTerm = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"termId");
siteCodeFrom = genericUtility.getColumnValue("site_code__from", headerDom);
System.out.println("Site Code From............." + siteCodeFrom);
if (siteCodeFrom == null || siteCodeFrom.trim().length() == 0)
{
errString = itmDBAccessEJB.getErrorString("", "VPSTCDFR1", "", "", conn);
return errString;
}
siteCodeTo = genericUtility.getColumnValue("site_code__to", headerDom);
System.out.println("Site Code To..............." + siteCodeTo);
if (siteCodeTo == null || siteCodeTo.trim().length() == 0)
{
errString = itmDBAccessEJB.getErrorString("", "VPSTCDTO1", "", "", conn);
return errString;
}
itemCodeFrom = genericUtility.getColumnValue("item_code__from", headerDom);
System.out.println("Item Code From............." + itemCodeFrom);
if (itemCodeFrom == null || itemCodeFrom.trim().length() == 0)
{
errString = itmDBAccessEJB.getErrorString("", "NULLITMC", "", "", conn);
return errString;
}
itemCodeTo = genericUtility.getColumnValue("item_code__to", headerDom);
System.out.println("Item Code To............." + itemCodeTo);
if (itemCodeTo == null || itemCodeTo.trim().length() == 0)
{
errString = itmDBAccessEJB.getErrorString("", "NULLITMC", "", "", conn);
return errString;
}
sDateFrom = genericUtility.getColumnValue("date_from", headerDom);
System.out.println("From Date............." + sDateFrom);
if (sDateFrom == null || sDateFrom.trim().length() == 0)
{
errString = itmDBAccessEJB.getErrorString("", "VPFROMBTBK", "", "", conn);
return errString;
}
sDateTo = genericUtility.getColumnValue("date_to", headerDom);
System.out.println("To Date............." + sDateTo);
if (sDateTo == null || sDateTo.trim().length() == 0)
{
errString = itmDBAccessEJB.getErrorString("", "BLKTODT", "", "", conn);
return errString;
}
itemSerFrom = genericUtility.getColumnValue("item_ser__from", headerDom);
System.out.println("Item Series From............." + itemSerFrom);
if (itemSerFrom == null || itemSerFrom.trim().length() == 0)
{
errString = itmDBAccessEJB.getErrorString("", "VMITMSER1 ", "", "", conn);
return errString;
}
itemSerTo = genericUtility.getColumnValue("item_ser__to", headerDom);
System.out.println("To Item Series............." + itemSerTo);
if (itemSerTo == null || itemSerTo.trim().length() == 0)
{
errString = itmDBAccessEJB.getErrorString("", "VMITMSER1 ", "", "", conn);
return errString;
}
sDateFrom = genericUtility.getColumnValue("date_from", headerDom);
sDateTo = genericUtility.getColumnValue("date_to", headerDom);
dbDateFrom = sDateFrom;
dbDateTo = sDateTo;
dbDateFrom = genericUtility.getValidDateString(dbDateFrom, genericUtility.getApplDateFormat(), "dd-MMM-yyyy");
System.out.println("sDateFrom : " + sDateFrom);
dbDateTo = genericUtility.getValidDateString(dbDateTo, genericUtility.getApplDateFormat(), "dd-MMM-yyyy");
System.out.println("Db Date from :" + dbDateFrom);
System.out.println("Db Date to :" + dbDateTo);
standingOrdTypes = itmDBAccessEJB.getEnvDis("999999", "STANDING_ORDTYPES", conn);
if (standingOrdTypes.equals("NULLFOUND")){
standingOrdTypes = "";
}
arrStdOrdType = genericUtility.getTokenList(standingOrdTypes, ",");
standingOrdTypes = "";
for (int index = 0; index < arrStdOrdType.size(); index++)
{
if (index == arrStdOrdType.size() - 1)
{
standingOrdTypes = standingOrdTypes.concat("'").concat((String) arrStdOrdType.get(index)).concat("'");
} else
{
standingOrdTypes = standingOrdTypes.concat("'").concat((String) arrStdOrdType.get(index)).concat("',");
}
}
System.out.println("Final standingOrdTypes :" + standingOrdTypes);
externalSqlMap = new HashMap<String, String>();
sql = "SELECT SUPPLY_QTY,DEMAND_QTY FROM INV_DEM_SUPP WHERE SITE_CODE= ? AND ITEM_CODE=? AND REF_SER = ? AND REF_ID =? AND REF_LINE = ? AND DUE_DATE=? ";
pstmt1 = conn.prepareStatement(sql);
sqlFileName = CommonConstants.JBOSSHOME + File.separator + "sql" + File.separator + "demandSupplyOverwriteOracle.sql";
adpQuery = checkNull(readFile(sqlFileName));
System.out.println("Replacing Values.in SQL.....");
adpQuery = adpQuery.replaceAll("@sitecodeFr@", siteCodeFrom);
adpQuery = adpQuery.replaceAll("@sitecodeTo@", siteCodeTo);
adpQuery = adpQuery.replaceAll("@itemcodeFr@", itemCodeFrom);
adpQuery = adpQuery.replaceAll("@itemcodeTo@", itemCodeTo);
adpQuery = adpQuery.replaceAll("@itemserFr@", itemSerFrom);
adpQuery = adpQuery.replaceAll("@itemserTo@", itemSerTo);
adpQuery = adpQuery.replaceAll("@fromdate@", dbDateFrom);
adpQuery = adpQuery.replaceAll("@todate@", dbDateTo);
adpQuery = adpQuery.replaceAll("@ordtypes@", standingOrdTypes);
System.out.println("Replacing Values.in SQL.....adpQuery >>> "+adpQuery);
pstmt = conn.prepareStatement(adpQuery);
rs = pstmt.executeQuery();
while (rs.next())
{
currentRec ++;
System.out.println("Total Reocrd ::[] Current ["+currentRec+"]");
itemCode = checkNull(rs.getString("item_code"));
dueDate = rs.getTimestamp("due_date");
currentDemand = rs.getDouble("demand");
currentSupply = rs.getDouble("supply");
tranId = checkNull(rs.getString("tran_id"));
lineNo = checkNull(rs.getString("line_no"));
tranSer = checkNull(rs.getString("tran_ser"));
siteCode = checkNull(rs.getString("site_code"));
pstmt1.setString(1,siteCode);
pstmt1.setString(2,itemCode);
pstmt1.setString(3,tranSer);
pstmt1.setString(4,tranId);
pstmt1.setString(5,lineNo);
pstmt1.setTimestamp(6,dueDate);
rs1 = pstmt1.executeQuery();
if (rs1.next())
{
supply= rs1.getDouble(1);
demand = rs1.getDouble(2);
}
rs = null;
pstmt1.clearParameters();
if(currentDemand !=demand )
{
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
errString = itmDBAccessEJB.getErrorString("", "VTDEMMISM", "", "", conn);
return errString;
}
if(currentSupply != supply)
{
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
errString = itmDBAccessEJB.getErrorString("", "VTSUPPMISM", "", "", conn);
return errString;
}
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
}
catch (Exception e)
{
System.out.println("Exception :InvDemSuppSummVerifyPrc :process(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
throw new ITMException(e);
}
finally
{
try
{
conn.close();
conn = null;
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
catch(Exception e)
{
e.printStackTrace();
}
}
return errString;
}
// for check null
private String checkNullTrim( String input )
{
return E12GenericUtility.checkNull(input);
}
private String checkNull( String input )
{
if( input == null || "null".equals(input) )
{
input = "";
}
else
{
input = input.trim();
}
return input;
}
private String readFile(String file) throws Exception
{
BaseLogger.log("2", null, null, "readFile.....finally called");
String sqlQry = "";
FileInputStream fin = null;
BufferedReader br = null;
try
{
// System.out.println("File "+file);
fin = new FileInputStream(file);
br = new BufferedReader(new InputStreamReader(fin));
String tempStr = "";
while ((tempStr = br.readLine()) != null)
{
sqlQry = sqlQry + tempStr;
}
} catch (FileNotFoundException fe)
{
fe.printStackTrace();
throw new ITMException(fe);
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
if(br != null)
{
br.close();
br = null;
}
if(fin != null)
{
fin.close();
fin = null;
}
}
return sqlQry;
}
}
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