Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/QaAppConstants.java =================================================================== diff -u -r792f3d848039cb49080fbaf49d9bc2b2d461943e -r45a3263a49a830c6e5392591ccd854264c5e6730 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/QaAppConstants.java (.../QaAppConstants.java) (revision 792f3d848039cb49080fbaf49d9bc2b2d461943e) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/QaAppConstants.java (.../QaAppConstants.java) (revision 45a3263a49a830c6e5392591ccd854264c5e6730) @@ -64,7 +64,8 @@ public static final String DEFINE_LATER ="defineLater"; public static final String REQUESTED_MODULE ="requestedModule"; - public static final String SOURCE_MC_STARTER ="sourceMcStarter"; + public static final String SOURCE_MC_STARTER ="sourceMcStarter"; + public static final Integer MAX_QUESTION_COUNT =new Integer(50); public static final String IS_MONITORED_CONTENT_IN_USE ="isMonitoredContentInUse"; public static final String LOAD_MONITORING_CONTENT_EDITACTIVITY ="loadMonitoringEditActivity"; @@ -139,7 +140,8 @@ public static final String USER_EXCEPTION_CONTENT_DEFINE_LATER ="userExceptionContentDefineLater"; public static final String USER_EXCEPTION_RUN_OFFLINE ="userExceptionRunOffline"; public static final String USER_EXCEPTION_MODE_REQUIRED ="userExceptionModeRequired"; - public static final String USER_EXCEPTION_MODE_INVALID ="userExceptionModeInvalid"; + public static final String USER_EXCEPTION_MODE_INVALID ="userExceptionModeInvalid"; + public static final String USER_EXCEPTION_QUESTIONS_DUPLICATE ="userExceptionQuestionsDuplicate"; public static final String COUNT_SESSION_COMPLETE ="countSessionComplete"; public static final String CURRENT_MONITORED_TOOL_SESSION ="currentMonitoredToolSession"; Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/QaResources.properties =================================================================== diff -u -rd1cdabac4d9bf576c83d0130e74684cc9914b8e4 -r45a3263a49a830c6e5392591ccd854264c5e6730 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/QaResources.properties (.../QaResources.properties) (revision d1cdabac4d9bf576c83d0130e74684cc9914b8e4) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/QaResources.properties (.../QaResources.properties) (revision 45a3263a49a830c6e5392591ccd854264c5e6730) @@ -142,6 +142,7 @@ error.learningUser.notAvailable =Tool Activity Error! Can't continue. Tool Activity expects a user id. error.learner.userId.required ==Tool Activity Error! Can't continue. Tool Activity expects learner's user id. error.noLearnerActivity =Summary report is not available since no users attempted the activity yet. +error.questions.duplicate =Please correct this: The questions must be unique. #Monitoring mode resources button.startLesson =Start Lesson Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/QaUtils.java =================================================================== diff -u -r792f3d848039cb49080fbaf49d9bc2b2d461943e -r45a3263a49a830c6e5392591ccd854264c5e6730 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/QaUtils.java (.../QaUtils.java) (revision 792f3d848039cb49080fbaf49d9bc2b2d461943e) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/QaUtils.java (.../QaUtils.java) (revision 45a3263a49a830c6e5392591ccd854264c5e6730) @@ -554,6 +554,7 @@ request.getSession().removeAttribute(USER_EXCEPTION_MODE_REQUIRED); request.getSession().removeAttribute(USER_EXCEPTION_RUN_OFFLINE); request.getSession().removeAttribute(USER_EXCEPTION_MODE_INVALID); + request.getSession().removeAttribute(USER_EXCEPTION_QUESTIONS_DUPLICATE); } Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/IQaQueContentDAO.java =================================================================== diff -u -r7affae8017cd4fc74dc2316f2104740253241228 -r45a3263a49a830c6e5392591ccd854264c5e6730 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/IQaQueContentDAO.java (.../IQaQueContentDAO.java) (revision 7affae8017cd4fc74dc2316f2104740253241228) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/IQaQueContentDAO.java (.../IQaQueContentDAO.java) (revision 45a3263a49a830c6e5392591ccd854264c5e6730) @@ -46,11 +46,15 @@ public void removeQueContent(long qaQueContentId); + public void removeQaQueContent(QaQueContent qaQueContent); + public List getQaQueContentsByContentId(long qaContentId); public List getAllQuestionEntries(final long qaContentId); public QaQueContent getQuestionContentByQuestionText(final String question, Long qaContentId); public QaQueContent getQuestionContentByDisplayOrder(Long displayOrder, Long qaContentId); + + public List getAllQuestionEntriesSorted(final long qaContentId); } Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/hibernate/QaQueContentDAO.java =================================================================== diff -u -r7affae8017cd4fc74dc2316f2104740253241228 -r45a3263a49a830c6e5392591ccd854264c5e6730 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/hibernate/QaQueContentDAO.java (.../QaQueContentDAO.java) (revision 7affae8017cd4fc74dc2316f2104740253241228) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/hibernate/QaQueContentDAO.java (.../QaQueContentDAO.java) (revision 45a3263a49a830c6e5392591ccd854264c5e6730) @@ -29,6 +29,7 @@ import org.hibernate.Session; import org.apache.log4j.Logger; + import org.lamsfoundation.lams.tool.qa.QaContent; import org.lamsfoundation.lams.tool.qa.QaQueContent; import org.lamsfoundation.lams.tool.qa.dao.IQaQueContentDAO; @@ -52,7 +53,8 @@ private static final String GET_QUESTION_IDS_FOR_CONTENT = "select qaQueContent.qaQueContentId from QaQueContent qaQueContent where qaQueContent.qaContentId = :qa"; private static final String LOAD_QUESTION_CONTENT_BY_QUESTION_TEXT = "from qaQueContent in class QaQueContent where qaQueContent.question=:question and qaQueContent.qaContentId=:qaContentId"; private static final String LOAD_QUESTION_CONTENT_BY_DISPLAY_ORDER = "from qaQueContent in class QaQueContent where qaQueContent.displayOrder=:displayOrder and qaQueContent.qaContentId=:qaContentId"; - + private static final String SORT_QUESTION_CONTENT_BY_DISPLAY_ORDER = "from qaQueContent in class QaQueContent where qaQueContent.qaContentId=:qaContentId order by qaQueContent.displayOrder"; + public QaQueContent getToolDefaultQuestionContent(final long qaContentId) { return (QaQueContent) getHibernateTemplate().execute(new HibernateCallback() @@ -116,7 +118,17 @@ return null; } + public List getAllQuestionEntriesSorted(final long qaContentId) + { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(SORT_QUESTION_CONTENT_BY_DISPLAY_ORDER) + .setLong("qaContentId", qaContentId) + .list(); + return list; + } + + public List getQuestionIndsForContent(QaContent qa) { @@ -157,6 +169,14 @@ this.getSession().setFlushMode(FlushMode.AUTO); this.getHibernateTemplate().delete(qaQueContent); } + + + public void removeQaQueContent(QaQueContent qaQueContent) + { + this.getSession().setFlushMode(FlushMode.AUTO); + this.getHibernateTemplate().delete(qaQueContent); + } + public List getQaQueContentsByContentId(long qaContentId){ return getHibernateTemplate().findByNamedParam(LOAD_QUESTION_CONTENT_BY_CONTENT_ID, "qaContentId", new Long(qaContentId)); Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/IQaService.java =================================================================== diff -u -r7affae8017cd4fc74dc2316f2104740253241228 -r45a3263a49a830c6e5392591ccd854264c5e6730 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/IQaService.java (.../IQaService.java) (revision 7affae8017cd4fc74dc2316f2104740253241228) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/IQaService.java (.../IQaService.java) (revision 45a3263a49a830c6e5392591ccd854264c5e6730) @@ -33,8 +33,8 @@ import org.lamsfoundation.lams.tool.qa.QaQueContent; import org.lamsfoundation.lams.tool.qa.QaQueUsr; import org.lamsfoundation.lams.tool.qa.QaSession; -import org.lamsfoundation.lams.tool.qa.QaUsrResp; import org.lamsfoundation.lams.tool.qa.QaUploadedFile; +import org.lamsfoundation.lams.tool.qa.QaUsrResp; import org.lamsfoundation.lams.usermanagement.User; @@ -86,6 +86,8 @@ public void createQaQue(QaQueContent qaQueContent) throws QaApplicationException; + public void removeQaQueContent(QaQueContent qaQueContent) throws QaApplicationException; + public void createQaUsrResp(QaUsrResp qaUsrResp) throws QaApplicationException; public QaUsrResp retrieveQaUsrResp(long responseId) throws QaApplicationException; @@ -96,6 +98,8 @@ public QaQueContent getQuestionContentByDisplayOrder(Long displayOrder, Long contentUid) throws QaApplicationException; + public List getAllQuestionEntriesSorted(final long qaContentId) throws QaApplicationException; + public void updateQaQueContent(QaQueContent qaQueContent) throws QaApplicationException; /** Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaServicePOJO.java =================================================================== diff -u -r7affae8017cd4fc74dc2316f2104740253241228 -r45a3263a49a830c6e5392591ccd854264c5e6730 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaServicePOJO.java (.../QaServicePOJO.java) (revision 7affae8017cd4fc74dc2316f2104740253241228) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaServicePOJO.java (.../QaServicePOJO.java) (revision 45a3263a49a830c6e5392591ccd854264c5e6730) @@ -734,6 +734,36 @@ e); } } + + + public List getAllQuestionEntriesSorted(final long qaContentId) throws QaApplicationException + { + try + { + return qaQueContentDAO.getAllQuestionEntriesSorted(qaContentId); + } + catch (DataAccessException e) + { + throw new QaApplicationException("Exception occured when lams is getting all question entries: " + + e.getMessage(), + e); + } + } + + + public void removeQaQueContent(QaQueContent qaQueContent) throws QaApplicationException + { + try + { + qaQueContentDAO.removeQaQueContent(qaQueContent); + } + catch (DataAccessException e) + { + throw new QaApplicationException("Exception occured when lams is removing question content: " + + e.getMessage(), + e); + } + } public User getCurrentUserData(String username) throws QaApplicationException Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/AuthoringUtil.java =================================================================== diff -u -r7affae8017cd4fc74dc2316f2104740253241228 -r45a3263a49a830c6e5392591ccd854264c5e6730 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/AuthoringUtil.java (.../AuthoringUtil.java) (revision 7affae8017cd4fc74dc2316f2104740253241228) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/AuthoringUtil.java (.../AuthoringUtil.java) (revision 45a3263a49a830c6e5392591ccd854264c5e6730) @@ -35,7 +35,6 @@ import org.lamsfoundation.lams.tool.qa.QaComparator; import org.lamsfoundation.lams.tool.qa.QaContent; import org.lamsfoundation.lams.tool.qa.QaQueContent; -import org.lamsfoundation.lams.tool.qa.QaStringComparator; import org.lamsfoundation.lams.tool.qa.service.IQaService; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.web.session.SessionManager; @@ -137,7 +136,7 @@ long queIndex= new Long(request.getSession().getAttribute("queIndex").toString()).longValue(); logger.debug("queIndex: " + queIndex); - /** if there is data in the Map remaining from previous session remove those */ + /* if there is data in the Map remaining from previous session remove those */ mapQuestionContent.clear(); logger.debug("Map got initialized: " + mapQuestionContent); @@ -241,7 +240,79 @@ return qaContent; } + /** + * removes unused question entries from db + * removeRedundantQuestions (Map mapQuestionContent, IQaService qaService, QaAuthoringForm qaAuthoringForm) + * + * @param mapQuestionContent + * @param qaService + * @param qaAuthoringForm + */ + public void removeRedundantQuestions (Map mapQuestionContent, IQaService qaService, QaAuthoringForm qaAuthoringForm) + { + logger.debug("removing unused entries... "); + logger.debug("mapQuestionContent: " + mapQuestionContent); + logger.debug("qaAuthoringForm.getToolContentId(): " + qaAuthoringForm.getToolContentId()); + + QaContent qaContent=qaService.loadQa(new Long(qaAuthoringForm.getToolContentId()).longValue()); + logger.debug("qaContent: " + qaContent); + + if (qaContent != null) + { + logger.debug("qaContent uid: " + qaContent.getUid()); + List allQuestions=qaService.getAllQuestionEntries(qaContent.getUid()); + logger.debug("allQuestions: " + allQuestions); + + Iterator listIterator=allQuestions.iterator(); + Long mapIndex=new Long(1); + boolean entryUsed=false; + while (listIterator.hasNext()) + { + QaQueContent queContent=(QaQueContent)listIterator.next(); + logger.debug("queContent data: " + queContent); + logger.debug("queContent: " + queContent.getQuestion() + " " + queContent.getDisplayOrder()); + + entryUsed=false; + Iterator itMap = mapQuestionContent.entrySet().iterator(); + int diplayOrder=0; + while (itMap.hasNext()) + { + entryUsed=false; + Map.Entry pairs = (Map.Entry)itMap.next(); + logger.debug("using the pair: " + pairs.getKey() + " = " + pairs.getValue()); + if (pairs.getValue().toString().length() != 0) + { + logger.debug("text from map:" + pairs.getValue().toString()); + logger.debug("text from db:" + queContent.getQuestion()); + if (pairs.getValue().toString().equals(queContent.getQuestion())) + { + logger.debug("used entry in db:" + queContent.getQuestion()); + entryUsed=true; + break; + } + } + } + + if (entryUsed == false) + { + logger.debug("removing unused entry in db:" + queContent.getQuestion()); + + QaQueContent removeableQaQueContent=qaService.getQuestionContentByQuestionText(queContent.getQuestion(), qaContent.getUid()); + logger.debug("removeableQaQueContent" + removeableQaQueContent); + if (removeableQaQueContent != null) + { + qaService.removeQaQueContent(removeableQaQueContent); + logger.debug("removed removeableQaQueContent from the db: " + removeableQaQueContent); + } + + } + } + } + + } + + /** * createQuestionContent(TreeMap mapQuestionContent, HttpServletRequest request) * return void * @@ -252,16 +323,17 @@ logger.debug("content uid is: " + qaContent.getUid()); List questions=qaService.retrieveQaQueContentsByToolContentId(qaContent.getUid().longValue()); logger.debug("questions: " + questions); - + + /* Iterator listIterator=questions.iterator(); Long mapIndex=new Long(1); - while (listIterator.hasNext()) { QaQueContent queContent=(QaQueContent)listIterator.next(); logger.debug("queContent data: " + queContent); logger.debug("queContent: " + queContent.getQuestion() + "" + queContent.getDisplayOrder()); } + */ Iterator itMap = mapQuestionContent.entrySet().iterator(); int diplayOrder=0; @@ -284,30 +356,106 @@ null); - /* is this question already recorded?*/ + /* checks if the question is already recorded*/ logger.debug("question text is: " + pairs.getValue().toString()); logger.debug("content uid is: " + qaContent.getUid()); logger.debug("question display order is: " + diplayOrder); QaQueContent existingQaQueContent=qaService.getQuestionContentByDisplayOrder(new Long(diplayOrder), qaContent.getUid()); logger.debug("existingQaQueContent: " + existingQaQueContent); if (existingQaQueContent == null) { - logger.debug("creating a new question content: " + queContent); - logger.debug("adding a new question to content: " + queContent); - qaContent.getQaQueContents().add(queContent); - queContent.setQaContent(qaContent); - - qaService.createQaQue(queContent); + /*make sure a question with the same question text is not already saved*/ + QaQueContent duplicateQaQueContent=qaService.getQuestionContentByQuestionText(pairs.getValue().toString(), qaContent.getUid()); + logger.debug("duplicateQaQueContent: " + duplicateQaQueContent); + if (duplicateQaQueContent == null) + { + logger.debug("adding a new question to content: " + queContent); + qaContent.getQaQueContents().add(queContent); + queContent.setQaContent(qaContent); + + qaService.createQaQue(queContent); + } } else { existingQaQueContent.setQuestion(pairs.getValue().toString()); logger.debug("updating the existing question content: " + existingQaQueContent); qaService.updateQaQueContent(existingQaQueContent); } - } - logger.debug("returning qaContent: " + qaContent); + } } return qaContent; } + + + /** + * sorts the questions by the display order + * reOrganizeDisplayOrder(Map mapQuestionContent, IQaService qaService, QaAuthoringForm qaAuthoringForm, QaContent qaContent) + * + * @param mapQuestionContent + * @param qaService + * @param qaAuthoringForm + * @param qaContent + */ + public void reOrganizeDisplayOrder(Map mapQuestionContent, IQaService qaService, QaAuthoringForm qaAuthoringForm, QaContent qaContent) + { + logger.debug("content uid: " + qaContent.getUid()); + List sortedQuestions=qaService.getAllQuestionEntriesSorted(qaContent.getUid().longValue()); + logger.debug("sortedQuestions: " + sortedQuestions); + + Iterator listIterator=sortedQuestions.iterator(); + int displayOrder=1; + while (listIterator.hasNext()) + { + QaQueContent queContent=(QaQueContent)listIterator.next(); + logger.debug("queContent data: " + queContent); + logger.debug("queContent: " + queContent.getQuestion() + " " + queContent.getDisplayOrder()); + + QaQueContent existingQaQueContent=qaService.getQuestionContentByQuestionText(queContent.getQuestion(), qaContent.getUid()); + logger.debug("existingQaQueContent: " + existingQaQueContent); + existingQaQueContent.setDisplayOrder(displayOrder); + logger.debug("updating the existing question content for displayOrder: " + existingQaQueContent); + qaService.updateQaQueContent(existingQaQueContent); + displayOrder++; + } + logger.debug("done with reOrganizeDisplayOrder..."); + } + + + /** + * checks if any entry is duplicate + * verifyDuplicatesOptionsMap(Map mapQuestions) + * + * @param mapQuestions + * @return + */ + public static boolean verifyDuplicatesOptionsMap(Map mapQuestions) + { + Map originalMap=mapQuestions; + Map backupMap=mapQuestions; + + int optionCount=0; + for (long i=1; i <= MAX_QUESTION_COUNT.longValue() ; i++) + { + String currentOption=(String)originalMap.get(new Long(i).toString()); + + optionCount=0; + for (long j=1; j <= MAX_QUESTION_COUNT.longValue() ; j++) + { + String backedOption=(String)backupMap.get(new Long(j).toString()); + + if ((currentOption != null) && (backedOption !=null)) + { + if (currentOption.equals(backedOption)) + { + optionCount++; + } + + if (optionCount > 1) + return false; + } + } + } + return true; + } } \ No newline at end of file Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaAction.java =================================================================== diff -u -rdb0178754076b52281a78a5e57ee8302e883703d -r45a3263a49a830c6e5392591ccd854264c5e6730 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaAction.java (.../QaAction.java) (revision db0178754076b52281a78a5e57ee8302e883703d) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaAction.java (.../QaAction.java) (revision 45a3263a49a830c6e5392591ccd854264c5e6730) @@ -156,11 +156,33 @@ authoringUtil.reconstructQuestionContentMapForSubmit(mapQuestionContent, request); logger.debug("before saveOrUpdateQaContent."); + boolean verifyDuplicatesOptionsMap=AuthoringUtil.verifyDuplicatesOptionsMap(mapQuestionContent); + logger.debug("verifyDuplicatesOptionsMap: " + verifyDuplicatesOptionsMap); + request.getSession().removeAttribute(USER_EXCEPTION_QUESTIONS_DUPLICATE); + if (verifyDuplicatesOptionsMap == false) + { + errors= new ActionMessages(); + errors.add(Globals.ERROR_KEY,new ActionMessage("error.questions.duplicate")); + request.getSession().setAttribute(USER_EXCEPTION_QUESTIONS_DUPLICATE, new Boolean(true).toString()); + logger.debug("add error.questions.duplicate to ActionMessages"); + saveErrors(request,errors); + qaAuthoringForm.resetUserAction(); + return (mapping.findForward(LOAD_QUESTIONS)); + } + + + /*to remove deleted entries in the questions table based on mapQuestionContent */ + authoringUtil.removeRedundantQuestions(mapQuestionContent, qaService, qaAuthoringForm); + logger.debug("end of removing unused entries... "); + QaContent qaContent=authoringUtil.saveOrUpdateQaContent(mapQuestionContent, qaService, qaAuthoringForm); logger.debug("qaContent: " + qaContent); + + authoringUtil.reOrganizeDisplayOrder(mapQuestionContent, qaService, qaAuthoringForm, qaContent); List attacments=saveAttachments(qaContent, attachmentList, deletedAttachmentList, mapping, request); logger.debug("attacments: " + attacments); + errors.clear(); errors.add(Globals.ERROR_KEY, new ActionMessage("submit.successful")); Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaMonitoringAction.java =================================================================== diff -u -r792f3d848039cb49080fbaf49d9bc2b2d461943e -r45a3263a49a830c6e5392591ccd854264c5e6730 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaMonitoringAction.java (.../QaMonitoringAction.java) (revision 792f3d848039cb49080fbaf49d9bc2b2d461943e) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaMonitoringAction.java (.../QaMonitoringAction.java) (revision 45a3263a49a830c6e5392591ccd854264c5e6730) @@ -485,8 +485,8 @@ ServletException { QaUtils.cleanUpSessionAbsolute(request); - /*forward outside of the app. Currently it is index.jsp */ - return (mapping.findForward(LOAD_STARTER)); + /*check this again */ + return (mapping.findForward(LOAD_MONITORING)); } Index: lams_tool_laqa/web/authoring/BasicContent.jsp =================================================================== diff -u -r1f174bd80945a04023d087aba42b4041e450d557 -r45a3263a49a830c6e5392591ccd854264c5e6730 --- lams_tool_laqa/web/authoring/BasicContent.jsp (.../BasicContent.jsp) (revision 1f174bd80945a04023d087aba42b4041e450d557) +++ lams_tool_laqa/web/authoring/BasicContent.jsp (.../BasicContent.jsp) (revision 45a3263a49a830c6e5392591ccd854264c5e6730) @@ -38,6 +38,14 @@ + + + + + + + +