Commit f8460770 authored by pborate's avatar pborate

Updated account activity component.

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@180599 ce508802-f39f-4f6c-b175-0d175dae99d5
parent f06fe833
package ibase.dashboard.hibernate.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.json.JSONException;
import org.json.JSONObject;
public class ActivityTime {
private static final long serialVersionUID = 1L;
long seconds = 0;
long minutes = 0;
long hours = 0;
public ActivityTime()
{
}
public ActivityTime(String startTime, String endTime)
{
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss.");
Date d1 = null;
Date d2 = null;
try
{
d1 = format.parse(startTime);
d2 = format.parse(endTime);
long diff = d2.getTime() - d1.getTime();
this.seconds = diff / 1000 % 60;
this.minutes = diff / (60 * 1000) % 60;
this.hours = diff / (60 * 60 * 1000);
//System.out.println("diff: " + diff );
}
catch (ParseException e)
{
e.printStackTrace();
}
//System.out.println("Time in : " + this.seconds + " seconds.");
//System.out.println("Time in : " + this.minutes + " minutes.");
//System.out.println("Time in : " + this.hours + " hours.");
}
public ActivityTime(Date startTime, Date endTime)
{
try
{
long diff = endTime.getTime() - startTime.getTime();
this.seconds = diff / 1000 % 60;
this.minutes = diff / (60 * 1000) % 60;
this.hours = diff / (60 * 60 * 1000);
//System.out.println("diff: " + diff );
}
catch (Exception e)
{
e.printStackTrace();
}
//System.out.println("Time in : " + this.seconds + " seconds.");
//System.out.println("Time in : " + this.minutes + " minutes.");
//System.out.println("Time in : " + this.hours + " hours.");
}
public void addTime(ActivityTime time)
{
System.out.println("addTime :1:time[" + time + "]this[" + this + "]" );
this.seconds = this.seconds + time.seconds;
if(this.seconds > 59)
{
this.seconds = this.seconds % 60;
long mins = this.seconds / 60;
this.minutes = this.minutes + mins;
System.out.println("this.seconds > 59 ::" + this.seconds );
}
this.minutes = this.minutes + time.minutes;
if(this.minutes > 59)
{
this.minutes = this.minutes % 60;
long hrs = this.minutes / 60;
this.hours = this.hours + hrs;
System.out.println("this.minutes > 59 ::" + this.minutes );
}
this.hours = this.hours + time.hours;
if(this.hours >= 23) //Should not come here
{
System.out.println("this.hours >= 23 ::" + this.hours );
}
System.out.println("addTime :2:time[" + time + "]this[" + this + "]" );
}
public JSONObject toJSON()
{
JSONObject jObj = new JSONObject();
try
{
jObj.put("hours", this.hours);
jObj.put("minutes", this.minutes);
jObj.put("seconds", this.seconds);
}
catch (JSONException e)
{
e.printStackTrace();
}
return jObj;
}
public String toString()
{
return this.toJSON().toString();
}
}
package ibase.dashboard.hibernate.util;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
public class GenericUtil
{
public List<String> getDateList(String fromDate, String toDate, String format) throws ParseException
{
SimpleDateFormat newFormat = new SimpleDateFormat(format);
DateFormat formatter = new SimpleDateFormat("dd-MM-yy");
Date startDate = (Date) formatter.parse(fromDate);
Date endDate = (Date) formatter.parse(toDate);
List<String> formattedDateRange = new ArrayList<String>();
Calendar calendar = new GregorianCalendar();
calendar.setTime(startDate);
while (calendar.getTime().before(endDate))
{
Date currentDate = calendar.getTime();
calendar.add(Calendar.DATE, 1);
formattedDateRange.add( newFormat.format(currentDate) );
}
formattedDateRange.add(newFormat.format(endDate));
System.out.println(" getDateList formattedDateRange::::" + formattedDateRange);
return formattedDateRange;
}
public String getEnclosedString(List<String> valueList)
{
StringBuffer enclosedStringBuffer = new StringBuffer();
int len = 0;
for(String value : valueList)
{
enclosedStringBuffer.append("'").append(value.trim()).append("'");
len++;
if( len < valueList.size() )
{
enclosedStringBuffer.append(",");
}
}
if( enclosedStringBuffer.length() == 0 )
{
enclosedStringBuffer.append("''");
}
System.out.println("Inside getEnclosedString enclosedStringBuffer: [" + enclosedStringBuffer +"]");
return enclosedStringBuffer.toString();
}
public Object checkNull(Object data)
{
if(data==null)
{
return "NA";
}
else
{
return data;
}
}
public Object checkNullDate(Object data)
{
System.out.println("Inside checkNull"+data);
if(data==null)
{
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
}
else
{
return data;
}
}
}
package ibase.dashboard.common.webService;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import ibase.dashboard.common.hibernate.dao.AccountActivityDao;
import org.json.JSONObject;
import ibase.dashboard.hibernate.dao.AccountActivityDao;
import ibase.utility.BaseException;
import ibase.utility.UserInfoBean;
......@@ -17,32 +23,79 @@ public class AccountActivityService {
@Context
HttpServletRequest request; // The proxy of Request will be injected into this singleton
private AccountActivityDao accountActivityDao = new AccountActivityDao();
@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public String getLog() throws Exception {
public String getAccountActivityData(@QueryParam("fromDate") String fromDate,
@QueryParam("toDate") String toDate,
@QueryParam("date") String date,
@QueryParam("startBattery") int startBattery,
@QueryParam("USER_INFO") String userInfoString) throws Exception
{
JSONObject accountActivityData = new JSONObject();
System.out.println("getAccountActivityData fromDate date [" + fromDate + "]");
System.out.println("getAccountActivityData toDate date [" + toDate + "]");
System.out.println("getAccountActivityData date [" + date + "]");
System.out.println("getAccountActivityData startBattery [" + startBattery + "]");
if(date != null){
fromDate = date;
toDate = date;
System.out.println("getAccountActivityData date not null [" + fromDate + "] toDate ["+toDate+"]");
}
if (fromDate == null)
{
DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("dd-MM-YY");
fromDate = LocalDate.now().format(formatter1);
System.out.println("getAccountActivityData fromDate is null [" + fromDate + "]");
}
if (toDate == null)
{
DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("dd-MM-YY");
toDate = LocalDate.now().format(formatter1);
System.out.println("getAccountActivityData toDate is null [" + toDate + "]");
}
if (startBattery == 0)
{
startBattery = 100;
System.out.println("getAccountActivityData startBattery is null [" + startBattery + "]");
}
if( userInfoString == null )
{
HttpSession session = request.getSession();
Object userObj = session.getAttribute( "USER_INFO" );
String userId = "" ;
String profileId="";
System.out.println(" userObj >>[" + userObj + "]" );
if(userObj != null)
{
UserInfoBean userInfo;
try {
userInfo = new UserInfoBean( userObj.toString() );
Object userObj = session.getAttribute("USER_INFO");
System.out.println("getAccountActivityData userObj [" + userObj + "]");
if (userObj != null)
{
userInfoString = userObj.toString();
}
else
{
userInfoString = null;
}
}
String userId = "";
String profileId = "";
System.out.println("getAccountActivityData userInfoString [" + userInfoString + "]");
if (userInfoString != null)
{
try
{
AccountActivityDao accountActivityDao = new AccountActivityDao();
UserInfoBean userInfo = new UserInfoBean( userInfoString );
userId = userInfo.getLoginCode();
profileId = userInfo.getProfileId();
System.out.println(" userInfo >>[" + userId + "] profile Id ["+profileId+"]" );
} catch (BaseException e) {
System.out.println(" userInfo >>[" + userId + "] profile Id [" + profileId + "]");
accountActivityData = accountActivityDao.getUserActivityData(userId, profileId, fromDate, toDate, startBattery);
}
catch (BaseException e)
{
e.printStackTrace();
}
}
String logDetails = accountActivityDao. getUserActivityData(userId,profileId);
return logDetails;
System.out.println("getAccountActivityData accountActivityData : " + accountActivityData.toString());
return accountActivityData.toString();
}
}
\ No newline at end of file
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