Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAppConstants.java =================================================================== diff -u -rcad6df7d203a1565dbbedf61b9088288ed13c19c -r5e1d707c3adf190cd76bb2459b89a60d511e7077 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAppConstants.java (.../McAppConstants.java) (revision cad6df7d203a1565dbbedf61b9088288ed13c19c) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAppConstants.java (.../McAppConstants.java) (revision 5e1d707c3adf190cd76bb2459b89a60d511e7077) @@ -65,6 +65,7 @@ /* these constants are from org.lamsfoundation.lams.web.util.AttributeNames */ public static final String USER = "user"; public static final String TOOL_CONTENT_ID = "toolContentID"; + public static final String TOOL_CONTENT_UID = "toolContentUID"; public static final String TOOL_SESSION_ID = "toolSessionID"; public static final String MODE = "mode"; public static final String USER_ID = "userID"; Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUsrAttempt.java =================================================================== diff -u -r25a3cd766f44f20c25042ad630f87b5b79a53671 -r5e1d707c3adf190cd76bb2459b89a60d511e7077 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUsrAttempt.java (.../McUsrAttempt.java) (revision 25a3cd766f44f20c25042ad630f87b5b79a53671) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUsrAttempt.java (.../McUsrAttempt.java) (revision 5e1d707c3adf190cd76bb2459b89a60d511e7077) @@ -79,6 +79,8 @@ } + + /** default constructor */ public McUsrAttempt() { } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUtils.java =================================================================== diff -u -r434092d51899472f987f50d982a6c151874f93d5 -r5e1d707c3adf190cd76bb2459b89a60d511e7077 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUtils.java (.../McUtils.java) (revision 434092d51899472f987f50d982a6c151874f93d5) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUtils.java (.../McUtils.java) (revision 5e1d707c3adf190cd76bb2459b89a60d511e7077) @@ -51,8 +51,83 @@ IMcService mcService=(IMcService)request.getSession().getAttribute(TOOL_SERVICE); return mcService; } + + /** + * + * getGMTDateTime(HttpServletRequest request) + * + * @param request + * @return + */ + /* fix this */ + public static Date getGMTDateTime() + { + Date date=new Date(System.currentTimeMillis()); + logger.debug("date: " + date); + return date; + } + + public static UserDTO getToolUser() + { + /*obtain user object from the session*/ + HttpSession ss = SessionManager.getSession(); + /* get back login user DTO */ + UserDTO toolUser = (UserDTO) ss.getAttribute(AttributeNames.USER); + logger.debug("retrieving toolUser: " + toolUser); + return toolUser; + } + + public static Long getUserId() + { + UserDTO toolUser=getToolUser(); + long userId=toolUser.getUserID().longValue(); + logger.debug("userId: " + userId); + return new Long(userId); + } + + public static String getUserName() + { + /* double check if username and login is the same */ + UserDTO toolUser=getToolUser(); + String userName=toolUser.getLogin(); + logger.debug("userName: " + userName); + return userName; + } + + public static String getUserFullName() + { + UserDTO toolUser=getToolUser(); + String fullName=toolUser.getFirstName() + " " + toolUser.getLastName(); + logger.debug("fullName: " + fullName); + return fullName; + } + + public static String getFormattedDateString(Date date) + { + logger.debug(logger + " " + " McUtils getFormattedDateString: " + + DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(date)); + return (DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(date)); + } + + public static void persistTimeZone(HttpServletRequest request) + { + TimeZone timeZone=TimeZone.getDefault(); + logger.debug("current timezone: " + timeZone.getDisplayName()); + request.getSession().setAttribute(TIMEZONE, timeZone.getDisplayName()); + logger.debug("current timezone id: " + timeZone.getID()); + request.getSession().setAttribute(TIMEZONE_ID, timeZone.getID()); + } + + public static String getCurrentTimeZone() + { + TimeZone timeZone=TimeZone.getDefault(); + logger.debug("current timezone: " + timeZone.getDisplayName()); + return timeZone.getDisplayName(); + } + + /** * existsContent(long toolContentId) * @param long toolContentId @@ -135,23 +210,6 @@ } - public static String getFormattedDateString(Date date) - { - logger.debug(logger + " " + " McUtils getFormattedDateString: " + - DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(date)); - return (DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(date)); - } - - public static void persistTimeZone(HttpServletRequest request) - { - TimeZone timeZone=TimeZone.getDefault(); - logger.debug("current timezone: " + timeZone.getDisplayName()); - request.getSession().setAttribute(TIMEZONE, timeZone.getDisplayName()); - logger.debug("current timezone id: " + timeZone.getID()); - request.getSession().setAttribute(TIMEZONE_ID, timeZone.getID()); - } - - public static void persistRichText(HttpServletRequest request) { String richTextOfflineInstructions=request.getParameter(RICHTEXT_OFFLINEINSTRUCTIONS); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcQueContentDAO.java =================================================================== diff -u -r25a3cd766f44f20c25042ad630f87b5b79a53671 -r5e1d707c3adf190cd76bb2459b89a60d511e7077 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcQueContentDAO.java (.../IMcQueContentDAO.java) (revision 25a3cd766f44f20c25042ad630f87b5b79a53671) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcQueContentDAO.java (.../IMcQueContentDAO.java) (revision 5e1d707c3adf190cd76bb2459b89a60d511e7077) @@ -53,6 +53,8 @@ */ public McQueContent getToolDefaultQuestionContent(final long mcContentId); + + /** * *

Return the persistent instance of a McQueContent * with the given identifier question and mcContentUid, returns null if not found.

@@ -64,6 +66,16 @@ public McQueContent getQuestionContentByQuestionText(final String question, final Long mcContentUid); /** + * *

Return the persistent instance of a McQueContent + * with the given identifier displayOrder and mcContentUid, returns null if not found.

+ * + * @param displayOrder + * @param mcContentUid + * @return McQueContent + */ + public McQueContent getQuestionContentByDisplayOrder(final Long displayOrder, final Long mcContentUid); + + /** * *

Return a list of McQueContent * with the given identifier question and mcContentUid, returns null if not found.

* Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McQueContentDAO.java =================================================================== diff -u -re47ae0076c4cd0eae4874a006baaaa8da251c667 -r5e1d707c3adf190cd76bb2459b89a60d511e7077 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McQueContentDAO.java (.../McQueContentDAO.java) (revision e47ae0076c4cd0eae4874a006baaaa8da251c667) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McQueContentDAO.java (.../McQueContentDAO.java) (revision 5e1d707c3adf190cd76bb2459b89a60d511e7077) @@ -49,6 +49,10 @@ private static final String REFRESH_QUESTION_CONTENT = "from mcQueContent in class McQueContent where mcQueContent.mcContentId=:mcContentId and mcQueContent.disabled=false order by mcQueContent.displayOrder"; private static final String LOAD_QUESTION_CONTENT_BY_QUESTION_TEXT = "from mcQueContent in class McQueContent where mcQueContent.question=:question and mcQueContent.mcContentId=:mcContentUid"; + + private static final String LOAD_QUESTION_CONTENT_BY_DISPLAY_ORDER = "from mcQueContent in class McQueContent where mcQueContent.displayOrder=:displayOrder and mcQueContent.mcContentId=:mcContentUid"; + + public McQueContent getMcQueContentByUID(Long uid) @@ -72,6 +76,7 @@ return null; } + public List getAllQuestionEntries(final long mcContentId) { HibernateTemplate templ = this.getHibernateTemplate(); @@ -108,6 +113,23 @@ return null; } + + public McQueContent getQuestionContentByDisplayOrder(final Long displayOrder, final Long mcContentUid) + { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_QUESTION_CONTENT_BY_DISPLAY_ORDER) + .setLong("displayOrder", displayOrder.longValue()) + .setLong("mcContentUid", mcContentUid.longValue()) + .list(); + + if(list != null && list.size() > 0){ + McQueContent mcq = (McQueContent) list.get(0); + return mcq; + } + return null; + } + + public void removeQuestionContentByMcUid(final Long mcContentUid) { HibernateTemplate templ = this.getHibernateTemplate(); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java =================================================================== diff -u -r9310fe30da9974d1f174319efc054e3bde9eed84 -r5e1d707c3adf190cd76bb2459b89a60d511e7077 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java (.../IMcService.java) (revision 9310fe30da9974d1f174319efc054e3bde9eed84) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java (.../IMcService.java) (revision 5e1d707c3adf190cd76bb2459b89a60d511e7077) @@ -58,11 +58,13 @@ public void createMcQue(McQueContent mcQueContent) throws McApplicationException; + public McQueContent getQuestionContentByDisplayOrder(final Long displayOrder, final Long mcContentUid) throws McApplicationException; + public void createMcSession(McSession mcSession) throws McApplicationException; public void createMcQueUsr(McQueUsr mcQueUsr) throws McApplicationException; - public McQueUsr retrieveMcQueUsr(Long userId) throws McApplicationException; + public McQueUsr retrieveMcQueUsr(Long userId) throws McApplicationException; public void createMcUsrAttempt(McUsrAttempt mcUsrAttempt) throws McApplicationException; Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java =================================================================== diff -u -r3df81dc2e2e2f813fca6da1baf53c3e5ab43cfec -r5e1d707c3adf190cd76bb2459b89a60d511e7077 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java (.../McServicePOJO.java) (revision 3df81dc2e2e2f813fca6da1baf53c3e5ab43cfec) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java (.../McServicePOJO.java) (revision 5e1d707c3adf190cd76bb2459b89a60d511e7077) @@ -172,7 +172,21 @@ } } + public McQueContent getQuestionContentByDisplayOrder(final Long displayOrder, final Long mcContentUid) throws McApplicationException + { + try + { + return mcQueContentDAO.getQuestionContentByDisplayOrder(displayOrder, mcContentUid); + } + catch (DataAccessException e) + { + throw new McApplicationException("Exception occured when lams is getting mc que content by display order: " + + e.getMessage(), + e); + } + } + public void saveOrUpdateMcQueContent(McQueContent mcQueContent) throws McApplicationException { try Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/LearningUtil.java =================================================================== diff -u -r690cf7460e6899ac1279fc823d9819a2060744b1 -r5e1d707c3adf190cd76bb2459b89a60d511e7077 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/LearningUtil.java (.../LearningUtil.java) (revision 690cf7460e6899ac1279fc823d9819a2060744b1) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/LearningUtil.java (.../LearningUtil.java) (revision 5e1d707c3adf190cd76bb2459b89a60d511e7077) @@ -3,10 +3,12 @@ */ package org.lamsfoundation.lams.tool.mc.web; +import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.TreeMap; +import java.util.TreeSet; import javax.servlet.http.HttpServletRequest; @@ -16,6 +18,9 @@ import org.lamsfoundation.lams.tool.mc.McContent; import org.lamsfoundation.lams.tool.mc.McOptsContent; import org.lamsfoundation.lams.tool.mc.McQueContent; +import org.lamsfoundation.lams.tool.mc.McQueUsr; +import org.lamsfoundation.lams.tool.mc.McSession; +import org.lamsfoundation.lams.tool.mc.McUsrAttempt; import org.lamsfoundation.lams.tool.mc.McUtils; import org.lamsfoundation.lams.tool.mc.service.IMcService; @@ -361,4 +366,131 @@ return false; } + + /** + * creates the user in the db + * createUser(HttpServletRequest request) + * + * @param request + */ + public static void createUser(HttpServletRequest request) + { + IMcService mcService =McUtils.getToolService(request); + Long queUsrId=McUtils.getUserId(); + logger.debug("queUsrId: " + queUsrId); + + String username=McUtils.getUserName(); + logger.debug("userName: " + username); + + String fullname=McUtils.getUserFullName(); + logger.debug("fullName: " + fullname); + + Long toolSessionId=(Long) request.getSession().getAttribute(TOOL_SESSION_ID); + logger.debug("toolSessionId: " + toolSessionId); + + McSession mcSession=mcService.retrieveMcSession(toolSessionId); + logger.debug("retrieving mcSession: " + mcSession); + + McQueUsr mcQueUsr= new McQueUsr(queUsrId, + username, + fullname, + mcSession, + new TreeSet()); + logger.debug("created mcQueUsr : " + mcQueUsr); + mcService.createMcQueUsr(mcQueUsr); + logger.debug("created mcQueUsr in the db: " + mcQueUsr); + } + + + /** + * checks if the user is in the db + * doesUserExists(HttpServletRequest request) + * + * @param request + */ + public static boolean doesUserExists(HttpServletRequest request) + { + IMcService mcService =McUtils.getToolService(request); + Long queUsrId=McUtils.getUserId(); + logger.debug("queUsrId: " + queUsrId); + + McQueUsr mcQueUsr=mcService.retrieveMcQueUsr(queUsrId); + logger.debug("mcQueUsr: " + mcQueUsr); + + if (mcQueUsr != null) + return true; + + return false; + } + + + public static McQueUsr getUser(HttpServletRequest request) + { + IMcService mcService =McUtils.getToolService(request); + Long queUsrId=McUtils.getUserId(); + logger.debug("queUsrId: " + queUsrId); + + McQueUsr mcQueUsr=mcService.retrieveMcQueUsr(queUsrId); + logger.debug("mcQueUsr: " + mcQueUsr); + + return mcQueUsr; + } + + + + /** + * creates a user attempt in the db + * createAttempt(HttpServletRequest request) + * + * @param request + */ + public static void createAttempt(HttpServletRequest request, McQueUsr mcQueUsr, Map mapGeneralCheckedOptionsContent) + { + IMcService mcService =McUtils.getToolService(request); + Date attempTime=McUtils.getGMTDateTime(); + logger.debug("attempTime: " + attempTime); + + String timeZone= McUtils.getCurrentTimeZone(); + logger.debug("timeZone: " + timeZone); + + Long toolContentUID= (Long) request.getSession().getAttribute(TOOL_CONTENT_UID); + logger.debug("toolContentUID: " + toolContentUID); + + Iterator itCheckedMap = mapGeneralCheckedOptionsContent.entrySet().iterator(); + while (itCheckedMap.hasNext()) + { + Map.Entry checkedPairs = (Map.Entry)itCheckedMap.next(); + logger.debug("using the pair: " + checkedPairs.getKey() + " = " + checkedPairs.getValue()); + + Map mapCheckedOptions=(Map) checkedPairs.getValue(); + logger.debug("question index:" + checkedPairs.getKey()+ " options: "+ mapCheckedOptions); + Long questionDisplayOrder=new Long(checkedPairs.getKey().toString()); + logger.debug("questionDisplayOrder:" + questionDisplayOrder); + + McQueContent mcQueContent=mcService.getQuestionContentByDisplayOrder(questionDisplayOrder, toolContentUID); + logger.debug("mcQueContent:" + mcQueContent); + createIndividualOptions(request, mapCheckedOptions, mcQueContent, mcQueUsr, attempTime, timeZone); + } + } + + + public static void createIndividualOptions(HttpServletRequest request, Map mapCheckedOptions, McQueContent mcQueContent, McQueUsr mcQueUsr, Date attempTime, String timeZone) + { + IMcService mcService =McUtils.getToolService(request); + + Iterator itCheckedMap = mapCheckedOptions.entrySet().iterator(); + while (itCheckedMap.hasNext()) + { + Map.Entry checkedPairs = (Map.Entry)itCheckedMap.next(); + logger.debug("option value :" + checkedPairs.getValue()); + McOptsContent mcOptsContent= mcService.getOptionContentByOptionText(checkedPairs.getValue().toString(), mcQueContent.getUid()); + logger.debug("mcOptsContent :" + mcOptsContent); + McUsrAttempt mcUsrAttempt=new McUsrAttempt(attempTime, timeZone, mcQueContent, mcQueUsr, mcOptsContent); + logger.debug("mcUsrAttempt :" + mcUsrAttempt); + mcService.createMcUsrAttempt(mcUsrAttempt); + logger.debug("created mcUsrAttempt in the db :" + mcUsrAttempt); + } + } + + } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAction.java =================================================================== diff -u -rcad6df7d203a1565dbbedf61b9088288ed13c19c -r5e1d707c3adf190cd76bb2459b89a60d511e7077 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAction.java (.../McAction.java) (revision cad6df7d203a1565dbbedf61b9088288ed13c19c) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAction.java (.../McAction.java) (revision 5e1d707c3adf190cd76bb2459b89a60d511e7077) @@ -49,6 +49,7 @@ import org.lamsfoundation.lams.tool.mc.McContent; import org.lamsfoundation.lams.tool.mc.McOptsContent; import org.lamsfoundation.lams.tool.mc.McQueContent; +import org.lamsfoundation.lams.tool.mc.McQueUsr; import org.lamsfoundation.lams.tool.mc.McUtils; import org.lamsfoundation.lams.tool.mc.service.IMcService; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; @@ -2114,7 +2115,18 @@ logger.debug("will assess"); LearningUtil.assess(request, mapGeneralCheckedOptionsContent, toolContentId); logger.debug("assesment complete"); - + + boolean isUserDefined=LearningUtil.doesUserExists(request); + logger.debug("isUserDefined"); + if (isUserDefined == false) + { + LearningUtil.createUser(request); + logger.debug("created user in the db"); + } + McQueUsr mcQueUsr=LearningUtil.getUser(request); + logger.debug("mcQueUsr: " + mcQueUsr); + LearningUtil.createAttempt(request, mcQueUsr, mapGeneralCheckedOptionsContent); + logger.debug("created user attempt in the db"); mcLearningForm.resetCommands(); return (mapping.findForward(INDIVIDUAL_REPORT)); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningStarterAction.java =================================================================== diff -u -rcad6df7d203a1565dbbedf61b9088288ed13c19c -r5e1d707c3adf190cd76bb2459b89a60d511e7077 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningStarterAction.java (.../McLearningStarterAction.java) (revision cad6df7d203a1565dbbedf61b9088288ed13c19c) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningStarterAction.java (.../McLearningStarterAction.java) (revision 5e1d707c3adf190cd76bb2459b89a60d511e7077) @@ -177,6 +177,9 @@ request.getSession().setAttribute(TOOL_CONTENT_ID, mcContent.getMcContentId()); logger.debug("using TOOL_CONTENT_ID: " + mcContent.getMcContentId()); + request.getSession().setAttribute(TOOL_CONTENT_UID, mcContent.getUid()); + logger.debug("using TOOL_CONTENT_UID: " + mcContent.getUid()); + /* * The content we retrieved above must have been created before in Authoring time. * And the passed tool session id already refers to it. Index: lams_tool_lamc/web/IndividualLearnerResults.jsp =================================================================== diff -u -rcad6df7d203a1565dbbedf61b9088288ed13c19c -r5e1d707c3adf190cd76bb2459b89a60d511e7077 --- lams_tool_lamc/web/IndividualLearnerResults.jsp (.../IndividualLearnerResults.jsp) (revision cad6df7d203a1565dbbedf61b9088288ed13c19c) +++ lams_tool_lamc/web/IndividualLearnerResults.jsp (.../IndividualLearnerResults.jsp) (revision 5e1d707c3adf190cd76bb2459b89a60d511e7077) @@ -97,7 +97,7 @@ - + @@ -121,7 +121,7 @@ - +