Commit af41b7de authored by kpandey's avatar kpandey

Changes for landing page dashboard

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@202590 ce508802-f39f-4f6c-b175-0d175dae99d5
parent b2a70a0d
......@@ -6,6 +6,7 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
......@@ -39,7 +40,9 @@ import ibase.webitm.ejb.DocumentHandlerWrapperEJB;
import ibase.webitm.utility.ITMException;
import java.util.Calendar;
import java.util.Collection;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
public class CourseDAO
{
......@@ -81,6 +84,21 @@ public class CourseDAO
courseObj.put("courseStatus", courseStatus); // Open Courses - Yet to visit
}
String daysRemaining = "0";
try
{
Date date1 = course.getEndDate();
Date date2 = new Date();
long diff = date1.getTime() - date2.getTime();
daysRemaining = Long.toString( TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS) );
System.out.println ("Days to go : " + daysRemaining);
}
catch (Exception e)
{
e.printStackTrace();
}
courseObj.put("daysToGo", daysRemaining);
JSONArray courseContents = getCourseContents(courseCode, courseStatus);
JSONArray courseQuestions = getCourseQuestions(courseCode);
......
......@@ -25,6 +25,7 @@ import org.hibernate.query.NativeQuery;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
......@@ -66,6 +67,7 @@ public class DashboardUtil
private String userSite;
//To fetch empCode of user
private String empCode;
private String profileId;
public JSONObject getDashboardConfig(String dashboardFileName,UserInfoBean userInfo)
{
......@@ -77,6 +79,7 @@ public class DashboardUtil
userTranDB =userInfo.getTransDB();
userSite =userInfo.getSiteCode();
empCode = userInfo.getEmpCode();
profileId = userInfo.getProfileId();
}
System.out.println("userTranDB =" + userTranDB);
CommonConstants.setIBASEHOME();
......@@ -280,6 +283,31 @@ public class DashboardUtil
System.out.println(e.getMessage());
}
}
else if(dataSourceType.equalsIgnoreCase("jsondata")) {
try
{
JSONObject valueObj = new JSONObject(value);
JSONArray quicklinks = valueObj.optJSONArray("quicklinks");
JSONArray quicklinksFinal=new JSONArray();
for(int i = 0, size = quicklinks.length(); i < size; i++) {
JSONObject quicklinkObj=quicklinks.optJSONObject(i);
String objName = quicklinkObj.getString("obj_name_rights");
if( objName != null )
{
String displayLink = getObjUserRights(objName, profileId);
quicklinkObj.put("displayLink", displayLink);
}
quicklinksFinal.put(quicklinkObj);
}
valueObj.put("quicklinks", quicklinksFinal);
datasourceObj.put("value",valueObj.toString() );
}
catch (JSONException e)
{
e.printStackTrace();
}
}
}
......@@ -1117,7 +1145,7 @@ public class DashboardUtil
}
/* DONE FOR DISPLAYING DASHBOARD BASED ON OBJ_RIGHTS */
private String getObjUserRights(String objNameRights, String profileId) throws SQLException
private String getObjUserRights(String objNameRights, String profileId)
{
String display = "Y";
List<Object>resultList = new ArrayList<Object>();
......
package ibase.dashboard.common.hibernate.dao;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import ibase.system.config.ConnDriver;
import ibase.utility.BaseLogger;
import ibase.utility.E12GenericUtility;
import ibase.utility.UserInfoBean;
import ibase.webitm.ejb.DBAccessEJB;
import ibase.webitm.utility.ITMException;
public class UserHistoryDAO
{
private UserInfoBean userInfo = null;
public UserInfoBean getUserInfo() {
return this.userInfo;
}
public void setUserInfo(UserInfoBean userInfo) {
this.userInfo = userInfo;
}
public JSONArray getDeviceHistory(String loginUser, String transDB) throws Exception
{
System.out.println("indside get device history");
PreparedStatement pstmt = null;
ResultSet rs = null;
Connection conn =null;
JSONArray getDeviceHistory = new JSONArray();
try
{
String transDb = "";
transDb= transDB;
System.out.println("transdb ::::::::::"+transDb);
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB( transDb );
StringBuffer sql=new StringBuffer();
sql.append(" SELECT user_id, device_os, device_type, device_make, device_mac_addr, device_id__push, active, chg_term, chg_date ")
.append(" FROM user_device ")
.append(" WHERE user_id ='"+loginUser+"' ")
.append(" order by chg_date DESC")
;
System.out.println("sql.toString()+++ device history"+sql.toString());
pstmt = conn.prepareStatement(sql.toString());
System.out.println("pstmtdevice history"+pstmt);
rs = pstmt.executeQuery();
System.out.println("rs"+rs);
while(rs.next())
{
System.out.println(" inside rs device history");
JSONObject allDeviceHisJson = new JSONObject();
String userId = rs.getString("user_id");
String deviceOs = rs.getString("device_os");
String deviceType = rs.getString("device_type");
String deviceMake = rs.getString("device_make");
String deviceMaCAddr = rs.getString("device_mac_addr");
String deviceIdPush = rs.getString("device_id__push");
String active = rs.getString("active");
String chgTerm = rs.getString("chg_term");
String chgDate = rs.getString("chg_date");
allDeviceHisJson.put("USER_ID", userId);
allDeviceHisJson.put("DEVICE_OS", deviceOs);
allDeviceHisJson.put("DEVICE_TYPE", deviceType);
allDeviceHisJson.put("DEVICE_MAKE", deviceMake);
allDeviceHisJson.put("DEVICE_MAC_ADDRESS", deviceMaCAddr);
allDeviceHisJson.put("DEVICE_ID_PUSH", deviceIdPush);
allDeviceHisJson.put("ACTIVE", active);
allDeviceHisJson.put("CHG_TERM", chgTerm);
allDeviceHisJson.put("CHG_DATE", chgDate);
System.out.println(" allDeviceHisJson ["+allDeviceHisJson+"]");
getDeviceHistory.put(allDeviceHisJson);
System.out.println(" getDeviceHistory ["+getDeviceHistory+"]");
}
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if( pstmt != null )
{
pstmt.close();
pstmt = null;
}
if ( rs != null )
{
rs.close();
rs = null;
}
if ( conn != null )
{
conn.close();
conn = null;
}
}
catch(Exception e)
{
}
}
System.out.println("getDeviceHistory :: "+getDeviceHistory);
return getDeviceHistory;
}
public JSONArray getPassChgHistory(String loginUser, String transDB) throws Exception
{
System.out.println("indside getPassHisObject");
java.sql.PreparedStatement pstmt = null;
ResultSet rs = null;
Connection conn =null;
JSONArray userPasswdHisArr = new JSONArray();
try
{
String transDb = "";
transDb= transDB;
System.out.println("transdb ::::::::::"+transDb);
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB( transDb );
for(int i=1; i<=5; i++)
{
System.out.println("i ::::::::::"+i);
StringBuffer sql=new StringBuffer();
sql.append(" SELECT uph.pass_chg_date"+i+", uph.device_id"+i+", uph.chg_ip"+i+", ud.device_os, ud.device_type, ud.device_make ")
.append(" FROM usr_pass_his uph, user_device ud ")
.append(" WHERE uph.code ='"+loginUser+"' ")
.append(" AND uph.pass_wd_"+i+" IS NOT NULL ")
.append(" AND uph.device_id"+i+" = ud.device_id__push ");
System.out.println("sql.toString()+++"+sql.toString());
pstmt = conn.prepareStatement(sql.toString());
System.out.println("pstmt"+pstmt);
rs = pstmt.executeQuery();
System.out.println("rs"+rs);
while(rs.next())
{
System.out.println(" inside rs");
JSONObject userPasswdHis = new JSONObject();
String passChgDate = rs.getString("pass_chg_date"+i);
String deviceId = rs.getString("device_id"+i);
String chgIp = rs.getString("chg_ip"+i);
String deviceOs = rs.getString("device_os");
String deviceType = rs.getString("device_type");
String deviceMake = rs.getString("device_make");
userPasswdHis.put("PASS_CHG_SEQ", Integer.toString(i));
userPasswdHis.put("PASS_CHG_DATE", passChgDate);
userPasswdHis.put("DEVICE_ID", deviceId);
userPasswdHis.put("CHG_IP", chgIp);
userPasswdHis.put("DEVICE_OS", deviceOs);
userPasswdHis.put("DEVICE_TYPE", deviceType);
userPasswdHis.put("DEVICE_MAKE", deviceMake);
userPasswdHisArr.put(userPasswdHis);
System.out.println("getAllLoginHistory==>["+userPasswdHis+"]");
}
if( pstmt != null )
{
pstmt.close();
pstmt = null;
}
if ( rs != null )
{
rs.close();
rs = null;
}
}
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if( pstmt != null )
{
pstmt.close();
pstmt = null;
}
if ( rs != null )
{
rs.close();
rs = null;
}
if ( conn != null )
{
conn.close();
conn = null;
}
}
catch(Exception e)
{
}
}
System.out.println("getAllLoginHistory :: "+userPasswdHisArr);
return userPasswdHisArr;
}
public JSONArray getAllLoginHistory(String loginUser, String transDB) throws Exception {
System.out.println("indside get all ogin history");
java.sql.PreparedStatement pstmt = null;
ResultSet rs = null;
Connection conn =null;
JSONArray loginHistoryArr = new JSONArray();
try
{
String transDb = "";
transDb= transDB;
System.out.println("transdb ::::::::::"+transDb);
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB( transDb );
StringBuffer sql=new StringBuffer();
sql.append(" SELECT userid, logintime, logouttime, device_type, host_name, host_ip, current_geo_pos, os_name, os_version, client_app, client_app_ver ")
.append(" FROM logintrace ")
.append(" WHERE TO_CHAR(logintime, 'DD/MM/YYYY HH:MI:SS') IN ")
.append(" ( SELECT a.date_pt || ' ' || MAX(a.time_pt) AS logintime ")
.append(" FROM ( ")
.append(" SELECT TO_CHAR(?, 'DD/MM/YYYY') AS start_date_pt, ")
.append(" TO_CHAR(?, 'DD/MM/YYYY') AS end_date_pt, ")
.append(" TO_CHAR(logintime, 'DD/MM/YYYY') AS date_pt, ")
.append(" TO_CHAR(logintime, 'HH:MI:SS') AS time_pt, ")
.append(" os_name, ")
.append(" os_version, ")
.append(" client_app, ")
.append(" client_app_ver, ")
.append(" host_name ")
.append(" FROM logintrace ")
.append(" WHERE userid ='"+loginUser+"' ")
.append(" )a ")
.append(" WHERE to_date(a.date_pt, 'DD/MM/YYYY') between to_date( start_date_pt, 'DD/MM/YYYY' ) and to_date( end_date_pt, 'DD/MM/YYYY' ) ")
.append(" and a.client_app is not null ")
.append(" and a.client_app_ver is not null ")
.append(" GROUP BY a.date_pt, a.os_name, a.os_version, a.client_app, a.client_app_ver, a.host_name ")
.append(" ) ")
.append(" ORDER BY logintime desc ");
System.out.println("sql.toString()+++"+sql.toString());
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.DATE, -15);
Calendar cal1 = Calendar.getInstance();
cal1.setTime(new Date());
/*pstmt.setDate(1, (java.sql.Date) cal.getTime());
pstmt.setDate(2, (java.sql.Date) cal1.getTime());*/
Timestamp ts = new Timestamp(cal.getTimeInMillis());
System.out.println(" ts timeStamp ["+ts+"]");
Timestamp ts2 = new Timestamp(cal1.getTimeInMillis());
System.out.println(" ts2 timeStamp ["+ts2+"]");
pstmt = conn.prepareStatement(sql.toString());
System.out.println("pstmt"+pstmt);
pstmt.setTimestamp(1, ts);
pstmt.setTimestamp(2, ts2);
rs = pstmt.executeQuery();
System.out.println("rs"+rs);
while(rs.next())
{
System.out.println(" inside rs");
JSONObject loginHistory = new JSONObject();
String userId = rs.getString("userid");
String loginTime = rs.getString("logintime");
String logoutTime = rs.getString("logouttime");
String deviceType = rs.getString("device_type");
String hostName = rs.getString("host_name");
String hostIP = rs.getString("host_ip");
String currentGeoPos = rs.getString("current_geo_pos");
String osName = rs.getString("os_name");
String osVersion = rs.getString("os_version");
String clientAPP = rs.getString("client_app");
String clientAppVer = rs.getString("client_app_ver");
loginHistory.put("USER_ID", userId);
loginHistory.put("LOGIN_TIME", loginTime);
loginHistory.put("LOG_OUT", logoutTime);
loginHistory.put("DEVICE_TYPE", deviceType);
loginHistory.put("HOST_NAME", hostName);
loginHistory.put("HOST_IP", hostIP);
loginHistory.put("CURRENT_GEO_POS", currentGeoPos);
loginHistory.put("OS_NAME", osName);
loginHistory.put("OS_VERSION", osVersion);
loginHistory.put("CLIENTA_APP", clientAPP);
loginHistory.put("CLIENT_APP_VER", clientAppVer);
loginHistoryArr.put(loginHistory);
}
}
catch(Exception e)
{
System.out.println("Exception in getAllLoginHistory :: "+ e.getMessage());
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if( pstmt != null )
{
pstmt.close();
pstmt = null;
}
if ( rs != null )
{
rs.close();
rs = null;
}
if ( conn != null )
{
conn.close();
conn = null;
}
}
catch(Exception e)
{
System.out.println("Exception in finally getAllLoginHistory :: "+ e.getMessage());
e.printStackTrace();
}
}
System.out.println("getAllLoginHistory :: "+loginHistoryArr);
return loginHistoryArr;
}
public JSONObject getUserActivitySummary(String loginUser, String userName, String transDB)
{
JSONObject userHisObj = new JSONObject();
System.out.println("inside getUserActivitySummary");
try
{
String last_login_date = getSQLResult(" logintrace ", " max(logintime) ", " userid = '" + loginUser + "'", transDB);
System.out.println("Last Login Date ==>"+last_login_date);
String last_passwrd_change_date = getSQLResult(" users ", " last_pwd_chgdate ", " code = '" + loginUser + "'", transDB);
System.out.println("Last Passwrd Change Date ==>"+last_passwrd_change_date);
Date lastLoginDate = getDateTimeObject(last_login_date);
Date lastPasswrdChangeDate = getDateTimeObject(last_passwrd_change_date);
System.out.println("lastLoginDate ==>"+lastLoginDate + " lastPasswrdChangeDate ==> " + lastPasswrdChangeDate );
userHisObj.put("LAST_LOGIN", getDifference(new Date(), lastLoginDate) );
userHisObj.put("LAST_PWD_CHG", getDifference(new Date(), lastPasswrdChangeDate));
userHisObj.put("LAST_LOGIN_DATE", last_login_date != null ? last_login_date : new Date() );
userHisObj.put("LAST_PWD_CHG_DATE", last_passwrd_change_date);
String no_of_doc_content = getSQLResult(" user_doc_contents ", " count(doc_id) ", " user_id = '" + loginUser + "' and doc_stat <> 'D'", transDB);
System.out.println("No Of Contents ==>"+no_of_doc_content);
String no_of_places = getSQLResult(" place_time_ent ", " count(pte_id) ", " user_id = '" + loginUser + "'", transDB);
System.out.println("No Of Places ==>"+no_of_places);
userHisObj.put("NO_OF_CONTENTS", no_of_doc_content != null ? no_of_doc_content : "0");
userHisObj.put("NO_OF_PLACES", no_of_places != null ? no_of_places : "0");
userHisObj.put("USER_NAME", userName );
}
catch (JSONException e)
{
System.out.println("JSONException in getUserActivitySummary :: "+ e.getMessage());
e.printStackTrace();
}
catch (Exception e )
{
System.out.println("Exception in getUserActivitySummary :: "+ e.getMessage());
e.printStackTrace();
}
return userHisObj;
}
public void changeDeviceStatus(String loginUser, String deviceId, String active, String transDB) throws Exception
{
Connection con = null;
PreparedStatement pstmt = null;
try
{
String transDb = "";
transDb= transDB;
System.out.println("transdb ::::::::::"+transDb);
ConnDriver connDriver = new ConnDriver();
con = connDriver.getConnectDB( transDb );
StringBuffer sql=new StringBuffer();
if("true".equalsIgnoreCase(active))
{
sql.append(" UPDATE user_device SET active = 'Y' ");
}
else
{
sql.append(" UPDATE user_device SET active = 'N' ");
}
sql.append(" WHERE user_id ='"+loginUser+"' AND device_id__push ='"+deviceId+"' ");
pstmt = con.prepareStatement(sql.toString());
pstmt.setString(1, loginUser);
pstmt.executeQuery();
pstmt.close();
}
catch ( Exception e )
{
throw new Exception(e) ;
}
finally
{
if (con != null )
{
try
{
con.commit();
con.close();
con = null;
}
catch (SQLException e)
{
}
}
}
}
private String getSQLResult(String tableName, String columnName, String condition, String transDB)
{
System.out.println("inside getSQLResult");
DBAccessEJB dbAccessEJB = new DBAccessEJB();
String columnValue = null;
try
{
columnValue= dbAccessEJB.getDBColumnValue(tableName, columnName , condition, transDB);
}
catch (RemoteException | ITMException e)
{
System.out.println("RemoteException | ITMException in getSQLResult :: "+ e.getMessage());
e.printStackTrace();
}
catch (Exception e )
{
System.out.println("Exception in getSQLResult :: "+ e.getMessage());
e.printStackTrace();
}
System.out.println("getSQLResult [" + columnValue + "]");
return columnValue;
}
private Date getDateTimeObject(String dateStr)
{
Date dat = null;
SimpleDateFormat simpleDateFormat = null;
try
{
E12GenericUtility genUtil = new E12GenericUtility();
simpleDateFormat = new SimpleDateFormat(genUtil.getDBDateTimeFormat());
dat = simpleDateFormat.parse(dateStr);
}
catch(Exception e)
{
BaseLogger.log("0",null,null,"Exception :UserHistoryDAO :getDateTimeObject :==>\n"+e.getMessage());
}
finally
{
simpleDateFormat = null;
}
return dat;
}
private String getDifference(Date date1, Date date2)
{
String daysRemaining = null;
try
{
long diff = date1.getTime() - date2.getTime();
daysRemaining = Long.toString( TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS) );
System.out.println ("Days to go : " + daysRemaining);
}
catch (Exception e)
{
e.printStackTrace();
}
return daysRemaining;
}
}
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