Commit 88ce6613 authored by kpandey's avatar kpandey

Changes for to display dashboard based on userRights and to fetch siteCode of of user from userInfo

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@189454 ce508802-f39f-4f6c-b175-0d175dae99d5
parent b6b3e141
......@@ -2,6 +2,7 @@ package ibase.dashboard.common.hibernate.dao;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
......@@ -14,6 +15,8 @@ import org.apache.commons.io.FileUtils;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.dialect.identity.SybaseAnywhereIdentityColumnSupport;
import org.hibernate.query.NativeQuery;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
......@@ -29,12 +32,15 @@ import ibase.utility.CommonConstants;
import ibase.utility.E12GenericUtility;
import ibase.utility.UserInfoBean;
import ibase.webitm.ejb.DBAccessEJB;
//import ibase.webitm.ejb.DBAccessRemote;
import ibase.webitm.utility.ITMException;
public class DashboardUtil
{
private String userTranDB = "DEFAULT";
//To fetch siteCode of user
private String userSite;
public JSONObject getDashboardConfig(String dashboardFileName,UserInfoBean userInfo)
{
//JSONObject dashboardConfig = new JSONObject();
......@@ -43,6 +49,7 @@ public class DashboardUtil
{
if(userInfo != null) {
userTranDB =userInfo.getTransDB();
userSite =userInfo.getSiteCode();
}
System.out.println("userTranDB =" + userTranDB);
CommonConstants.setIBASEHOME();
......@@ -54,6 +61,15 @@ public class DashboardUtil
String dashboardFileContents = FileUtils.readFileToString(dashboardFile);
System.out.println("dashboardFileContents =" + dashboardFileContents);
dashboardConfigFinal = processMetadataXML(dashboardFileContents,userInfo);
JSONObject userInfoJson = xmlToJson("<Root>" + userInfo.toString()+ "</Root>");
System.out.println("forFetchingSiteCode of User"+userInfoJson);
JSONObject userInfoObject= userInfoJson.optJSONObject("UserInfo");
userInfoObject.remove("loginPwd");
dashboardConfigFinal.put("USER_INFO", userInfoObject);
System.out.println("dashboardConfigFinal forFetchingSiteCode of User"+dashboardConfigFinal);
}
catch (IOException e)
{
......@@ -257,10 +273,12 @@ public class DashboardUtil
System.out.println("objName:::"+objName);
JSONObject objNameobj=componentData.optJSONObject("obj_name");
System.out.println("objNameobj:::"+objNameobj);
String objNameRights = componentData.optString("obj_name_rights");
System.out.println("objNameRights:::"+objNameRights);
if(userInfo != null && (!objName.isEmpty() || objNameobj != null)) {
System.out.println("userInfo for dbAccess"+userInfo+","+objName);
System.out.println("<<<<<<< .mineuserInfo for dbAccess"+userInfo+","+objName);
AppConnectParm appConnect = new AppConnectParm();
InitialContext ctx = new InitialContext(appConnect.getProperty());
//DBAccessRemote dbAccess = ( DBAccessRemote )ctx.lookup( "ibase/DBAccessEJB/remote" );
......@@ -282,6 +300,28 @@ public class DashboardUtil
}
}
/* FOR DISPLAYING DASHBOARD BASED ON OB_RIGHTS */
if(userInfo != null && (!objNameRights.isEmpty() && objNameRights != null && objNameRights != ""))
{
System.out.println("display for userRights == >UserLevel[" + userInfo.getUserLevel() + "] objNameRights["+ objNameRights + "]");
String display;
if( ! "0".equalsIgnoreCase( userInfo.getUserLevel() ) )
{
display = getObjUserRights(objNameRights,userInfo.getProfileId().trim());
System.out.println("diplay for getOBJUSERRIGHTSuserRights == >"+display);
}
else
{
display = "Y";
}
componentData.put("display", display);
}
else
{
componentData.put("display", "Y");
}
if(componentData.has("pivotrows") && componentData.has("pivotvalues") && componentData.has("pivotcolumns")) {
JSONObject pivotTableData=new JSONObject();
pivotTableData=getPivotTableData(componentData);
......@@ -634,8 +674,6 @@ public class DashboardUtil
{
JSONArray filter= filters.optJSONArray("filter");
JSONArray filterTemp=filter;
E12GenericUtility genericUtility = new E12GenericUtility();
String sourceDateFormat=genericUtility.getApplDateFormat();
if(filter !=null)
{
......@@ -653,14 +691,20 @@ public class DashboardUtil
System.out.println("defaultValue::::"+defaultValue);
if(defaultValue ==null || defaultValue instanceof JSONObject) {
if(type.equalsIgnoreCase("4")) {
System.out.println("Inside if processDashboardFilter 4::::"+sourceDateFormat);
fil.put("default_value", new SimpleDateFormat(sourceDateFormat).format(new Date()));
System.out.println("Inside if processDashboardFilter 4::::");
fil.put("default_value", new SimpleDateFormat("dd/MM/yyyy").format(new Date()));
}
else {
fil.put("default_value","");
}
}
//TO FETCH SITECODE OF USER LOGGED IN
else if(defaultValue !=null && "CURRENT_SITE".equalsIgnoreCase(defaultValue.toString())) {
fil.put("default_value",userSite+",");
System.out.println("toget user site code => "+fil);
}
System.out.println("default value "+fil);
System.out.println("Inside type processDashboardFilter>>>>>>"+type);
JSONObject popHelpData = new JSONObject();
......@@ -876,5 +920,45 @@ public class DashboardUtil
return null;
}
/* DONE FOR DISPLAYING DASHBOARD BASED ON OBJ_RIGHTS */
private String getObjUserRights(String objNameRights, String profileId) throws SQLException
{
String display = "Y";
List<Object>resultList = new ArrayList<Object>();
Session session = null;
try
{
System.out.println("Inside getObjUserRights method !! objNameRights:["+objNameRights+"],profileId: ["+profileId+"]");
session = HibernateUtil.getSessionFactory(userTranDB).openSession();
NativeQuery query = session.createNativeQuery("SELECT * FROM USER_RIGHTS WHERE OBJ_NAME = '"+objNameRights+"' AND PROFILE_ID = '"+profileId+"' ");
resultList = query.list();
System.out.println("resultList for userRights : ["+resultList+"]");
if( resultList != null && resultList.size() > 0) {
display = "Y";
}
else
{
display = "N";
}
session.close();
}
catch(Exception e)
{
System.out.println("HibernateException :"+e);
System.out.println(e.getMessage());
}
finally
{
try
{
session.close();
}
catch (Exception e) {
}
}
return display;
}
}
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