Index: lams_tool_scratchie/conf/language/lams/ApplicationResources_en_AU.properties =================================================================== diff -u -r9b7493fc93eb90730d3ba034af874e6b84fe2eb5 -rc7569597546126af159f169353e68e91241b7f10 --- lams_tool_scratchie/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision 9b7493fc93eb90730d3ba034af874e6b84fe2eb5) +++ lams_tool_scratchie/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision c7569597546126af159f169353e68e91241b7f10) @@ -108,15 +108,7 @@ label.attempts =Attempts label.choice.number =Choice #{0} label.group.leader =Group Leader: {0} -label.are.you.going.to.be.leader =Are you going to be a leader of this group? -label.leader.selection =Leader selection -label.users.from.group =Other users participating in current group: -label.yes.become.leader =Yes, I want to become a leader -label.no =No label.refresh =Refresh -label.waiting.for.leader =Please, wait while somebody will become a group leader. -label.manage.leaders =Manage Leaders -label.plese.select.leaders =Please, select leaders label.export.excel =Export Excel label.research.analysis =Research and Analysis label.scratchie.report =Scratchie Report @@ -141,7 +133,6 @@ label.questions =Questions label.teams =TEAMS label.yes =yes -label.no =no label.spss.analysis =For_XLS_export(SPSS analysis) label.student.name =Student Name label.team =Team @@ -176,3 +167,6 @@ label.learners.feedback =Learner's feedback label.monitoring.team.leader =team leader label.authoring.import.qti =Import IMS QTI +label.authoring.advanced.show.results.page =Use leader selection tool results. +label.waiting.for.leader =Please, wait while somebody will become a group leader. +label.users.from.group =Other users participating in current group: Index: lams_tool_scratchie/conf/xdoclet/struts-actions.xml =================================================================== diff -u -r4b178984cfb2aebc0e9c1e9e586c06a1c6ea40bc -rc7569597546126af159f169353e68e91241b7f10 --- lams_tool_scratchie/conf/xdoclet/struts-actions.xml (.../struts-actions.xml) (revision 4b178984cfb2aebc0e9c1e9e586c06a1c6ea40bc) +++ lams_tool_scratchie/conf/xdoclet/struts-actions.xml (.../struts-actions.xml) (revision c7569597546126af159f169353e68e91241b7f10) @@ -189,7 +189,7 @@ type="org.lamsfoundation.lams.tool.scratchie.web.action.LearningAction" parameter="start" > - + @@ -199,10 +199,6 @@ parameter="refreshQuestionList" > - - @@ -251,15 +247,6 @@ parameter="itemSummary" > - - - - - Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/ScratchieConstants.java =================================================================== diff -u -rd3d95be637b35c0566741de9c36ad1e8643ee14c -rc7569597546126af159f169353e68e91241b7f10 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/ScratchieConstants.java (.../ScratchieConstants.java) (revision d3d95be637b35c0566741de9c36ad1e8643ee14c) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/ScratchieConstants.java (.../ScratchieConstants.java) (revision c7569597546126af159f169353e68e91241b7f10) @@ -150,6 +150,12 @@ public static final String ATTR_USER = "user"; public static final String ATTR_GROUP_LEADER = "groupLeader"; + + public static final String ATTR_IS_USER_LEADER = "isUserLeader"; public static final String LEARNER_MARK = "learner.mark"; + + //Leader selection tool Constants + public static final String LEADER_SELECTION_TOOL_SIGNATURE = "lalead11"; + public static final String LEADER_SELECTION_TOOL_OUTPUT_NAME_LEADER_USERID = "leader.user.id"; } Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dbupdates/patch20130502_wviCustomUpdate.sql =================================================================== diff -u --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dbupdates/patch20130502_wviCustomUpdate.sql (revision 0) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dbupdates/patch20130502_wviCustomUpdate.sql (revision c7569597546126af159f169353e68e91241b7f10) @@ -0,0 +1,15 @@ +-- Turn off autocommit, so nothing is committed if there is an error +SET AUTOCOMMIT = 0; + +----------------------Put all sql statements below here------------------------- + +-- LKC-4 Modify Scratchie Tool to use Select Leader Tool Outputs +ALTER TABLE tl_lascrt11_session ADD COLUMN group_leader_uid BIGINT; +ALTER TABLE tl_lascrt11_session ADD INDEX FK_lalead11_session1 (group_leader_uid), ADD CONSTRAINT FK_lalead11_session1 FOREIGN KEY (group_leader_uid) REFERENCES tl_lascrt11_user (uid); +ALTER TABLE tl_lascrt11_user DROP COLUMN leader; + +----------------------Put all sql statements above here------------------------- + +-- If there were no errors, commit and restore autocommit to on +COMMIT; +SET AUTOCOMMIT = 1; \ No newline at end of file Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/model/ScratchieSession.java =================================================================== diff -u -r6aaee4b2fe2caa08b0c63a0de11f05042d5a3e18 -rc7569597546126af159f169353e68e91241b7f10 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/model/ScratchieSession.java (.../ScratchieSession.java) (revision 6aaee4b2fe2caa08b0c63a0de11f05042d5a3e18) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/model/ScratchieSession.java (.../ScratchieSession.java) (revision c7569597546126af159f169353e68e91241b7f10) @@ -50,6 +50,7 @@ private int status; // scratchie Items private Set scratchieItems; + private ScratchieUser groupLeader; // ********************************************************** // Get/Set methods @@ -160,5 +161,17 @@ public void setScratchieItems(Set scratchieItems) { this.scratchieItems = scratchieItems; } + + /** + * @hibernate.many-to-one not-null="true" + * @hibernate.column name="group_leader_uid" + */ + public ScratchieUser getGroupLeader() { + return this.groupLeader; + } + public void setGroupLeader(ScratchieUser groupLeader) { + this.groupLeader = groupLeader; + } + } Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/model/ScratchieUser.java =================================================================== diff -u -r6b651e7c25c7baa6a942ea7348f59701bbb4e603 -rc7569597546126af159f169353e68e91241b7f10 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/model/ScratchieUser.java (.../ScratchieUser.java) (revision 6b651e7c25c7baa6a942ea7348f59701bbb4e603) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/model/ScratchieUser.java (.../ScratchieUser.java) (revision c7569597546126af159f169353e68e91241b7f10) @@ -47,7 +47,6 @@ private String loginName; private boolean sessionFinished; private boolean scratchingFinished; - private boolean leader; private ScratchieSession session; private Scratchie scratchie; @@ -222,21 +221,7 @@ public void setScratchingFinished(boolean scratchingFinished) { this.scratchingFinished = scratchingFinished; } - - /** - * Indicates whether user is leader of his group. - * - * @hibernate.property column="leader" - * @return - */ - public boolean isLeader() { - return leader; - } - public void setLeader(boolean leader) { - this.leader = leader; - } - public boolean equals(Object obj) { if (this == obj) return true; Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/scratchieApplicationContext.xml =================================================================== diff -u -r8de4e6f48a6ad07b55ce8cc4a4eced6490838d0c -rc7569597546126af159f169353e68e91241b7f10 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/scratchieApplicationContext.xml (.../scratchieApplicationContext.xml) (revision 8de4e6f48a6ad07b55ce8cc4a4eced6490838d0c) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/scratchieApplicationContext.xml (.../scratchieApplicationContext.xml) (revision c7569597546126af159f169353e68e91241b7f10) @@ -98,10 +98,13 @@ - - + + - + + + + @@ -119,7 +122,7 @@ PROPAGATION_REQUIRED,-java.lang.Exception PROPAGATION_REQUIRED,-java.lang.Exception PROPAGATION_REQUIRED,-java.lang.Exception - PROPAGATION_REQUIRED,-java.lang.Exception + PROPAGATION_REQUIRED,-java.lang.Exception PROPAGATION_REQUIRED,-java.lang.Exception PROPAGATION_REQUIRED,-java.lang.Exception PROPAGATION_REQUIRED,-java.lang.Exception Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/IScratchieService.java =================================================================== diff -u -r5a5f3640c4d5fdf0c302347e7d6b502a972fd9cc -rc7569597546126af159f169353e68e91241b7f10 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/IScratchieService.java (.../IScratchieService.java) (revision 5a5f3640c4d5fdf0c302347e7d6b502a972fd9cc) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/IScratchieService.java (.../IScratchieService.java) (revision c7569597546126af159f169353e68e91241b7f10) @@ -59,18 +59,19 @@ Scratchie getScratchieByContentId(Long contentId); /** + * @param user * @param toolSessionId - * @return group leader if available, null otherwise + * @return */ - ScratchieUser getGroupLeader(Long toolSessionId); + boolean isUserGroupLeader(ScratchieUser user, Long toolSessionId); /** * Set specified user as a leader. Also the previous leader (if any) is marked as non-leader. * * @param userId * @param toolSessionId */ - void setGroupLeader(Long userId, Long toolSessionId); + ScratchieUser checkLeaderSelectToolForSessionLeader(ScratchieUser user, Long toolSessionId); ScratchieAnswer getScratchieAnswerById (Long answerUid); @@ -320,15 +321,6 @@ * @return message content */ String getMessage(String key); - - /** - * Finds out which lesson the given tool content belongs to and returns its monitoring users. - * - * @param sessionId - * tool session ID - * @return list of teachers that monitor the lesson which contains the tool with given session ID - */ - List getMonitorsByToolSessionId(Long sessionId); /** * Returns whether activity is grouped and therefore it is expected more than one tool session. Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java =================================================================== diff -u -rbdce379f89973a36878d1aaf707423b54f092351 -rc7569597546126af159f169353e68e91241b7f10 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java (.../ScratchieServiceImpl.java) (revision bdce379f89973a36878d1aaf707423b54f092351) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java (.../ScratchieServiceImpl.java) (revision c7569597546126af159f169353e68e91241b7f10) @@ -56,17 +56,21 @@ import org.lamsfoundation.lams.contentrepository.service.SimpleCredentials; import org.lamsfoundation.lams.events.IEventNotificationService; import org.lamsfoundation.lams.learning.service.ILearnerService; +import org.lamsfoundation.lams.learningdesign.Activity; +import org.lamsfoundation.lams.learningdesign.LearningDesign; +import org.lamsfoundation.lams.learningdesign.ToolActivity; +import org.lamsfoundation.lams.learningdesign.dao.IActivityDAO; import org.lamsfoundation.lams.learningdesign.service.ExportToolContentException; import org.lamsfoundation.lams.learningdesign.service.IExportToolContentService; import org.lamsfoundation.lams.learningdesign.service.ImportToolContentException; -import org.lamsfoundation.lams.lesson.service.ILessonService; import org.lamsfoundation.lams.notebook.model.NotebookEntry; import org.lamsfoundation.lams.notebook.service.CoreNotebookConstants; import org.lamsfoundation.lams.notebook.service.ICoreNotebookService; import org.lamsfoundation.lams.tool.ToolContentImport102Manager; import org.lamsfoundation.lams.tool.ToolContentManager; import org.lamsfoundation.lams.tool.ToolOutput; import org.lamsfoundation.lams.tool.ToolOutputDefinition; +import org.lamsfoundation.lams.tool.ToolSession; import org.lamsfoundation.lams.tool.ToolSessionExportOutputData; import org.lamsfoundation.lams.tool.ToolSessionManager; import org.lamsfoundation.lams.tool.exception.DataMissingException; @@ -92,6 +96,7 @@ import org.lamsfoundation.lams.tool.scratchie.util.ScratchieAnswerComparator; import org.lamsfoundation.lams.tool.scratchie.util.ScratchieItemComparator; import org.lamsfoundation.lams.tool.scratchie.util.ScratchieToolContentHandler; +import org.lamsfoundation.lams.tool.service.ILamsCoreToolService; import org.lamsfoundation.lams.tool.service.ILamsToolService; import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; @@ -106,7 +111,7 @@ public class ScratchieServiceImpl implements IScratchieService, ToolContentManager, ToolSessionManager, ToolContentImport102Manager { private static Logger log = Logger.getLogger(ScratchieServiceImpl.class.getName()); - + private static final ExcelCell[] EMPTY_ROW = new ExcelCell[4]; private ScratchieDAO scratchieDao; @@ -141,7 +146,9 @@ private IEventNotificationService eventNotificationService; - private ILessonService lessonService; + private ILamsCoreToolService lamsCoreToolService; + + private IActivityDAO activityDAO; private ScratchieOutputFactory scratchieOutputFactory; @@ -271,57 +278,102 @@ public void deleteScratchieItem(Long uid) { scratchieItemDao.removeObject(ScratchieItem.class, uid); } - + @Override - public ScratchieUser getGroupLeader(Long toolSessionId) { - List users = scratchieUserDao.getBySessionID(toolSessionId); + public boolean isUserGroupLeader(ScratchieUser user, Long toolSessionId) { + + ScratchieSession session = this.getScratchieSessionBySessionId(toolSessionId); + ScratchieUser groupLeader = session.getGroupLeader(); - ScratchieUser groupLeader = null; - for (ScratchieUser user : users) { - if (user.isLeader()) { - groupLeader = user; - break; - } - } - - return groupLeader; + boolean isUserLeader = (groupLeader != null) && user.getUid().equals(groupLeader.getUid()); + return isUserLeader; } - + @Override - public void setGroupLeader(Long userId, Long toolSessionId) { - if (userId==null || toolSessionId==null) { - return; + public ScratchieUser checkLeaderSelectToolForSessionLeader(ScratchieUser user, Long toolSessionId) { + if (user == null || toolSessionId == null) { + return null; } - - ScratchieUser leader = getUserByIDAndSession(userId, toolSessionId); - if (!leader.isLeader()) { - // set previous leader set as a non-leader - ScratchieUser previousGroupLeader = getGroupLeader(toolSessionId); - if ((previousGroupLeader != null) && !previousGroupLeader.equals(leader)) { - previousGroupLeader.setLeader(false); - saveUser(previousGroupLeader); + + ScratchieSession scratchieSession = getScratchieSessionBySessionId(toolSessionId); + ScratchieUser leader = scratchieSession.getGroupLeader(); + // check leader select tool for a leader only in case scratchie tool doesn't know it. As otherwise it will screw + // up previous scratches done + if (leader == null) { + + ToolSession toolSession = toolService.getToolSession(toolSessionId); + LearningDesign learningDesign = toolSession.getToolActivity().getLearningDesign(); + + // find leaderSelection Tool in a lesson + /* + * Hibernate CGLIB is failing to load the first activity in the sequence as a ToolActivity for some + * mysterious reason Causes a ClassCastException when you try to cast it, even if it is a ToolActivity. + * + * THIS IS A HACK to retrieve the first tool activity manually so it can be cast as a ToolActivity - if it + * is one + */ + Set activities = new TreeSet(); + Activity firstActivity = activityDAO.getActivityByActivityId(learningDesign.getFirstActivity() + .getActivityId()); + activities.add(firstActivity); + activities.addAll(learningDesign.getActivities()); + + ToolActivity leaderSelectionTool = null; + for (Activity activity : activities) { + if (activity instanceof ToolActivity) { + ToolActivity toolActivity = (ToolActivity) activity; + if (ScratchieConstants.LEADER_SELECTION_TOOL_SIGNATURE.equals(toolActivity.getTool().getToolSignature())) { + leaderSelectionTool = toolActivity; + } + } } - - //mark user as a leader - leader.setLeader(true); - saveUser(leader); + + // check if there is leaderSelectionTool in a sequence + if (leaderSelectionTool != null) { + User learner = (User) getUserManagementService().findById(User.class, user.getUserId().intValue()); + String outputName = ScratchieConstants.LEADER_SELECTION_TOOL_OUTPUT_NAME_LEADER_USERID; + ToolSession leaderSelectionSession = lamsCoreToolService.getToolSessionByLearner(learner, + leaderSelectionTool); + ToolOutput output = lamsCoreToolService.getOutputFromTool(outputName, leaderSelectionSession, null); + + // check if tool produced output + if (output != null && output.getValue() != null) { + Long userId = output.getValue().getLong(); + leader = getUserByIDAndSession(userId, toolSessionId); + + // create new user in a DB + if (leader == null) { + log.debug("creating new user with userId: " + userId); + User leaderDto = (User) getUserManagementService().findById(User.class, userId.intValue()); + leader = new ScratchieUser(leaderDto.getUserDTO(), scratchieSession); + this.createUser(leader); + } + + // set group leader + scratchieSession.setGroupLeader(leader); + saveOrUpdateScratchieSession(scratchieSession); + } + } } - } - + + return leader; + } + @Override public void copyScratchesFromLeader(ScratchieUser user, ScratchieUser leader) { - - if ((user == null) || (leader == null) || user.equals(leader)) { + + if ((user == null) || (leader == null) || user.getUid().equals(leader.getUid())) { return; } - + List leaderLogs = scratchieAnswerVisitDao.getLogsByScratchieUser(leader.getUid()); - + for (ScratchieAnswerVisitLog leaderLog : leaderLogs) { ScratchieAnswer answer = leaderLog.getScratchieAnswer(); - ScratchieAnswerVisitLog log = scratchieAnswerVisitDao.getScratchieAnswerLog(answer.getUid(), user.getUserId()); - - //create and save new ScratchieAnswerVisitLog + ScratchieAnswerVisitLog log = scratchieAnswerVisitDao.getScratchieAnswerLog(answer.getUid(), + user.getUserId()); + + // create and save new ScratchieAnswerVisitLog if (log == null) { log = new ScratchieAnswerVisitLog(); log.setScratchieAnswer(answer); @@ -424,7 +476,7 @@ @Override public void setAnswerAccess(Long answerUid, Long sessionId) { - + List users = getUsersBySession(sessionId); for (ScratchieUser user : users) { ScratchieAnswerVisitLog log = scratchieAnswerVisitDao.getScratchieAnswerLog(answerUid, user.getUserId()); @@ -440,12 +492,12 @@ } } - + @Override - public ScratchieAnswer getScratchieAnswerById (Long answerUid) { - return (ScratchieAnswer) userManagementService.findById(ScratchieAnswer.class, answerUid); + public ScratchieAnswer getScratchieAnswerById(Long answerUid) { + return (ScratchieAnswer) userManagementService.findById(ScratchieAnswer.class, answerUid); } - + @Override public void setScratchingFinished(Long toolSessionId) { List users = getUsersBySession(toolSessionId); @@ -462,7 +514,7 @@ ScratchieUser user = scratchieUserDao.getUserByUserIDAndSessionID(userId, toolSessionId); user.setSessionFinished(true); scratchieUserDao.saveObject(user); - + nextUrl = this.leaveToolSession(toolSessionId, userId); } catch (DataMissingException e) { throw new ScratchieApplicationException(e); @@ -476,32 +528,32 @@ public ScratchieItem getScratchieItemByUid(Long itemUid) { return scratchieItemDao.getByUid(itemUid); } - + @Override public Set getAllLearners(Long contentId) { Set users = new TreeSet(); - + List sessionList = scratchieSessionDao.getByContentId(contentId); for (ScratchieSession session : sessionList) { Long sessionId = session.getSessionId(); List sessionUsers = scratchieUserDao.getBySessionID(sessionId); users.addAll(sessionUsers); } - + return users; } - + @Override public List getUsersBySession(Long toolSessionId) { return scratchieUserDao.getBySessionID(toolSessionId); } - + @Override public void saveUser(ScratchieUser user) { scratchieUserDao.saveObject(user); } - + @Override public List getMonitoringSummary(Long contentId) { List groupSummaryList = new ArrayList(); @@ -514,52 +566,54 @@ List users = scratchieUserDao.getBySessionID(sessionId); for (ScratchieUser user : users) { - - int totalAttempts = scratchieAnswerVisitDao.getLogCountTotal(sessionId, user.getUserId()); + + int totalAttempts = scratchieAnswerVisitDao.getLogCountTotal(sessionId, user.getUserId()); user.setTotalAttempts(totalAttempts); - - //for displaying purposes if there is no attemps we assign -1 which will be shown as "-" - int mark = (totalAttempts == 0) ? -1 : getUserMark(sessionId, user.getUserId()); + + // for displaying purposes if there is no attemps we assign -1 which will be shown as "-" + int mark = (totalAttempts == 0) ? -1 : getUserMark(sessionId, user.getUserId()); user.setMark(mark); } - + groupSummary.setUsers(users); groupSummaryList.add(groupSummary); } return groupSummaryList; } - + @Override public void retrieveScratchesOrder(Collection items, ScratchieUser user) { - + for (ScratchieItem item : items) { - List itemLogs = scratchieAnswerVisitDao.getLogsByScratchieUserAndItem(user.getUid(), item.getUid()); - + List itemLogs = scratchieAnswerVisitDao.getLogsByScratchieUserAndItem( + user.getUid(), item.getUid()); + for (ScratchieAnswer answer : (Set) item.getAnswers()) { int attemptNumber; - ScratchieAnswerVisitLog log = scratchieAnswerVisitDao.getScratchieAnswerLog(answer.getUid(), user.getUserId()); + ScratchieAnswerVisitLog log = scratchieAnswerVisitDao.getScratchieAnswerLog(answer.getUid(), + user.getUserId()); if (log == null) { // -1 if there is no log attemptNumber = -1; } else { - //adding 1 to start from 1. + // adding 1 to start from 1. attemptNumber = itemLogs.indexOf(log) + 1; } answer.setAttemptOrder(attemptNumber); } } - + } - + @Override public void retrieveScratched(Collection items, ScratchieUser user) { - + for (ScratchieItem item : items) { - - for (ScratchieAnswer answer : (Set)item.getAnswers()) { + + for (ScratchieAnswer answer : (Set) item.getAnswers()) { ScratchieAnswerVisitLog log = scratchieAnswerVisitDao.getScratchieAnswerLog(answer.getUid(), user.getUserId()); if (log == null) { @@ -568,11 +622,11 @@ answer.setScratched(true); } } - + item.setUnraveled(isItemUnraveled(item, user.getUserId())); } } - + private boolean isItemUnraveled(ScratchieItem item, Long userId) { boolean isItemUnraveled = false; @@ -585,21 +639,21 @@ return isItemUnraveled; } - + @Override public int getUserMark(Long sessionId, Long userId) { ScratchieSession session = scratchieSessionDao.getSessionBySessionId(sessionId); Scratchie scratchie = session.getScratchie(); Set items = scratchie.getScratchieItems(); - + int mark = 0; for (ScratchieItem item : items) { mark += getUserMarkPerItem(scratchie, item, sessionId, userId); } - + return mark; } - + /** * * @@ -609,7 +663,7 @@ * @return */ private int getUserMarkPerItem(Scratchie scratchie, ScratchieItem item, Long sessionId, Long userId) { - + int mark = 0; // add mark only if an item was unraveled if (isItemUnraveled(item, userId)) { @@ -621,54 +675,54 @@ mark++; } } - + return mark; } - + @Override public Set populateItemsResults(Long sessionId, Long userId) { ScratchieSession session = scratchieSessionDao.getSessionBySessionId(sessionId); Scratchie scratchie = session.getScratchie(); Set items = scratchie.getScratchieItems(); - + for (ScratchieItem item : items) { int mark = getUserMarkPerItem(scratchie, item, sessionId, userId); item.setUserMark(mark); - + int attempts = scratchieAnswerVisitDao.getLogCountPerItem(sessionId, userId, item.getUid()); item.setUserAttempts(attempts); - + String correctAnswer = ""; - for (ScratchieAnswer answer : (Set)item.getAnswers()) { + for (ScratchieAnswer answer : (Set) item.getAnswers()) { if (answer.isCorrect()) { correctAnswer = answer.getDescription(); } } item.setCorrectAnswer(correctAnswer); } - + return items; } - + @Override public List getQuestionSummary(Long contentId, Long itemUid) { - + List groupSummaryList = new ArrayList(); ScratchieItem item = scratchieItemDao.getByUid(itemUid); Collection answers = item.getAnswers(); - + List sessionList = scratchieSessionDao.getByContentId(contentId); for (ScratchieSession session : sessionList) { Long sessionId = session.getSessionId(); - + // one new summary for one session. GroupSummary groupSummary = new GroupSummary(sessionId, session.getSessionName()); - + Map answerMap = new HashMap(); - for (ScratchieAnswer dbAnswer : (Set)answers) { - - //clone it so it doesn't interfere with values from other sessions + for (ScratchieAnswer dbAnswer : (Set) answers) { + + // clone it so it doesn't interfere with values from other sessions ScratchieAnswer answer = (ScratchieAnswer) dbAnswer.clone(); answer.setUid(dbAnswer.getUid()); int[] attempts = new int[answers.size()]; @@ -677,26 +731,27 @@ } List users = scratchieUserDao.getBySessionID(sessionId); - //calculate attempts table + // calculate attempts table for (ScratchieUser user : users) { - + int attemptNumber = 0; - List userAttempts = scratchieAnswerVisitDao.getLogsByScratchieUserAndItem(user.getUid(), itemUid); + List userAttempts = scratchieAnswerVisitDao.getLogsByScratchieUserAndItem( + user.getUid(), itemUid); for (ScratchieAnswerVisitLog userAttempt : userAttempts) { ScratchieAnswer answer = answerMap.get(userAttempt.getScratchieAnswer().getUid()); int[] attempts = answer.getAttempts(); - //+1 for corresponding choice + // +1 for corresponding choice attempts[attemptNumber++]++; } } - + Collection sortedAnswers = new TreeSet(new ScratchieAnswerComparator()); sortedAnswers.addAll(answerMap.values()); groupSummary.setAnswers(sortedAnswers); groupSummaryList.add(groupSummary); } - - //show total groupSummary if there is more than 1 group available + + // show total groupSummary if there is more than 1 group available if (sessionList.size() > 1) { Long sessionId = new Long(0); GroupSummary groupSummaryTotal = new GroupSummary(sessionId, "Summary"); @@ -714,10 +769,10 @@ Collection sortedAnswers = groupSummary.getAnswers(); for (ScratchieAnswer sortedAnswer : sortedAnswers) { int[] attempts = sortedAnswer.getAttempts(); - + ScratchieAnswer answerTotal = answerMapTotal.get(sortedAnswer.getUid()); int[] attemptsTotal = answerTotal.getAttempts(); - for (int i = 0; i < attempts.length; i++) { + for (int i = 0; i < attempts.length; i++) { attemptsTotal[i] += attempts[i]; } } @@ -728,33 +783,33 @@ groupSummaryTotal.setAnswers(sortedAnswers); groupSummaryList.add(0, groupSummaryTotal); } - + return groupSummaryList; } @Override public List getReflectionList(Long contentId) { - + ArrayList reflections = new ArrayList(); List sessionList = scratchieSessionDao.getByContentId(contentId); for (ScratchieSession session : sessionList) { Long sessionId = session.getSessionId(); - + List users = scratchieUserDao.getBySessionID(sessionId); - + for (ScratchieUser user : users) { NotebookEntry notebookEntry = getEntry(sessionId, CoreNotebookConstants.NOTEBOOK_TOOL, ScratchieConstants.TOOL_SIGNATURE, user.getUserId().intValue()); if ((notebookEntry != null) && StringUtils.isNotBlank(notebookEntry.getEntry())) { ReflectDTO reflectDTO = new ReflectDTO(notebookEntry.getUser()); reflectDTO.setReflection(notebookEntry.getEntry()); - reflectDTO.setIsGroupLeader(user.isLeader()); + reflectDTO.setIsGroupLeader(this.isUserGroupLeader(user, sessionId)); reflections.add(reflectDTO); } } - + } return reflections; @@ -786,59 +841,60 @@ public ScratchieUser getUser(Long uid) { return (ScratchieUser) scratchieUserDao.getObject(ScratchieUser.class, uid); } - + @Override public LinkedHashMap exportExcel(Long contentId) { Scratchie scratchie = scratchieDao.getByContentId(contentId); Collection items = new TreeSet(new ScratchieItemComparator()); items.addAll(scratchie.getScratchieItems()); - + LinkedHashMap dataToExport = new LinkedHashMap(); - - //======================================================= Research and Analysis page ======================================= - + + // ======================================================= Research and Analysis page + // ======================================= + // all rows List rowList = new LinkedList(); - + // Caption ExcelCell[] row = new ExcelCell[2]; row[0] = new ExcelCell(getMessage("label.scratchie.report"), true); rowList.add(row); rowList.add(EMPTY_ROW); rowList.add(EMPTY_ROW); - + // Overall Summary by Team -------------------------------------------------- row = new ExcelCell[2]; row[0] = new ExcelCell(getMessage("label.overall.summary.by.team"), true); rowList.add(row); - row = new ExcelCell[items.size()*3 + 1]; + row = new ExcelCell[items.size() * 3 + 1]; int columnCount = 1; - for (int itemCount = 0; itemCount summaryByTeam = getSummaryByTeam(scratchie, items); for (GroupSummary summary : summaryByTeam) { row = new ExcelCell[items.size() * 3 + 1]; columnCount = 0; - + row[columnCount++] = new ExcelCell(summary.getSessionName(), false); - + for (ScratchieItem item : summary.getItems()) { int attempts = item.getUserAttempts(); - + String isFirstChoice; if (item.getCorrectAnswer().equals(Boolean.TRUE.toString())) { isFirstChoice = getMessage("label.correct"); @@ -857,7 +913,7 @@ rowList.add(EMPTY_ROW); rowList.add(EMPTY_ROW); rowList.add(EMPTY_ROW); - + // Overall Summary By Individual Student in each Team---------------------------------------- row = new ExcelCell[2]; row[0] = new ExcelCell(getMessage("label.overall.summary.by.individual.student"), true); @@ -884,43 +940,43 @@ } rowList.add(EMPTY_ROW); rowList.add(EMPTY_ROW); - + // Question Reports----------------------------------------------------------------- row = new ExcelCell[1]; row[0] = new ExcelCell(getMessage("label.question.reports"), true); rowList.add(row); rowList.add(EMPTY_ROW); - + SimpleDateFormat fullDateFormat = new SimpleDateFormat("dd/MM/yy HH:mm:ss"); - + for (ScratchieItem item : items) { List itemSummary = getQuestionSummary(contentId, item.getUid()); - + row = new ExcelCell[1]; - row[0] = new ExcelCell(getMessage("label.question.semicolon", new Object[] {item.getTitle()}), true); + row[0] = new ExcelCell(getMessage("label.question.semicolon", new Object[] { item.getTitle() }), true); rowList.add(row); - + row = new ExcelCell[1]; row[0] = new ExcelCell(removeHtmlMarkup(item.getDescription()), true); rowList.add(row); rowList.add(EMPTY_ROW); rowList.add(EMPTY_ROW); - - //show all team summary in case there is more than 1 group + + // show all team summary in case there is more than 1 group if (summaryList.size() > 1) { row = new ExcelCell[1]; row[0] = new ExcelCell(getMessage("label.all.teams.summary"), true); rowList.add(row); - + GroupSummary allTeamSummary = itemSummary.get(0); Collection answers = allTeamSummary.getAnswers(); - + row = new ExcelCell[1 + answers.size()]; - for (int i = 0; i < answers.size(); i++ ) { + for (int i = 0; i < answers.size(); i++) { row[i + 1] = new ExcelCell((long) i + 1, false); } rowList.add(row); - + for (ScratchieAnswer answer : answers) { row = new ExcelCell[1 + answers.size()]; String answerTitle = removeHtmlMarkup(answer.getDescription()); @@ -929,7 +985,7 @@ } columnCount = 0; row[columnCount++] = new ExcelCell(answerTitle, false); - + for (int numberAttempts : answer.getAttempts()) { row[columnCount++] = new ExcelCell(new Long(numberAttempts), false); } @@ -938,27 +994,27 @@ rowList.add(EMPTY_ROW); rowList.add(EMPTY_ROW); } - + row = new ExcelCell[1]; row[0] = new ExcelCell(getMessage("label.breakdown.by.team"), true); rowList.add(row); for (GroupSummary groupSummary : itemSummary) { if (groupSummary.getSessionId().equals(0L)) { continue; } - + Collection answers = groupSummary.getAnswers(); - + row = new ExcelCell[1]; row[0] = new ExcelCell(groupSummary.getSessionName(), true); rowList.add(row); - + row = new ExcelCell[1 + answers.size()]; - for (int i = 0; i < answers.size(); i++ ) { - row[i+1] = new ExcelCell(new Long(i+1), false); + for (int i = 0; i < answers.size(); i++) { + row[i + 1] = new ExcelCell(new Long(i + 1), false); } rowList.add(row); - + for (ScratchieAnswer answer : answers) { row = new ExcelCell[1 + answers.size()]; String answerTitle = removeHtmlMarkup(answer.getDescription()); @@ -967,31 +1023,31 @@ } columnCount = 0; row[columnCount++] = new ExcelCell(answerTitle, false); - + for (int numberAttempts : answer.getAttempts()) { row[columnCount++] = new ExcelCell(new Long(numberAttempts), false); } rowList.add(row); } - + } rowList.add(EMPTY_ROW); rowList.add(EMPTY_ROW); } - - //Breakdown By Student with Timing---------------------------------------------------- - + + // Breakdown By Student with Timing---------------------------------------------------- + row = new ExcelCell[1]; row[0] = new ExcelCell(getMessage("label.breakdown.by.student.with.timing"), true); rowList.add(row); rowList.add(EMPTY_ROW); - + List sessionList = scratchieSessionDao.getByContentId(scratchie.getContentId()); for (ScratchieSession session : sessionList) { - - ScratchieUser groupLeader = getGroupLeader(session.getSessionId()); + + ScratchieUser groupLeader = session.getGroupLeader(); Long sessionId = session.getSessionId(); - + if (groupLeader != null) { Long userId = groupLeader.getUserId(); @@ -1003,19 +1059,21 @@ row[3] = new ExcelCell(getMessage("label.mark") + ":", false); row[4] = new ExcelCell(new Long(getUserMark(sessionId, userId)), false); rowList.add(row); - + row = new ExcelCell[1]; row[0] = new ExcelCell(getMessage("label.team.leader") + session.getSessionName(), false); rowList.add(row); - + for (ScratchieItem item : items) { row = new ExcelCell[1]; - row[0] = new ExcelCell(getMessage("label.question.semicolon", new Object[] {item.getTitle()}), false); + row[0] = new ExcelCell(getMessage("label.question.semicolon", new Object[] { item.getTitle() }), + false); rowList.add(row); rowList.add(EMPTY_ROW); - + int i = 1; - List logs = scratchieAnswerVisitDao.getLogsByScratchieUserAndItem(groupLeader.getUid(), item.getUid()); + List logs = scratchieAnswerVisitDao.getLogsByScratchieUserAndItem( + groupLeader.getUid(), item.getUid()); for (ScratchieAnswerVisitLog log : logs) { row = new ExcelCell[4]; row[0] = new ExcelCell(new Long(i++), false); @@ -1026,48 +1084,48 @@ } rowList.add(EMPTY_ROW); } - + } } - ExcelCell[][] firstPageData = rowList.toArray(new ExcelCell[][] {}); dataToExport.put(getMessage("label.research.analysis"), firstPageData); - //======================================================= For Immediate Analysis page ======================================= + // ======================================================= For Immediate Analysis page + // ======================================= rowList = new LinkedList(); - + row = new ExcelCell[1]; row[0] = new ExcelCell(getMessage("label.quick.analysis"), true); rowList.add(row); row = new ExcelCell[2]; row[1] = new ExcelCell(getMessage("label.in.table.below.we.show"), false); rowList.add(row); rowList.add(EMPTY_ROW); - + row = new ExcelCell[3]; row[2] = new ExcelCell(getMessage("label.questions"), false); rowList.add(row); - + row = new ExcelCell[items.size() + 2]; columnCount = 1; row[columnCount++] = new ExcelCell(getMessage("label.teams"), true); - for (int itemCount = 0; itemCount(); - - //Table header------------------------------------ - + + // Table header------------------------------------ + int maxAnswers = 0; for (ScratchieItem item : items) { if (item.getAnswers().size() > maxAnswers) { maxAnswers = item.getAnswers().size(); } } - + row = new ExcelCell[9 + maxAnswers * 2]; columnCount = 0; row[columnCount++] = new ExcelCell(getMessage("label.student.name"), true); @@ -1115,32 +1174,33 @@ row[columnCount++] = new ExcelCell(getMessage("label.time.of.selection." + (i + 1)), true); } rowList.add(row); - - //Table content------------------------------------ - + + // Table content------------------------------------ + for (GroupSummary summary : summaryByTeam) { Long sessionId = summary.getSessionId(); - - ScratchieUser groupLeader = getGroupLeader(sessionId); + + ScratchieSession session = getScratchieSessionBySessionId(sessionId); + ScratchieUser groupLeader = session.getGroupLeader(); List users = scratchieUserDao.getBySessionID(sessionId); - - for (ScratchieUser user: users) { - + + for (ScratchieUser user : users) { + int questionCount = 1; for (ScratchieItem item : summary.getItems()) { - + row = new ExcelCell[9 + maxAnswers * 2]; columnCount = 0; - //user name + // user name row[columnCount++] = new ExcelCell(user.getFirstName() + " " + user.getLastName(), false); - //group name + // group name row[columnCount++] = new ExcelCell(summary.getSessionName(), false); - //question number + // question number row[columnCount++] = new ExcelCell(new Long(questionCount++), false); - //question title + // question title row[columnCount++] = new ExcelCell(item.getTitle(), false); - - //correct answer + + // correct answer String correctAnswer = ""; Set answers = item.getAnswers(); for (ScratchieAnswer answer : answers) { @@ -1149,8 +1209,8 @@ } } row[columnCount++] = new ExcelCell(correctAnswer, false); - - //isFirstChoice + + // isFirstChoice int attempts = item.getUserAttempts(); String isFirstChoice; if (item.getCorrectAnswer().equals(Boolean.TRUE.toString())) { @@ -1161,13 +1221,13 @@ isFirstChoice = getMessage("label.incorrect"); } row[columnCount++] = new ExcelCell(isFirstChoice, false); - //attempts + // attempts row[columnCount++] = new ExcelCell(new Long(attempts), false); - //mark + // mark Object mark = (item.getUserMark() == -1) ? "" : new Long(item.getUserMark()); row[columnCount++] = new ExcelCell(mark, false); - - //Answers selected + + // Answers selected List logs = (groupLeader != null) ? scratchieAnswerVisitDao .getLogsByScratchieUserAndItem(groupLeader.getUid(), item.getUid()) : new ArrayList(); @@ -1181,17 +1241,17 @@ for (int i = answers.size(); i < maxAnswers; i++) { row[columnCount++] = new ExcelCell("", false); } - - //Date + + // Date String dateStr = ""; if (logs.size() > 0) { SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yy"); Date accessDate = logs.iterator().next().getAccessDate(); dateStr = dateFormat.format(accessDate); } row[columnCount++] = new ExcelCell(dateStr, false); - - //time of selection + + // time of selection SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss"); for (ScratchieAnswerVisitLog log : logs) { Date accessDate = log.getAccessDate(); @@ -1201,32 +1261,31 @@ for (int i = logs.size(); i < maxAnswers; i++) { row[columnCount++] = new ExcelCell("", false); } - + rowList.add(row); } - + } - + } ExcelCell[][] userData = rowList.toArray(new ExcelCell[][] {}); dataToExport.put(getMessage("label.spss.analysis"), userData); - + return dataToExport; } // ***************************************************************************** // private methods // ***************************************************************************** - - + /** * Currently removes only
tags. */ private String removeHtmlMarkup(String string) { return string.replaceAll("[<](/)?div[^>]*[>]", ""); } - + /** * Serves merely for excel export purposes. Produces data for "Summary By Team" section. */ @@ -1240,41 +1299,43 @@ GroupSummary groupSummary = new GroupSummary(sessionId, session.getSessionName()); ArrayList items = new ArrayList(); - ScratchieUser groupLeader = getGroupLeader(sessionId); - + ScratchieUser groupLeader = session.getGroupLeader(); + for (ScratchieItem item : sortedItems) { ScratchieItem newItem = new ScratchieItem(); int attempts = 0; int mark = -1; boolean isFirstChoice = false; - + // if there is no group leader don't calculate numbers - they aren't any if (groupLeader != null) { - attempts = scratchieAnswerVisitDao.getLogCountPerItem(sessionId, groupLeader.getUserId(), item.getUid()); + attempts = scratchieAnswerVisitDao.getLogCountPerItem(sessionId, groupLeader.getUserId(), + item.getUid()); // for displaying purposes if there is no attemps we assign -1 which will be shown as "-" - mark = (attempts == 0) ? -1 : getUserMarkPerItem(scratchie, item, sessionId, groupLeader.getUserId()); - + mark = (attempts == 0) ? -1 : getUserMarkPerItem(scratchie, item, sessionId, + groupLeader.getUserId()); + isFirstChoice = (attempts == 1) && isItemUnraveled(item, groupLeader.getUserId()); } - + newItem.setUid(item.getUid()); newItem.setTitle(item.getTitle()); newItem.setAnswers(item.getAnswers()); newItem.setUserAttempts(attempts); newItem.setUserMark(mark); newItem.setCorrectAnswer("" + isFirstChoice); - + items.add(newItem); } - + groupSummary.setItems(items); groupSummaries.add(groupSummary); } return groupSummaries; } - + private Scratchie getDefaultScratchie() throws ScratchieApplicationException { Long defaultScratchieId = getToolDefaultContentIdBySignature(ScratchieConstants.TOOL_SIGNATURE); Scratchie defaultScratchie = getScratchieByContentId(defaultScratchieId); @@ -1658,7 +1719,7 @@ public void setEventNotificationService(IEventNotificationService eventNotificationService) { this.eventNotificationService = eventNotificationService; } - + @Override public String getMessage(String key) { return messageService.getMessage(key); @@ -1670,26 +1731,15 @@ public String getMessage(String key, Object[] args) { return messageService.getMessage(key, args); } - - public ILessonService getLessonService() { - return lessonService; + + public void setActivityDAO(IActivityDAO activityDAO) { + this.activityDAO = activityDAO; } - public void setLessonService(ILessonService lessonService) { - this.lessonService = lessonService; + public void setLamsCoreToolService(ILamsCoreToolService lamsCoreToolService) { + this.lamsCoreToolService = lamsCoreToolService; } - /** - * Finds out which lesson the given tool content belongs to and returns its monitoring users. - * - * @param sessionId - * tool session ID - * @return list of teachers that monitor the lesson which contains the tool with given session ID - */ - public List getMonitorsByToolSessionId(Long sessionId) { - return getLessonService().getMonitorsByToolSessionId(sessionId); - } - public Class[] getSupportedToolOutputDefinitionClasses(int definitionType) { return getScratchieOutputFactory().getSupportedDefinitionClasses(definitionType); } Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/LearningAction.java =================================================================== diff -u -r00c7a1f28f5ef0e4f890aabd0ff5b97701d4b1bb -rc7569597546126af159f169353e68e91241b7f10 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/LearningAction.java (.../LearningAction.java) (revision 00c7a1f28f5ef0e4f890aabd0ff5b97701d4b1bb) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/LearningAction.java (.../LearningAction.java) (revision c7569597546126af159f169353e68e91241b7f10) @@ -87,9 +87,6 @@ if (param.equals("refreshQuestionList")) { return refreshQuestionList(mapping, form, request, response); } - if (param.equals("becomeLeader")) { - return becomeLeader(mapping, form, request, response); - } if (param.equals("scratchItem")) { return scratchItem(mapping, form, request, response); } @@ -128,7 +125,7 @@ // get back the scratchie and item list and display them on page IScratchieService service = getScratchieService(); Scratchie scratchie = service.getScratchieBySessionId(toolSessionId); - + ScratchieUser user = null; if (mode != null && mode.isTeacher()) { // monitoring mode - user is specified in URL @@ -138,38 +135,38 @@ } else { user = getCurrentUser(service, toolSessionId); } - - ScratchieUser groupLeader = service.getGroupLeader(toolSessionId); - //forwards to the leaderSelection page - if ((groupLeader == null) && !mode.isTeacher()) { + + ScratchieUser groupLeader = service.checkLeaderSelectToolForSessionLeader(user, toolSessionId); + + // forwards to the leaderSelection page + if (groupLeader == null && !mode.isTeacher()) { + List groupUsers = service.getUsersBySession(toolSessionId); request.setAttribute(ScratchieConstants.ATTR_GROUP_USERS, groupUsers); request.setAttribute(ScratchieConstants.PARAM_TOOL_SESSION_ID, toolSessionId); request.setAttribute(ScratchieConstants.ATTR_SCRATCHIE, scratchie); - - //checks whether to display dialog prompting to become a leader - boolean nodialog = WebUtil.readBooleanParam(request, "nodialog", false); - request.setAttribute("nodialog", nodialog); - return mapping.findForward("leaderSelection"); + + return mapping.findForward("waitforleader"); } - - //in case user joins the lesson after leader has scratched some answers already - we need to make sure he has the same scratches as leader - if (!mode.isTeacher()) { + + if (groupLeader != null && !mode.isTeacher()) { + // in case user joins the lesson after leader has scratched some answers already - we need to make sure + // he has the same scratches as leader service.copyScratchesFromLeader(user, groupLeader); - - //if user joins a lesson after leader has already finished an activity set his scratchingFinished parameter to true + + // if user joins a lesson after leader has already finished an activity set his scratchingFinished + // parameter to true if (groupLeader.isScratchingFinished()) { user.setScratchingFinished(true); service.saveUser(user); } } - + // initial Session Map SessionMap sessionMap = new SessionMap(); request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap); request.setAttribute(ScratchieConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID()); - // get notebook entry String entryText = new String(); if (groupLeader != null) { @@ -186,6 +183,8 @@ sessionMap.put(ScratchieConstants.ATTR_USER_ID, user.getUserId()); sessionMap.put(ScratchieConstants.ATTR_USER, user); sessionMap.put(ScratchieConstants.ATTR_GROUP_LEADER, groupLeader); + boolean isUserLeader = service.isUserGroupLeader(user, toolSessionId); + sessionMap.put(ScratchieConstants.ATTR_IS_USER_LEADER, isUserLeader); boolean isUserFinished = user != null && user.isSessionFinished(); sessionMap.put(ScratchieConstants.ATTR_USER_FINISHED, isUserFinished); sessionMap.put(ScratchieConstants.ATTR_IS_SHOW_RESULTS_PAGE, scratchie.isShowResultsPage()); @@ -206,10 +205,10 @@ scratchie.setDefineLater(false); service.saveOrUpdateScratchie(scratchie); - ActivityPositionDTO activityPosition = LearningWebUtil.putActivityPositionInRequestByToolSessionId(toolSessionId, request, getServlet() - .getServletContext()); + ActivityPositionDTO activityPosition = LearningWebUtil.putActivityPositionInRequestByToolSessionId( + toolSessionId, request, getServlet().getServletContext()); sessionMap.put(AttributeNames.ATTR_ACTIVITY_POSITION, activityPosition); - + // add run offline support if (scratchie.getRunOffline()) { sessionMap.put(ScratchieConstants.PARAM_RUN_OFFLINE, true); @@ -219,13 +218,14 @@ } Set initialItems = scratchie.getScratchieItems(); - // becuase in webpage will use this login name. Here is just initialize it to avoid session close error in proxy object. + // becuase in webpage will use this login name. Here is just initialize it to avoid session close error in proxy + // object. for (ScratchieItem item : initialItems) { if (item.getCreateBy() != null) { item.getCreateBy().getLoginName(); } } - + // for teacher in monitoring display the number of attempt. if (mode.isTeacher()) { service.retrieveScratchesOrder(initialItems, user); @@ -235,15 +235,15 @@ if (user != null) { service.retrieveScratched(initialItems, user); } - + Collection items = new TreeSet(new ScratchieItemComparator()); items.addAll(initialItems); sessionMap.put(ScratchieConstants.ATTR_ITEM_LIST, items); sessionMap.put(ScratchieConstants.ATTR_SCRATCHIE, scratchie); boolean isScratchingFinished = user != null && user.isScratchingFinished(); sessionMap.put(ScratchieConstants.ATTR_IS_SCRATCHING_FINISHED, isScratchingFinished); - - //decide whether to show results page or learning one + + // decide whether to show results page or learning one if (scratchie.isShowResultsPage() && isScratchingFinished && !mode.isTeacher()) { ActionRedirect redirect = new ActionRedirect(mapping.findForwardConfig("showResults")); redirect.addParameter(ScratchieConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID()); @@ -252,95 +252,68 @@ } else { return mapping.findForward(ScratchieConstants.SUCCESS); } - + } - + /** * Refresh - * */ private ActionForward refreshQuestionList(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - + String sessionMapID = request.getParameter(ScratchieConstants.ATTR_SESSION_MAP_ID); SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); request.setAttribute(ScratchieConstants.ATTR_SESSION_MAP_ID, sessionMapID); IScratchieService service = getScratchieService(); Long toolSessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); ScratchieUser user = getCurrentUser(service, toolSessionId); - + // get back the scratchie and item list and display them on page Scratchie scratchie = service.getScratchieBySessionId(toolSessionId); Collection items = new TreeSet(new ScratchieItemComparator()); items.addAll(scratchie.getScratchieItems()); - + // set scratched flag for display purpose if (user != null) { service.retrieveScratched(items, user); } - + sessionMap.put(ScratchieConstants.ATTR_ITEM_LIST, items); - //refresh leadership status + // refresh leadership status sessionMap.put(ScratchieConstants.ATTR_USER, user); - //refresh ScratchingFinished status + // refresh ScratchingFinished status boolean isScratchingFinished = user != null && user.isScratchingFinished(); sessionMap.put(ScratchieConstants.ATTR_IS_SCRATCHING_FINISHED, isScratchingFinished); - + return mapping.findForward(ScratchieConstants.SUCCESS); - + } - + /** - * Sets current user as a leader of a group. - * - * @param mapping - * @param form - * @param request - * @param response - * @return - * @throws JSONException - * @throws IOException - */ - private ActionForward becomeLeader(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws JSONException, IOException { - IScratchieService service = getScratchieService(); - Long toolSessionId = new Long(request.getParameter(ScratchieConstants.PARAM_TOOL_SESSION_ID)); - - ScratchieUser groupLeader = service.getGroupLeader(toolSessionId); - //check there is no leader yet. Just in case somebody has pressed "Yes" button faster - if (groupLeader == null) { - ScratchieUser user = getCurrentUser(service, toolSessionId); - service.setGroupLeader(user.getUserId(), toolSessionId); - } - - return null; - } - - /** * Scratch specified answer. * * @param mapping * @param form * @param request * @param response * @return - * @throws JSONException - * @throws IOException + * @throws JSONException + * @throws IOException */ private ActionForward scratchItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws JSONException, IOException { - + IScratchieService service = getScratchieService(); String sessionMapID = WebUtil.readStrParam(request, ScratchieConstants.ATTR_SESSION_MAP_ID); SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); Long toolSessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); - + ScratchieUser user = getCurrentUser(service, toolSessionId); - //only leaders are allowed to scratch answers - if (!user.isLeader()) { + // only leaders are allowed to scratch answers + if (!service.isUserGroupLeader(user, toolSessionId)) { return null; } @@ -352,14 +325,14 @@ service.setAnswerAccess(answer.getUid(), toolSessionId); - JSONObject JSONObject = new JSONObject(); + JSONObject JSONObject = new JSONObject(); JSONObject.put(ScratchieConstants.ATTR_ANSWER_CORRECT, answer.isCorrect()); response.setContentType("application/x-json;charset=utf-8"); response.getWriter().print(JSONObject); return null; } - + /** * Leader presses button show results. All the users set scratchingFinished to true. * @@ -380,8 +353,8 @@ IScratchieService service = getScratchieService(); Long userId = (Long) sessionMap.get(ScratchieConstants.ATTR_USER_ID); - - //only leaders should get to here to finalize scratching + + // only leaders should get to here to finalize scratching service.setScratchingFinished(toolSessionId); Set items = service.populateItemsResults(toolSessionId, userId); @@ -408,12 +381,12 @@ Long toolSessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); ScratchieUser user = (ScratchieUser) sessionMap.get(AttributeNames.USER); IScratchieService service = getScratchieService(); - - //in case of the leader we should let all other learners see Next Activity button - if (user.isLeader()) { + + // in case of the leader we should let all other learners see Next Activity button + if (service.isUserGroupLeader(user, toolSessionId)) { service.setScratchingFinished(toolSessionId); } - + String nextActivityUrl = null; try { nextActivityUrl = service.finishToolSession(toolSessionId, user.getUserId()); @@ -503,7 +476,7 @@ // ************************************************************************************* // Private method // ************************************************************************************* - + private IScratchieService getScratchieService() { WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() .getServletContext()); Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/MonitoringAction.java =================================================================== diff -u -r5a5f3640c4d5fdf0c302347e7d6b502a972fd9cc -rc7569597546126af159f169353e68e91241b7f10 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/MonitoringAction.java (.../MonitoringAction.java) (revision 5a5f3640c4d5fdf0c302347e7d6b502a972fd9cc) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/MonitoringAction.java (.../MonitoringAction.java) (revision c7569597546126af159f169353e68e91241b7f10) @@ -74,12 +74,6 @@ if (param.equals("itemSummary")) { return itemSummary(mapping, form, request, response); } - if (param.equals("manageLeaders")) { - return manageLeaders(mapping, form, request, response); - } - if (param.equals("saveLeaders")) { - return saveLeaders(mapping, form, request, response); - } if (param.equals("exportExcel")) { return exportExcel(mapping, form, request, response); } @@ -145,62 +139,6 @@ } /** - * Show leaders manage page - */ - private ActionForward manageLeaders(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - String sessionMapID = request.getParameter(ScratchieConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); - request.setAttribute(ScratchieConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID()); - return mapping.findForward(ScratchieConstants.SUCCESS); - } - - /** - * Save selected users as a leaders - */ - private ActionForward saveLeaders(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - String sessionMapID = request.getParameter(ScratchieConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); - request.setAttribute(ScratchieConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID()); - IScratchieService service = getScratchieService(); - - List summaryList = (List) sessionMap.get(ScratchieConstants.ATTR_SUMMARY_LIST); - for (GroupSummary summary : summaryList) { - Long toolSessionId = summary.getSessionId(); - Long leaderUserId = WebUtil.readLongParam(request, "sessionId" + toolSessionId, true); - - // save selected users as a leaders - if (leaderUserId != null) { - service.setGroupLeader(leaderUserId, toolSessionId); - } - } - - // refresh users leadership status in summaryList - Long contentId = (Long) sessionMap.get(ScratchieConstants.ATTR_TOOL_CONTENT_ID); - summaryList = service.getMonitoringSummary(contentId); - sessionMap.put(ScratchieConstants.ATTR_SUMMARY_LIST, summaryList); - - return null; - } - - private ActionForward viewReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - - Long uid = WebUtil.readLongParam(request, ScratchieConstants.ATTR_USER_UID); - Long sessionID = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID); - - IScratchieService service = getScratchieService(); - ScratchieUser user = service.getUser(uid); - NotebookEntry notebookEntry = service.getEntry(sessionID, CoreNotebookConstants.NOTEBOOK_TOOL, - ScratchieConstants.TOOL_SIGNATURE, user.getUserId().intValue()); - - ScratchieSession session = service.getScratchieSessionBySessionId(sessionID); - - return mapping.findForward("success"); - } - - /** * Exports tool results into excel. * @throws IOException */ Fisheye: Tag c7569597546126af159f169353e68e91241b7f10 refers to a dead (removed) revision in file `lams_tool_scratchie/web/pages/learning/leaderselection.jsp'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_tool_scratchie/web/pages/learning/learning.jsp =================================================================== diff -u -r9e864ab873d7cfd46f81b0347b272e7813daab39 -rc7569597546126af159f169353e68e91241b7f10 --- lams_tool_scratchie/web/pages/learning/learning.jsp (.../learning.jsp) (revision 9e864ab873d7cfd46f81b0347b272e7813daab39) +++ lams_tool_scratchie/web/pages/learning/learning.jsp (.../learning.jsp) (revision c7569597546126af159f169353e68e91241b7f10) @@ -10,7 +10,7 @@ - + Index: lams_tool_scratchie/web/pages/learning/questionlist.jsp =================================================================== diff -u -r00c7a1f28f5ef0e4f890aabd0ff5b97701d4b1bb -rc7569597546126af159f169353e68e91241b7f10 --- lams_tool_scratchie/web/pages/learning/questionlist.jsp (.../questionlist.jsp) (revision 00c7a1f28f5ef0e4f890aabd0ff5b97701d4b1bb) +++ lams_tool_scratchie/web/pages/learning/questionlist.jsp (.../questionlist.jsp) (revision c7569597546126af159f169353e68e91241b7f10) @@ -9,7 +9,7 @@ - + Index: lams_tool_scratchie/web/pages/learning/results.jsp =================================================================== diff -u -r00c7a1f28f5ef0e4f890aabd0ff5b97701d4b1bb -rc7569597546126af159f169353e68e91241b7f10 --- lams_tool_scratchie/web/pages/learning/results.jsp (.../results.jsp) (revision 00c7a1f28f5ef0e4f890aabd0ff5b97701d4b1bb) +++ lams_tool_scratchie/web/pages/learning/results.jsp (.../results.jsp) (revision c7569597546126af159f169353e68e91241b7f10) @@ -10,7 +10,7 @@ - + Index: lams_tool_scratchie/web/pages/learning/waitforleader.jsp =================================================================== diff -u --- lams_tool_scratchie/web/pages/learning/waitforleader.jsp (revision 0) +++ lams_tool_scratchie/web/pages/learning/waitforleader.jsp (revision c7569597546126af159f169353e68e91241b7f10) @@ -0,0 +1,54 @@ + + +<%@ include file="/common/taglibs.jsp"%> + + + + <fmt:message key="label.learning.title" /> + <%@ include file="/common/header.jsp"%> + + + + + +
+

+ ${scratchie.title} +

+ +

+ +

+ +
+ +
+ +
+ +
+ ${user.firstName} ${user.lastName} +
+
+
+ +
+ + + +
+ +
+ + + + +
\ No newline at end of file Fisheye: Tag c7569597546126af159f169353e68e91241b7f10 refers to a dead (removed) revision in file `lams_tool_scratchie/web/pages/monitoring/manageLeaders.jsp'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_tool_scratchie/web/pages/monitoring/summary.jsp =================================================================== diff -u -r6b651e7c25c7baa6a942ea7348f59701bbb4e603 -rc7569597546126af159f169353e68e91241b7f10 --- lams_tool_scratchie/web/pages/monitoring/summary.jsp (.../summary.jsp) (revision 6b651e7c25c7baa6a942ea7348f59701bbb4e603) +++ lams_tool_scratchie/web/pages/monitoring/summary.jsp (.../summary.jsp) (revision c7569597546126af159f169353e68e91241b7f10) @@ -197,9 +197,6 @@ - > - -