Commit cd693125 authored by Saurabh Narayan Singh's avatar Saurabh Narayan Singh
Browse files

Tracking - moved code to service builder


Signed-off-by: default avatarSaurabh Narayan Singh <singh@fortiss.fortiss.org>
parent 3c858a11
......@@ -8,5 +8,6 @@ Export-Package:\
analysisService.service.persistence,\
analysisSerivce.data.machinelearning,\
analysisSerivce.data.mining,\
analysisService.service.enums,\
org.tensorflow.*
-includeresource: META-INF/service.xml=../analysisService-service/service.xml
\ No newline at end of file
......@@ -25,6 +25,8 @@ import com.liferay.portal.kernel.service.ServiceContext;
import java.io.Serializable;
import java.util.Date;
/**
* The base model interface for the SessionTime service. Represents a row in the &quot;ANALYSIS_SessionTime&quot; database table, with each column mapped to a property of this class.
*
......@@ -94,28 +96,28 @@ public interface SessionTimeModel extends BaseModel<SessionTime> {
*
* @return the start time of this session time
*/
public long getStartTime();
public Date getStartTime();
/**
* Sets the start time of this session time.
*
* @param StartTime the start time of this session time
*/
public void setStartTime(long StartTime);
public void setStartTime(Date StartTime);
/**
* Returns the end time of this session time.
*
* @return the end time of this session time
*/
public long getEndTime();
public Date getEndTime();
/**
* Sets the end time of this session time.
*
* @param EndTime the end time of this session time
*/
public void setEndTime(long EndTime);
public void setEndTime(Date EndTime);
@Override
public boolean isNew();
......
......@@ -19,6 +19,7 @@ import aQute.bnd.annotation.ProviderType;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
......@@ -105,24 +106,24 @@ public class SessionTimeSoap implements Serializable {
_GroupID = GroupID;
}
public long getStartTime() {
public Date getStartTime() {
return _StartTime;
}
public void setStartTime(long StartTime) {
public void setStartTime(Date StartTime) {
_StartTime = StartTime;
}
public long getEndTime() {
public Date getEndTime() {
return _EndTime;
}
public void setEndTime(long EndTime) {
public void setEndTime(Date EndTime) {
_EndTime = EndTime;
}
private long _SessionID;
private String _GroupID;
private long _StartTime;
private long _EndTime;
private Date _StartTime;
private Date _EndTime;
}
\ No newline at end of file
......@@ -23,6 +23,7 @@ import com.liferay.portal.kernel.service.ServiceContext;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
......@@ -79,13 +80,13 @@ public class SessionTimeWrapper implements SessionTime,
setGroupID(GroupID);
}
Long StartTime = (Long)attributes.get("StartTime");
Date StartTime = (Date)attributes.get("StartTime");
if (StartTime != null) {
setStartTime(StartTime);
}
Long EndTime = (Long)attributes.get("EndTime");
Date EndTime = (Date)attributes.get("EndTime");
if (EndTime != null) {
setEndTime(EndTime);
......@@ -173,10 +174,20 @@ public class SessionTimeWrapper implements SessionTime,
* @return the end time of this session time
*/
@Override
public long getEndTime() {
public Date getEndTime() {
return _sessionTime.getEndTime();
}
/**
* Returns the start time of this session time.
*
* @return the start time of this session time
*/
@Override
public Date getStartTime() {
return _sessionTime.getStartTime();
}
/**
* Returns the primary key of this session time.
*
......@@ -197,16 +208,6 @@ public class SessionTimeWrapper implements SessionTime,
return _sessionTime.getSessionID();
}
/**
* Returns the start time of this session time.
*
* @return the start time of this session time
*/
@Override
public long getStartTime() {
return _sessionTime.getStartTime();
}
@Override
public void persist() {
_sessionTime.persist();
......@@ -223,7 +224,7 @@ public class SessionTimeWrapper implements SessionTime,
* @param EndTime the end time of this session time
*/
@Override
public void setEndTime(long EndTime) {
public void setEndTime(Date EndTime) {
_sessionTime.setEndTime(EndTime);
}
......@@ -289,7 +290,7 @@ public class SessionTimeWrapper implements SessionTime,
* @param StartTime the start time of this session time
*/
@Override
public void setStartTime(long StartTime) {
public void setStartTime(Date StartTime) {
_sessionTime.setStartTime(StartTime);
}
......
......@@ -18,6 +18,8 @@ import aQute.bnd.annotation.ProviderType;
import analysisService.model.SessionTime;
import analysisService.service.enums.ButtonPositions;
import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery;
import com.liferay.portal.kernel.dao.orm.DynamicQuery;
import com.liferay.portal.kernel.dao.orm.IndexableActionableDynamicQuery;
......@@ -36,6 +38,7 @@ import com.liferay.portal.kernel.util.OrderByComparator;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
......@@ -208,7 +211,7 @@ public interface SessionTimeLocalService extends BaseLocalService,
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public List<SessionTime> getSessionTimes(int start, int end);
public long addNewSession(long time);
public long addNewSession(Date time, java.lang.String groupID);
/**
* Returns the number of rows matching the dynamic query.
......@@ -227,4 +230,14 @@ public interface SessionTimeLocalService extends BaseLocalService,
*/
public long dynamicQueryCount(DynamicQuery dynamicQuery,
Projection projection);
/**
* groupID : String : ID of the portal. Used to track the session length.
* buttonID : String : Used to keep track of clicks on the button based on ID
* ButtonPositions : ENUM : FIRST - LAST - MIDDLE
* sessionID : If it's the first click, send default sessionID - 0
* returns the sessionID after logging the click
*/
public long trackClick(java.lang.String groupID, java.lang.String buttonID,
ButtonPositions position, long sessionID);
}
\ No newline at end of file
......@@ -228,8 +228,9 @@ public class SessionTimeLocalServiceUtil {
return getService().getSessionTimes(start, end);
}
public static long addNewSession(long time) {
return getService().addNewSession(time);
public static long addNewSession(java.util.Date time,
java.lang.String groupID) {
return getService().addNewSession(time, groupID);
}
/**
......@@ -256,6 +257,19 @@ public class SessionTimeLocalServiceUtil {
return getService().dynamicQueryCount(dynamicQuery, projection);
}
/**
* groupID : String : ID of the portal. Used to track the session length.
* buttonID : String : Used to keep track of clicks on the button based on ID
* ButtonPositions : ENUM : FIRST - LAST - MIDDLE
* sessionID : If it's the first click, send default sessionID - 0
* returns the sessionID after logging the click
*/
public static long trackClick(java.lang.String groupID,
java.lang.String buttonID,
analysisService.service.enums.ButtonPositions position, long sessionID) {
return getService().trackClick(groupID, buttonID, position, sessionID);
}
public static SessionTimeLocalService getService() {
return _serviceTracker.getService();
}
......
......@@ -234,8 +234,8 @@ public class SessionTimeLocalServiceWrapper implements SessionTimeLocalService,
}
@Override
public long addNewSession(long time) {
return _sessionTimeLocalService.addNewSession(time);
public long addNewSession(java.util.Date time, java.lang.String groupID) {
return _sessionTimeLocalService.addNewSession(time, groupID);
}
/**
......@@ -265,6 +265,20 @@ public class SessionTimeLocalServiceWrapper implements SessionTimeLocalService,
projection);
}
/**
* groupID : String : ID of the portal. Used to track the session length.
* buttonID : String : Used to keep track of clicks on the button based on ID
* ButtonPositions : ENUM : FIRST - LAST - MIDDLE
* sessionID : If it's the first click, send default sessionID - 0
* returns the sessionID after logging the click
*/
@Override
public long trackClick(java.lang.String groupID, java.lang.String buttonID,
analysisService.service.enums.ButtonPositions position, long sessionID) {
return _sessionTimeLocalService.trackClick(groupID, buttonID, position,
sessionID);
}
@Override
public SessionTimeLocalService getWrappedService() {
return _sessionTimeLocalService;
......
package analysisService.service.enums;
public enum ButtonPositions {
FIRST("First"),MIDDLE("Middle"),LAST("Last");
private final String buttonPositionDescription;
private ButtonPositions(String s){
buttonPositionDescription = s;
}
public String getButtonPositionDescription(){
return buttonPositionDescription;
}
}
......@@ -36,8 +36,8 @@
<entity name="SessionTime" local-service="true">
<column name="SessionID" type="long" primary="true" id-type="increment"></column>
<column name="GroupID" type="String"></column>
<column name="StartTime" type="long"></column>
<column name="EndTime" type="long"></column>
<column name="StartTime" type="Date"></column>
<column name="EndTime" type="Date"></column>
</entity>
<exceptions>
<exception>NoSuchAlgorithm</exception>
......
......@@ -28,6 +28,8 @@ import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Date;
/**
* The cache model class for representing SessionTime in entity cache.
*
......@@ -92,8 +94,19 @@ public class SessionTimeCacheModel implements CacheModel<SessionTime>,
sessionTimeImpl.setGroupID(GroupID);
}
sessionTimeImpl.setStartTime(StartTime);
sessionTimeImpl.setEndTime(EndTime);
if (StartTime == Long.MIN_VALUE) {
sessionTimeImpl.setStartTime(null);
}
else {
sessionTimeImpl.setStartTime(new Date(StartTime));
}
if (EndTime == Long.MIN_VALUE) {
sessionTimeImpl.setEndTime(null);
}
else {
sessionTimeImpl.setEndTime(new Date(EndTime));
}
sessionTimeImpl.resetOriginalValues();
......@@ -104,9 +117,7 @@ public class SessionTimeCacheModel implements CacheModel<SessionTime>,
public void readExternal(ObjectInput objectInput) throws IOException {
SessionID = objectInput.readLong();
GroupID = objectInput.readUTF();
StartTime = objectInput.readLong();
EndTime = objectInput.readLong();
}
......@@ -123,7 +134,6 @@ public class SessionTimeCacheModel implements CacheModel<SessionTime>,
}
objectOutput.writeLong(StartTime);
objectOutput.writeLong(EndTime);
}
......
......@@ -38,6 +38,7 @@ import java.io.Serializable;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -68,19 +69,19 @@ public class SessionTimeModelImpl extends BaseModelImpl<SessionTime>
public static final Object[][] TABLE_COLUMNS = {
{ "SessionID", Types.BIGINT },
{ "GroupID", Types.VARCHAR },
{ "StartTime", Types.BIGINT },
{ "EndTime", Types.BIGINT }
{ "StartTime", Types.TIMESTAMP },
{ "EndTime", Types.TIMESTAMP }
};
public static final Map<String, Integer> TABLE_COLUMNS_MAP = new HashMap<String, Integer>();
static {
TABLE_COLUMNS_MAP.put("SessionID", Types.BIGINT);
TABLE_COLUMNS_MAP.put("GroupID", Types.VARCHAR);
TABLE_COLUMNS_MAP.put("StartTime", Types.BIGINT);
TABLE_COLUMNS_MAP.put("EndTime", Types.BIGINT);
TABLE_COLUMNS_MAP.put("StartTime", Types.TIMESTAMP);
TABLE_COLUMNS_MAP.put("EndTime", Types.TIMESTAMP);
}
public static final String TABLE_SQL_CREATE = "create table ANALYSIS_SessionTime (SessionID LONG not null primary key,GroupID VARCHAR(75) null,StartTime LONG,EndTime LONG)";
public static final String TABLE_SQL_CREATE = "create table ANALYSIS_SessionTime (SessionID LONG not null primary key,GroupID VARCHAR(75) null,StartTime DATE null,EndTime DATE null)";
public static final String TABLE_SQL_DROP = "drop table ANALYSIS_SessionTime";
public static final String ORDER_BY_JPQL = " ORDER BY sessionTime.SessionID ASC";
public static final String ORDER_BY_SQL = " ORDER BY ANALYSIS_SessionTime.SessionID ASC";
......@@ -201,13 +202,13 @@ public class SessionTimeModelImpl extends BaseModelImpl<SessionTime>
setGroupID(GroupID);
}
Long StartTime = (Long)attributes.get("StartTime");
Date StartTime = (Date)attributes.get("StartTime");
if (StartTime != null) {
setStartTime(StartTime);
}
Long EndTime = (Long)attributes.get("EndTime");
Date EndTime = (Date)attributes.get("EndTime");
if (EndTime != null) {
setEndTime(EndTime);
......@@ -243,23 +244,23 @@ public class SessionTimeModelImpl extends BaseModelImpl<SessionTime>
@JSON
@Override
public long getStartTime() {
public Date getStartTime() {
return _StartTime;
}
@Override
public void setStartTime(long StartTime) {
public void setStartTime(Date StartTime) {
_StartTime = StartTime;
}
@JSON
@Override
public long getEndTime() {
public Date getEndTime() {
return _EndTime;
}
@Override
public void setEndTime(long EndTime) {
public void setEndTime(Date EndTime) {
_EndTime = EndTime;
}
......@@ -370,9 +371,23 @@ public class SessionTimeModelImpl extends BaseModelImpl<SessionTime>
sessionTimeCacheModel.GroupID = null;
}
sessionTimeCacheModel.StartTime = getStartTime();
Date StartTime = getStartTime();
sessionTimeCacheModel.EndTime = getEndTime();
if (StartTime != null) {
sessionTimeCacheModel.StartTime = StartTime.getTime();
}
else {
sessionTimeCacheModel.StartTime = Long.MIN_VALUE;
}
Date EndTime = getEndTime();
if (EndTime != null) {
sessionTimeCacheModel.EndTime = EndTime.getTime();
}
else {
sessionTimeCacheModel.EndTime = Long.MIN_VALUE;
}
return sessionTimeCacheModel;
}
......@@ -430,7 +445,7 @@ public class SessionTimeModelImpl extends BaseModelImpl<SessionTime>
};
private long _SessionID;
private String _GroupID;
private long _StartTime;
private long _EndTime;
private Date _StartTime;
private Date _EndTime;
private SessionTime _escapedModel;
}
\ No newline at end of file
......@@ -14,10 +14,18 @@
package analysisService.service.impl;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import analysisService.model.ClickCount;
import analysisService.model.SessionTime;
import analysisService.model.impl.SessionTimeImpl;
import analysisService.service.ClickCountLocalServiceUtil;
import analysisService.service.SessionTimeLocalServiceUtil;
import analysisService.service.base.SessionTimeLocalServiceBaseImpl;
import analysisService.service.enums.ButtonPositions;
import analysisService.service.persistence.ClickCountPK;
/**
* The implementation of the session time local service.
......@@ -40,12 +48,59 @@ public class SessionTimeLocalServiceImpl extends SessionTimeLocalServiceBaseImpl
* Never reference this class directly. Always use {@link analysisService.service.SessionTimeLocalServiceUtil} to access the session time local service.
*/
public long addNewSession(long time){
public long addNewSession(Date time, String groupID){
SessionTime newSessionTime = new SessionTimeImpl();
newSessionTime.setStartTime(time);
newSessionTime.setGroupID(groupID);
SessionTimeLocalServiceUtil.addSessionTime(newSessionTime);
return newSessionTime.getPrimaryKey();
}
/**
* groupID : String : ID of the portal. Used to track the session length.
* buttonID : String : Used to keep track of clicks on the button based on ID
* ButtonPositions : ENUM : FIRST - LAST - MIDDLE
* sessionID : If it's the first click, send default sessionID - 0
* returns the sessionID after logging the click
*/
public long trackClick(String groupID, String buttonID, ButtonPositions position, long sessionID){
DateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.S");
ClickCount trackClickObject;
if(ClickCountLocalServiceUtil.fetchClickCount(new ClickCountPK(groupID, buttonID))==null){
trackClickObject = ClickCountLocalServiceUtil.createClickCount(new ClickCountPK(groupID, buttonID));
trackClickObject.setCount(1);
}else{
trackClickObject = ClickCountLocalServiceUtil.fetchClickCount(new ClickCountPK(groupID, buttonID));
trackClickObject.setCount(trackClickObject.getCount()+1);
}
ClickCountLocalServiceUtil.updateClickCount(trackClickObject);
//Create date object with format : yyyy/MM/dd HH:mm:ss.S
DateFormat df = DateFormat.getDateInstance();
Date timeNow = new Date();
try{
timeNow = df.parse(sdf.format(new Date()));
}catch(Exception ex){
}
//create an object for session tracking
SessionTime testSession ;
//check for default value, meaning session has not been stored in service builder yet
if("First".equals(position.getButtonPositionDescription())&&sessionID==0){
return(SessionTimeLocalServiceUtil.addNewSession(timeNow, groupID));
}
if("Last".equals(position.getButtonPositionDescription())&&sessionID!=0)
{
testSession = SessionTimeLocalServiceUtil.fetchSessionTime(sessionID);
if(testSession!=null){
testSession.setEndTime(timeNow);
}
SessionTimeLocalServiceUtil.updateSessionTime(testSession);
}
return sessionID;
}
}
\ No newline at end of file
......@@ -32,7 +32,7 @@
<generator class="increment" />
</id>
<property name="GroupID" type="com.liferay.portal.dao.orm.hibernate.StringType" />
<property name="StartTime" type="com.liferay.portal.dao.orm.hibernate.LongType" />
<property name="EndTime" type="com.liferay.portal.dao.orm.hibernate.LongType" />
<property name="StartTime" type="org.hibernate.type.TimestampType" />
<property name="EndTime" type="org.hibernate.type.TimestampType" />
</class>
</hibernate-mapping>
\ No newline at end of file
......@@ -22,7 +22,7 @@
<model name="analysisService.model.SessionTime">
<field name="SessionID" type="long" />
<field name="GroupID" type="String" />
<field name="StartTime" type="long" />
<field name="EndTime" type="long" />
<field name="StartTime" type="Date" />