Commit 69802f77 authored by asikarwar's avatar asikarwar

add validation of rights in process


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@92126 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 3f0c2edf
...@@ -133,7 +133,7 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U ...@@ -133,7 +133,7 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U
// 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");
...@@ -153,7 +153,7 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U ...@@ -153,7 +153,7 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U
retTabSepStrBuff.append(" \t"); retTabSepStrBuff.append(" \t");
//DESCR //DESCR
retTabSepStrBuff.append(" \t"); retTabSepStrBuff.append(" \t");
//RIGHTS //RIGHTS
...@@ -168,7 +168,7 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U ...@@ -168,7 +168,7 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U
} }
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);
...@@ -192,8 +192,8 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U ...@@ -192,8 +192,8 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U
// " 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);
...@@ -229,33 +229,33 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U ...@@ -229,33 +229,33 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U
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 ";
...@@ -267,51 +267,51 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U ...@@ -267,51 +267,51 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U
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
...@@ -320,11 +320,13 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U ...@@ -320,11 +320,13 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U
{ {
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
} }
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
} }
finally finally
{ {
...@@ -339,7 +341,9 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U ...@@ -339,7 +341,9 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U
conn.close(); conn.close();
conn = null; conn = null;
} }
catch(Exception e){} catch(Exception e){
throw new ITMException(e);// added by akhilesh on 31/oct/12
}
} }
resultString = retTabSepStrBuff.toString(); resultString = retTabSepStrBuff.toString();
...@@ -369,7 +373,7 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U ...@@ -369,7 +373,7 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U
{ {
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)
{ {
...@@ -381,297 +385,339 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U ...@@ -381,297 +385,339 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U
} }
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;
Statement stmt = null; PreparedStatement pSelectStmt = null;// added by akhilesh on 31/oct/12
ResultSet rs = null; Statement stmt = null;
java.sql.Timestamp orderDate = new java.sql.Timestamp(System.currentTimeMillis()); ResultSet rs = null;
java.sql.Timestamp udfDate = null; java.sql.Timestamp orderDate = new java.sql.Timestamp(System.currentTimeMillis());
ArrayList relArray = new ArrayList(); java.sql.Timestamp udfDate = null;
String returnString = ""; ArrayList relArray = new ArrayList(); // added by akhilesh on 31/oct/12
String returnString = "";
//Declaring fields of the table User_Rights
String profileId = null; //Declaring fields of the table User_Rights
String application = null; String profileId = null;
String level1 = null, level2 = null, level3 = null, level4 = null, level5 = null; String application = null;
String menuName = null; String level1 = null, level2 = null, level3 = null, level4 = null, level5 = null;
String rights = null; String menuName = null;
String accFilt = null; String rights = null;
String defFilt = null; String accFilt = null;
String objName = null; String defFilt = null;
String objName = null;
NodeList parentNodeList = null; String winName = null;
NodeList childNodeList = null;
Node parentNode = null; NodeList parentNodeList = null;
Node childNode = null; NodeList childNodeList = null;
String childNodeName = ""; Node parentNode = null;
Node childNode = null;
boolean bDetailFound = false; String childNodeName = "";
int parentNodeListLength = 0;
int childNodeListLength = 0, insertCount =0, updateCount =0, deleteCount = 0; boolean bDetailFound = false;
String delSql = ""; int parentNodeListLength = 0;
int childNodeListLength = 0, insertCount =0, updateCount =0, deleteCount = 0;
String delSql = "";
profileId = genericUtility.getColumnValue("profile_id", headerDom);
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)"
+ " VALUES ( '" + profileId + "' , ?, ?, ?, ?, ?, ?, ?, ?,? )";
System.out.println("Insert Sql :: " + batchInesertSql);
String batchUpdateSql = "UPDATE USER_RIGHTS SET " +
" RIGHTS = ?, " +
" OBJ_NAME = ? " +
" WHERE PROFILE_ID = '" + profileId + "' " +
" AND APPLICATION = ? " +
" AND MENU_ROW = ? " +
" AND MENU_COL = ? " +
" AND MENU_SUBCOL = ? " +
" AND LEVEL_4 = ? " +
" AND LEVEL_5 = ? ";
String batchDeleteSql = " DELETE FROM USER_RIGHTS " +
" WHERE PROFILE_ID = '" + profileId + "' " +
" AND APPLICATION = ? " +
" AND MENU_ROW = ? " +
" AND MENU_COL = ? " +
" AND MENU_SUBCOL = ? " +
" AND LEVEL_4 = ? " +
" AND LEVEL_5 = ? ";
String searchKey = null;
int operation = 0;
profileId = genericUtility.getColumnValue("profile_id", headerDom); try
System.out.println("profileId..............."+profileId); {
if(conn == null)
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 + "' , ?, ?, ?, ?, ?, ?, ?, ?,? )"; connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
System.out.println("Insert Sql :: " + batchInesertSql); conn.setAutoCommit(false);
connDriver = null;
String batchUpdateSql = "UPDATE USER_RIGHTS SET " + pInsertStmt = conn.prepareStatement(batchInesertSql);
" RIGHTS = ?, " + pUpdateStmt = conn.prepareStatement(batchUpdateSql);
" OBJ_NAME = ? " + pDeleteStmt = conn.prepareStatement(batchDeleteSql);
" WHERE PROFILE_ID = '" + profileId + "' " + }
" AND APPLICATION = ? " +
" AND MENU_ROW = ? " +
" AND MENU_COL = ? " +
" AND MENU_SUBCOL = ? " +
" AND LEVEL_4 = ? " +
" AND LEVEL_5 = ? ";
String batchDeleteSql = " DELETE FROM USER_RIGHTS " +
" WHERE PROFILE_ID = '" + profileId + "' " +
" AND APPLICATION = ? " +
" AND MENU_ROW = ? " +
" AND MENU_COL = ? " +
" AND MENU_SUBCOL = ? " +
" AND LEVEL_4 = ? " +
" AND LEVEL_5 = ? ";
String searchKey = null;
int operation = 0;
try
parentNodeList = detailDom.getElementsByTagName("Detail2");
parentNodeListLength = parentNodeList.getLength();
System.out.println("ParentNodeListLength....::- "+parentNodeListLength);
for (int selectedRow = 0; selectedRow < parentNodeListLength; selectedRow++)
{ {
if(conn == null) operation = 0;
parentNode = parentNodeList.item(selectedRow);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
System.out.println("ChildNodeListLength.........:-"+ childNodeListLength);
for (int childRow = 0; childRow < childNodeListLength; childRow++)
{ {
connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
conn.setAutoCommit(false);
connDriver = null;
pInsertStmt = conn.prepareStatement(batchInesertSql);
pUpdateStmt = conn.prepareStatement(batchUpdateSql);
pDeleteStmt = conn.prepareStatement(batchDeleteSql);
}
childNode = childNodeList.item(childRow);
childNodeName = childNode.getNodeName();
parentNodeList = detailDom.getElementsByTagName("Detail2"); if (childNodeName.equals("application"))
parentNodeListLength = parentNodeList.getLength();
System.out.println("ParentNodeListLength....::- "+parentNodeListLength);
for (int selectedRow = 0; selectedRow < parentNodeListLength; selectedRow++)
{
operation = 0;
parentNode = parentNodeList.item(selectedRow);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
System.out.println("ChildNodeListLength.........:-"+ childNodeListLength);
for (int childRow = 0; childRow < childNodeListLength; childRow++)
{ {
if (childNode.getFirstChild() != null) // ****************
{
application = (childNode.getFirstChild().getNodeValue()).trim();
System.out.println("APPLICATION:::::["+ application+"]");
}
childNode = childNodeList.item(childRow); }
childNodeName = childNode.getNodeName();
if (childNodeName.equals("application")) if (childNodeName.equals("level_1"))
{
if (childNode.getFirstChild() != null) // ****************
{ {
if (childNode.getFirstChild() != null) // **************** level1 = (childNode.getFirstChild().getNodeValue()).trim();
{ System.out.println("level1:::::"+ level1);
application = (childNode.getFirstChild().getNodeValue()).trim();
System.out.println("APPLICATION:::::["+ application+"]");
}
} }
if (childNodeName.equals("level_1")) }
if (childNodeName.equals("level_2"))
{
if (childNode.getFirstChild() != null) // ****************
{ {
if (childNode.getFirstChild() != null) // **************** level2 = (childNode.getFirstChild().getNodeValue()).trim();
{ }
level1 = (childNode.getFirstChild().getNodeValue()).trim(); System.out.println("level2:::::"+ level2);
System.out.println("level1:::::"+ level1); }
}
if (childNodeName.equals("level_3"))
{
if (childNode.getFirstChild() != null) // ****************
{
level3 = (childNode.getFirstChild().getNodeValue()).trim();
} }
if (childNodeName.equals("level_2")) System.out.println("level3:::::"+ level3);
}
if (childNodeName.equals("level_4"))
{
if (childNode.getFirstChild() != null) // ****************
{ {
if (childNode.getFirstChild() != null) // **************** level4 = (childNode.getFirstChild().getNodeValue()).trim();
{
level2 = (childNode.getFirstChild().getNodeValue()).trim();
}
System.out.println("level2:::::"+ level2);
} }
System.out.println("level_4:::::"+ level4);
}
if (childNodeName.equals("level_5"))
{
if (childNodeName.equals("level_3")) if (childNode.getFirstChild() != null) // ****************
{ {
if (childNode.getFirstChild() != null) // **************** if (childNode.getFirstChild() != null) // ****************
{ {
level3 = (childNode.getFirstChild().getNodeValue()).trim(); level5 = (childNode.getFirstChild().getNodeValue()).trim();
} }
System.out.println("level3:::::"+ level3);
} }
if (childNodeName.equals("level_4")) System.out.println("level_5:::::" + level5);
}
if (childNodeName.equals("descr"))
{
if (childNode.getFirstChild() != null) // ****************
{ {
if (childNode.getFirstChild() != null) // **************** menuName = (childNode.getFirstChild().getNodeValue()).trim();
{ System.out.println("menu_name:::"+ menuName);
level4 = (childNode.getFirstChild().getNodeValue()).trim();
}
System.out.println("level_4:::::"+ level4);
} }
if (childNodeName.equals("level_5"))
{
if (childNode.getFirstChild() != null) // **************** }
if (childNodeName.equals("rights"))
{
/*if (childNode.getFirstChild() != null) // ****************
{*/// commented by akhilesh on 31/oct/12
// added by akhilesh on 31/oct/12 for validation rights
if (childNode.getFirstChild() != null )
{ {
if (childNode.getFirstChild() != null) // **************** rights = (childNode.getFirstChild().getNodeValue());
{
level5 = (childNode.getFirstChild().getNodeValue()).trim();
}
} }
System.out.println("level_5:::::" + level5); else
}
if (childNodeName.equals("descr"))
{
if (childNode.getFirstChild() != null) // ****************
{ {
menuName = (childNode.getFirstChild().getNodeValue()).trim(); rights ="";
System.out.println("menu_name:::"+ menuName);
} }
winName=this.genericUtility.getColumnValue("win_name", detailDom);
} System.out.println("windowName ::::"+ windowName);
System.out.println("rights and winName ::::"+ rights+""+winName);
if (childNodeName.equals("rights")) if(winName.trim().length() > 2)
{
if (childNode.getFirstChild() != null) // ****************
{ {
rights = (childNode.getFirstChild().getNodeValue()).trim(); objName =winName.substring(2);
System.out.println("rights::::"+ rights);
} }
else System.out.println("objName ::::"+ objName);
rights = null; String selectSql = "SELECT DISTINCT (RIGHTS_CHAR) FROM OBJ_LINKS WHERE OBJ_NAME = ?";
} pSelectStmt =conn.prepareStatement(selectSql);
} pSelectStmt.setString(1,objName);
rs = pSelectStmt.executeQuery();
// 01/06/10 manoharan while(rs.next())
if (level1 == null || level1.trim().length() == 0) {
{ relArray.add(rs.getString(1));
level1 = "0"; }
} System.out.println("relArray and rights value"+relArray+""+rights);
if (level2 == null || level2.trim().length() == 0)
{ rs.close();
level2 = "0"; rs = null;
} pSelectStmt.close();
if (level3 == null || level3.trim().length() == 0) pSelectStmt = null;
{
level3 = "0"; if(!(relArray.contains(rights) || "*".equals(rights)))
} {
if (level4 == null || level4.trim().length() == 0) System.out.println("r************"+relArray+""+rights);
{ returnString="VTRIGHT";
level4 = "0"; returnString = itmDBAccessEJB.getErrorString("",returnString,"","",conn);
} return returnString;
if (level5 == null || level5.trim().length() == 0) }
{ //ended by akhilesh
level5 = "0";
/*}commented by akhilesh on 31/oct/12
else
rights = null;*/
} }
// end 01/06/10 manoharan }
searchKey = application + ":" + level1 + ":" + level2 + ":" + level3 + ":" + level4 + ":" + level5;
// // 01/06/10 manoharan
//get all submenu if found if (level1 == null || level1.trim().length() == 0)
ArrayList subMenuList = null; {
level1 = "0";
}
if (level2 == null || level2.trim().length() == 0)
{
level2 = "0";
}
if (level3 == null || level3.trim().length() == 0)
{
level3 = "0";
}
if (level4 == null || level4.trim().length() == 0)
{
level4 = "0";
}
if (level5 == null || level5.trim().length() == 0)
{
level5 = "0";
}
// end 01/06/10 manoharan
searchKey = application + ":" + level1 + ":" + level2 + ":" + level3 + ":" + level4 + ":" + level5;
//
//get all submenu if found
ArrayList subMenuList = null;
subMenuList = getAllSubMenu(application, Integer.parseInt(level1), Integer.parseInt(level2), Integer.parseInt(level3), Integer.parseInt(level4), Integer.parseInt(level5), conn); subMenuList = getAllSubMenu(application, Integer.parseInt(level1), Integer.parseInt(level2), Integer.parseInt(level3), Integer.parseInt(level4), Integer.parseInt(level5), conn);
System.out.println("SubMenu List :: " + subMenuList.toString()); System.out.println("SubMenu List :: " + subMenuList.toString());
// //
//operation = searchUserRight(searchKey, rights); //operation = searchUserRight(searchKey, rights);
if(subMenuList != null) if(subMenuList != null)
{
for(int index = 0; index < subMenuList.size(); index++)
{ {
for(int index = 0; index < subMenuList.size(); index++) String searchStr = null;
{ searchStr = (String)subMenuList.get(index);
String searchStr = null; objName = "";
System.out.print("obj name @@@@@@@@@@@@"+objName+""+searchStr+""+index+""+subMenuList.size());
searchStr = (String)subMenuList.get(index); objName = (String)winNameMap.get(searchStr);
objName = ""; System.out.print("obj name @@@@@@@@@@@@"+objName+""+searchStr+""+index+""+subMenuList.size());
objName = (String)winNameMap.get(searchStr); //Get parameters from searchStr
StringTokenizer subMenuToken = new StringTokenizer(searchStr, ":");
//Get parameters from searchStr
StringTokenizer subMenuToken = new StringTokenizer(searchStr, ":"); if(subMenuToken.hasMoreTokens())
application = subMenuToken.nextToken();
if(subMenuToken.hasMoreTokens()) if(subMenuToken.hasMoreTokens())
application = subMenuToken.nextToken(); level1 = subMenuToken.nextToken();
if(subMenuToken.hasMoreTokens()) if(subMenuToken.hasMoreTokens())
level1 = subMenuToken.nextToken(); level2 = subMenuToken.nextToken();
if(subMenuToken.hasMoreTokens()) if(subMenuToken.hasMoreTokens())
level2 = subMenuToken.nextToken(); level3 = subMenuToken.nextToken();
if(subMenuToken.hasMoreTokens()) if(subMenuToken.hasMoreTokens())
level3 = subMenuToken.nextToken(); level4 = subMenuToken.nextToken();
if(subMenuToken.hasMoreTokens()) if(subMenuToken.hasMoreTokens())
level4 = subMenuToken.nextToken(); level5 = subMenuToken.nextToken();
if(subMenuToken.hasMoreTokens())
level5 = subMenuToken.nextToken(); menuName = (String)menuNameMap.get(searchStr);
menuName = (String)menuNameMap.get(searchStr); System.out.println("SerarchStr = " + searchStr + " :: " + application + " : " + level1 + " : " + level2 + " : " + level3 + " : " + level4 + " : " + level5);
// 01/06/10 manoharan
System.out.println("SerarchStr = " + searchStr + " :: " + application + " : " + level1 + " : " + level2 + " : " + level3 + " : " + level4 + " : " + level5); //operation = searchUserRight(searchStr, rights);
// 01/06/10 manoharan operation = searchUserRight(profileId, application,Integer.parseInt(level1),Integer.parseInt(level2),Integer.parseInt(level3),Integer.parseInt(level4),Integer.parseInt(level5),rights,conn);
//operation = searchUserRight(searchStr, rights); // end 01/06/10 manoharan
operation = searchUserRight(profileId, application,Integer.parseInt(level1),Integer.parseInt(level2),Integer.parseInt(level3),Integer.parseInt(level4),Integer.parseInt(level5),rights,conn); System.out.println("Operation ["+ operation +"]");
// end 01/06/10 manoharan /*
System.out.println("Operation ["+ operation +"]");
/*
1 - insert 1 - insert
2 - update 2 - update
3 - delete 3 - delete
*/ */
if(operation == 1 && rights.trim().length() > 0) if(operation == 1 && rights.trim().length() > 0)
{ {
//pInsertStmt.setString(1, profileId); //pInsertStmt.setString(1, profileId);
pInsertStmt.setString(1, application); pInsertStmt.setString(1, application);
pInsertStmt.setInt(2, Integer.parseInt(level1)); pInsertStmt.setInt(2, Integer.parseInt(level1));
pInsertStmt.setInt(3, Integer.parseInt(level2)); pInsertStmt.setInt(3, Integer.parseInt(level2));
pInsertStmt.setInt(4, Integer.parseInt(level3)); pInsertStmt.setInt(4, Integer.parseInt(level3));
pInsertStmt.setInt(5, Integer.parseInt(level4)); pInsertStmt.setInt(5, Integer.parseInt(level4));
pInsertStmt.setInt(6, Integer.parseInt(level5)); pInsertStmt.setInt(6, Integer.parseInt(level5));
pInsertStmt.setString(7, menuName); pInsertStmt.setString(7, menuName);
pInsertStmt.setString(8, rights.trim()); pInsertStmt.setString(8, rights.trim());
pInsertStmt.setString(9, objName); pInsertStmt.setString(9, objName);
insertCount++; insertCount++;
pInsertStmt.addBatch(); pInsertStmt.addBatch();
} }
else if(operation == 2) else if(operation == 2)
{ {
pUpdateStmt.setString(1, rights.trim()); pUpdateStmt.setString(1, rights.trim());
//pUpdateStmt.setString(2, profileId); //pUpdateStmt.setString(2, profileId);
pUpdateStmt.setString(2, objName); pUpdateStmt.setString(2, objName);
pUpdateStmt.setString(3, application); pUpdateStmt.setString(3, application);
pUpdateStmt.setInt(4, Integer.parseInt(level1)); pUpdateStmt.setInt(4, Integer.parseInt(level1));
pUpdateStmt.setInt(5, Integer.parseInt(level2)); pUpdateStmt.setInt(5, Integer.parseInt(level2));
pUpdateStmt.setInt(6, Integer.parseInt(level3)); pUpdateStmt.setInt(6, Integer.parseInt(level3));
pUpdateStmt.setInt(7, Integer.parseInt(level4)); pUpdateStmt.setInt(7, Integer.parseInt(level4));
pUpdateStmt.setInt(8, Integer.parseInt(level5)); pUpdateStmt.setInt(8, Integer.parseInt(level5));
updateCount++; updateCount++;
pUpdateStmt.addBatch(); pUpdateStmt.addBatch();
} }
else if(operation == 3) else if(operation == 3)
{ {
//pDeleteStmt.setString(1, profileId); //pDeleteStmt.setString(1, profileId);
pDeleteStmt.setString(1, application); pDeleteStmt.setString(1, application);
pDeleteStmt.setInt(2, Integer.parseInt(level1)); pDeleteStmt.setInt(2, Integer.parseInt(level1));
pDeleteStmt.setInt(3, Integer.parseInt(level2)); pDeleteStmt.setInt(3, Integer.parseInt(level2));
pDeleteStmt.setInt(4, Integer.parseInt(level3)); pDeleteStmt.setInt(4, Integer.parseInt(level3));
pDeleteStmt.setInt(5, Integer.parseInt(level4)); pDeleteStmt.setInt(5, Integer.parseInt(level4));
pDeleteStmt.setInt(6, Integer.parseInt(level5)); pDeleteStmt.setInt(6, Integer.parseInt(level5));
deleteCount++; deleteCount++;
pDeleteStmt.addBatch(); pDeleteStmt.addBatch();
} }
}//End of subMenuList iteration for loop }//End of subMenuList iteration for loop
}//End of if subMenuList is not null }//End of if subMenuList is not null
//} //}
}//outer for }//outer for
...@@ -705,23 +751,30 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U ...@@ -705,23 +751,30 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U
returnString = be.getMessage(); returnString = be.getMessage();
System.out.println("BatchUpdateException :RunMRPPrcEJB: CreatePlanDemand(ADPElement)" + returnString); System.out.println("BatchUpdateException :RunMRPPrcEJB: CreatePlanDemand(ADPElement)" + returnString);
System.out.println("Detail Exception : " + be.getNextException()); System.out.println("Detail Exception : " + be.getNextException());
throw new ITMException(be);// added by akhilesh on 31/oct/12
} }
catch (SQLException ex) catch (SQLException ex)
{ {
returnString = ex.getMessage(); returnString = ex.getMessage();
try{conn.rollback(); try{conn.rollback();
}catch(Exception e){} }catch(Exception e){
throw new ITMException(e);// added by akhilesh on 31/oct/12
}
ex.printStackTrace(); ex.printStackTrace();
throw new ITMException(ex);// added by akhilesh on 31/oct/12
} }
catch (Exception e) catch (Exception e)
{ {
returnString = e.getMessage(); returnString = e.getMessage();
try{ try{
conn.rollback(); conn.rollback();
}catch(Exception ec){} }catch(Exception ec){
throw new ITMException(ec);// added by akhilesh on 31/oct/12
}
e.printStackTrace(); e.printStackTrace();
throw new ITMException(e);// added by akhilesh on 31/oct/12
} }
finally finally
{ {
...@@ -742,10 +795,13 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U ...@@ -742,10 +795,13 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U
conn.close(); conn.close();
conn = null; conn = null;
}catch(Exception e){}
}catch(Exception e){
throw new ITMException(e);// added by akhilesh on 31/oct/12
}
//return returnString; //return returnString;
} }
if (returnString == null || returnString.trim().length() == 0) if (returnString == null || returnString.trim().length() == 0)
{ {
System.out.println("errString is null************** "); System.out.println("errString is null************** ");
...@@ -773,7 +829,7 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U ...@@ -773,7 +829,7 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U
return 2 return 2
else if Found and rights = null else if Found and rights = null
return 3 return 3
*/ */
// 01/06/10 manoharan // 01/06/10 manoharan
int searchUserRight(String profileId, String application,int level1,int level2,int level3,int level4,int level5, String rights,Connection conn) throws Exception int searchUserRight(String profileId, String application,int level1,int level2,int level3,int level4,int level5, String rights,Connection conn) throws Exception
{ {
...@@ -782,13 +838,13 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U ...@@ -782,13 +838,13 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U
ResultSet rs = null; ResultSet rs = null;
String alreadyExists = "N"; String alreadyExists = "N";
String sql = " SELECT RIGHTS FROM USER_RIGHTS " String sql = " SELECT RIGHTS FROM USER_RIGHTS "
+ " WHERE PROFILE_ID = ? " + " WHERE PROFILE_ID = ? "
+ " 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 = ? ";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
...@@ -850,7 +906,7 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U ...@@ -850,7 +906,7 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U
} }
private ArrayList getAllSubMenu(String application, int level1, int level2, int level3, int level4, int level5, Connection conn) private ArrayList getAllSubMenu(String application, int level1, int level2, int level3, int level4, int level5, Connection conn)
throws SQLException throws SQLException
{ {
String tApplication = null; String tApplication = null;
int tLevel1 = 0; int tLevel1 = 0;
...@@ -863,12 +919,12 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U ...@@ -863,12 +919,12 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U
String gotUserRights = null; String gotUserRights = null;
String getSubMenuSql = " SELECT APPLICATION, LEVEL_1, LEVEL_2, LEVEL_3, LEVEL_4, LEVEL_5, WIN_NAME, DESCR FROM ITM2MENU " + String getSubMenuSql = " SELECT APPLICATION, LEVEL_1, LEVEL_2, LEVEL_3, LEVEL_4, LEVEL_5, WIN_NAME, DESCR FROM ITM2MENU " +
" where APPLICATION = '" + application + "' " + " where APPLICATION = '" + application + "' " +
" and ( level_1 = 0 or (level_1 <> 0 and (LEVEL_1 = " + level1 + " AND LEVEL_2 > 0))) " + " and ( level_1 = 0 or (level_1 <> 0 and (LEVEL_1 = " + level1 + " AND LEVEL_2 > 0))) " +
" and ( level_2 = 0 or (level_2 <> 0 and (LEVEL_2 = " + level2 + " AND LEVEL_3 > 0))) " + " 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))) " + " and ( level_3 = 0 or ( level_3 <> 0 and (LEVEL_3 = " + level3 + " AND LEVEL_4 > 0))) " +
" and ( level_4 = 0 or ( level_4 <> 0 and (LEVEL_4 = " + level4 + " AND LEVEL_5 > 0))) " + " and ( level_4 = 0 or ( level_4 <> 0 and (LEVEL_4 = " + level4 + " AND LEVEL_5 > 0))) " +
" and WIN_NAME <> '-' " ; " and WIN_NAME <> '-' " ;
System.out.println("Get All Sub Menu SQL :: " + getSubMenuSql); System.out.println("Get All Sub Menu SQL :: " + getSubMenuSql);
...@@ -924,17 +980,17 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U ...@@ -924,17 +980,17 @@ public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , U
} }
private String getUserRights(String profileId, String application, int level1, int level2, int level3, int level4, int level5, Connection conn) private String getUserRights(String profileId, String application, int level1, int level2, int level3, int level4, int level5, Connection conn)
throws SQLException throws SQLException
{ {
String userRightsSql = " select RIGHTS " + String userRightsSql = " select RIGHTS " +
" from user_rights " + " from user_rights " +
" where profile_id = '" + profileId + "' " + " where profile_id = '" + profileId + "' " +
" and APPLICATION = '" + application + "' " + " and APPLICATION = '" + application + "' " +
" and MENU_ROW = " + level1 + " and MENU_ROW = " + level1 +
" and MENU_COL = " + level2 + " and MENU_COL = " + level2 +
" and MENU_SUBCOL = " +level3 + " and MENU_SUBCOL = " +level3 +
" and LEVEL_4 = " + level4 + " and LEVEL_4 = " + level4 +
" and LEVEL_5 = " + level5; " and LEVEL_5 = " + level5;
String rights = null; String rights = null;
System.out.println("userRightsSql :: " + userRightsSql); System.out.println("userRightsSql :: " + userRightsSql);
......
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