Commit bb26a128 authored by manohar's avatar manohar

Bug fixing, windowmap and menumap not populate in case the detail table is not...

Bug fixing, windowmap and menumap not populate in case the detail table is not reset which is corrected


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@93739 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 2323677d
......@@ -313,6 +313,10 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U
menuNameMap.put(key, tMenuName);
}//while
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
// end 24/03/12 manoharan
}//try
......@@ -456,6 +460,8 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U
try
{
if(conn == null)
{
connDriver = new ConnDriver();
......@@ -466,6 +472,31 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U
pUpdateStmt = conn.prepareStatement(batchUpdateSql);
pDeleteStmt = conn.prepareStatement(batchDeleteSql);
}
//////////////////////////////////////////////////////////////////////
// 08/10/13 manoharan re initialise if necessary
//System.out.print("winNameMap before ["+ winNameMap + "]");
//System.out.print("menuNameMap before [" + menuNameMap + "]");
menuNameMap = null;
winNameMap = null;
userRightsMap = null;
if (userRightsMap == null)
{
userRightsMap = new HashMap();
}
if (winNameMap == null)
{
winNameMap = new HashMap();
}
if (menuNameMap == null)
{
menuNameMap = new HashMap();
populateMap(headerDom, detailDom, xtraParams);
}
populateMap(headerDom, detailDom, xtraParams);
System.out.print("winNameMap after ["+ winNameMap + "]");
System.out.print("menuNameMap after [" + menuNameMap + "]");
// end 08/10/13 manoharan ////////////////////////////////////////////////////////////////////
parentNodeList = detailDom.getElementsByTagName("Detail2");
......@@ -684,7 +715,8 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U
//
//operation = searchUserRight(searchKey, rights);
if(subMenuList != null)
//if(subMenuList != null) // 08/10/13 manoharan commented
if(subMenuList != null && subMenuList.size() > 0)
{
for(int index = 0; index < subMenuList.size(); index++)
{
......@@ -692,8 +724,8 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U
searchStr = (String)subMenuList.get(index);
objName = "";
System.out.print("searchStr [" + searchStr +"]["+index+"]["+subMenuList.size() + "]");
System.out.print("winNameMap ["+ winNameMap + "]");
System.out.print("menuNameMap [" + menuNameMap + "]");
//System.out.print("winNameMap ["+ winNameMap + "]");
//System.out.print("menuNameMap [" + menuNameMap + "]");
objName = (String)winNameMap.get(searchStr);
System.out.print("obj name @@@@@@@@@@@@"+objName+""+searchStr+""+index+""+subMenuList.size());
//Get parameters from searchStr
......@@ -1024,6 +1056,23 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U
try
{
//////////////////////////////////////////////////////////////////////
// 08/10/13 manoharan re initialise if necessary
if (userRightsMap == null)
{
userRightsMap = new HashMap();
}
if (winNameMap == null)
{
winNameMap = new HashMap();
}
if (menuNameMap == null)
{
menuNameMap = new HashMap();
}
// end 08/10/13 manoharan ////////////////////////////////////////////////////////////////////
pstmt = conn.prepareStatement(getSubMenuSql);
rs = pstmt.executeQuery();
......@@ -1061,7 +1110,62 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U
pstmt = null;
if(subMenuList.size() == 0)
subMenuList.add(parentKey);
{
// 08/10/13 manoharan in order to avoid nullpointer exception - get the win_name, menu_name and rights also and add to the corresponding map
//////////////////////////////////////////////////////////////////////////////////////////////
//subMenuList.add(parentKey); // commented and following code added
System.out.println("parentKey [" + parentKey + "] no submenu found so adding parent key");
getSubMenuSql = " SELECT APPLICATION, LEVEL_1, LEVEL_2, LEVEL_3, LEVEL_4, LEVEL_5, WIN_NAME, DESCR FROM ITM2MENU " +
" where APPLICATION = '" + application + "' " +
" and LEVEL_1 = " + level1 + " " +
" and LEVEL_2 = " + level2 + " " +
" and LEVEL_3 = " + level3 + " " +
" and LEVEL_4 = " + level4 + " " +
" and WIN_NAME <> '-' " ;
System.out.println("Get Menu SQL :: " + getSubMenuSql);
pstmt = conn.prepareStatement(getSubMenuSql);
rs = pstmt.executeQuery();
if(rs.next())
{
tApplication = rs.getString(1);
tLevel1 = rs.getInt(2);
tLevel2 = rs.getInt(3);
tLevel3 = rs.getInt(4);
tLevel4 = rs.getInt(5);
tLevel5 = rs.getInt(6);
tWinName = rs.getString(7);
tKey = tApplication + ":" + tLevel1 + ":" + tLevel2 + ":" + tLevel3 + ":" + tLevel4 + ":" + tLevel5;
System.out.println("tKey [" + tKey + "] tWinName [" + tWinName + "]");
subMenuList.add(tKey);
tMenuName = rs.getString(8);
if(!menuNameMap.containsKey(tKey))
menuNameMap.put(tKey, tMenuName);
winNameMap.put(tKey, tWinName.trim().substring(2, tWinName.trim().length()));
gotUserRights = (String) userRightsMap.get(tKey);
if(gotUserRights == null || gotUserRights.trim().length() == 0){
gotUserRights = getUserRights(profileId, tApplication, tLevel1, tLevel2, tLevel3, tLevel4, tLevel5, conn);
if(gotUserRights != null && gotUserRights.trim().length() > 0)
userRightsMap.put(tKey, gotUserRights);
}
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
//////////////////////////////////////////////////////////////////////////////////////////////
}
catch (Exception e)
{
......@@ -1145,6 +1249,208 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U
return rights;
}
public void populateMap(Document headerDom, Document detailDom, String xtraParams) throws RemoteException,ITMException
{
Statement stmt = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
//StringBuffer retTabSepStrBuff = new StringBuffer();
String userId = null;
Object date = null;
String sql = "";
String errCode = "";
String errString = "";
String resultString = "";
String curUserId = "", curProfileId = "";
//String profileId =null;
double quantity = 0.0,pendingQty = 0.0;
int count = 0, usrLev = 0;
String tApplication = null;
String key = null;
String tWinName = null;
String tMenuName = null;
String sqlStr = "";
try
{
if(conn == null)
{
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
conn.setAutoCommit(false);
connDriver = null;
}
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"userId");
profileId = genericUtility.getColumnValue("profile_id", headerDom);
//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
curUserId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
System.out.println("Current userid curUserId ["+ curUserId + "] profileId [" + profileId + "]");
if (curUserId != null || curUserId.trim().length() > 0)
{
sql = " select profile_id,usr_lev from users where code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,curUserId);
rs = pstmt.executeQuery();
if(rs.next())
{
curProfileId = rs.getString("profile_id");
usrLev = rs.getInt("usr_lev");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("Current curProfileId ["+ curProfileId + "] usrLev [" + usrLev + "]");
////////////////
//If profile Id is blank or doesnt exist in the User_Rights table then prompt error
//String profileSql = " select count(*) " +
// " from user_rights " +
// " where profile_id = '" + profileId + "' " ;
String profileSql = " select count(1) " +
" from gencodes " +
" where fld_name = 'PROFILE_ID' and fld_value = '" + profileId + "' " ;
int profileCount = 0;
System.out.println("ProfileSql :: " + profileSql);
PreparedStatement pProfileStmt = null;
ResultSet profileRs = null;
pProfileStmt = conn.prepareStatement(profileSql);
profileRs = pProfileStmt.executeQuery();
if(profileRs.next())
{
profileCount = profileRs.getInt(1);
System.out.println("Profile Count = " + profileCount);
}
profileRs.close();
profileRs = null;
pProfileStmt.close();
pProfileStmt = null;
///////////////
if(profileCount == 0)
{
errString = itmDBAccessEJB.getErrorString("","PNOTEXIST","","",conn);
}
userRightsMap = new HashMap();
winNameMap = new HashMap();
menuNameMap = new HashMap();
sqlStr = " SELECT ITM2MENU.APPLICATION, " +
" ITM2MENU.LEVEL_1, " +
" ITM2MENU.LEVEL_2, " +
" ITM2MENU.LEVEL_3, " +
" ITM2MENU.LEVEL_4, " +
" ITM2MENU.LEVEL_5, " +
" ITM2MENU.WIN_NAME, " +
" ITM2MENU.DESCR, " +
" (SELECT USER_RIGHTS.RIGHTS FROM USER_RIGHTS " +
" WHERE USER_RIGHTS.PROFILE_ID = ? " +
" AND USER_RIGHTS.APPLICATION = ITM2MENU.APPLICATION " +
" AND USER_RIGHTS.MENU_ROW = ITM2MENU.LEVEL_1 " +
" AND USER_RIGHTS.MENU_COL = ITM2MENU.LEVEL_2 " +
" AND USER_RIGHTS.MENU_SUBCOL = ITM2MENU.LEVEL_3 " +
" AND USER_RIGHTS.LEVEL_4 = ITM2MENU.LEVEL_4 " +
" AND USER_RIGHTS.LEVEL_5 = ITM2MENU.LEVEL_5 " +
" ) AS RIGHTS " +
" FROM ITM2MENU " ;
if (usrLev > 0 )
{
sqlStr = sqlStr + " where exists (select 1 from user_rights u "
+ " where u.profile_id in ('" + curProfileId + "','" + profileId + "') "
+ " and u.application = ITM2MENU.application "
+ " and u.menu_row = ITM2MENU.level_1 "
+ " and u.menu_col = ITM2MENU.level_2 "
+ " and u.menu_subcol = ITM2MENU.level_3 "
+ " and u.level_4 = ITM2MENU.level_4 "
+ " 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 ";
pstmt = conn.prepareStatement(sqlStr);
pstmt.setString(1,profileId);
//System.out.println("The getData sql is:-"+ sqlStr);
rs = pstmt.executeQuery();
while (rs.next())
{
tApplication = rs.getString(1);
if(tApplication != null)
key = tApplication + ":" + rs.getInt(2) + ":" + rs.getInt(3) + ":" + rs.getInt(4)
+ ":" + rs.getInt(5) + ":" + rs.getInt(6);
//DESCR
tMenuName = rs.getString(8);
//WIN_NAME
tWinName = rs.getString(7);
userRightsMap.put(key, rs.getString(9));
if(tWinName != null && tWinName.trim().length() > 2)
winNameMap.put(key, tWinName.trim().substring(2, tWinName.trim().length()));
menuNameMap.put(key, tMenuName);
}//while
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
// end 24/03/12 manoharan
}//try
catch (SQLException e)
{
System.out.println("SQLException ::" + sqlStr + e.getMessage() + ":");
e.printStackTrace();
throw new ITMException(e);// added by akhilesh on 31/oct/12
}
catch(Exception ex)
{
System.out.println("Exception []::" + ex.getMessage());
ex.printStackTrace();
throw new ITMException(ex);// added by akhilesh on 31/oct/12
}
finally
{
try
{
if(rs != null){rs.close();// added by akhilesh on 08/nov/12
rs = null;}
if(pstmt != null){pstmt.close();// added by akhilesh on 08/nov/12
pstmt = null;}
if(conn != null){conn.close();// added by akhilesh on 08/nov/12
conn = null;}
}
catch(Exception e){
throw new ITMException(e);// added by akhilesh on 31/oct/12
}
}
}//populateMap
}//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