Index: TestHarness4LAMS2/src/org/lamsfoundation/testharness/learner/MockLearner.java =================================================================== diff -u -r92f41485ed2aa68db48ad1a4e2b9f4891135ca6c -rbff78521da917cfaff7cccf024f8cf0a343db734 --- TestHarness4LAMS2/src/org/lamsfoundation/testharness/learner/MockLearner.java (.../MockLearner.java) (revision 92f41485ed2aa68db48ad1a4e2b9f4891135ca6c) +++ TestHarness4LAMS2/src/org/lamsfoundation/testharness/learner/MockLearner.java (.../MockLearner.java) (revision bff78521da917cfaff7cccf024f8cf0a343db734) @@ -100,6 +100,7 @@ private static final Pattern SCRATCHIE_SCRATCH_PATTERN = Pattern.compile("scratchItem\\((\\d+), (\\d+)\\)"); private static final String SCRATCHIE_FINISH_AVAILABLE = "return finish()"; private static final String SCRATCHIE_REFLECTION_AVAILABLE = "return continueReflect()"; + private static final String SCRATCHIE_IS_LEADER_SUBSTRING = "isUserLeader=true"; private static final String KNOCK_GATE_SUBSTRING = "/lams/learning/gate.do?method=knockGate"; @@ -344,24 +345,11 @@ private WebResponse handleScratchie(WebResponse resp) throws SAXException, IOException { String asText = resp.getText(); - Matcher m = MockLearner.SCRATCHIE_SCRATCH_PATTERN.matcher(asText); - Map> uids = new TreeMap>(); - while (m.find()) { - Long questionID = Long.valueOf(m.group(1)); - List answerUids = uids.get(questionID); - if (answerUids == null) { - answerUids = new ArrayList(); - uids.put(questionID, answerUids); - } - answerUids.add(Long.valueOf(m.group(2))); - } - - String scratchURL = "/lams/tool/lascrt11/learning/isAnswerCorrect.do?answerUid="; - m = MockLearner.SESSION_MAP_ID_PATTERN.matcher(asText); - + boolean isLeader = asText.contains(SCRATCHIE_IS_LEADER_SUBSTRING); String sessionMapID = null; String recordScratchedURL = null; String refreshQuestionsURL = null; + Matcher m = MockLearner.SESSION_MAP_ID_PATTERN.matcher(asText); if (m.find()) { sessionMapID = m.group(1); recordScratchedURL = "/lams/tool/lascrt11/learning/recordItemScratched.do?sessionMapID=" + sessionMapID @@ -370,56 +358,66 @@ } else { MockLearner.log.warn("Session map ID was not found in Scratchie Tool"); } - Random generator = new Random(); - while (!uids.isEmpty()) { - Long questionID = uids.keySet().iterator().next(); - List answerUids = uids.get(questionID); + if (isLeader) { + m = MockLearner.SCRATCHIE_SCRATCH_PATTERN.matcher(asText); + Map> uids = new TreeMap>(); + while (m.find()) { + Long questionID = Long.valueOf(m.group(1)); + List answerUids = uids.get(questionID); + if (answerUids == null) { + answerUids = new ArrayList(); + uids.put(questionID, answerUids); + } + answerUids.add(Long.valueOf(m.group(2))); + } - int index = generator.nextInt(answerUids.size()); - Long answerUid = answerUids.get(index); - answerUids.remove(index); - MockLearner.log.debug("Scratching answer UID " + answerUid + " for question " + questionID); - WebResponse scratchResponse = (WebResponse) new Call(wc, test, "Scratch response", scratchURL + answerUid) - .execute(); - boolean answerCorrect = scratchResponse.getText().indexOf("true") != -1; - MockLearner.log.debug("Scratched answer UID " + answerUid + " for question " + questionID + " and it was " - + (answerCorrect ? "correct" : "incorrect")); + String scratchURL = "/lams/tool/lascrt11/learning/isAnswerCorrect.do?answerUid="; + Random generator = new Random(); - if (answerCorrect) { - uids.remove(questionID); - } + while (!uids.isEmpty()) { + Long questionID = uids.keySet().iterator().next(); + List answerUids = uids.get(questionID); -// if (recordScratchedURL != null) { -// MockLearner.log.debug("Recording scratched answer UID " + answerUid); -// new Call(wc, test, "Record answer scratched", recordScratchedURL + answerUid).execute(); -// } + int index = generator.nextInt(answerUids.size()); + Long answerUid = answerUids.get(index); + answerUids.remove(index); + MockLearner.log.debug("Scratching answer UID " + answerUid + " for question " + questionID); + WebResponse scratchResponse = (WebResponse) new Call(wc, test, "Scratch response", scratchURL + + answerUid).execute(); + boolean answerCorrect = scratchResponse.getText().indexOf("true") != -1; + MockLearner.log.debug("Scratched answer UID " + answerUid + " for question " + questionID + + " and it was " + (answerCorrect ? "correct" : "incorrect")); - if (refreshQuestionsURL != null) { - MockLearner.log.debug("Refreshing scratchie question list"); - new Call(wc, test, "Refresh question list", refreshQuestionsURL).execute(); - } + if (recordScratchedURL != null) { + MockLearner.log.debug("Recording scratched answer UID " + answerUid); + new Call(wc, test, "Record answer scratched", recordScratchedURL + answerUid).execute(); + } - if (!answerCorrect && !answerUids.isEmpty()) { + if (answerCorrect) { + uids.remove(questionID); + } + if (!answerUids.isEmpty()) { + delay(); + } + } + } else { + while (refreshQuestionsURL != null + && !(asText.contains(MockLearner.SCRATCHIE_FINISH_AVAILABLE) || asText + .contains(MockLearner.SCRATCHIE_REFLECTION_AVAILABLE))) { + MockLearner.log.debug("Waiting for leader to finish scratchie"); try { Thread.sleep(3000); } catch (InterruptedException e) { - MockLearner.log.warn("Waiting to scratch was interuppted"); + log.error("Interrupted waiting between question list refresh in scratchie"); } + String url = resp.getURL().toString() + "&reqId=" + System.currentTimeMillis(); + WebResponse questionRefreshResp = (WebResponse) new Call(wc, test, "Scratchie refresh question list", + refreshQuestionsURL).execute(); + asText = questionRefreshResp.getText(); } } - while (refreshQuestionsURL != null - && !(asText.contains(MockLearner.SCRATCHIE_FINISH_AVAILABLE) || asText - .contains(MockLearner.SCRATCHIE_REFLECTION_AVAILABLE))) { - MockLearner.log.debug("Waiting for leader to finish scratchie"); - delay(); - String url = resp.getURL().toString() + "&reqId=" + System.currentTimeMillis(); - WebResponse questionRefreshResp = (WebResponse) new Call(wc, test, "Scratchie refresh", refreshQuestionsURL) - .execute(); - asText = questionRefreshResp.getText(); - } - String reflectionURL = findURLInLocationHref(resp, MockLearner.SCRATCHIE_REFLECTION_SUBSTRING); if (reflectionURL != null) { MockLearner.log.debug("Showing reflection of scratchie using url " + reflectionURL); Index: lams_tool_scratchie/web/pages/learning/questionlist.jsp =================================================================== diff -u -r94be37497fa57d778f02fbb3e13436e673b12e30 -rbff78521da917cfaff7cccf024f8cf0a343db734 --- lams_tool_scratchie/web/pages/learning/questionlist.jsp (.../questionlist.jsp) (revision 94be37497fa57d778f02fbb3e13436e673b12e30) +++ lams_tool_scratchie/web/pages/learning/questionlist.jsp (.../questionlist.jsp) (revision bff78521da917cfaff7cccf024f8cf0a343db734) @@ -12,6 +12,8 @@ + +

${item.title}

${item.description}