Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/model/QaQueContent.java =================================================================== diff -u -r86c25c80d92701a94c3161575c76c363891402ad -r8a5ba0f4e4ced295600d75bca2fef2ef727d7eb0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/model/QaQueContent.java (.../QaQueContent.java) (revision 86c25c80d92701a94c3161575c76c363891402ad) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/model/QaQueContent.java (.../QaQueContent.java) (revision 8a5ba0f4e4ced295600d75bca2fef2ef727d7eb0) @@ -59,7 +59,7 @@ public QaQueContent(QbQuestion qbQuestion, int displayOrder, QaContent qaContent) { this.qbQuestion = qbQuestion; this.qaContent = qaContent; - this.toolContentId = qaContent.getQaContentId(); + this.toolContentId = qaContent == null ? null : qaContent.getQaContentId(); this.displayOrder = displayOrder; } @@ -81,6 +81,6 @@ public void setQaContent(QaContent qaContent) { this.qaContent = qaContent; - this.toolContentId = qaContent.getQaContentId(); + this.toolContentId = qaContent == null ? null : qaContent.getQaContentId(); } } \ No newline at end of file Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/controller/QaAuthoringController.java =================================================================== diff -u -r6a00057c1bd113919030bcd00ce1e3c7327c7b2e -r8a5ba0f4e4ced295600d75bca2fef2ef727d7eb0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/controller/QaAuthoringController.java (.../QaAuthoringController.java) (revision 6a00057c1bd113919030bcd00ce1e3c7327c7b2e) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/controller/QaAuthoringController.java (.../QaAuthoringController.java) (revision 8a5ba0f4e4ced295600d75bca2fef2ef727d7eb0) @@ -58,6 +58,7 @@ import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; import org.lamsfoundation.lams.util.CommonConstants; +import org.lamsfoundation.lams.util.FileUtil; import org.lamsfoundation.lams.util.MessageService; import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.web.session.SessionManager; @@ -87,7 +88,7 @@ @Autowired private IQbService qbService; - + @Autowired private IUserManagementService userManagementService; @@ -158,12 +159,15 @@ /** * submits content into the tool database - * @throws NoSuchMethodException - * @throws InvocationTargetException - * @throws IllegalAccessException + * + * @throws NoSuchMethodException + * @throws InvocationTargetException + * @throws IllegalAccessException */ @RequestMapping("/submitAllContent") - public String submitAllContent(@ModelAttribute("authoringForm") QaAuthoringForm form, HttpServletRequest request) throws IOException, ServletException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { + public String submitAllContent(@ModelAttribute("authoringForm") QaAuthoringForm form, HttpServletRequest request) + throws IOException, ServletException, IllegalAccessException, InvocationTargetException, + NoSuchMethodException { SessionMap sessionMap = getSessionMap(form, request); ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request); request.setAttribute(AttributeNames.ATTR_MODE, mode.toString()); @@ -176,19 +180,19 @@ qaPO = qa; qaPO.setCreationDate(new Timestamp(new Date().getTime())); qaPO.setUpdateDate(new Timestamp(new Date().getTime())); - + } else { // copyProperties() below sets qaPO's conditions to empty collection // but the conditions still exist in Hibernate cache, so we need to evict them now for (QaCondition condition : qaPO.getConditions()) { qaService.releaseFromCache(condition); } - + qaPO.getQaQueContents().clear(); qaPO.getConditions().clear(); Long uid = qaPO.getUid(); PropertyUtils.copyProperties(qaPO, qa); - + // set back UID qaPO.setUid(uid); @@ -204,7 +208,7 @@ qaPO.setUpdateDate(new Timestamp(new Date().getTime())); } - + // *******************************Handle user******************* UserDTO toolUser = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER); long userId = 0; @@ -221,7 +225,7 @@ } qaPO.setCreatedBy(userId); qaService.saveOrUpdateQaContent(qaPO); - + // ************************* Handle Q&A questions ******************* Set items = new LinkedHashSet<>(); Set newItems = getQuestions(sessionMap); @@ -232,7 +236,7 @@ items.add(question); } qaPO.setQaQueContents(items); - + // ************************* Handle Q&A conditions ******************* SortedSet conditions = QaAuthoringConditionController.getConditions(sessionMap); for (QaCondition condition : conditions) { @@ -246,14 +250,14 @@ } } qaPO.setConditions(conditions); - + //reorder questions so displayOrder numbers come in strictly sequential order (it's required for proper work of learning) int displayOrder = 1; for (QaQueContent question : newItems) { question.setDisplayOrder(displayOrder++); qaService.saveOrUpdate(question); } - + qaService.saveOrUpdateQaContent(qaPO); // ************************* Handle rating criterias ******************* @@ -262,7 +266,7 @@ request.setAttribute(AttributeNames.ATTR_MODE, mode.toString()); request.setAttribute(CommonConstants.LAMS_AUTHORING_SUCCESS_FLAG, Boolean.TRUE); - + // remove deleted questions List deletedQuestions = getDeletedQuestions(sessionMap); for (QaQueContent deletedQuestion : deletedQuestions) { @@ -335,6 +339,7 @@ qbQuestion = new QbQuestion(); qbQuestion.setType(QbQuestion.TYPE_ESSAY); qbQuestion.setQuestionId(form.getQuestionId()); + qbQuestion.setContentFolderId(form.getContentFolderID()); qaQuestion = new QaQueContent(); int maxSeq = 1; @@ -345,7 +350,7 @@ qaQuestion.setDisplayOrder(maxSeq); qaQuestions.add(qaQuestion); - // edit + // edit } else { List rList = new ArrayList<>(qaQuestions); qaQuestion = rList.get(itemIdx); @@ -369,7 +374,8 @@ switch (isQbQuestionModified) { case IQbService.QUESTION_MODIFIED_VERSION_BUMP: { // impossible scenario as long as ESSAY question type can't have version - throw new RuntimeException("Impossible scenario as long as ESSAY question type can't have new versions"); + throw new RuntimeException( + "Impossible scenario as long as ESSAY question type can't have new versions"); } case IQbService.QUESTION_MODIFIED_ID_BUMP: { // new question gets created @@ -403,20 +409,19 @@ return "authoring/itemlist"; } - + /** * Ajax call, will add one more input line for new resource item instruction. */ @RequestMapping("/newQuestionBox") private String newQuestionBox(@ModelAttribute("newQuestionForm") QbQuestionForm form, HttpServletRequest request, - @RequestParam String sessionMapID, @RequestParam String contentFolderID) { + @RequestParam String sessionMapID) { form.setSessionMapID(sessionMapID); - form.setContentFolderID(contentFolderID); + String questionContentFolderID = FileUtil.generateUniqueContentFolderID(); + form.setContentFolderID(questionContentFolderID); form.setQuestionId(qbService.generateNextQuestionId()); // generate a new question ID right away, so another user won't "take it" - - QbUtils.fillFormWithUserCollections(qbService, form, null); - request.setAttribute(AttributeNames.PARAM_CONTENT_FOLDER_ID, contentFolderID); + QbUtils.fillFormWithUserCollections(qbService, form, null); return "authoring/newQuestionBox"; } @@ -431,7 +436,7 @@ .getAttribute(sessionMapID); String contentFolderID = (String) sessionMap.get(AttributeNames.PARAM_CONTENT_FOLDER_ID); Set qaQuestions = getQuestions(sessionMap); - + List rList = new ArrayList<>(qaQuestions); QaQueContent qaQuestion = rList.get(questionIndex); QbQuestion qbQuestion = qaQuestion.getQbQuestion(); @@ -446,10 +451,10 @@ form.setMinWordsLimit(qbQuestion.getMinWordsLimit()); form.setFeedback(qbQuestion.getFeedback()); - form.setContentFolderID(contentFolderID); + form.setContentFolderID(qbQuestion.getContentFolderId()); form.setSessionMapID(sessionMapID); QbUtils.fillFormWithUserCollections(qbService, form, qbQuestion.getUid()); - + request.setAttribute(AttributeNames.PARAM_CONTENT_FOLDER_ID, contentFolderID); return "authoring/newQuestionBox"; } @@ -463,7 +468,7 @@ SessionMap sessionMap = getSessionMap(form, request); int questionIndex = NumberUtils.toInt(request.getParameter("questionIndex"), -1); Set qaQuestions = getQuestions(sessionMap); - + if (questionIndex != -1) { List rList = new ArrayList<>(qaQuestions); QaQueContent questionToDelete = rList.remove(questionIndex); @@ -473,7 +478,7 @@ // add to delList List delList = getDeletedQuestions(sessionMap); delList.add(questionToDelete); - + //take care about conditions SortedSet conditions = QaAuthoringConditionController.getConditions(sessionMap); Iterator conditionIter = conditions.iterator(); @@ -498,8 +503,8 @@ * moves a question down in the list */ @RequestMapping("/moveQuestionDown") - public String moveQuestionDown(@ModelAttribute("newQuestionForm") QaAuthoringForm form, - HttpServletRequest request) throws IOException, ServletException { + public String moveQuestionDown(@ModelAttribute("newQuestionForm") QaAuthoringForm form, HttpServletRequest request) + throws IOException, ServletException { swapQuestions(form, request, "down"); return "authoring/itemlist"; @@ -509,8 +514,8 @@ * moves a question up in the list */ @RequestMapping("/moveQuestionUp") - public String moveQuestionUp(@ModelAttribute("newQuestionForm") QaAuthoringForm form, - HttpServletRequest request) throws IOException, ServletException { + public String moveQuestionUp(@ModelAttribute("newQuestionForm") QaAuthoringForm form, HttpServletRequest request) + throws IOException, ServletException { swapQuestions(form, request, "up"); return "authoring/itemlist"; @@ -526,15 +531,15 @@ // get current and the target item, and switch their sequence QaQueContent originalQuestion = rList.get(originalQuestionIndex); QaQueContent replacedQuestion = rList.get(replacedQuestionIndex); - + int upSeqId = replacedQuestion.getDisplayOrder(); replacedQuestion.setDisplayOrder(originalQuestion.getDisplayOrder()); originalQuestion.setDisplayOrder(upSeqId); // put back list, it will be sorted again questions.clear(); questions.addAll(rList); - + return questions; } @@ -546,7 +551,7 @@ } return false; } - + /** * List current Q&A questions. * @@ -562,7 +567,7 @@ } return list; } - + /** * List save deleted scratchie items, which could be persisted or non-persisted items. * @@ -578,14 +583,14 @@ } return list; } - + @SuppressWarnings("unchecked") private SessionMap getSessionMap(QaAuthoringForm form, HttpServletRequest request) { String sessionMapID = form.getSessionMapID(); request.setAttribute(QaAppConstants.ATTR_SESSION_MAP_ID, sessionMapID); return (SessionMap) request.getSession().getAttribute(sessionMapID); } - + @SuppressWarnings("unchecked") private SessionMap getSessionMap(QbQuestionForm form, HttpServletRequest request) { String sessionMapID = form.getSessionMapID(); Index: lams_tool_laqa/web/authoring/BasicContent.jsp =================================================================== diff -u -r86c25c80d92701a94c3161575c76c363891402ad -r8a5ba0f4e4ced295600d75bca2fef2ef727d7eb0 --- lams_tool_laqa/web/authoring/BasicContent.jsp (.../BasicContent.jsp) (revision 86c25c80d92701a94c3161575c76c363891402ad) +++ lams_tool_laqa/web/authoring/BasicContent.jsp (.../BasicContent.jsp) (revision 8a5ba0f4e4ced295600d75bca2fef2ef727d7eb0) @@ -88,7 +88,7 @@
- ?contentFolderID=${authoringForm.contentFolderID}&sessionMapID=${authoringForm.sessionMapID}&KeepThis=true&TB_iframe=true&modal=true + ?sessionMapID=${authoringForm.sessionMapID}&KeepThis=true&TB_iframe=true&modal=true