Commit 5be98259 authored by asikarwar's avatar asikarwar

add code for multple rights


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@92160 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 15b7c855
package ibase.webitm.ejb.sys; package ibase.webitm.ejb.sys;
import java.io.*; import java.io.*;
import java.sql.*; import java.sql.*;
import java.util.*; import java.util.*;
import java.lang.*; import java.lang.*;
import javax.ejb.*; import javax.ejb.*;
import org.w3c.dom.*; import org.w3c.dom.*;
import javax.xml.parsers.*; import javax.xml.parsers.*;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import javax.naming.InitialContext; import javax.naming.InitialContext;
import ibase.webitm.ejb.*; import ibase.webitm.ejb.*;
import ibase.webitm.utility.*; import ibase.webitm.utility.*;
import ibase.system.config.*; import ibase.system.config.*;
import ibase.utility.CommonConstants; import ibase.utility.CommonConstants;
import ibase.webitm.utility.ITMException; import ibase.webitm.utility.ITMException;
import ibase.webitm.utility.GenericUtility; import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.TransIDGenerator; import ibase.webitm.utility.TransIDGenerator;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import javax.xml.transform.*; import javax.xml.transform.*;
import javax.xml.transform.dom.*; import javax.xml.transform.dom.*;
import javax.xml.transform.TransformerFactory; import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer; import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamSource; import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerConfigurationException;
import javax.ejb.Stateless; // added for ejb3 import javax.ejb.Stateless; // added for ejb3
@Stateless // added for ejb3 @Stateless // added for ejb3
public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , UserRightsPrcRemote // SessionBean public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , UserRightsPrcRemote // SessionBean
{ {
GenericUtility genericUtility = GenericUtility.getInstance(); GenericUtility genericUtility = GenericUtility.getInstance();
CommonConstants commonConstants = new CommonConstants(); CommonConstants commonConstants = new CommonConstants();
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB(); ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
Connection conn = null; Connection conn = null;
HashMap userRightsMap = null; HashMap userRightsMap = null;
HashMap winNameMap = null; HashMap winNameMap = null;
HashMap menuNameMap = null; HashMap menuNameMap = null;
String profileId = null; String profileId = null;
String processStr = null; String processStr = null;
/*public void ejbCreate() throws RemoteException, CreateException /*public void ejbCreate() throws RemoteException, CreateException
{ {
} }
public void ejbRemove() public void ejbRemove()
{ {
} }
public void ejbActivate() public void ejbActivate()
{ {
} }
public void ejbPassivate() public void ejbPassivate()
{ {
}*/ }*/
public String process() throws RemoteException,ITMException public String process() throws RemoteException,ITMException
{ {
return ""; return "";
} }
public String getData(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException public String getData(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException
{ {
String rtrStr = ""; String rtrStr = "";
Document headerDom = null; Document headerDom = null;
Document detailDom = null; Document detailDom = null;
try try
{ {
System.out.println("xmlString ["+xmlString+"]"); System.out.println("xmlString ["+xmlString+"]");
System.out.println("xmlString2 ["+xmlString2+"]"); System.out.println("xmlString2 ["+xmlString2+"]");
System.out.println("windowName ["+windowName+"]"); System.out.println("windowName ["+windowName+"]");
System.out.println("xtraParams ["+xtraParams+"]"); System.out.println("xtraParams ["+xtraParams+"]");
if(xmlString != null && xmlString.trim().length()!=0 ) if(xmlString != null && xmlString.trim().length()!=0 )
{ {
headerDom = genericUtility.parseString(xmlString); headerDom = genericUtility.parseString(xmlString);
} }
if(xmlString2 != null && xmlString2.trim().length()!=0) if(xmlString2 != null && xmlString2.trim().length()!=0)
{ {
detailDom = genericUtility.parseString(xmlString2); detailDom = genericUtility.parseString(xmlString2);
} }
rtrStr = getData(headerDom, detailDom, windowName, xtraParams); rtrStr = getData(headerDom, detailDom, windowName, xtraParams);
} }
catch (Exception e) catch (Exception e)
{ {
System.out.println("Exception :UserRightsEJB :getData(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":"); System.out.println("Exception :UserRightsEJB :getData(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
throw new ITMException(e); throw new ITMException(e);
} }
return rtrStr; return rtrStr;
} }
public String getData(Document headerDom, Document detailDom, String windowName, String xtraParams) throws RemoteException,ITMException public String getData(Document headerDom, Document detailDom, String windowName, String xtraParams) throws RemoteException,ITMException
{ {
Statement stmt = null; Statement stmt = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
StringBuffer retTabSepStrBuff = new StringBuffer(); StringBuffer retTabSepStrBuff = new StringBuffer();
String userId = null; String userId = null;
Object date = null; Object date = null;
String sql = ""; String sql = "";
String errCode = ""; String errCode = "";
String errString = ""; String errString = "";
String resultString = ""; String resultString = "";
String curUserId = "", curProfileId = ""; String curUserId = "", curProfileId = "";
//String profileId =null; //String profileId =null;
double quantity = 0.0,pendingQty = 0.0; double quantity = 0.0,pendingQty = 0.0;
int count = 0, usrLev = 0; int count = 0, usrLev = 0;
String tApplication = null; String tApplication = null;
String key = null; String key = null;
String tWinName = null; String tWinName = null;
String tMenuName = null; String tMenuName = null;
String sqlStr = ""; String sqlStr = "";
try try
{ {
if(conn == null) if(conn == null)
{ {
ConnDriver connDriver = new ConnDriver(); ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM"); conn = connDriver.getConnectDB("DriverITM");
conn.setAutoCommit(false); conn.setAutoCommit(false);
connDriver = null; connDriver = null;
} }
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"userId"); userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"userId");
profileId = genericUtility.getColumnValue("profile_id", headerDom); profileId = genericUtility.getColumnValue("profile_id", headerDom);
//System.out.println("profileId ::- "+ profileId); //System.out.println("profileId ::- "+ profileId);
// 24/03/12 manoharan get the current logged in user and show only the menus for which the current user has rights // 24/03/12 manoharan get the current logged in user and show only the menus for which the current user has rights
curUserId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode"); curUserId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
System.out.println("Current userid curUserId ["+ curUserId + "] profileId [" + profileId + "]"); System.out.println("Current userid curUserId ["+ curUserId + "] profileId [" + profileId + "]");
if (curUserId == null || curUserId.trim().length() == 0) if (curUserId == null || curUserId.trim().length() == 0)
{ {
retTabSepStrBuff.append(" \t"); retTabSepStrBuff.append(" \t");
//LEVEL_1 //LEVEL_1
retTabSepStrBuff.append(" \t"); retTabSepStrBuff.append(" \t");
//LEVEL_2 //LEVEL_2
retTabSepStrBuff.append(" \t"); retTabSepStrBuff.append(" \t");
//LEVEL_3 //LEVEL_3
retTabSepStrBuff.append(" \t"); retTabSepStrBuff.append(" \t");
//LEVEL_4 //LEVEL_4
retTabSepStrBuff.append(" \t"); retTabSepStrBuff.append(" \t");
//LEVEL_5 //LEVEL_5
retTabSepStrBuff.append(" \t"); retTabSepStrBuff.append(" \t");
//DESCR //DESCR
retTabSepStrBuff.append(" \t"); retTabSepStrBuff.append(" \t");
//RIGHTS //RIGHTS
retTabSepStrBuff.append(" \t"); retTabSepStrBuff.append(" \t");
//WIN_NAME //WIN_NAME
retTabSepStrBuff.append(" \t"); retTabSepStrBuff.append(" \t");
retTabSepStrBuff.append(" ").append("\t"); retTabSepStrBuff.append(" ").append("\t");
retTabSepStrBuff.append("\n"); retTabSepStrBuff.append("\n");
resultString = retTabSepStrBuff.toString(); resultString = retTabSepStrBuff.toString();
} }
else else
{ {
sql = " select profile_id,usr_lev from users where code = ?"; sql = " select profile_id,usr_lev from users where code = ?";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setString(1,curUserId); pstmt.setString(1,curUserId);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if(rs.next()) if(rs.next())
{ {
curProfileId = rs.getString("profile_id"); curProfileId = rs.getString("profile_id");
usrLev = rs.getInt("usr_lev"); usrLev = rs.getInt("usr_lev");
} }
rs.close(); rs.close();
rs = null; rs = null;
pstmt.close(); pstmt.close();
pstmt = null; pstmt = null;
System.out.println("Current curProfileId ["+ curProfileId + "] usrLev [" + usrLev + "]"); System.out.println("Current curProfileId ["+ curProfileId + "] usrLev [" + usrLev + "]");
//////////////// ////////////////
//If profile Id is blank or doesnt exist in the User_Rights table then prompt error //If profile Id is blank or doesnt exist in the User_Rights table then prompt error
//String profileSql = " select count(*) " + //String profileSql = " select count(*) " +
// " from user_rights " + // " from user_rights " +
// " where profile_id = '" + profileId + "' " ; // " where profile_id = '" + profileId + "' " ;
String profileSql = " select count(1) " + String profileSql = " select count(1) " +
" from gencodes " + " from gencodes " +
" where fld_name = 'PROFILE_ID' and fld_value = '" + profileId + "' " ; " where fld_name = 'PROFILE_ID' and fld_value = '" + profileId + "' " ;
int profileCount = 0; int profileCount = 0;
System.out.println("ProfileSql :: " + profileSql); System.out.println("ProfileSql :: " + profileSql);
PreparedStatement pProfileStmt = null; PreparedStatement pProfileStmt = null;
ResultSet profileRs = null; ResultSet profileRs = null;
pProfileStmt = conn.prepareStatement(profileSql); pProfileStmt = conn.prepareStatement(profileSql);
profileRs = pProfileStmt.executeQuery(); profileRs = pProfileStmt.executeQuery();
if(profileRs.next()) if(profileRs.next())
{ {
profileCount = profileRs.getInt(1); profileCount = profileRs.getInt(1);
System.out.println("Profile Count = " + profileCount); System.out.println("Profile Count = " + profileCount);
} }
profileRs.close(); profileRs.close();
profileRs = null; profileRs = null;
pProfileStmt.close(); pProfileStmt.close();
pProfileStmt = null; pProfileStmt = null;
/////////////// ///////////////
if(profileCount == 0) if(profileCount == 0)
{ {
errString = itmDBAccessEJB.getErrorString("","PNOTEXIST","","",conn); errString = itmDBAccessEJB.getErrorString("","PNOTEXIST","","",conn);
return errString; return errString;
} }
userRightsMap = new HashMap(); userRightsMap = new HashMap();
winNameMap = new HashMap(); winNameMap = new HashMap();
menuNameMap = new HashMap(); menuNameMap = new HashMap();
sqlStr = " SELECT ITM2MENU.APPLICATION, " + sqlStr = " SELECT ITM2MENU.APPLICATION, " +
" ITM2MENU.LEVEL_1, " + " ITM2MENU.LEVEL_1, " +
" ITM2MENU.LEVEL_2, " + " ITM2MENU.LEVEL_2, " +
" ITM2MENU.LEVEL_3, " + " ITM2MENU.LEVEL_3, " +
" ITM2MENU.LEVEL_4, " + " ITM2MENU.LEVEL_4, " +
" ITM2MENU.LEVEL_5, " + " ITM2MENU.LEVEL_5, " +
" ITM2MENU.WIN_NAME, " + " ITM2MENU.WIN_NAME, " +
" ITM2MENU.DESCR, " + " ITM2MENU.DESCR, " +
" (SELECT USER_RIGHTS.RIGHTS FROM USER_RIGHTS " + " (SELECT USER_RIGHTS.RIGHTS FROM USER_RIGHTS " +
" WHERE USER_RIGHTS.PROFILE_ID = ? " + " WHERE USER_RIGHTS.PROFILE_ID = ? " +
" AND USER_RIGHTS.APPLICATION = ITM2MENU.APPLICATION " + " AND USER_RIGHTS.APPLICATION = ITM2MENU.APPLICATION " +
" AND USER_RIGHTS.MENU_ROW = ITM2MENU.LEVEL_1 " + " AND USER_RIGHTS.MENU_ROW = ITM2MENU.LEVEL_1 " +
" AND USER_RIGHTS.MENU_COL = ITM2MENU.LEVEL_2 " + " AND USER_RIGHTS.MENU_COL = ITM2MENU.LEVEL_2 " +
" AND USER_RIGHTS.MENU_SUBCOL = ITM2MENU.LEVEL_3 " + " AND USER_RIGHTS.MENU_SUBCOL = ITM2MENU.LEVEL_3 " +
" AND USER_RIGHTS.LEVEL_4 = ITM2MENU.LEVEL_4 " + " AND USER_RIGHTS.LEVEL_4 = ITM2MENU.LEVEL_4 " +
" AND USER_RIGHTS.LEVEL_5 = ITM2MENU.LEVEL_5 " + " AND USER_RIGHTS.LEVEL_5 = ITM2MENU.LEVEL_5 " +
" ) AS RIGHTS " + " ) AS RIGHTS " +
" FROM ITM2MENU " ; " FROM ITM2MENU " ;
if (usrLev > 0 ) if (usrLev > 0 )
{ {
sqlStr = sqlStr + " where exists (select 1 from user_rights u " sqlStr = sqlStr + " where exists (select 1 from user_rights u "
+ " where u.profile_id in ('" + curProfileId + "','" + profileId + "') " + " where u.profile_id in ('" + curProfileId + "','" + profileId + "') "
+ " and u.application = ITM2MENU.application " + " and u.application = ITM2MENU.application "
+ " and u.menu_row = ITM2MENU.level_1 " + " and u.menu_row = ITM2MENU.level_1 "
+ " and u.menu_col = ITM2MENU.level_2 " + " and u.menu_col = ITM2MENU.level_2 "
+ " and u.menu_subcol = ITM2MENU.level_3 " + " and u.menu_subcol = ITM2MENU.level_3 "
+ " and u.level_4 = ITM2MENU.level_4 " + " and u.level_4 = ITM2MENU.level_4 "
+ " and u.level_5 = ITM2MENU.level_5) " ; + " and u.level_5 = ITM2MENU.level_5) " ;
} }
sqlStr = sqlStr + " ORDER BY ITM2MENU.APPLICATION, ITM2MENU.LEVEL_1, ITM2MENU.LEVEL_2, ITM2MENU.LEVEL_3, ITM2MENU.LEVEL_4, ITM2MENU.LEVEL_5 "; sqlStr = sqlStr + " ORDER BY ITM2MENU.APPLICATION, ITM2MENU.LEVEL_1, ITM2MENU.LEVEL_2, ITM2MENU.LEVEL_3, ITM2MENU.LEVEL_4, ITM2MENU.LEVEL_5 ";
pstmt = conn.prepareStatement(sqlStr); pstmt = conn.prepareStatement(sqlStr);
pstmt.setString(1,profileId); pstmt.setString(1,profileId);
//System.out.println("The getData sql is:-"+ sqlStr); //System.out.println("The getData sql is:-"+ sqlStr);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
{ {
tApplication = rs.getString(1); tApplication = rs.getString(1);
if(tApplication != null) if(tApplication != null)
key = tApplication + ":" + rs.getInt(2) + ":" + rs.getInt(3) + ":" + rs.getInt(4) key = tApplication + ":" + rs.getInt(2) + ":" + rs.getInt(3) + ":" + rs.getInt(4)
+ ":" + rs.getInt(5) + ":" + rs.getInt(6); + ":" + rs.getInt(5) + ":" + rs.getInt(6);
//APPLICATION //APPLICATION
retTabSepStrBuff.append(tApplication==null?"":rs.getString(1)).append("\t"); retTabSepStrBuff.append(tApplication==null?"":rs.getString(1)).append("\t");
//LEVEL_1 //LEVEL_1
retTabSepStrBuff.append(rs.getInt(2)).append("\t"); retTabSepStrBuff.append(rs.getInt(2)).append("\t");
//LEVEL_2 //LEVEL_2
retTabSepStrBuff.append(rs.getInt(3)).append("\t"); retTabSepStrBuff.append(rs.getInt(3)).append("\t");
//LEVEL_3 //LEVEL_3
retTabSepStrBuff.append(rs.getInt(4)).append("\t"); retTabSepStrBuff.append(rs.getInt(4)).append("\t");
//LEVEL_4 //LEVEL_4
retTabSepStrBuff.append(rs.getInt(5)).append("\t"); retTabSepStrBuff.append(rs.getInt(5)).append("\t");
//LEVEL_5 //LEVEL_5
retTabSepStrBuff.append(rs.getInt(6)).append("\t"); retTabSepStrBuff.append(rs.getInt(6)).append("\t");
//DESCR //DESCR
tMenuName = rs.getString(8); tMenuName = rs.getString(8);
retTabSepStrBuff.append(rs.getString(8)==null?"":rs.getString(8)).append("\t"); retTabSepStrBuff.append(rs.getString(8)==null?"":rs.getString(8)).append("\t");
//RIGHTS //RIGHTS
retTabSepStrBuff.append(rs.getString(9)==null?"":rs.getString(9)).append("\t"); retTabSepStrBuff.append(rs.getString(9)==null?"":rs.getString(9)).append("\t");
//WIN_NAME //WIN_NAME
tWinName = rs.getString(7); tWinName = rs.getString(7);
retTabSepStrBuff.append(rs.getString(7)==null?"":rs.getString(7)).append("\t"); retTabSepStrBuff.append(rs.getString(7)==null?"":rs.getString(7)).append("\t");
retTabSepStrBuff.append(" ").append("\t"); retTabSepStrBuff.append(" ").append("\t");
retTabSepStrBuff.append("\n"); retTabSepStrBuff.append("\n");
System.out.println("Key getdata function ["+key+"]"); System.out.println("Key getdata function ["+key+"]");
System.out.println("rights in function ["+ rs.getString(9) +"]"); System.out.println("rights in function ["+ rs.getString(9) +"]");
userRightsMap.put(key, rs.getString(9)); userRightsMap.put(key, rs.getString(9));
if(tWinName != null && tWinName.trim().length() > 2) if(tWinName != null && tWinName.trim().length() > 2)
winNameMap.put(key, tWinName.trim().substring(2, tWinName.trim().length())); winNameMap.put(key, tWinName.trim().substring(2, tWinName.trim().length()));
menuNameMap.put(key, tMenuName); menuNameMap.put(key, tMenuName);
}//while }//while
} }
// end 24/03/12 manoharan // end 24/03/12 manoharan
}//try }//try
catch (SQLException e) catch (SQLException e)
{ {
System.out.println("SQLException ::" + sqlStr + e.getMessage() + ":"); System.out.println("SQLException ::" + sqlStr + e.getMessage() + ":");
e.printStackTrace(); e.printStackTrace();
throw new ITMException(e);// added by akhilesh on 31/oct/12 throw new ITMException(e);// added by akhilesh on 31/oct/12
} }
catch(Exception ex) catch(Exception ex)
{ {
System.out.println("Exception []::" + ex.getMessage()); System.out.println("Exception []::" + ex.getMessage());
ex.printStackTrace(); ex.printStackTrace();
throw new ITMException(ex);// added by akhilesh on 31/oct/12 throw new ITMException(ex);// added by akhilesh on 31/oct/12
} }
finally finally
{ {
try try
{ {
if(rs != null){rs.close();// added by akhilesh on 08/nov/12 if(rs != null){rs.close();// added by akhilesh on 08/nov/12
rs = null;} rs = null;}
if(pstmt != null){pstmt.close();// added by akhilesh on 08/nov/12 if(pstmt != null){pstmt.close();// added by akhilesh on 08/nov/12
pstmt = null;} pstmt = null;}
if(conn != null){conn.close();// added by akhilesh on 08/nov/12 if(conn != null){conn.close();// added by akhilesh on 08/nov/12
conn = null;} conn = null;}
} }
catch(Exception e){ catch(Exception e){
throw new ITMException(e);// added by akhilesh on 31/oct/12 throw new ITMException(e);// added by akhilesh on 31/oct/12
} }
} }
resultString = retTabSepStrBuff.toString(); resultString = retTabSepStrBuff.toString();
return resultString; return resultString;
}//getData() }//getData()
//process() //process()
public String process(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException public String process(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException
{ {
String retStr = ""; String retStr = "";
Document detailDom = null; Document detailDom = null;
Document headerDom = null; Document headerDom = null;
System.out.println("xmlString2-->"+ xmlString2); System.out.println("xmlString2-->"+ xmlString2);
GenericUtility genericUtility = GenericUtility.getInstance(); GenericUtility genericUtility = GenericUtility.getInstance();
try try
{ {
System.out.println("xmlString ["+xmlString+"]"); System.out.println("xmlString ["+xmlString+"]");
System.out.println("xmlString2 ["+xmlString2+"]"); System.out.println("xmlString2 ["+xmlString2+"]");
System.out.println("windowName ["+windowName+"]"); System.out.println("windowName ["+windowName+"]");
System.out.println("xtraParams ["+xtraParams+"]"); System.out.println("xtraParams ["+xtraParams+"]");
if(xmlString != null && xmlString.trim().length()!=0) if(xmlString != null && xmlString.trim().length()!=0)
{ {
headerDom = genericUtility.parseString(xmlString); headerDom = genericUtility.parseString(xmlString);
} }
if(xmlString2 != null && xmlString2.trim().length()!=0) if(xmlString2 != null && xmlString2.trim().length()!=0)
{ {
detailDom = genericUtility.parseString(xmlString2); detailDom = genericUtility.parseString(xmlString2);
} }
retStr = process(headerDom, detailDom, windowName, xtraParams); retStr = process(headerDom, detailDom, windowName, xtraParams);
} }
catch (Exception e) catch (Exception e)
{ {
System.out.println("Exception :UserRightsEJB :process(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":"); System.out.println("Exception :UserRightsEJB :process(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
e.printStackTrace(); e.printStackTrace();
throw new ITMException(e); throw new ITMException(e);
} }
return retStr; return retStr;
} }
public String process(Document headerDom, Document detailDom, String windowName, String xtraParams) throws RemoteException,ITMException public String process(Document headerDom, Document detailDom, String windowName, String xtraParams) throws RemoteException,ITMException
{ {
processStr = null; processStr = null;
GenericUtility genericUtility = GenericUtility.getInstance(); GenericUtility genericUtility = GenericUtility.getInstance();
ConnDriver connDriver = new ConnDriver(); ConnDriver connDriver = new ConnDriver();
Connection conn = null; Connection conn = null;
PreparedStatement pInsertStmt = null; PreparedStatement pInsertStmt = null;
PreparedStatement pUpdateStmt = null; PreparedStatement pUpdateStmt = null;
PreparedStatement pDeleteStmt = null; PreparedStatement pDeleteStmt = null;
PreparedStatement pSelectStmt = null;// added by akhilesh on 31/oct/12 PreparedStatement pSelectStmt = null;// added by akhilesh on 31/oct/12
Statement stmt = null; Statement stmt = null;
ResultSet rs = null; ResultSet rs = null;
java.sql.Timestamp orderDate = new java.sql.Timestamp(System.currentTimeMillis()); java.sql.Timestamp orderDate = new java.sql.Timestamp(System.currentTimeMillis());
java.sql.Timestamp udfDate = null; java.sql.Timestamp udfDate = null;
ArrayList relArray = new ArrayList(); // added by akhilesh on 31/oct/12 ArrayList relArray = new ArrayList(); // added by akhilesh on 31/oct/12
ArrayList relArray1 = new ArrayList(); // added by akhilesh on 07/nov/12 ArrayList relArray1 = new ArrayList(); // added by akhilesh on 07/nov/12
String returnString = ""; String returnString = "";
//Declaring fields of the table User_Rights //Declaring fields of the table User_Rights
String profileId = null; String profileId = null;
String application = null; String application = null;
String level1 = null, level2 = null, level3 = null, level4 = null, level5 = null; String level1 = null, level2 = null, level3 = null, level4 = null, level5 = null;
String menuName = null; String menuName = null;
String rights = null; String rights = null;
String accFilt = null; String accFilt = null;
String defFilt = null; String defFilt = null;
String objName = null; String objName = null;
String winName = null; String winName = null;
NodeList parentNodeList = null; NodeList parentNodeList = null;
NodeList childNodeList = null; NodeList childNodeList = null;
Node parentNode = null; Node parentNode = null;
Node childNode = null; Node childNode = null;
String childNodeName = ""; String childNodeName = "";
boolean bDetailFound = false; boolean bDetailFound = false;
int parentNodeListLength = 0; int parentNodeListLength = 0;
int childNodeListLength = 0, insertCount =0, updateCount =0, deleteCount = 0; int childNodeListLength = 0, insertCount =0, updateCount =0, deleteCount = 0;
String delSql = ""; String delSql = "";
profileId = genericUtility.getColumnValue("profile_id", headerDom); profileId = genericUtility.getColumnValue("profile_id", headerDom);
System.out.println("profileId..............."+profileId); System.out.println("profileId..............."+profileId);
String batchInesertSql = "INSERT INTO USER_RIGHTS ( PROFILE_ID, APPLICATION, MENU_ROW, MENU_COL, MENU_SUBCOL, LEVEL_4, LEVEL_5, MENU_NAME, RIGHTS, OBJ_NAME)" String batchInesertSql = "INSERT INTO USER_RIGHTS ( PROFILE_ID, APPLICATION, MENU_ROW, MENU_COL, MENU_SUBCOL, LEVEL_4, LEVEL_5, MENU_NAME, RIGHTS, OBJ_NAME)"
+ " VALUES ( '" + profileId + "' , ?, ?, ?, ?, ?, ?, ?, ?,? )"; + " VALUES ( '" + profileId + "' , ?, ?, ?, ?, ?, ?, ?, ?,? )";
System.out.println("Insert Sql :: " + batchInesertSql); System.out.println("Insert Sql :: " + batchInesertSql);
String batchUpdateSql = "UPDATE USER_RIGHTS SET " + String batchUpdateSql = "UPDATE USER_RIGHTS SET " +
" RIGHTS = ?, " + " RIGHTS = ?, " +
" OBJ_NAME = ? " + " OBJ_NAME = ? " +
" WHERE PROFILE_ID = '" + profileId + "' " + " WHERE PROFILE_ID = '" + profileId + "' " +
" AND APPLICATION = ? " + " AND APPLICATION = ? " +
" AND MENU_ROW = ? " + " AND MENU_ROW = ? " +
" AND MENU_COL = ? " + " AND MENU_COL = ? " +
" AND MENU_SUBCOL = ? " + " AND MENU_SUBCOL = ? " +
" AND LEVEL_4 = ? " + " AND LEVEL_4 = ? " +
" AND LEVEL_5 = ? "; " AND LEVEL_5 = ? ";
String batchDeleteSql = " DELETE FROM USER_RIGHTS " + String batchDeleteSql = " DELETE FROM USER_RIGHTS " +
" WHERE PROFILE_ID = '" + profileId + "' " + " WHERE PROFILE_ID = '" + profileId + "' " +
" AND APPLICATION = ? " + " AND APPLICATION = ? " +
" AND MENU_ROW = ? " + " AND MENU_ROW = ? " +
" AND MENU_COL = ? " + " AND MENU_COL = ? " +
" AND MENU_SUBCOL = ? " + " AND MENU_SUBCOL = ? " +
" AND LEVEL_4 = ? " + " AND LEVEL_4 = ? " +
" AND LEVEL_5 = ? "; " AND LEVEL_5 = ? ";
String searchKey = null; String searchKey = null;
int operation = 0; int operation = 0;
try try
{ {
if(conn == null) if(conn == null)
{ {
connDriver = new ConnDriver(); connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM"); conn = connDriver.getConnectDB("DriverITM");
conn.setAutoCommit(false); conn.setAutoCommit(false);
connDriver = null; connDriver = null;
pInsertStmt = conn.prepareStatement(batchInesertSql); pInsertStmt = conn.prepareStatement(batchInesertSql);
pUpdateStmt = conn.prepareStatement(batchUpdateSql); pUpdateStmt = conn.prepareStatement(batchUpdateSql);
pDeleteStmt = conn.prepareStatement(batchDeleteSql); pDeleteStmt = conn.prepareStatement(batchDeleteSql);
} }
parentNodeList = detailDom.getElementsByTagName("Detail2"); parentNodeList = detailDom.getElementsByTagName("Detail2");
parentNodeListLength = parentNodeList.getLength(); parentNodeListLength = parentNodeList.getLength();
System.out.println("ParentNodeListLength....::- "+parentNodeListLength); System.out.println("ParentNodeListLength....::- "+parentNodeListLength);
for (int selectedRow = 0; selectedRow < parentNodeListLength; selectedRow++) for (int selectedRow = 0; selectedRow < parentNodeListLength; selectedRow++)
{ {
operation = 0; operation = 0;
parentNode = parentNodeList.item(selectedRow); parentNode = parentNodeList.item(selectedRow);
childNodeList = parentNode.getChildNodes(); childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength(); childNodeListLength = childNodeList.getLength();
System.out.println("ChildNodeListLength.........:-"+ childNodeListLength); System.out.println("ChildNodeListLength.........:-"+ childNodeListLength);
for (int childRow = 0; childRow < childNodeListLength; childRow++) for (int childRow = 0; childRow < childNodeListLength; childRow++)
{ {
childNode = childNodeList.item(childRow); childNode = childNodeList.item(childRow);
childNodeName = childNode.getNodeName(); childNodeName = childNode.getNodeName();
if (childNodeName.equals("application")) if (childNodeName.equals("application"))
{ {
if (childNode.getFirstChild() != null) // **************** if (childNode.getFirstChild() != null) // ****************
{ {
application = (childNode.getFirstChild().getNodeValue()).trim(); application = (childNode.getFirstChild().getNodeValue()).trim();
System.out.println("APPLICATION:::::["+ application+"]"); System.out.println("APPLICATION:::::["+ application+"]");
} }
} }
if (childNodeName.equals("level_1")) if (childNodeName.equals("level_1"))
{ {
if (childNode.getFirstChild() != null) // **************** if (childNode.getFirstChild() != null) // ****************
{ {
level1 = (childNode.getFirstChild().getNodeValue()).trim(); level1 = (childNode.getFirstChild().getNodeValue()).trim();
System.out.println("level1:::::"+ level1); System.out.println("level1:::::"+ level1);
} }
} }
if (childNodeName.equals("level_2")) if (childNodeName.equals("level_2"))
{ {
if (childNode.getFirstChild() != null) // **************** if (childNode.getFirstChild() != null) // ****************
{ {
level2 = (childNode.getFirstChild().getNodeValue()).trim(); level2 = (childNode.getFirstChild().getNodeValue()).trim();
} }
System.out.println("level2:::::"+ level2); System.out.println("level2:::::"+ level2);
} }
if (childNodeName.equals("level_3")) if (childNodeName.equals("level_3"))
{ {
if (childNode.getFirstChild() != null) // **************** if (childNode.getFirstChild() != null) // ****************
{ {
level3 = (childNode.getFirstChild().getNodeValue()).trim(); level3 = (childNode.getFirstChild().getNodeValue()).trim();
} }
System.out.println("level3:::::"+ level3); System.out.println("level3:::::"+ level3);
} }
if (childNodeName.equals("level_4")) if (childNodeName.equals("level_4"))
{ {
if (childNode.getFirstChild() != null) // **************** if (childNode.getFirstChild() != null) // ****************
{ {
level4 = (childNode.getFirstChild().getNodeValue()).trim(); level4 = (childNode.getFirstChild().getNodeValue()).trim();
} }
System.out.println("level_4:::::"+ level4); System.out.println("level_4:::::"+ level4);
} }
if (childNodeName.equals("level_5")) if (childNodeName.equals("level_5"))
{ {
if (childNode.getFirstChild() != null) // **************** if (childNode.getFirstChild() != null) // ****************
{ {
if (childNode.getFirstChild() != null) // **************** if (childNode.getFirstChild() != null) // ****************
{ {
level5 = (childNode.getFirstChild().getNodeValue()).trim(); level5 = (childNode.getFirstChild().getNodeValue()).trim();
} }
} }
System.out.println("level_5:::::" + level5); System.out.println("level_5:::::" + level5);
} }
if (childNodeName.equals("descr")) if (childNodeName.equals("descr"))
{ {
if (childNode.getFirstChild() != null) // **************** if (childNode.getFirstChild() != null) // ****************
{ {
menuName = (childNode.getFirstChild().getNodeValue()).trim(); menuName = (childNode.getFirstChild().getNodeValue()).trim();
System.out.println("menu_name:::"+ menuName); System.out.println("menu_name:::"+ menuName);
} }
} }
if (childNodeName.equals("rights")) if (childNodeName.equals("rights"))
{ {
/*if (childNode.getFirstChild() != null) // **************** /*if (childNode.getFirstChild() != null) // ****************
{*/// commented by akhilesh on 31/oct/12 {*/// commented by akhilesh on 31/oct/12
// added by akhilesh on 31/oct/12 for validation rights // added by akhilesh on 31/oct/12 for validation rights
if (childNode.getFirstChild() != null ) if (childNode.getFirstChild() != null )
{ {
rights = (childNode.getFirstChild().getNodeValue()); rights = (childNode.getFirstChild().getNodeValue());
} }
else else
{ {
rights =""; rights ="";
} }
winName=this.genericUtility.getColumnValue("win_name", detailDom); winName=this.genericUtility.getColumnValue("win_name", detailDom);
System.out.println("windowName ::::"+ windowName); System.out.println("windowName ::::"+ windowName);
System.out.println("rights and winName ::::"+ rights+""+winName); System.out.println("rights and winName ::::"+ rights+""+winName);
if(winName.trim().length() > 2)
{ //added by akhilesh on 09/oct/12
objName =winName.substring(2); String rightStr[] = rights.split(",");
} System.out.println("after split the right@@@@@@@ ::::"+ rightStr);
System.out.println("objName ::::"+ objName); if(winName.trim().length() > 2)
String selectSql = "SELECT DISTINCT (RIGHTS_CHAR) FROM OBJ_LINKS WHERE OBJ_NAME = ?"; {
pSelectStmt =conn.prepareStatement(selectSql); objName =winName.substring(2);
pSelectStmt.setString(1,objName); }
rs = pSelectStmt.executeQuery(); System.out.println("objName ::::"+ objName);
while(rs.next()) for(int i= 0 ; i<rightStr.length; i++)
{ {
relArray.add(rs.getString(1)); System.out.println("rights and winName ::::"+ rightStr[i]);
}
System.out.println("relArray and rights value"+relArray+""+rights); String selectSql = "SELECT DISTINCT (RIGHTS_CHAR) FROM OBJ_LINKS WHERE OBJ_NAME = ?";
pSelectStmt =conn.prepareStatement(selectSql);
rs.close(); pSelectStmt.setString(1,objName);
rs = null; rs = pSelectStmt.executeQuery();
pSelectStmt.close(); while(rs.next())
pSelectStmt = null; {
relArray.add(rs.getString(1));
// added by akhilesh on 07/nov/12 }
String selectSql1 = "SELECT DISTINCT (RIGHTS_CHAR) FROM OBJ_ACTIONS WHERE OBJ_NAME = ?"; System.out.println("relArray and rights value"+relArray);
pSelectStmt =conn.prepareStatement(selectSql1);
pSelectStmt.setString(1,objName); rs.close();
rs = pSelectStmt.executeQuery(); rs = null;
while(rs.next()) pSelectStmt.close();
{ pSelectStmt = null;
relArray1.add(rs.getString(1));
} // added by akhilesh on 07/nov/12
System.out.println("relArray and rights value"+relArray1+""+rights); String selectSql1 = "SELECT DISTINCT (RIGHTS_CHAR) FROM OBJ_ACTIONS WHERE OBJ_NAME = ?";
pSelectStmt =conn.prepareStatement(selectSql1);
rs.close(); pSelectStmt.setString(1,objName);
rs = null; rs = pSelectStmt.executeQuery();
pSelectStmt.close(); while(rs.next())
pSelectStmt = null; {
//ended by akhilesh relArray1.add(rs.getString(1));
}
if(!(relArray1.contains(rights) || relArray.contains(rights) || "*".equals(rights))) System.out.println("relArray1 and rights value"+relArray1);
{
System.out.println("r************"+relArray+""+rights); rs.close();
returnString="VTRIGHT"; rs = null;
returnString = itmDBAccessEJB.getErrorString("",returnString,"","",conn); pSelectStmt.close();
return returnString; pSelectStmt = null;
} //ended by akhilesh
//ended by akhilesh
if(!(relArray1.contains(rightStr[i]) || relArray.contains(rightStr[i]) || "*".equals(rightStr[i])))
/*}commented by akhilesh on 31/oct/12 {
else System.out.println("error************");
rights = null;*/ returnString="VTRIGHT";
} returnString = itmDBAccessEJB.getErrorString("",returnString,"","",conn);
} return returnString;
}
// 01/06/10 manoharan }//ended by akhilesh on 09/oct/12
if (level1 == null || level1.trim().length() == 0)
{
level1 = "0"; /*}commented by akhilesh on 31/oct/12
} else
if (level2 == null || level2.trim().length() == 0) rights = null;*/
{ }
level2 = "0"; }
}
if (level3 == null || level3.trim().length() == 0) // 01/06/10 manoharan
{ if (level1 == null || level1.trim().length() == 0)
level3 = "0"; {
} level1 = "0";
if (level4 == null || level4.trim().length() == 0) }
{ if (level2 == null || level2.trim().length() == 0)
level4 = "0"; {
} level2 = "0";
if (level5 == null || level5.trim().length() == 0) }
{ if (level3 == null || level3.trim().length() == 0)
level5 = "0"; {
} level3 = "0";
// end 01/06/10 manoharan }
searchKey = application + ":" + level1 + ":" + level2 + ":" + level3 + ":" + level4 + ":" + level5; if (level4 == null || level4.trim().length() == 0)
// {
//get all submenu if found level4 = "0";
ArrayList subMenuList = null; }
if (level5 == null || level5.trim().length() == 0)
subMenuList = getAllSubMenu(application, Integer.parseInt(level1), Integer.parseInt(level2), Integer.parseInt(level3), Integer.parseInt(level4), Integer.parseInt(level5), conn); {
level5 = "0";
System.out.println("SubMenu List :: " + subMenuList.toString()); }
// // end 01/06/10 manoharan
searchKey = application + ":" + level1 + ":" + level2 + ":" + level3 + ":" + level4 + ":" + level5;
//operation = searchUserRight(searchKey, rights); //
if(subMenuList != null) //get all submenu if found
{ ArrayList subMenuList = null;
for(int index = 0; index < subMenuList.size(); index++)
{ subMenuList = getAllSubMenu(application, Integer.parseInt(level1), Integer.parseInt(level2), Integer.parseInt(level3), Integer.parseInt(level4), Integer.parseInt(level5), conn);
String searchStr = null;
searchStr = (String)subMenuList.get(index); System.out.println("SubMenu List :: " + subMenuList.toString());
objName = ""; //
System.out.print("obj name @@@@@@@@@@@@"+objName+""+searchStr+""+index+""+subMenuList.size());
objName = (String)winNameMap.get(searchStr); //operation = searchUserRight(searchKey, rights);
System.out.print("obj name @@@@@@@@@@@@"+objName+""+searchStr+""+index+""+subMenuList.size()); if(subMenuList != null)
//Get parameters from searchStr {
StringTokenizer subMenuToken = new StringTokenizer(searchStr, ":"); for(int index = 0; index < subMenuList.size(); index++)
{
if(subMenuToken.hasMoreTokens()) String searchStr = null;
application = subMenuToken.nextToken(); searchStr = (String)subMenuList.get(index);
if(subMenuToken.hasMoreTokens()) objName = "";
level1 = subMenuToken.nextToken(); System.out.print("obj name @@@@@@@@@@@@"+objName+""+searchStr+""+index+""+subMenuList.size());
if(subMenuToken.hasMoreTokens()) objName = (String)winNameMap.get(searchStr);
level2 = subMenuToken.nextToken(); System.out.print("obj name @@@@@@@@@@@@"+objName+""+searchStr+""+index+""+subMenuList.size());
if(subMenuToken.hasMoreTokens()) //Get parameters from searchStr
level3 = subMenuToken.nextToken(); StringTokenizer subMenuToken = new StringTokenizer(searchStr, ":");
if(subMenuToken.hasMoreTokens())
level4 = subMenuToken.nextToken(); if(subMenuToken.hasMoreTokens())
if(subMenuToken.hasMoreTokens()) application = subMenuToken.nextToken();
level5 = subMenuToken.nextToken(); if(subMenuToken.hasMoreTokens())
level1 = subMenuToken.nextToken();
menuName = (String)menuNameMap.get(searchStr); if(subMenuToken.hasMoreTokens())
level2 = subMenuToken.nextToken();
System.out.println("SerarchStr = " + searchStr + " :: " + application + " : " + level1 + " : " + level2 + " : " + level3 + " : " + level4 + " : " + level5); if(subMenuToken.hasMoreTokens())
// 01/06/10 manoharan level3 = subMenuToken.nextToken();
//operation = searchUserRight(searchStr, rights); if(subMenuToken.hasMoreTokens())
operation = searchUserRight(profileId, application,Integer.parseInt(level1),Integer.parseInt(level2),Integer.parseInt(level3),Integer.parseInt(level4),Integer.parseInt(level5),rights,conn); level4 = subMenuToken.nextToken();
// end 01/06/10 manoharan if(subMenuToken.hasMoreTokens())
System.out.println("Operation ["+ operation +"]"); level5 = subMenuToken.nextToken();
/*
1 - insert menuName = (String)menuNameMap.get(searchStr);
2 - update
3 - delete System.out.println("SerarchStr = " + searchStr + " :: " + application + " : " + level1 + " : " + level2 + " : " + level3 + " : " + level4 + " : " + level5);
*/ // 01/06/10 manoharan
//operation = searchUserRight(searchStr, rights);
if(operation == 1 && rights.trim().length() > 0) operation = searchUserRight(profileId, application,Integer.parseInt(level1),Integer.parseInt(level2),Integer.parseInt(level3),Integer.parseInt(level4),Integer.parseInt(level5),rights,conn);
{ // end 01/06/10 manoharan
//pInsertStmt.setString(1, profileId); System.out.println("Operation ["+ operation +"]");
pInsertStmt.setString(1, application); /*
pInsertStmt.setInt(2, Integer.parseInt(level1)); 1 - insert
pInsertStmt.setInt(3, Integer.parseInt(level2)); 2 - update
pInsertStmt.setInt(4, Integer.parseInt(level3)); 3 - delete
pInsertStmt.setInt(5, Integer.parseInt(level4)); */
pInsertStmt.setInt(6, Integer.parseInt(level5));
pInsertStmt.setString(7, menuName); if(operation == 1 && rights.trim().length() > 0)
pInsertStmt.setString(8, rights.trim()); {
pInsertStmt.setString(9, objName); //pInsertStmt.setString(1, profileId);
insertCount++; pInsertStmt.setString(1, application);
pInsertStmt.addBatch(); pInsertStmt.setInt(2, Integer.parseInt(level1));
} pInsertStmt.setInt(3, Integer.parseInt(level2));
else if(operation == 2) pInsertStmt.setInt(4, Integer.parseInt(level3));
{ pInsertStmt.setInt(5, Integer.parseInt(level4));
pUpdateStmt.setString(1, rights.trim()); pInsertStmt.setInt(6, Integer.parseInt(level5));
//pUpdateStmt.setString(2, profileId); pInsertStmt.setString(7, menuName);
pUpdateStmt.setString(2, objName); pInsertStmt.setString(8, rights.trim());
pUpdateStmt.setString(3, application); pInsertStmt.setString(9, objName);
pUpdateStmt.setInt(4, Integer.parseInt(level1)); insertCount++;
pUpdateStmt.setInt(5, Integer.parseInt(level2)); pInsertStmt.addBatch();
pUpdateStmt.setInt(6, Integer.parseInt(level3)); }
pUpdateStmt.setInt(7, Integer.parseInt(level4)); else if(operation == 2)
pUpdateStmt.setInt(8, Integer.parseInt(level5)); {
updateCount++; pUpdateStmt.setString(1, rights.trim());
pUpdateStmt.addBatch(); //pUpdateStmt.setString(2, profileId);
} pUpdateStmt.setString(2, objName);
else if(operation == 3) pUpdateStmt.setString(3, application);
{ pUpdateStmt.setInt(4, Integer.parseInt(level1));
//pDeleteStmt.setString(1, profileId); pUpdateStmt.setInt(5, Integer.parseInt(level2));
pDeleteStmt.setString(1, application); pUpdateStmt.setInt(6, Integer.parseInt(level3));
pDeleteStmt.setInt(2, Integer.parseInt(level1)); pUpdateStmt.setInt(7, Integer.parseInt(level4));
pDeleteStmt.setInt(3, Integer.parseInt(level2)); pUpdateStmt.setInt(8, Integer.parseInt(level5));
pDeleteStmt.setInt(4, Integer.parseInt(level3)); updateCount++;
pDeleteStmt.setInt(5, Integer.parseInt(level4)); pUpdateStmt.addBatch();
pDeleteStmt.setInt(6, Integer.parseInt(level5)); }
deleteCount++; else if(operation == 3)
pDeleteStmt.addBatch(); {
} //pDeleteStmt.setString(1, profileId);
}//End of subMenuList iteration for loop pDeleteStmt.setString(1, application);
}//End of if subMenuList is not null pDeleteStmt.setInt(2, Integer.parseInt(level1));
//} pDeleteStmt.setInt(3, Integer.parseInt(level2));
}//outer for pDeleteStmt.setInt(4, Integer.parseInt(level3));
pDeleteStmt.setInt(5, Integer.parseInt(level4));
if (insertCount > 0) pDeleteStmt.setInt(6, Integer.parseInt(level5));
{ deleteCount++;
System.out.println("Before Delete Batch"); pDeleteStmt.addBatch();
pInsertStmt.executeBatch(); }
System.out.println("After Insert Batch" ); }//End of subMenuList iteration for loop
} }//End of if subMenuList is not null
//}
if (updateCount > 0) }//outer for
{
System.out.println("Before Update Batch"); if (insertCount > 0)
pUpdateStmt.executeBatch(); {
System.out.println("After Update Batch = "); System.out.println("Before Delete Batch");
} pInsertStmt.executeBatch();
System.out.println("After Insert Batch" );
if (deleteCount > 0) }
{
System.out.println("Before Delete Batch"); if (updateCount > 0)
pDeleteStmt.executeBatch(); {
System.out.println("After Delete Batch = "); System.out.println("Before Update Batch");
} pUpdateStmt.executeBatch();
System.out.println("After Update Batch = ");
conn.commit(); }
System.out.println("After Commit");
} if (deleteCount > 0)
catch(BatchUpdateException be) {
{ System.out.println("Before Delete Batch");
be.printStackTrace(); pDeleteStmt.executeBatch();
returnString = be.getMessage(); System.out.println("After Delete Batch = ");
System.out.println("BatchUpdateException :RunMRPPrcEJB: CreatePlanDemand(ADPElement)" + returnString); }
System.out.println("Detail Exception : " + be.getNextException());
throw new ITMException(be);// added by akhilesh on 31/oct/12 conn.commit();
} System.out.println("After Commit");
catch (SQLException ex) }
{ catch(BatchUpdateException be)
returnString = ex.getMessage(); {
try{conn.rollback(); be.printStackTrace();
}catch(Exception e){ returnString = be.getMessage();
throw new ITMException(e);// added by akhilesh on 31/oct/12 System.out.println("BatchUpdateException :RunMRPPrcEJB: CreatePlanDemand(ADPElement)" + returnString);
} System.out.println("Detail Exception : " + be.getNextException());
ex.printStackTrace(); throw new ITMException(be);// added by akhilesh on 31/oct/12
}
throw new ITMException(ex);// added by akhilesh on 31/oct/12 catch (SQLException ex)
} {
catch (Exception e) returnString = ex.getMessage();
{ try{conn.rollback();
returnString = e.getMessage(); }catch(Exception e){
try{ throw new ITMException(e);// added by akhilesh on 31/oct/12
conn.rollback(); }
}catch(Exception ec){ ex.printStackTrace();
throw new ITMException(ec);// added by akhilesh on 31/oct/12
} throw new ITMException(ex);// added by akhilesh on 31/oct/12
}
e.printStackTrace(); catch (Exception e)
throw new ITMException(e);// added by akhilesh on 31/oct/12 {
} returnString = e.getMessage();
finally try{
{ conn.rollback();
try }catch(Exception ec){
{ throw new ITMException(ec);// added by akhilesh on 31/oct/12
userRightsMap = null; }
winNameMap = null;
menuNameMap = null; e.printStackTrace();
throw new ITMException(e);// added by akhilesh on 31/oct/12
profileId = null; }
finally
pInsertStmt.close(); {
pInsertStmt = null; try
pUpdateStmt.close(); {
pUpdateStmt = null; userRightsMap = null;
pDeleteStmt.close(); winNameMap = null;
pDeleteStmt = null; menuNameMap = null;
conn.close(); profileId = null;
conn = null;
pInsertStmt.close();
}catch(Exception e){ pInsertStmt = null;
throw new ITMException(e);// added by akhilesh on 31/oct/12 pUpdateStmt.close();
} pUpdateStmt = null;
//return returnString; pDeleteStmt.close();
} pDeleteStmt = null;
if (returnString == null || returnString.trim().length() == 0) conn.close();
{ conn = null;
System.out.println("errString is null************** ");
returnString="VTCOMPL"; }catch(Exception e){
returnString = itmDBAccessEJB.getErrorString("",returnString,"","",conn); throw new ITMException(e);// added by akhilesh on 31/oct/12
return returnString; }
} //return returnString;
else }
{
System.out.println("errString is not null ***************"); if (returnString == null || returnString.trim().length() == 0)
returnString="VTPRCERR"; {
returnString = itmDBAccessEJB.getErrorString("",returnString,"","",conn); System.out.println("errString is null************** ");
return returnString; returnString="VTCOMPL";
} returnString = itmDBAccessEJB.getErrorString("",returnString,"","",conn);
return returnString;
}//process() }
else
/* 1 - insert {
2- update System.out.println("errString is not null ***************");
3-delete returnString="VTPRCERR";
Searches HashMap for availability of rights for searchKey returnString = itmDBAccessEJB.getErrorString("",returnString,"","",conn);
if Not Found and rights is not null then return returnString;
return 1 }
else if Found and rights is not null then
return 2 }//process()
else if Found and rights = null
return 3 /* 1 - insert
*/ 2- update
// 01/06/10 manoharan 3-delete
int searchUserRight(String profileId, String application,int level1,int level2,int level3,int level4,int level5, String rights,Connection conn) throws Exception Searches HashMap for availability of rights for searchKey
{ if Not Found and rights is not null then
return 1
PreparedStatement pstmt = null; else if Found and rights is not null then
ResultSet rs = null; return 2
String alreadyExists = "N"; else if Found and rights = null
String sql = " SELECT RIGHTS FROM USER_RIGHTS " return 3
+ " WHERE PROFILE_ID = ? " */
+ " AND APPLICATION = ? " // 01/06/10 manoharan
+ " AND MENU_ROW = ? " int searchUserRight(String profileId, String application,int level1,int level2,int level3,int level4,int level5, String rights,Connection conn) throws Exception
+ " AND MENU_COL = ? " {
+ " AND MENU_SUBCOL = ? "
+ " AND LEVEL_4 = ? " PreparedStatement pstmt = null;
+ " AND LEVEL_5 = ? "; ResultSet rs = null;
String alreadyExists = "N";
pstmt = conn.prepareStatement(sql); String sql = " SELECT RIGHTS FROM USER_RIGHTS "
+ " WHERE PROFILE_ID = ? "
String foundRights = null; + " AND APPLICATION = ? "
int operation = -1; + " AND MENU_ROW = ? "
+ " AND MENU_COL = ? "
pstmt.setString(1,profileId); + " AND MENU_SUBCOL = ? "
pstmt.setString(2,application); + " AND LEVEL_4 = ? "
pstmt.setInt(3,level1); + " AND LEVEL_5 = ? ";
pstmt.setInt(4,level2);
pstmt.setInt(5,level3); pstmt = conn.prepareStatement(sql);
pstmt.setInt(6,level4);
pstmt.setInt(7,level5); String foundRights = null;
rs = pstmt.executeQuery(); int operation = -1;
if (rs.next())
{ pstmt.setString(1,profileId);
foundRights = rs.getString(1); pstmt.setString(2,application);
alreadyExists = "Y"; pstmt.setInt(3,level1);
} pstmt.setInt(4,level2);
rs.close(); pstmt.setInt(5,level3);
rs = null; pstmt.setInt(6,level4);
pstmt.close(); pstmt.setInt(7,level5);
pstmt = null; rs = pstmt.executeQuery();
//foundRights = (String) userRightsMap.get(searchKey); if (rs.next())
{
System.out.println("Found rights in function ["+foundRights+"] rights [" + rights +"] alreadyExists [" + alreadyExists + "]"); foundRights = rs.getString(1);
alreadyExists = "Y";
if(foundRights == null && rights != null && "N".equals(alreadyExists)) }
operation = 1; rs.close();
else if((foundRights != null && rights != null) || ("Y".equals(alreadyExists) && foundRights == null && rights != null) ) rs = null;
operation = 2; pstmt.close();
else if(foundRights != null && rights == null && "Y".equals(alreadyExists)) pstmt = null;
operation = 3; //foundRights = (String) userRightsMap.get(searchKey);
return operation; System.out.println("Found rights in function ["+foundRights+"] rights [" + rights +"] alreadyExists [" + alreadyExists + "]");
}
// end 01/06/10 manoharan if(foundRights == null && rights != null && "N".equals(alreadyExists))
int searchUserRight(String searchKey, String rights) operation = 1;
{ else if((foundRights != null && rights != null) || ("Y".equals(alreadyExists) && foundRights == null && rights != null) )
System.out.println("searchKey in function ["+searchKey+"]"); operation = 2;
System.out.println("rights in function ["+rights+"]"); else if(foundRights != null && rights == null && "Y".equals(alreadyExists))
operation = 3;
String foundRights = null;
int operation = -1; return operation;
}
// end 01/06/10 manoharan
foundRights = (String) userRightsMap.get(searchKey); int searchUserRight(String searchKey, String rights)
{
System.out.println("Found rights in function ["+foundRights+"]"); System.out.println("searchKey in function ["+searchKey+"]");
System.out.println("rights in function ["+rights+"]");
if(foundRights == null && rights != null)
operation = 1; String foundRights = null;
else if(foundRights != null && rights != null) int operation = -1;
operation = 2;
else if(foundRights != null && rights == null)
operation = 3; foundRights = (String) userRightsMap.get(searchKey);
return operation; System.out.println("Found rights in function ["+foundRights+"]");
}
if(foundRights == null && rights != null)
private ArrayList getAllSubMenu(String application, int level1, int level2, int level3, int level4, int level5, Connection conn) operation = 1;
throws SQLException else if(foundRights != null && rights != null)
{ operation = 2;
String tApplication = null; else if(foundRights != null && rights == null)
int tLevel1 = 0; operation = 3;
int tLevel2 = 0;
int tLevel3 = 0; return operation;
int tLevel4 = 0; }
int tLevel5 = 0;
String tMenuName = null; private ArrayList getAllSubMenu(String application, int level1, int level2, int level3, int level4, int level5, Connection conn)
throws SQLException
String gotUserRights = null; {
String tApplication = null;
String getSubMenuSql = " SELECT APPLICATION, LEVEL_1, LEVEL_2, LEVEL_3, LEVEL_4, LEVEL_5, WIN_NAME, DESCR FROM ITM2MENU " + int tLevel1 = 0;
" where APPLICATION = '" + application + "' " + int tLevel2 = 0;
" and ( level_1 = 0 or (level_1 <> 0 and (LEVEL_1 = " + level1 + " AND LEVEL_2 > 0))) " + int tLevel3 = 0;
" and ( level_2 = 0 or (level_2 <> 0 and (LEVEL_2 = " + level2 + " AND LEVEL_3 > 0))) " + int tLevel4 = 0;
" and ( level_3 = 0 or ( level_3 <> 0 and (LEVEL_3 = " + level3 + " AND LEVEL_4 > 0))) " + int tLevel5 = 0;
" and ( level_4 = 0 or ( level_4 <> 0 and (LEVEL_4 = " + level4 + " AND LEVEL_5 > 0))) " + String tMenuName = null;
" and WIN_NAME <> '-' " ;
String gotUserRights = null;
System.out.println("Get All Sub Menu SQL :: " + getSubMenuSql);
String getSubMenuSql = " SELECT APPLICATION, LEVEL_1, LEVEL_2, LEVEL_3, LEVEL_4, LEVEL_5, WIN_NAME, DESCR FROM ITM2MENU " +
String parentKey = application + ":" + level1 + ":" + level2 + ":" + level3 + ":" + level4 + ":" + level5; " where APPLICATION = '" + application + "' " +
" and ( level_1 = 0 or (level_1 <> 0 and (LEVEL_1 = " + level1 + " AND LEVEL_2 > 0))) " +
ArrayList subMenuList = new ArrayList(); " and ( level_2 = 0 or (level_2 <> 0 and (LEVEL_2 = " + level2 + " AND LEVEL_3 > 0))) " +
" and ( level_3 = 0 or ( level_3 <> 0 and (LEVEL_3 = " + level3 + " AND LEVEL_4 > 0))) " +
PreparedStatement pstmt = null; " and ( level_4 = 0 or ( level_4 <> 0 and (LEVEL_4 = " + level4 + " AND LEVEL_5 > 0))) " +
ResultSet rs = null; " and WIN_NAME <> '-' " ;
pstmt = conn.prepareStatement(getSubMenuSql); System.out.println("Get All Sub Menu SQL :: " + getSubMenuSql);
rs = pstmt.executeQuery(); String parentKey = application + ":" + level1 + ":" + level2 + ":" + level3 + ":" + level4 + ":" + level5;
while(rs.next()) ArrayList subMenuList = new ArrayList();
{
tApplication = rs.getString(1); PreparedStatement pstmt = null;
tLevel1 = rs.getInt(2); ResultSet rs = null;
tLevel2 = rs.getInt(3);
tLevel3 = rs.getInt(4); pstmt = conn.prepareStatement(getSubMenuSql);
tLevel4 = rs.getInt(5);
tLevel5 = rs.getInt(6); rs = pstmt.executeQuery();
String tWinName = null;
tWinName = rs.getString(7); while(rs.next())
String tKey = null; {
tKey = tApplication + ":" + tLevel1 + ":" + tLevel2 + ":" + tLevel3 + ":" + tLevel4 + ":" + tLevel5; tApplication = rs.getString(1);
System.out.println("tKey :: " + tKey); tLevel1 = rs.getInt(2);
subMenuList.add(tKey); tLevel2 = rs.getInt(3);
tLevel3 = rs.getInt(4);
tMenuName = rs.getString(8); tLevel4 = rs.getInt(5);
if(!menuNameMap.containsKey(tKey)) tLevel5 = rs.getInt(6);
menuNameMap.put(tKey, tMenuName); String tWinName = null;
tWinName = rs.getString(7);
winNameMap.put(tKey, tWinName.trim().substring(2, tWinName.trim().length())); String tKey = null;
gotUserRights = (String) userRightsMap.get(tKey); tKey = tApplication + ":" + tLevel1 + ":" + tLevel2 + ":" + tLevel3 + ":" + tLevel4 + ":" + tLevel5;
if(gotUserRights == null || gotUserRights.trim().length() == 0){ System.out.println("tKey :: " + tKey);
gotUserRights = getUserRights(profileId, tApplication, tLevel1, tLevel2, tLevel3, tLevel4, tLevel5, conn); subMenuList.add(tKey);
if(gotUserRights != null && gotUserRights.trim().length() > 0)
userRightsMap.put(tKey, gotUserRights); tMenuName = rs.getString(8);
} if(!menuNameMap.containsKey(tKey))
} menuNameMap.put(tKey, tMenuName);
rs.close(); winNameMap.put(tKey, tWinName.trim().substring(2, tWinName.trim().length()));
rs = null; gotUserRights = (String) userRightsMap.get(tKey);
if(gotUserRights == null || gotUserRights.trim().length() == 0){
pstmt.close(); gotUserRights = getUserRights(profileId, tApplication, tLevel1, tLevel2, tLevel3, tLevel4, tLevel5, conn);
pstmt = null; if(gotUserRights != null && gotUserRights.trim().length() > 0)
userRightsMap.put(tKey, gotUserRights);
if(subMenuList.size() == 0) }
subMenuList.add(parentKey); }
return subMenuList; rs.close();
} rs = null;
private String getUserRights(String profileId, String application, int level1, int level2, int level3, int level4, int level5, Connection conn) pstmt.close();
throws SQLException pstmt = null;
{
String userRightsSql = " select RIGHTS " + if(subMenuList.size() == 0)
" from user_rights " + subMenuList.add(parentKey);
" where profile_id = '" + profileId + "' " +
" and APPLICATION = '" + application + "' " + return subMenuList;
" and MENU_ROW = " + level1 + }
" and MENU_COL = " + level2 +
" and MENU_SUBCOL = " +level3 + private String getUserRights(String profileId, String application, int level1, int level2, int level3, int level4, int level5, Connection conn)
" and LEVEL_4 = " + level4 + throws SQLException
" and LEVEL_5 = " + level5; {
String userRightsSql = " select RIGHTS " +
String rights = null; " from user_rights " +
System.out.println("userRightsSql :: " + userRightsSql); " where profile_id = '" + profileId + "' " +
" and APPLICATION = '" + application + "' " +
String key = application + ":" + level1 + ":" + level2 + ":" + level3 + ":" + level4 + ":" + level5; " and MENU_ROW = " + level1 +
" and MENU_COL = " + level2 +
PreparedStatement pstmt = null; " and MENU_SUBCOL = " +level3 +
ResultSet rs = null; " and LEVEL_4 = " + level4 +
" and LEVEL_5 = " + level5;
pstmt = conn.prepareStatement(userRightsSql);
String rights = null;
rs = pstmt.executeQuery(); System.out.println("userRightsSql :: " + userRightsSql);
if(rs.next()) String key = application + ":" + level1 + ":" + level2 + ":" + level3 + ":" + level4 + ":" + level5;
{
rights = rs.getString(1); PreparedStatement pstmt = null;
System.out.println("Key = " + key + " : Rights = " + rights); ResultSet rs = null;
}
pstmt = conn.prepareStatement(userRightsSql);
rs.close();
rs = null; rs = pstmt.executeQuery();
pstmt.close(); if(rs.next())
pstmt = null; {
rights = rs.getString(1);
return rights; System.out.println("Key = " + key + " : Rights = " + rights);
} }
}//class
rs.close();
rs = null;
pstmt.close();
pstmt = null;
return rights;
}
}//class
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