Index: lams_tool_scratchie/conf/language/lams/ApplicationResources_en_AU.properties =================================================================== diff -u -r9ecffbf5351e9dbf37af3b94a83f8450b314bf62 -r4b178984cfb2aebc0e9c1e9e586c06a1c6ea40bc --- lams_tool_scratchie/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision 9ecffbf5351e9dbf37af3b94a83f8450b314bf62) +++ lams_tool_scratchie/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision 4b178984cfb2aebc0e9c1e9e586c06a1c6ea40bc) @@ -175,4 +175,4 @@ label.none =None label.learners.feedback =Learner's feedback label.monitoring.team.leader =team leader - +label.authoring.import.qti =Import IMS QTI Index: lams_tool_scratchie/conf/xdoclet/struts-actions.xml =================================================================== diff -u -r9ecffbf5351e9dbf37af3b94a83f8450b314bf62 -r4b178984cfb2aebc0e9c1e9e586c06a1c6ea40bc --- lams_tool_scratchie/conf/xdoclet/struts-actions.xml (.../struts-actions.xml) (revision 9ecffbf5351e9dbf37af3b94a83f8450b314bf62) +++ lams_tool_scratchie/conf/xdoclet/struts-actions.xml (.../struts-actions.xml) (revision 4b178984cfb2aebc0e9c1e9e586c06a1c6ea40bc) @@ -97,6 +97,14 @@ + + + + answerList = new TreeSet(new ScratchieAnswerComparator()); answerList.addAll(item.getAnswers()); item.setAnswers(answerList); - + if (item.getCreateBy() == null) { if (scratchieUser == null) { // get back login user DTO @@ -300,7 +306,7 @@ return mapping.findForward(ScratchieConstants.DEFINE_LATER); } } - + /** * This method will persist all inforamtion in this authoring page, include all scratchie item, information etc. */ @@ -463,7 +469,7 @@ ScratchieForm scratchieForm = (ScratchieForm) form; // get back sessionMAP SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(scratchieForm.getSessionMapID()); - + SortedSet itemList = getItemList(sessionMap); request.setAttribute(ScratchieConstants.ATTR_ITEM_LIST, itemList); @@ -538,10 +544,10 @@ // get back sessionMAP String sessionMapID = WebUtil.readStrParam(request, ScratchieConstants.ATTR_SESSION_MAP_ID); SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); - + SortedSet itemList = getItemList(sessionMap); request.setAttribute(ScratchieConstants.ATTR_ITEM_LIST, itemList); - + Long versionID = new Long(WebUtil.readLongParam(request, ScratchieConstants.PARAM_FILE_VERSION_ID)); Long uuID = new Long(WebUtil.readLongParam(request, ScratchieConstants.PARAM_FILE_UUID)); @@ -566,32 +572,32 @@ return mapping.findForward(ScratchieConstants.SUCCESS); } - + /** * Ajax call, will add one more input line for new resource item instruction. */ private ActionForward addItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - + String sessionMapID = WebUtil.readStrParam(request, ScratchieConstants.ATTR_SESSION_MAP_ID); SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); String contentFolderID = (String) sessionMap.get(AttributeNames.PARAM_CONTENT_FOLDER_ID); - ScratchieItemForm itemForm = (ScratchieItemForm) form; + ScratchieItemForm itemForm = (ScratchieItemForm) form; itemForm.setSessionMapID(sessionMapID); itemForm.setContentFolderID(contentFolderID); - + List answerList = new ArrayList(); for (int i = 0; i < ScratchieConstants.INITIAL_ANSWERS_NUMBER; i++) { ScratchieAnswer answer = new ScratchieAnswer(); - answer.setOrderId(i+1); + answer.setOrderId(i + 1); answerList.add(answer); } - request.setAttribute(ScratchieConstants.ATTR_ANSWER_LIST, answerList); - - request.setAttribute(AttributeNames.PARAM_CONTENT_FOLDER_ID, contentFolderID); + request.setAttribute(ScratchieConstants.ATTR_ANSWER_LIST, answerList); + + request.setAttribute(AttributeNames.PARAM_CONTENT_FOLDER_ID, contentFolderID); return mapping.findForward(ScratchieConstants.SUCCESS); } - + /** * Display edit page for existed scratchie item. */ @@ -602,16 +608,16 @@ String sessionMapID = WebUtil.readStrParam(request, ScratchieConstants.ATTR_SESSION_MAP_ID); SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); String contentFolderID = (String) sessionMap.get(AttributeNames.PARAM_CONTENT_FOLDER_ID); - + int itemIdx = NumberUtils.stringToInt(request.getParameter(ScratchieConstants.PARAM_ITEM_INDEX), -1); ScratchieItem item = null; if (itemIdx != -1) { SortedSet itemList = getItemList(sessionMap); List rList = new ArrayList(itemList); item = rList.get(itemIdx); if (item != null) { - ScratchieItemForm itemForm = (ScratchieItemForm) form; - itemForm.setTitle(item.getTitle()); + ScratchieItemForm itemForm = (ScratchieItemForm) form; + itemForm.setTitle(item.getTitle()); itemForm.setDescription(item.getDescription()); if (itemIdx >= 0) { itemForm.setItemIndex(new Integer(itemIdx).toString()); @@ -626,7 +632,7 @@ request.setAttribute(AttributeNames.PARAM_CONTENT_FOLDER_ID, contentFolderID); return mapping.findForward(ScratchieConstants.SUCCESS); } - + /** * This method will get necessary information from assessment question form and save or update into * HttpSession AssessmentQuestionList. Notice, this save is not persist them into database, just save @@ -635,7 +641,7 @@ */ private ActionForward saveItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - + ScratchieItemForm itemForm = (ScratchieItemForm) form; SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(itemForm.getSessionMapID()); // check whether it is "edit(old Question)" or "add(new Question)" @@ -660,7 +666,7 @@ item.setTitle(itemForm.getTitle()); item.setDescription(itemForm.getDescription()); - + // set options Set answerList = getAnswersFromRequest(request, true); Set answers = new LinkedHashSet(); @@ -675,8 +681,77 @@ request.setAttribute(ScratchieConstants.ATTR_SESSION_MAP_ID, itemForm.getSessionMapID()); return mapping.findForward(ScratchieConstants.SUCCESS); } - + /** + * Parses questions extracted from IMS QTI file and adds them as new items. + */ + @SuppressWarnings("rawtypes") + private ActionForward saveQTI(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws UnsupportedEncodingException { + // big part of code was taken from saveItem() method + String sessionMapId = request.getParameter(ScratchieConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapId); + SortedSet itemList = getItemList(sessionMap); + + Question[] questions = QuestionParser.parseQuestionChoiceForm(request.getQueryString()); + for (Question question : questions) { + ScratchieItem item = new ScratchieItem(); + item.setCreateDate(new Timestamp(new Date().getTime())); + int maxSeq = 1; + if (itemList != null && itemList.size() > 0) { + ScratchieItem last = itemList.last(); + maxSeq = last.getOrderId() + 1; + } + item.setOrderId(maxSeq); + item.setTitle(question.getText()); + + TreeSet answerList = new TreeSet(new ScratchieAnswerComparator()); + String correctAnswer = null; + int orderId = 1; + if (question.getAnswers() != null) { + for (Answer answer : question.getAnswers()) { + String answerText = answer.getText(); + if (correctAnswer != null && correctAnswer.equals(answerText)) { + log.warn("Skipping an answer with same text as the correct answer: " + answerText); + continue; + } + ScratchieAnswer scratchieAnswer = new ScratchieAnswer(); + scratchieAnswer.setDescription(answerText); + scratchieAnswer.setOrderId(orderId++); + + if ((answer.getScore() != null) && (answer.getScore() > 0)) { + if (correctAnswer == null) { + scratchieAnswer.setCorrect(true); + correctAnswer = answerText; + } else { + log.warn("Choosing only first correct answer, despite another one was found: " + answerText); + scratchieAnswer.setCorrect(false); + } + } else { + scratchieAnswer.setCorrect(false); + } + + answerList.add(scratchieAnswer); + } + } + + if (correctAnswer == null) { + log.warn("No correct answer found for question: " + question.getText()); + continue; + } + + item.setAnswers(answerList); + itemList.add(item); + if (log.isDebugEnabled()) { + log.debug("Added question: " + question.getText()); + } + } + + request.setAttribute(ScratchieConstants.ATTR_SESSION_MAP_ID, sessionMapId); + return mapping.findForward(ScratchieConstants.SUCCESS); + } + + /** * Ajax call, remove the given line of instruction of resource item. * * @param mapping @@ -699,7 +774,7 @@ ScratchieItem item = rList.remove(itemIndex); itemList.clear(); itemList.addAll(rList); - + // add to delList List delList = getDeletedItemList(sessionMap); delList.add(item); @@ -708,7 +783,7 @@ request.setAttribute(ScratchieConstants.ATTR_ITEM_LIST, itemList); return mapping.findForward(ScratchieConstants.SUCCESS); } - + /** * Move up current item. * @@ -742,11 +817,11 @@ request.setAttribute(ScratchieConstants.ATTR_SESSION_MAP_ID, sessionMapID); SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); SortedSet itemList = getItemList(sessionMap); - + int itemIndex = NumberUtils.stringToInt(request.getParameter(ScratchieConstants.PARAM_ITEM_INDEX), -1); if (itemIndex != -1) { List rList = new ArrayList(itemList); - + // get current and the target item, and switch their sequnece ScratchieItem item = rList.get(itemIndex); ScratchieItem repOption; @@ -755,7 +830,7 @@ } else { repOption = rList.get(++itemIndex); } - + int upSeqId = repOption.getOrderId(); repOption.setOrderId(item.getOrderId()); item.setOrderId(upSeqId); @@ -765,13 +840,12 @@ itemList.addAll(rList); } - request.setAttribute(ScratchieConstants.ATTR_ITEM_LIST, itemList); return mapping.findForward(ScratchieConstants.SUCCESS); } - + // ----------------------- Answers functions --------------- - + /** * Ajax call, will add one more input line for new resource item instruction. * @@ -783,9 +857,9 @@ */ private ActionForward addAnswer(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - + SortedSet answerList = getAnswersFromRequest(request, false); - + ScratchieAnswer answer = new ScratchieAnswer(); int maxSeq = 1; if (answerList != null && answerList.size() > 0) { @@ -794,13 +868,13 @@ } answer.setOrderId(maxSeq); answerList.add(answer); - + request.setAttribute(ScratchieConstants.ATTR_ANSWER_LIST, answerList); - request.setAttribute(AttributeNames.PARAM_CONTENT_FOLDER_ID, WebUtil.readStrParam(request, - AttributeNames.PARAM_CONTENT_FOLDER_ID)); + request.setAttribute(AttributeNames.PARAM_CONTENT_FOLDER_ID, + WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID)); return mapping.findForward(ScratchieConstants.SUCCESS); } - + /** * Ajax call, remove the given answer. * @@ -824,11 +898,11 @@ } request.setAttribute(ScratchieConstants.ATTR_ANSWER_LIST, answerList); - request.setAttribute(AttributeNames.PARAM_CONTENT_FOLDER_ID, WebUtil.readStrParam(request, - AttributeNames.PARAM_CONTENT_FOLDER_ID)); + request.setAttribute(AttributeNames.PARAM_CONTENT_FOLDER_ID, + WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID)); return mapping.findForward(ScratchieConstants.SUCCESS); } - + /** * Move up current answer. * @@ -859,11 +933,11 @@ private ActionForward switchAnswer(ActionMapping mapping, HttpServletRequest request, boolean up) { SortedSet answerList = getAnswersFromRequest(request, false); - + int answerIndex = NumberUtils.stringToInt(request.getParameter(ScratchieConstants.PARAM_ANSWER_INDEX), -1); if (answerIndex != -1) { List rList = new ArrayList(answerList); - + // get current and the target item, and switch their sequnece ScratchieAnswer answer = rList.get(answerIndex); ScratchieAnswer repAnswer; @@ -872,7 +946,7 @@ } else { repAnswer = rList.get(++answerIndex); } - + int upSeqId = repAnswer.getOrderId(); repAnswer.setOrderId(answer.getOrderId()); answer.setOrderId(upSeqId); @@ -885,9 +959,9 @@ request.setAttribute(ScratchieConstants.ATTR_ANSWER_LIST, answerList); return mapping.findForward(ScratchieConstants.SUCCESS); } - + // ----------------------- PedagogicalPlannerForm --------------- - + public ActionForward initPedagogicalPlannerForm(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { ScratchiePedagogicalPlannerForm plannerForm = (ScratchiePedagogicalPlannerForm) form; @@ -948,8 +1022,7 @@ * @return */ private SortedSet getItemList(SessionMap sessionMap) { - SortedSet list = (SortedSet) sessionMap - .get(ScratchieConstants.ATTR_ITEM_LIST); + SortedSet list = (SortedSet) sessionMap.get(ScratchieConstants.ATTR_ITEM_LIST); if (list == null) { list = new TreeSet(new ScratchieItemComparator()); sessionMap.put(ScratchieConstants.ATTR_ITEM_LIST, list); @@ -982,12 +1055,13 @@ } return list; } - + /** * Get answer options from HttpRequest * * @param request - * @param isForSaving whether the blank options will be preserved or not + * @param isForSaving + * whether the blank options will be preserved or not * */ private TreeSet getAnswersFromRequest(HttpServletRequest request, boolean isForSaving) { @@ -1009,27 +1083,28 @@ Integer orderId = NumberUtils.stringToInt(orderIdStr); answer.setOrderId(orderId); answer.setDescription(answerDescription); - if ((correctAnswerIndex!=null) && correctAnswerIndex.equals(orderId)) { + if ((correctAnswerIndex != null) && correctAnswerIndex.equals(orderId)) { answer.setCorrect(true); } answerList.add(answer); } - + return answerList; } - + /** * Split Request Parameter from HttpRequest * * @param request - * @param parameterName parameterName + * @param parameterName + * parameterName */ private Map splitRequestParameter(HttpServletRequest request, String parameterName) { String list = request.getParameter(parameterName); if (list == null) { return null; } - + String[] params = list.split("&"); Map paramMap = new HashMap(); String[] pair; @@ -1045,7 +1120,7 @@ } return paramMap; } - + /** * Removes redundant new line characters from options left by CKEditor (otherwise it will break Javascript in * monitor) @@ -1061,7 +1136,7 @@ answer.setDescription(answerDescription); } } - + } } Index: lams_tool_scratchie/web/pages/authoring/basic.jsp =================================================================== diff -u -rfb10906fb7b35d813643db3f60a0b005163196f7 -r4b178984cfb2aebc0e9c1e9e586c06a1c6ea40bc --- lams_tool_scratchie/web/pages/authoring/basic.jsp (.../basic.jsp) (revision fb10906fb7b35d813643db3f60a0b005163196f7) +++ lams_tool_scratchie/web/pages/authoring/basic.jsp (.../basic.jsp) (revision 4b178984cfb2aebc0e9c1e9e586c06a1c6ea40bc) @@ -82,6 +82,21 @@ function refreshThickbox(){ tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox }; + + function importQTI(){ + window.open('questionFile.jsp?chooseAnswers=true', + 'QuestionFile','width=500,height=200,scrollbars=yes'); + } + + function saveQTI(queryString) { + var url = '?' + queryString; + $(itemTargetDiv).load( + url, + { + sessionMapID: "${sessionMapID}" + } + ); + } @@ -119,5 +134,8 @@ + + +