Commit a1fbd807 authored by sdhaul's avatar sdhaul

Changes in srvUserInfo service to get course history of the user.

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@199545 ce508802-f39f-4f6c-b175-0d175dae99d5
parent a0bb8739
......@@ -5,7 +5,9 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -175,6 +177,57 @@ public class CourseDAO
return courseContentsArray;
}
public JSONObject getCourseContentsDetail(String courseCode)
{
System.out.println("getCourseContentsDetail of "+courseCode);
long contentsDuration = 0;
int videosCount = 0;
JSONObject contentDetails = new JSONObject();
try
{
String tranDB = this.userInfo.getTransDB();
List<CourseContent> courseContentList = getCourseContents(courseCode);
if( courseContentList !=null && !courseContentList.isEmpty() )
{
videosCount = courseContentList.size();
for( CourseContent courseContent : courseContentList )
{
String docId = getDocId(courseContent.getAttachment(), tranDB); // DOC_ID
DocContents docContents = getDocContents(docId, tranDB);
if( docContents != null )
{
String fileMetadata = checkNull(docContents.getFileMetadata());
try
{
JSONObject filemetadataJson = new JSONObject(fileMetadata);
String duration = filemetadataJson.getString("duration");
contentsDuration = contentsDuration + Long.parseLong(duration);
}
catch (Exception e)
{
System.out.println("Exception In CourseDAO" + e);
}
}
}
contentDetails.put("videos_count", videosCount);
contentDetails.put("total_duration", contentsDuration);
}
}
catch (Exception e)
{
BaseLogger.log("0", null, null, "Exception : getCourseContents::::::::: ");
BaseLogger.log("0", null, null, e.getMessage());
e.printStackTrace();
}
System.out.println("contentDetails in getCourseContentsDetail"+contentDetails);
return contentDetails;
}
private JSONArray getCourseQuestions(String courseCode)
{
JSONArray courseQuestionsArray = new JSONArray();
......
package ibase.dashboard.common.webService;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
......@@ -25,10 +27,13 @@ import org.json.JSONObject;
import ibase.dashboard.common.hibernate.bean.Course;
import ibase.dashboard.common.hibernate.bean.CourseAttend;
import ibase.dashboard.common.hibernate.bean.CourseContent;
import ibase.dashboard.common.hibernate.bean.CourseContentAtt;
import ibase.dashboard.common.hibernate.dao.CourseDAO;
import ibase.dashboard.common.hibernate.dao.CustomerInfoDao;
import ibase.utility.BaseException;
import ibase.utility.BaseLogger;
import ibase.utility.E12GenericUtility;
import ibase.utility.UserInfoBean;
@Path("/api")
......@@ -243,74 +248,102 @@ public class CourseAPIService
//For Servgyan User Information Dashboard
@GET
@Path("/srvUserInfo/{userCode}")
@Path("/srvUserInfo")
@Produces(MediaType.APPLICATION_JSON)
public String getSrvUserInfo(@PathParam("userCode") String userCode) throws Exception
public String getSrvUserInfo(@QueryParam("user_id") String userCode) throws Exception
{
System.out.println("In getSrvUserInfo:: strgCode["+userCode+"]");
System.out.println("Inside srvUserInfo "+userCode );
JSONObject srvUserInfoObj = new JSONObject();
JSONObject courseHistoryJson = new JSONObject();
JSONArray courseHistoryArray = new JSONArray();
UserInfoBean userInfo = getUserInfo();
String tranDb="";
String displayDateFormat;
E12GenericUtility genericUtility = new E12GenericUtility();
HashMap<String, JSONObject> courseHistoryMap = new HashMap<String, JSONObject> ();
try
{
if( userInfo != null )
if( userInfo != null && userCode != null )
{
tranDb=userInfo.getTransDB();
CourseDAO courseDao = new CourseDAO();
tranDb = userInfo.getTransDB();
displayDateFormat = genericUtility.getDispDateFormat();
courseDao.setUserInfo(userInfo);
srvUserInfoObj = courseDao.getSrvUserInfoData(userCode);
JSONArray srvCourseDetArray = new JSONArray();
List<CourseAttend> courseAttendList = courseDao.getUserCourses(userCode,tranDb);
if(courseAttendList != null && !courseAttendList.isEmpty())
{
for( CourseAttend courseAttend : courseAttendList )
{
JSONObject courseContentJSON = new JSONObject();
String courseCode = courseAttend.getCourseCode();
Course course = courseDao.getCourse(courseCode);
List<CourseAttend> courseContentList=courseDao.getUserCourses(userCode,tranDb);
String courseName = course.getDescr();
Date courseDate = course.getStartDate();
String courseDateStr = genericUtility.getValidDateTimeString(courseDate, displayDateFormat);
if(courseContentList != null && !courseContentList.isEmpty()) {
JSONObject courseContentDet = courseDao.getCourseContentsDetail(courseCode);
int videosCount = courseContentDet.optInt("videos_count");
long contentsDuration = courseContentDet.optLong("total_duration");
for( CourseAttend courseContent : courseContentList )
{
JSONObject courseDet=new JSONObject();
String courseCode=courseContent.getCourseCode();
System.out.println("course code "+courseCode);
if(courseCode != null) {
List<CourseContentAtt> courseContentDet= courseDao.getUserCourseContents(courseCode,userCode,tranDb);
if(courseContentDet != null && !courseContentDet.isEmpty()) {
courseContentJSON.put("COURSE_ID", courseCode);
courseContentJSON.put("COURSE_NAME", courseName);
courseContentJSON.put("COURSE_DATE", courseDateStr);
courseContentJSON.put("COURSE_TIME_START", "");
courseContentJSON.put("COURSE_SUMMARY", "");
courseContentJSON.put("COURSE_DURATION", contentsDuration);
courseContentJSON.put("COURSE_VIDEOS_COUNT", videosCount);
for( CourseContentAtt courseContDet : courseContentDet )
JSONArray existingCourses = courseHistoryJson.optJSONArray(courseDateStr);
if(existingCourses == null)
{
String contentName=courseContDet.getContentName();
String accessPos=courseContDet.getAccessPos();
String accessStat=courseContDet.getAcessStat();
Date lastAccessDate=courseContDet.getLastAccDate();
JSONObject courseContentJSON=new JSONObject();
courseContentJSON.put("CONTENT_NAME", contentName);
courseContentJSON.put("ACCESS_POS", accessPos);
courseContentJSON.put("ACCESS_STAT", accessStat);
courseContentJSON.put("LAST_ACCESS_DATE", lastAccessDate);
courseDet.put(courseCode, courseContentJSON);
System.out.println("OBJECT "+courseDet);
srvCourseDetArray.put(courseDet);
}
existingCourses = new JSONArray();
}
existingCourses.put(courseContentJSON);
courseHistoryJson.put(courseDateStr, existingCourses);
}
JSONObject courseHistoryDet = new JSONObject();
long totalCourseDuration = 0;
int totalCourses = 0;
int totalVideos = 0;
if(courseHistoryMap.containsKey(courseDateStr))
{
courseHistoryDet = courseHistoryMap.get(courseDateStr);
totalCourseDuration = courseHistoryDet.optLong("TOTAL_COURSE_DURATION");
totalCourses = courseHistoryDet.optInt("COURSES_COUNT");
totalVideos = courseHistoryDet.optInt("VIDEOS_COUNT");
}
totalCourseDuration = totalCourseDuration + contentsDuration;
totalCourses = totalCourses + 1;
totalVideos = totalVideos + videosCount;
courseHistoryDet.put("TOTAL_COURSE_DURATION", totalCourseDuration);
courseHistoryDet.put("COURSES_COUNT", totalCourses);
courseHistoryDet.put("VIDEOS_COUNT", totalVideos);
courseHistoryDet.put("COURSES", existingCourses);
courseHistoryMap.put(courseDateStr, courseHistoryDet);
}
srvUserInfoObj.put("COURSE_DATA", srvCourseDetArray);
for (String courseDate : courseHistoryMap.keySet())
{
JSONObject totalCourseHist = courseHistoryMap.get(courseDate);
courseHistoryArray.put(totalCourseHist);
}
srvUserInfoObj.put("COURSE_HISTORY", courseHistoryArray);
}
}
}
catch (Exception e)
{
e.printStackTrace();
srvUserInfoObj.put("status", "Failure" );
srvUserInfoObj = new JSONObject();
srvUserInfoObj.put("status", "failure" );
}
System.out.println("In getSrvUserInfo:: srvUserInfoObj["+srvUserInfoObj+"]");
return srvUserInfoObj.toString();
}
......
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