Index: lams_tool_laqa/conf/hibernate/mappings/org/lamsfoundation/lams/tool/qa/QaCondition.hbm.xml =================================================================== diff -u -r62bfc2c0cd9979e725e11c66ebd355b47471a81f -r33f9171c071c179459972380a9b732f1aeec87bf --- lams_tool_laqa/conf/hibernate/mappings/org/lamsfoundation/lams/tool/qa/QaCondition.hbm.xml (.../QaCondition.hbm.xml) (revision 62bfc2c0cd9979e725e11c66ebd355b47471a81f) +++ lams_tool_laqa/conf/hibernate/mappings/org/lamsfoundation/lams/tool/qa/QaCondition.hbm.xml (.../QaCondition.hbm.xml) (revision 33f9171c071c179459972380a9b732f1aeec87bf) @@ -18,7 +18,7 @@ table="tl_laqa11_condition_questions" lazy="false" inverse="false" - cascade="all" + cascade="save-update" sort="unsorted" order-by="question_uid asc" Index: lams_tool_laqa/conf/hibernate/mappings/org/lamsfoundation/lams/tool/qa/QaContent.hbm.xml =================================================================== diff -u -r0af4ed13b963a588f3499b080801863d57f8ad95 -r33f9171c071c179459972380a9b732f1aeec87bf --- lams_tool_laqa/conf/hibernate/mappings/org/lamsfoundation/lams/tool/qa/QaContent.hbm.xml (.../QaContent.hbm.xml) (revision 0af4ed13b963a588f3499b080801863d57f8ad95) +++ lams_tool_laqa/conf/hibernate/mappings/org/lamsfoundation/lams/tool/qa/QaContent.hbm.xml (.../QaContent.hbm.xml) (revision 33f9171c071c179459972380a9b732f1aeec87bf) @@ -178,7 +178,7 @@ name="qaQueContents" lazy="true" inverse="true" - cascade="all-delete-orphan" + cascade="all" sort="natural" > questions) { - super(conditionId, conditionUIID, orderId, name, displayName, type, startValue, endValue, exactMatchValue, - allWords, phrase, anyWords, excludedWords); + String allWords, String phrase, String anyWords, String excludedWords, Set questions) { + super(conditionId, conditionUIID, orderId, name, displayName, BranchCondition.OUTPUT_TYPE_COMPLEX, null, null, + null, allWords, phrase, anyWords, excludedWords); setQuestions(questions); } @@ -81,6 +81,7 @@ result = true; for (QaQueContent question : questions) { String textToMatch = answers[question.getDisplayOrder() - 1]; + textToMatch = removeHTMLtags(textToMatch); result &= matches(textToMatch); // if at least one answer does not satisfy the condition, there is no need to look further if (!result) { @@ -103,21 +104,60 @@ this.questions = questions; } + /** + * Notice that the original questions are assigned to the copy. + */ @Override public Object clone() { Set questionsCopy = new TreeSet(new QaQueContentComparator()); questionsCopy.addAll(questions); - return new QaCondition(null, null, orderId, name, displayName, type, null, null, null, allWords, phrase, - anyWords, excludedWords, questionsCopy); + return new QaCondition(null, null, orderId, name, displayName, allWords, phrase, anyWords, excludedWords, + questionsCopy); } + /** + * Notice that questions are copied with very little information and then they are assigned to the cloned object. + * This method is used when assigning BranchActivityEntry needs, so only basic information (in fact, only order ID) + * is needed. Also, there should be no link to Q&A content. + */ @Override public QaCondition clone(int uiidOffset) { Integer newConditionUIID = LearningDesign.addOffset(conditionUIID, uiidOffset); Set questionsCopy = new TreeSet(new QaQueContentComparator()); - questionsCopy.addAll(questions); - return new QaCondition(null, newConditionUIID, orderId, name, displayName, type, startValue, endValue, - exactMatchValue, allWords, phrase, anyWords, excludedWords, questionsCopy); + + for (QaQueContent question : getQuestions()) { + QaQueContent questionCopy = new QaQueContent(question.getQuestion(), question.getDisplayOrder(), null, + null, null, null); + questionsCopy.add(questionCopy); + } + return new QaCondition(null, newConditionUIID, orderId, name, displayName, allWords, phrase, anyWords, + excludedWords, questionsCopy); } + /** + * Notice that questions from the cloned (and not the original) tool content are assigned to the cloned condition. + * This method is used for cloning tool content. + */ + public QaCondition clone(QaContent qaContent) { + + Set questionsCopy = new TreeSet(new QaQueContentComparator()); + for (QaQueContent conditionQuestion : getQuestions()) { + for (QaQueContent contentQuestion : (Set) qaContent.getQaQueContents()) { + if (conditionQuestion.getDisplayOrder() == contentQuestion.getDisplayOrder()) { + questionsCopy.add(contentQuestion); + } + } + } + + return new QaCondition(null, null, orderId, name, displayName, allWords, phrase, anyWords, excludedWords, + questionsCopy); + } + + /** + * The condition must be bound with at least one question. + */ + @Override + protected boolean isValid() { + return getQuestions() != null && !getQuestions().isEmpty(); + } } \ No newline at end of file Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/QaContent.java =================================================================== diff -u -r62bfc2c0cd9979e725e11c66ebd355b47471a81f -r33f9171c071c179459972380a9b732f1aeec87bf --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/QaContent.java (.../QaContent.java) (revision 62bfc2c0cd9979e725e11c66ebd355b47471a81f) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/QaContent.java (.../QaContent.java) (revision 33f9171c071c179459972380a9b732f1aeec87bf) @@ -37,7 +37,7 @@ import org.lamsfoundation.lams.contentrepository.ItemNotFoundException; import org.lamsfoundation.lams.contentrepository.RepositoryCheckedException; import org.lamsfoundation.lams.contentrepository.client.IToolContentHandler; -import org.lamsfoundation.lams.tool.qa.util.QaConditionComparator; +import org.lamsfoundation.lams.learningdesign.TextSearchConditionComparator; /** * @author Ozgur Demirtas @@ -125,10 +125,8 @@ /** persistent field */ private Set qaUploadedFiles; /** persistent field */ - private Set conditions = new TreeSet(new QaConditionComparator()); + private Set conditions = new TreeSet(new TextSearchConditionComparator()); - private String nonHTMLtitle; - public QaContent() { }; @@ -185,7 +183,7 @@ .isQuestionsSequenced(), qa.isUsernameVisible(), qa.isSynchInMonitor(), qa.isLockWhenFinished(), qa .isContentLocked(), qa.isShowOtherAnswers(), qa.isReflect(), qa.getReflectionSubject(), qa .getCreationDate(), qa.getUpdateDate(), new TreeSet(), new TreeSet(), new TreeSet(), - new TreeSet(new QaConditionComparator())); + new TreeSet(new TextSearchConditionComparator())); newContent.setQaQueContents(qa.deepCopyQaQueContent(newContent)); QaContent.logger.debug(QaContent.logger + " " + "QaContent" + " " + "after doing deepCopyQaQueContent"); @@ -223,10 +221,10 @@ public Set deepCopyConditions(QaContent newQaContent) { - Set newConditions = new TreeSet(new QaConditionComparator()); + Set newConditions = new TreeSet(new TextSearchConditionComparator()); if (getConditions() != null) { for (QaCondition condition : getConditions()) { - newConditions.add((QaCondition) condition.clone()); + newConditions.add(condition.clone(newQaContent)); } } @@ -654,11 +652,4 @@ public void setConditions(Set conditions) { this.conditions = conditions; } - - public String getNonHTMLtitle() { - if (title == null) { - return null; - } - return title.replaceAll("\\<.*?>", ""); - } } \ No newline at end of file Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dbupdates/patch20080926_updateFrom21.sql =================================================================== diff -u -r0af4ed13b963a588f3499b080801863d57f8ad95 -r33f9171c071c179459972380a9b732f1aeec87bf --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dbupdates/patch20080926_updateFrom21.sql (.../patch20080926_updateFrom21.sql) (revision 0af4ed13b963a588f3499b080801863d57f8ad95) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dbupdates/patch20080926_updateFrom21.sql (.../patch20080926_updateFrom21.sql) (revision 33f9171c071c179459972380a9b732f1aeec87bf) @@ -17,4 +17,9 @@ REFERENCES tl_laqa11_conditions(condition_id) ON DELETE CASCADE ON UPDATE CASCADE , CONSTRAINT QaConditionQuestionToQaQuestion FOREIGN KEY (question_uid) REFERENCES tl_laqa11_que_content(uid) ON DELETE CASCADE ON UPDATE CASCADE -)TYPE=InnoDB; \ No newline at end of file +)TYPE=InnoDB; + +UPDATE lams_tool SET supports_outputs=1 WHERE tool_signature='lantbk11'; + +-- Condition copies created for branch activity entries won't have links to any existing Q&A contents. +ALTER TABLE tl_laqa11_que_content MODIFY COLUMN qa_content_id BIGINT(20); \ No newline at end of file Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaOutputFactory.java =================================================================== diff -u -r62bfc2c0cd9979e725e11c66ebd355b47471a81f -r33f9171c071c179459972380a9b732f1aeec87bf --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaOutputFactory.java (.../QaOutputFactory.java) (revision 62bfc2c0cd9979e725e11c66ebd355b47471a81f) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaOutputFactory.java (.../QaOutputFactory.java) (revision 33f9171c071c179459972380a9b732f1aeec87bf) @@ -40,6 +40,7 @@ import org.lamsfoundation.lams.tool.qa.QaContent; 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; /** @@ -71,8 +72,8 @@ .toString()); // Default condition checks if the first answer contains word "LAMS" QaCondition defaultCondition = new QaCondition(null, null, 1, name, getI18NText( - QaAppConstants.TEXT_SEARCH_DEFAULT_CONDITION_DISPLAY_NAME_KEY, false), "OUTPUT_COMPLEX", null, - null, null, "LAMS", null, null, null, questions); + QaAppConstants.TEXT_SEARCH_DEFAULT_CONDITION_DISPLAY_NAME_KEY, false), "LAMS", null, null, + null, questions); qaContent.getConditions().add(defaultCondition); allAnswersDefinition.getDefaultConditions().add(defaultCondition); @@ -134,14 +135,16 @@ public ToolOutput getToolOutput(String name, IQaService qaService, Long toolSessionId, Long learnerId) { if (isTextSearchConditionName(QaAppConstants.TEXT_SEARCH_DEFINITION_NAME)) { // user answers are loaded from the DB and array of strings is created - QaContent taskList = qaService.getQaContentBySessionId(toolSessionId); - Set questions = taskList.getQaQueContents(); + + QaSession session = qaService.retrieveQaSession(toolSessionId); + QaContent qaContent = session.getQaContent(); + Set questions = qaContent.getQaQueContents(); String[] answers = new String[questions.size()]; for (QaQueContent question : questions) { - QaQueUsr user = qaService.getQaQueUsrById(learnerId); + QaQueUsr user = qaService.getQaUserBySession(learnerId, session.getUid()); List attempts = null; if (user != null) { - attempts = qaService.getAttemptsForUserAndQuestionContent(user.getUid(), question.getQaContentId()); + attempts = qaService.getAttemptsForUserAndQuestionContent(user.getUid(), question.getUid()); } if (attempts != null && !attempts.isEmpty()) { // only the last attempt is taken into consideration Fisheye: Tag 33f9171c071c179459972380a9b732f1aeec87bf refers to a dead (removed) revision in file `lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/util/QaConditionComparator.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/AuthoringUtil.java =================================================================== diff -u -r0af4ed13b963a588f3499b080801863d57f8ad95 -r33f9171c071c179459972380a9b732f1aeec87bf --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/AuthoringUtil.java (.../AuthoringUtil.java) (revision 0af4ed13b963a588f3499b080801863d57f8ad95) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/AuthoringUtil.java (.../AuthoringUtil.java) (revision 33f9171c071c179459972380a9b732f1aeec87bf) @@ -38,14 +38,14 @@ import javax.servlet.http.HttpSession; import org.apache.log4j.Logger; +import org.lamsfoundation.lams.learningdesign.TextSearchConditionComparator; import org.lamsfoundation.lams.tool.qa.QaAppConstants; import org.lamsfoundation.lams.tool.qa.QaComparator; import org.lamsfoundation.lams.tool.qa.QaCondition; import org.lamsfoundation.lams.tool.qa.QaContent; import org.lamsfoundation.lams.tool.qa.QaQueContent; import org.lamsfoundation.lams.tool.qa.QaQuestionContentDTO; import org.lamsfoundation.lams.tool.qa.service.IQaService; -import org.lamsfoundation.lams.tool.qa.util.QaConditionComparator; import org.lamsfoundation.lams.tool.qa.util.QaQueContentComparator; import org.lamsfoundation.lams.tool.qa.util.QaQuestionContentDTOComparator; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; @@ -530,7 +530,7 @@ } - qaContent.setConditions(new TreeSet(new QaConditionComparator())); + qaContent.setConditions(new TreeSet(new TextSearchConditionComparator())); if (newContent) { AuthoringUtil.logger.debug("will create: " + qaContent); qaService.createQa(qaContent); Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaAuthoringConditionAction.java =================================================================== diff -u -r62bfc2c0cd9979e725e11c66ebd355b47471a81f -r33f9171c071c179459972380a9b732f1aeec87bf --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaAuthoringConditionAction.java (.../QaAuthoringConditionAction.java) (revision 62bfc2c0cd9979e725e11c66ebd355b47471a81f) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaAuthoringConditionAction.java (.../QaAuthoringConditionAction.java) (revision 33f9171c071c179459972380a9b732f1aeec87bf) @@ -43,12 +43,13 @@ import org.apache.struts.action.ActionMessage; import org.apache.struts.action.ActionMessages; import org.apache.struts.util.LabelValueBean; +import org.lamsfoundation.lams.learningdesign.TextSearchCondition; +import org.lamsfoundation.lams.learningdesign.TextSearchConditionComparator; import org.lamsfoundation.lams.tool.qa.QaAppConstants; import org.lamsfoundation.lams.tool.qa.QaCondition; import org.lamsfoundation.lams.tool.qa.QaQuestionContentDTO; import org.lamsfoundation.lams.tool.qa.service.IQaService; import org.lamsfoundation.lams.tool.qa.service.QaServiceProxy; -import org.lamsfoundation.lams.tool.qa.util.QaConditionComparator; import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.web.util.SessionMap; import org.springframework.web.context.WebApplicationContext; @@ -291,7 +292,7 @@ private SortedSet getQaConditionSet(SessionMap sessionMap) { SortedSet list = (SortedSet) sessionMap.get(QaAppConstants.ATTR_CONDITION_SET); if (list == null) { - list = new TreeSet(new QaConditionComparator()); + list = new TreeSet(new TextSearchConditionComparator()); sessionMap.put(QaAppConstants.ATTR_CONDITION_SET, list); } return list; @@ -385,7 +386,9 @@ for (QaQuestionContentDTO question : questions) { String nonHTMLQuestion = question.getQuestion(); if (nonHTMLQuestion != null) { - nonHTMLQuestion = nonHTMLQuestion.replaceAll(QaAppConstants.HTML_TAG_REGEX, ""); + nonHTMLQuestion = TextSearchCondition.removeHTMLtags(nonHTMLQuestion); + // we don't want to cite the whole question, so we just leave some first characters; it should be enough + // to recognise the question by a teacher if (nonHTMLQuestion.length() > QaAppConstants.QUESTION_CUTOFF_INDEX) { nonHTMLQuestion = nonHTMLQuestion.substring(0, QaAppConstants.QUESTION_CUTOFF_INDEX) + "..."; } Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaConditionForm.java =================================================================== diff -u -r62bfc2c0cd9979e725e11c66ebd355b47471a81f -r33f9171c071c179459972380a9b732f1aeec87bf --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaConditionForm.java (.../QaConditionForm.java) (revision 62bfc2c0cd9979e725e11c66ebd355b47471a81f) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaConditionForm.java (.../QaConditionForm.java) (revision 33f9171c071c179459972380a9b732f1aeec87bf) @@ -101,8 +101,8 @@ * @return created condition */ public QaCondition extractCondition() { - return new QaCondition(null, null, getOrderId(), null, getDisplayName(), "OUTPUT_COMPLEX", null, null, null, - getAllWords(), getPhrase(), getAnyWords(), getExcludedWords(), null); + return new QaCondition(null, null, getOrderId(), null, getDisplayName(), getAllWords(), getPhrase(), + getAnyWords(), getExcludedWords(), null); } public void extractCondition(QaCondition condition) { Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaStarterAction.java =================================================================== diff -u -r62bfc2c0cd9979e725e11c66ebd355b47471a81f -r33f9171c071c179459972380a9b732f1aeec87bf --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaStarterAction.java (.../QaStarterAction.java) (revision 62bfc2c0cd9979e725e11c66ebd355b47471a81f) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaStarterAction.java (.../QaStarterAction.java) (revision 33f9171c071c179459972380a9b732f1aeec87bf) @@ -145,6 +145,7 @@ import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; import org.apache.struts.action.ActionMessages; +import org.lamsfoundation.lams.learningdesign.TextSearchConditionComparator; import org.lamsfoundation.lams.tool.qa.QaAppConstants; import org.lamsfoundation.lams.tool.qa.QaApplicationException; import org.lamsfoundation.lams.tool.qa.QaComparator; @@ -156,7 +157,6 @@ import org.lamsfoundation.lams.tool.qa.QaUtils; import org.lamsfoundation.lams.tool.qa.service.IQaService; import org.lamsfoundation.lams.tool.qa.service.QaServiceProxy; -import org.lamsfoundation.lams.tool.qa.util.QaConditionComparator; import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.web.util.AttributeNames; import org.lamsfoundation.lams.web.util.SessionMap; @@ -487,7 +487,7 @@ request.setAttribute(QaAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); sessionMap.put(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - SortedSet conditionSet = new TreeSet(new QaConditionComparator()); + SortedSet conditionSet = new TreeSet(new TextSearchConditionComparator()); for (QaCondition condition : qaContent.getConditions()) { conditionSet.add(condition); for (QaQuestionContentDTO dto : (List) listQuestionContentDTO) { @@ -643,7 +643,7 @@ private SortedSet getQaConditionList(SessionMap sessionMap) { SortedSet list = (SortedSet) sessionMap.get(QaAppConstants.ATTR_CONDITION_SET); if (list == null) { - list = new TreeSet(new QaConditionComparator()); + list = new TreeSet(new TextSearchConditionComparator()); sessionMap.put(QaAppConstants.ATTR_CONDITION_SET, list); } return list;