Index: lams_central/src/java/org/lamsfoundation/lams/gradebook/service/GradeBookService.java =================================================================== RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/gradebook/service/Attic/GradeBookService.java,v diff -u -r1.13 -r1.14 --- lams_central/src/java/org/lamsfoundation/lams/gradebook/service/GradeBookService.java 2 Apr 2009 02:27:56 -0000 1.13 +++ lams_central/src/java/org/lamsfoundation/lams/gradebook/service/GradeBookService.java 3 Apr 2009 04:42:06 -0000 1.14 @@ -45,6 +45,7 @@ import org.lamsfoundation.lams.learningdesign.Activity; import org.lamsfoundation.lams.learningdesign.CompetenceMapping; import org.lamsfoundation.lams.learningdesign.ToolActivity; +import org.lamsfoundation.lams.lesson.CompletedActivityProgress; import org.lamsfoundation.lams.lesson.LearnerProgress; import org.lamsfoundation.lams.lesson.Lesson; import org.lamsfoundation.lams.lesson.service.ILessonService; @@ -105,24 +106,9 @@ Activity firstActivity = monitoringService.getActivityById(lesson.getLearningDesign().getFirstActivity() .getActivityId()); - long accumulatedTime = 0; - long startTime = 0; - if (learnerProgress != null) { - startTime = learnerProgress.getStartDate().getTime(); - } - if (firstActivity.isToolActivity() && firstActivity instanceof ToolActivity) { - long firstActivityTime = 0; - if (learnerProgress != null) { - if (learnerProgress.getCompletedActivities().get(firstActivity) != null) { - firstActivityTime = ((Date) learnerProgress.getCompletedActivities().get(firstActivity)).getTime() - - startTime - accumulatedTime; - accumulatedTime += firstActivityTime; - } - } - GBActivityGridRowDTO activityDTO = getGradeBookActivityDTO(firstActivity, learner, learnerProgress, - firstActivityTime); + GBActivityGridRowDTO activityDTO = getGradeBookActivityDTO(firstActivity, learner, learnerProgress); gradeBookActivityDTOs.add(activityDTO); } @@ -131,18 +117,8 @@ for (Activity activity : sortedActivities) { if (activity.getActivityId().longValue() != firstActivity.getActivityId().longValue()) { - long activityTime = 0; - if (learnerProgress != null) { - if (learnerProgress.getCompletedActivities().get(activity) != null) { - activityTime = ((Date) learnerProgress.getCompletedActivities().get(activity)).getTime() - - startTime - accumulatedTime; - accumulatedTime += activityTime; - } - } - - GBActivityGridRowDTO activityDTO = getGradeBookActivityDTO(activity, learner, learnerProgress, - activityTime); + GBActivityGridRowDTO activityDTO = getGradeBookActivityDTO(activity, learner, learnerProgress); gradeBookActivityDTOs.add(activityDTO); } } @@ -173,6 +149,8 @@ LearnerProgress learnerProgress = monitoringService.getLearnerProgress(learner.getUserId(), lesson .getLessonId()); gUserDTO.setStatus(getActivityStatusStr(learnerProgress, activity)); + gUserDTO.setTimeTaken(getActivityDuration(learnerProgress, activity)); + // Set the outputs and activity url, if there is one if (activity.isToolActivity() && activity instanceof ToolActivity) { @@ -260,7 +238,7 @@ for (User learner : learners) { GBUserGridRowDTO gradeBookUserDTO = new GBUserGridRowDTO(); gradeBookUserDTO.setId(new Long(learner.getUserId())); - gradeBookUserDTO.setRowName(learner.getLastName() + " " + learner.getFirstName()); + gradeBookUserDTO.setRowName(learner.getLastName() + " " + learner.getFirstName()); // Setting the status and time taken for the user's lesson LearnerProgress learnerProgress = monitoringService.getLearnerProgress(learner.getUserId(), lesson @@ -391,7 +369,7 @@ lessonRow.setLessonName(lesson.getLessonName()); lessonRow.setId(lesson.getLessonId()); lessonRow.setStartDate(getLocaleDateString(user, lesson.getStartDateTime())); - + // Setting the timeTaken value as the average for the lesson, as this is not a specific user view lessonRow.setTimeTaken(gradeBookDAO.getAverageDurationLesson(lesson.getLessonId())); @@ -509,15 +487,14 @@ * @return */ private GBActivityGridRowDTO getGradeBookActivityDTO(Activity activity, User learner, - LearnerProgress learnerProgress, long activityTime) { + LearnerProgress learnerProgress) { logger.debug("Getting gradebook data for activity: " + activity.getActivityId() + ". For user: " + learner.getUserId()); GBActivityGridRowDTO gactivityDTO = new GBActivityGridRowDTO(); gactivityDTO.setId(activity.getActivityId()); gactivityDTO.setRowName(activity.getTitle()); - gactivityDTO.setTimeTaken(activityTime); GradeBookUserActivity gradeBookActivity = gradeBookDAO.getGradeBookUserDataForActivity( activity.getActivityId(), learner.getUserId()); @@ -526,6 +503,8 @@ gactivityDTO.setFeedback(gradeBookActivity.getFeedback()); } + // Setting status + gactivityDTO.setTimeTaken(getActivityDuration(learnerProgress, activity)); gactivityDTO.setStatus(getActivityStatusStr(learnerProgress, activity)); if (activity.isToolActivity() && activity instanceof ToolActivity) { @@ -560,6 +539,22 @@ return gactivityDTO; } + + private Long getActivityDuration(LearnerProgress learnerProgress, Activity activity) { + if (learnerProgress != null) { + if (learnerProgress.getCompletedActivities().get(activity) != null) { + CompletedActivityProgress compProg = learnerProgress.getCompletedActivities().get(activity); + if (compProg != null) { + Date startTime = compProg.getStartDate(); + Date endTime = compProg.getFinishDate(); + if (startTime != null && endTime != null) { + return endTime.getTime() - startTime.getTime(); + } + } + } + } + return null; + } /** * Returns the lesson status string which is a reference to an image Index: lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/lesson/LearnerProgress.hbm.xml =================================================================== RCS file: /usr/local/cvsroot/lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/lesson/LearnerProgress.hbm.xml,v diff -u -r1.18 -r1.19 --- lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/lesson/LearnerProgress.hbm.xml 12 Feb 2009 00:22:51 -0000 1.18 +++ lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/lesson/LearnerProgress.hbm.xml 3 Apr 2009 04:42:06 -0000 1.19 @@ -34,21 +34,21 @@ + + + + + + - - - - - - - - - + + + + + Index: lams_common/db/sql/create_lams_11_tables.sql =================================================================== RCS file: /usr/local/cvsroot/lams_common/db/sql/create_lams_11_tables.sql,v diff -u -r1.135 -r1.136 --- lams_common/db/sql/create_lams_11_tables.sql 26 Mar 2009 10:00:34 -0000 1.135 +++ lams_common/db/sql/create_lams_11_tables.sql 3 Apr 2009 04:42:06 -0000 1.136 @@ -798,7 +798,7 @@ CREATE TABLE lams_progress_completed ( learner_progress_id BIGINT(20) NOT NULL , activity_id BIGINT(20) NOT NULL - , completed_date_time DATETIME NOT NULL + , completed_date_time DATETIME , PRIMARY KEY (learner_progress_id, activity_id) , INDEX (learner_progress_id) , CONSTRAINT FK_lams_progress_completed_1 FOREIGN KEY (learner_progress_id) @@ -811,6 +811,7 @@ CREATE TABLE lams_progress_attempted ( learner_progress_id BIGINT(20) NOT NULL , activity_id BIGINT(20) NOT NULL + , start_date_time DATETIME , PRIMARY KEY (learner_progress_id, activity_id) , INDEX (learner_progress_id) , CONSTRAINT FK_lams_progress_current_1 FOREIGN KEY (learner_progress_id) Index: lams_common/db/sql/insert_lams_unix_config_data.sql =================================================================== RCS file: /usr/local/cvsroot/lams_common/db/sql/insert_lams_unix_config_data.sql,v diff -u -r1.41 -r1.42 --- lams_common/db/sql/insert_lams_unix_config_data.sql 20 Mar 2009 04:20:32 -0000 1.41 +++ lams_common/db/sql/insert_lams_unix_config_data.sql 3 Apr 2009 04:42:06 -0000 1.42 @@ -1,5 +1,5 @@ insert into lams_configuration (config_key, config_value, description_key, header_name, format, required) -values ('ServerURL','http://shaun.melcoe.mq.edu.au/lams/', 'config.server.url', 'config.header.system', 'STRING', 1); +values ('ServerURL','http://172.20.100.188:8080/lams/', 'config.server.url', 'config.header.system', 'STRING', 1); insert into lams_configuration (config_key, config_value, description_key, header_name, format, required) values ('ServerURLContextPath','lams/', 'config.server.url.context.path', 'config.header.system', 'STRING', 1); @@ -14,7 +14,7 @@ values ('DumpDir','/var/opt/lams/dump', 'config.dump.dir', 'config.header.system', 'STRING', 1); insert into lams_configuration (config_key, config_value, description_key, header_name, format, required) -values ('EARDir','/usr/local/jboss-4.0.2/server/default/deploy/lams.ear/', 'config.ear.dir', 'config.header.system', 'STRING', 1); +values ('EARDir','/home/lfoxton/workspace/jboss-4.0.2/server/default/deploy/lams.ear/', 'config.ear.dir', 'config.header.system', 'STRING', 1); insert into lams_configuration (config_key, config_value, description_key, header_name, format, required) values ('SMTPServer','', 'config.smtp.server', 'config.header.email', 'STRING', 0); Index: lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch0015_updateFrom22.sql =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch0015_updateFrom22.sql,v diff -u -r1.11 -r1.12 --- lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch0015_updateFrom22.sql 27 Mar 2009 18:29:38 -0000 1.11 +++ lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch0015_updateFrom22.sql 3 Apr 2009 04:42:05 -0000 1.12 @@ -58,8 +58,12 @@ INSERT into lams_workspace_folder_type VALUES (3, 'PUBLIC SEQUENCES'); -- LDEV-2115 -------------- -ALTER TABLE lams_progress_completed ADD COLUMN completed_date_time DATETIME NOT NULL; +ALTER TABLE lams_progress_completed ADD COLUMN completed_date_time DATETIME; +-- LDEV-2173 -------------- Adding in start dates for activities for gradebook +ALTER TABLE lams_progress_attempted ADD COLUMN start_date_time DATETIME; +ALTER TABLE lams_progress_completed ADD COLUMN start_date_time DATETIME; + -- LDEV-2163 -------------- CREATE TABLE lams_activity_evaluation ( activity_evaluation_id BIGINT(20) NOT NULL auto_increment Index: lams_common/src/java/org/lamsfoundation/lams/lesson/CompletedActivityProgress.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/lesson/CompletedActivityProgress.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_common/src/java/org/lamsfoundation/lams/lesson/CompletedActivityProgress.java 3 Apr 2009 04:42:06 -0000 1.1 @@ -0,0 +1,108 @@ +/**************************************************************** + * Copyright (C) 2008 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +/* $Id: CompletedActivityProgress.java,v 1.1 2009/04/03 04:42:06 lfoxton Exp $ */ +package org.lamsfoundation.lams.lesson; + +import java.io.Serializable; +import java.util.Date; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.lamsfoundation.lams.learningdesign.Activity; + +/** + * A class representing a finished activity for a user + * + * @author lfoxton + * + */ +public class CompletedActivityProgress implements Serializable{ + + + private static final long serialVersionUID = -6210497575761751861L; + + LearnerProgress learnerProgress; + Activity activity; + Date startDate; + Date finishDate; + + public CompletedActivityProgress() {} + + public CompletedActivityProgress(LearnerProgress learnerProgress, Activity activity, Date startDate, Date finishDate) { + this.learnerProgress = learnerProgress; + this.activity = activity; + this.startDate = startDate; + this.finishDate = finishDate; + } + + public LearnerProgress getLearnerProgress() { + return learnerProgress; + } + + public void setLearnerProgress(LearnerProgress learnerProgress) { + this.learnerProgress = learnerProgress; + } + + public Activity getActivity() { + return activity; + } + + public void setActivity(Activity activity) { + this.activity = activity; + } + + public Date getStartDate() { + return startDate; + } + + public void setStartDate(Date startDate) { + this.startDate = startDate; + } + + public Date getFinishDate() { + return finishDate; + } + + public void setFinishDate(Date finishDate) { + this.finishDate = finishDate; + } + + @Override + public boolean equals(Object other) { + if ((this == other)) + return true; + if (!(other instanceof CompletedActivityProgress)) + return false; + CompletedActivityProgress castOther = (CompletedActivityProgress) other; + + EqualsBuilder eq = new EqualsBuilder(); + eq.append(this.getActivity().getActivityId(), castOther.getActivity().getActivityId()); + eq.append(this.getLearnerProgress().getLearnerProgressId(), castOther.getLearnerProgress().getLearnerProgressId()); + return eq.isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(this.getActivity().getActivityId().toString() + this.getLearnerProgress().getLearnerProgressId().toString()).toHashCode(); + } +} Index: lams_common/src/java/org/lamsfoundation/lams/lesson/LearnerProgress.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/lesson/LearnerProgress.java,v diff -u -r1.23 -r1.24 --- lams_common/src/java/org/lamsfoundation/lams/lesson/LearnerProgress.java 12 Mar 2009 01:30:52 -0000 1.23 +++ lams_common/src/java/org/lamsfoundation/lams/lesson/LearnerProgress.java 3 Apr 2009 04:42:06 -0000 1.24 @@ -22,48 +22,49 @@ /* $$Id$$ */ package org.lamsfoundation.lams.lesson; -import org.lamsfoundation.lams.usermanagement.User; -import org.lamsfoundation.lams.learningdesign.Activity; -import org.lamsfoundation.lams.learningdesign.ActivityOrderComparator; -import org.lamsfoundation.lams.learningdesign.ComplexActivity; -import org.lamsfoundation.lams.learningdesign.dao.IActivityDAO; -import org.lamsfoundation.lams.lesson.dto.LearnerProgressDTO; -import org.lamsfoundation.lams.lesson.dto.LearnerProgressCompletedDTO; -import org.lamsfoundation.lams.lesson.dto.CompletedActivityDTO; - import java.io.Serializable; import java.util.ArrayList; import java.util.Date; import java.util.Iterator; import java.util.LinkedList; import java.util.List; -import java.util.Set; import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; import java.util.TreeMap; -import java.util.TreeSet; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.ToStringBuilder; +import org.lamsfoundation.lams.learningdesign.Activity; +import org.lamsfoundation.lams.learningdesign.ActivityOrderComparator; +import org.lamsfoundation.lams.learningdesign.ComplexActivity; +import org.lamsfoundation.lams.learningdesign.dao.IActivityDAO; +import org.lamsfoundation.lams.lesson.dto.CompletedActivityDTO; +import org.lamsfoundation.lams.lesson.dto.LearnerProgressCompletedDTO; +import org.lamsfoundation.lams.lesson.dto.LearnerProgressDTO; +import org.lamsfoundation.lams.usermanagement.User; - /** - *

Holds data that describes the Users progress through a lesson. It records - * the exact position that a learner is in regarding a lesson.

+ *

+ * Holds data that describes the Users progress through a lesson. It records the + * exact position that a learner is in regarding a lesson. + *

* - *

It also helps lams to rebuild the learner page and progress bar whenever - * an unexpected error condition is identified.

+ *

+ * It also helps lams to rebuild the learner page and progress bar whenever an + * unexpected error condition is identified. + *

* * @author Chris - * @author Jacky Fang + * @author Jacky Fang * @version 1.1 - * + * */ -public class LearnerProgress implements Serializable -{ - private static final long serialVersionUID = -7866830317967062822L; - - //--------------------------------------------------------------------- +public class LearnerProgress implements Serializable { + private static final long serialVersionUID = -7866830317967062822L; + + //--------------------------------------------------------------------- // Class level constants //--------------------------------------------------------------------- /** Indicates activity has been completed */ @@ -72,498 +73,524 @@ public static final byte ACTIVITY_ATTEMPTED = 2; /** Indicates activity has not been attempted yet */ public static final byte ACTIVITY_NOT_ATTEMPTED = 3; - + /** Parallel waiting state: Not waiting in any way */ public static final byte PARALLEL_NO_WAIT = 0; - /** Parallel waiting state: One activity complete, the others still to be completed */ + /** + * Parallel waiting state: One activity complete, the others still to be + * completed + */ public static final byte PARALLEL_WAITING = 1; - /** Parallel waiting state: All activities completed, break out of parallel frames */ + /** + * Parallel waiting state: All activities completed, break out of parallel + * frames + */ public static final byte PARALLEL_WAITING_COMPLETE = 2; - + /** Learner has not completed the lesson */ public static final byte LESSON_NOT_COMPLETE = 0; /** Learner has completed the lesson in the normal manner. */ public static final byte LESSON_END_OF_DESIGN_COMPLETE = 1; - /** Learner has completed the lesson by reaching a "Stop After Activity" point */ + /** + * Learner has completed the lesson by reaching a "Stop After Activity" + * point + */ public static final byte LESSON_IN_DESIGN_COMPLETE = 2; - + //--------------------------------------------------------------------- // attributes //--------------------------------------------------------------------- /** Identifier field */ private Long learnerProgressId; - + /** The User to whom this progress data belongs. */ private User user; - - /** The Lesson this progress data is for*/ + + /** The Lesson this progress data is for */ private Lesson lesson; - - /** Set of attempted activities */ - private Set attemptedActivities; - + + /** Map of attempted activities with their start date */ + private Map attemptedActivities; + /** - * Set of completed activities that includes all completed activities - * before current activity. + * Set of completed activities that includes all completed activities before + * current activity */ - private Map completedActivities; - + private Map completedActivities; + /** - * The activity that user just completed. The purpose of this - * activity is to allow lams to remove unecessary frame for - * next activity. + * The activity that user just completed. The purpose of this activity is to + * allow lams to remove unecessary frame for next activity. */ private Activity previousActivity; - - /** + + /** * The current activity always present the activity with transition, which * means it won't be leaf node of a complex activity. To understand the - * activity tree, please read relevant documentation and comment. The current - * content could be the same as next activity if next activity is not the - * leaf node. The main purpose of current activity is to restore the - * progress states if the user exist without finishing the activity. + * activity tree, please read relevant documentation and comment. The + * current content could be the same as next activity if next activity is + * not the leaf node. The main purpose of current activity is to restore the + * progress states if the user exist without finishing the activity. */ private Activity currentActivity; - /** * The activity that progress engine is about to progress to. It could be - * next activity following the transition or leaf activity within a - * complex activity. + * next activity following the transition or leaf activity within a complex + * activity. */ private Activity nextActivity; - + /** * Indicates is the User has completed this lesson. */ private Byte lessonComplete; - + /** - * Indicates the learner progress is in a incomplete parallel activity - * or not. + * Indicates the learner progress is in a incomplete parallel activity or + * not. */ private byte parallelWaiting; - + /** * A list of completed activities ids before move on to next activity - * following transition. This is created to help flash calculation - * what has *just* been done. + * following transition. This is created to help flash calculation what has + * *just* been done. */ private List currentCompletedActivitiesList; - - /**Indicate whether the learning progress is restarting or not*/ + + /** Indicate whether the learning progress is restarting or not */ private boolean restarting; - + private Date startDate; private Date finishDate; + //--------------------------------------------------------------------- // Constructors //--------------------------------------------------------------------- /** default constructor */ - public LearnerProgress() - { - this.lessonComplete = new Byte(LESSON_NOT_COMPLETE); + public LearnerProgress() { + this.lessonComplete = new Byte(LESSON_NOT_COMPLETE); } + /** * Chain constructor to create new learner progress with minimum data. - * @param user the learner. - * @param lesson the lesson that currently is running. + * + * @param user + * the learner. + * @param lesson + * the lesson that currently is running. */ - public LearnerProgress(User user,Lesson lesson) - { - this(null,user,lesson,new TreeSet( new ActivityOrderComparator()),new TreeMap( new ActivityOrderComparator())); + public LearnerProgress(User user, Lesson lesson) { + this(null, user, lesson, new TreeMap(new ActivityOrderComparator()), + new TreeMap(new ActivityOrderComparator())); } - + /** full constructor */ - public LearnerProgress(Long learnerProgressId, User user, Lesson lesson, Set attemptedActivities, Map completedActivities) - { - this.learnerProgressId = learnerProgressId; - this.user = user; - this.lesson = lesson; - this.attemptedActivities = attemptedActivities; - this.completedActivities = completedActivities; - this.lessonComplete = new Byte(LESSON_NOT_COMPLETE); + public LearnerProgress(Long learnerProgressId, User user, Lesson lesson, Map attemptedActivities, + Map completedActivities) { + this.learnerProgressId = learnerProgressId; + this.user = user; + this.lesson = lesson; + this.attemptedActivities = attemptedActivities; + this.completedActivities = completedActivities; + this.lessonComplete = new Byte(LESSON_NOT_COMPLETE); } + //--------------------------------------------------------------------- // Getters and Setters //--------------------------------------------------------------------- /** - * - * + * + * */ - public Long getLearnerProgressId() - { - return this.learnerProgressId; + public Long getLearnerProgressId() { + return this.learnerProgressId; } - - public void setLearnerProgressId(Long learnerProgressId) - { - this.learnerProgressId = learnerProgressId; + + public void setLearnerProgressId(Long learnerProgressId) { + this.learnerProgressId = learnerProgressId; } - + /** - * + * */ - public User getUser() - { - return this.user; + public User getUser() { + return this.user; } - - public void setUser(User user) - { - this.user = user; + + public void setUser(User user) { + this.user = user; } - + /** - * + * */ - public Lesson getLesson() - { - return this.lesson; + public Lesson getLesson() { + return this.lesson; } - - public void setLesson(Lesson lesson) - { - this.lesson = lesson; + + public void setLesson(Lesson lesson) { + this.lesson = lesson; } - + /** - * - * + * + * */ - public Set getAttemptedActivities() - { - return this.attemptedActivities; + public Map getAttemptedActivities() { + return this.attemptedActivities; } - - public void setAttemptedActivities(java.util.Set attemptedActivities) - { - - this.attemptedActivities = attemptedActivities; + + public void setAttemptedActivities(Map attemptedActivities) { + + this.attemptedActivities = attemptedActivities; } - + /** - * - * + * + * */ - public Map getCompletedActivities() - { - - return this.completedActivities; + public Map getCompletedActivities() { + + return this.completedActivities; } - - public void setCompletedActivities(java.util.Map completedActivities) - { - - this.completedActivities = completedActivities; + + public void setCompletedActivities(Map completedActivities) { + + this.completedActivities = completedActivities; } - - public String toString() - { - return new ToStringBuilder(this) - .append("learnerProgressId", getLearnerProgressId()) - .toString(); + + public String toString() { + return new ToStringBuilder(this).append("learnerProgressId", getLearnerProgressId()).toString(); } - - public boolean equals(Object other) - { - if ( (this == other ) ) return true; - if ( !(other instanceof LearnerProgress) ) return false; - LearnerProgress castOther = (LearnerProgress) other; - return new EqualsBuilder() - .append(this.getLearnerProgressId(), castOther.getLearnerProgressId()) - .isEquals(); + + public boolean equals(Object other) { + if ((this == other)) + return true; + if (!(other instanceof LearnerProgress)) + return false; + LearnerProgress castOther = (LearnerProgress) other; + return new EqualsBuilder().append(this.getLearnerProgressId(), castOther.getLearnerProgressId()).isEquals(); } - - public int hashCode() - { - return new HashCodeBuilder() - .append(getLearnerProgressId()) - .toHashCode(); + + public int hashCode() { + return new HashCodeBuilder().append(getLearnerProgressId()).toHashCode(); } - + /** * Getter for property currentActivity. + * * @return Value of property currentActivity. */ - public Activity getCurrentActivity() - { - return this.currentActivity; + public Activity getCurrentActivity() { + return this.currentActivity; } - + /** * Setter for property currentActivity. - * @param currentActivity New value of property currentActivity. + * + * @param currentActivity + * New value of property currentActivity. */ - public void setCurrentActivity(Activity currentActivity) - { - this.currentActivity = currentActivity; + public void setCurrentActivity(Activity currentActivity) { + this.currentActivity = currentActivity; } /** * Gives the progress state of the specific activity. - * @param the activity whose progress state is required. - * @return ACTIVITY_COMPLETED, ACTIVITY_ATTEMPTED or ACTIVITY_NOT_ATTEMPTED. + * + * @param the + * activity whose progress state is required. + * @return ACTIVITY_COMPLETED, + * ACTIVITY_ATTEMPTED or + * ACTIVITY_NOT_ATTEMPTED. */ - public byte getProgressState(Activity activity) - { - if (completedActivities.containsKey(activity)) - { - return ACTIVITY_COMPLETED; - } - else if (attemptedActivities.contains(activity)) - { - return ACTIVITY_ATTEMPTED; - } - else - { - return ACTIVITY_NOT_ATTEMPTED; - } + public byte getProgressState(Activity activity) { + if (completedActivities.containsKey(activity)) { + return ACTIVITY_COMPLETED; + } else if (attemptedActivities.containsKey(activity)) { + return ACTIVITY_ATTEMPTED; + } else { + return ACTIVITY_NOT_ATTEMPTED; + } } - + /** - * Sets the progress state for an activity. + * Sets the progress state for an activity. * - * If the activity is moving from completed to not completed, then the call is recursive - - * it will reset all contained completed activities to the input state. + * If the activity is moving from completed to not completed, then the call + * is recursive - it will reset all contained completed activities to the + * input state. * - * Only want to "take action" ie add/remove if the state has really changed. Otherwise - * the recursive call to remove the completed flag will cause unexpected side effects - * when a Completed activity is reset to Completed - * - * @param activity whose progress is to be set - * @param state one of ACTIVITY_COMPLETED, ACTIVITY_ATTEMPTED or ACTIVITY_NOT_ATTEMPTED. - * @param activityDAO needed to get any child activities correctly from Hibernate (grr - shouldn't be required) + * Only want to "take action" ie add/remove if the state has really changed. + * Otherwise the recursive call to remove the completed flag will cause + * unexpected side effects when a Completed activity is reset to Completed + * + * @param activity + * whose progress is to be set + * @param state + * one of ACTIVITY_COMPLETED, + * ACTIVITY_ATTEMPTED or + * ACTIVITY_NOT_ATTEMPTED. + * @param activityDAO + * needed to get any child activities correctly from + * Hibernate (grr - shouldn't be required) */ public void setProgressState(Activity activity, byte state, IActivityDAO activityDAO) { - // remove activity from current set - byte oldState = getProgressState(activity); - if ( oldState == state) { - // no real change, forget the rest of the method - return; - } - - if (oldState == LearnerProgress.ACTIVITY_NOT_ATTEMPTED); - else if (oldState == LearnerProgress.ACTIVITY_ATTEMPTED ) { - this.attemptedActivities.remove(activity); - } - else if (oldState == LearnerProgress.ACTIVITY_COMPLETED ) { - this.completedActivities.remove(activity); - if ( activity.isComplexActivity() ) { - ComplexActivity complex = (ComplexActivity) activityDAO.getActivityByActivityId(activity.getActivityId(), ComplexActivity.class); - Iterator iter = complex.getActivities().iterator(); - while ( iter.hasNext() ) { - Activity child = (Activity) iter.next(); - setProgressState(child, state, activityDAO); - } - } - } - - // add activity to new set - if (state == LearnerProgress.ACTIVITY_NOT_ATTEMPTED); - else if (state == LearnerProgress.ACTIVITY_ATTEMPTED ) { - this.attemptedActivities.add(activity); - } - else if (state == LearnerProgress.ACTIVITY_COMPLETED) { - this.completedActivities.put(activity, new Date(System.currentTimeMillis())); - } + // remove activity from current set + byte oldState = getProgressState(activity); + if (oldState == state) { + // no real change, forget the rest of the method + return; + } + + Date activityStartDate = attemptedActivities.get(activity); + + if (oldState == LearnerProgress.ACTIVITY_NOT_ATTEMPTED) + ; + else if (oldState == LearnerProgress.ACTIVITY_ATTEMPTED) { + this.attemptedActivities.remove(activity); + } else if (oldState == LearnerProgress.ACTIVITY_COMPLETED) { + this.completedActivities.remove(activity); + if (activity.isComplexActivity()) { + ComplexActivity complex = (ComplexActivity) activityDAO.getActivityByActivityId(activity + .getActivityId(), ComplexActivity.class); + Iterator iter = complex.getActivities().iterator(); + while (iter.hasNext()) { + Activity child = (Activity) iter.next(); + setProgressState(child, state, activityDAO); + } + } + } + + // add activity to new set + if (state == LearnerProgress.ACTIVITY_NOT_ATTEMPTED) + ; + else if (state == LearnerProgress.ACTIVITY_ATTEMPTED) { + this.attemptedActivities.put(activity, new Date()); + } else if (state == LearnerProgress.ACTIVITY_COMPLETED) { + this.completedActivities.put(activity, new CompletedActivityProgress(this, activity, activityStartDate, new Date())); + } } /** - * Has the user completed the lesson? We don't care how (ie at end of sequence or after a "stop after activity") + * Has the user completed the lesson? We don't care how (ie at end of + * sequence or after a "stop after activity") */ - public boolean isComplete() - { + public boolean isComplete() { - return lessonComplete == LESSON_END_OF_DESIGN_COMPLETE || lessonComplete == LESSON_IN_DESIGN_COMPLETE; + return lessonComplete == LESSON_END_OF_DESIGN_COMPLETE || lessonComplete == LESSON_IN_DESIGN_COMPLETE; } /** * The "real" value for lessonComplete. - * @return LESSON_NOT_COMPLETE, LESSON_END_OF_DESIGN_COMPLETE, LESSON_IN_DESIGN_COMPLETE + * + * @return LESSON_NOT_COMPLETE, LESSON_END_OF_DESIGN_COMPLETE, + * LESSON_IN_DESIGN_COMPLETE */ - public Byte getLessonComplete() - { - return lessonComplete; + public Byte getLessonComplete() { + return lessonComplete; } - + /** * Setter for property lessonComplete. - * @param lessonComplete New value of property lessonComplete. + * + * @param lessonComplete + * New value of property lessonComplete. */ - public void setLessonComplete(Byte lessonComplete) - { - this.lessonComplete = lessonComplete; + public void setLessonComplete(Byte lessonComplete) { + this.lessonComplete = lessonComplete; } /** * Getter for property nextActivity. + * * @return Value of property nextActivity. */ - public Activity getNextActivity() - { + public Activity getNextActivity() { - return this.nextActivity; + return this.nextActivity; } /** * Setter for property nextActivity. - * @param nextActivity New value of property nextActivity. + * + * @param nextActivity + * New value of property nextActivity. */ - public void setNextActivity(Activity nextActivity) - { + public void setNextActivity(Activity nextActivity) { - this.nextActivity = nextActivity; + this.nextActivity = nextActivity; } - - /** * @return Returns the previousActivity. */ - public Activity getPreviousActivity() - { - return previousActivity; + public Activity getPreviousActivity() { + return previousActivity; } + /** - * @param previousActivity The previousActivity to set. + * @param previousActivity + * The previousActivity to set. */ - public void setPreviousActivity(Activity previousActivity) - { - this.previousActivity = previousActivity; + public void setPreviousActivity(Activity previousActivity) { + this.previousActivity = previousActivity; } + /** * @return Returns the isParallelWaiting. */ - public byte getParallelWaiting() - { - return parallelWaiting; + public byte getParallelWaiting() { + return parallelWaiting; } + /** - * @param isParallelWaiting The isParallelWaiting to set. + * @param isParallelWaiting + * The isParallelWaiting to set. */ - public void setParallelWaiting(byte parallelWaiting) - { - this.parallelWaiting = parallelWaiting; + public void setParallelWaiting(byte parallelWaiting) { + this.parallelWaiting = parallelWaiting; } + /** * @return Returns the currentCompletedActivitiesList. */ - public List getCurrentCompletedActivitiesList() - { - return currentCompletedActivitiesList; + public List getCurrentCompletedActivitiesList() { + return currentCompletedActivitiesList; } + /** - * @param completedActivitiesList The currentCompletedActivitiesList to set. + * @param completedActivitiesList + * The currentCompletedActivitiesList to set. */ - public void setCurrentCompletedActivitiesList(List completedActivitiesList) - { - this.currentCompletedActivitiesList = new LinkedList(); - this.currentCompletedActivitiesList.addAll(completedActivitiesList); + public void setCurrentCompletedActivitiesList(List completedActivitiesList) { + this.currentCompletedActivitiesList = new LinkedList(); + this.currentCompletedActivitiesList.addAll(completedActivitiesList); } + /** * @return Returns the isRestarting. */ - public boolean isRestarting() - { - return restarting; + public boolean isRestarting() { + return restarting; } + /** - * @param isRestarting The isRestarting to set. + * @param isRestarting + * The isRestarting to set. */ - public void setRestarting(boolean restarting) - { - this.restarting = restarting; + public void setRestarting(boolean restarting) { + this.restarting = restarting; } + //--------------------------------------------------------------------- // Service methods //--------------------------------------------------------------------- /** * Returns the learner progress data transfer object. */ - public LearnerProgressDTO getLearnerProgressData() - { - - return new LearnerProgressDTO(this.lesson.getLessonId(), - this.lesson.getLessonName(), - this.user.getLogin(), - this.user.getLastName(), - this.user.getFirstName(), - this.user.getUserId(), - this.currentActivity != null ? this.currentActivity.getActivityId() : null, - this.createIdArrayFrom(this.attemptedActivities), - this.createIdArrayFrom(this.completedActivities.keySet()), - isComplete()); + public LearnerProgressDTO getLearnerProgressData() { + + return new LearnerProgressDTO(this.lesson.getLessonId(), this.lesson.getLessonName(), this.user.getLogin(), + this.user.getLastName(), this.user.getFirstName(), this.user.getUserId(), + this.currentActivity != null ? this.currentActivity.getActivityId() : null, this + .createIdArrayFrom(this.attemptedActivities.keySet()), this + .createIdArrayFrom(this.completedActivities.keySet()), isComplete()); } - - public LearnerProgressCompletedDTO getLearnerProgressCompletedData() - { - return new LearnerProgressCompletedDTO(this.lesson.getLessonId(), - this.lesson.getLessonName(), - this.user.getLogin(), - this.user.getLastName(), - this.user.getFirstName(), - this.user.getUserId(), - this.createCompletedActivityArrayFrom(this.completedActivities), - isComplete(), - this.lesson.getStartDateTime().getTime(), - this.startDate.getTime()); - + + public LearnerProgressCompletedDTO getLearnerProgressCompletedData() { + return new LearnerProgressCompletedDTO(this.lesson.getLessonId(), this.lesson.getLessonName(), this.user + .getLogin(), this.user.getLastName(), this.user.getFirstName(), this.user.getUserId(), + createCompletedActivityArrayFromMap(this.completedActivities), isComplete(), this.lesson + .getStartDateTime().getTime(), this.startDate.getTime()); + } - + //--------------------------------------------------------------------- // Helper methods //--------------------------------------------------------------------- /** * Extract the Id from activities and set them into an array. - * @param activities the activities that is being used to create the - * array. + * + * @param activities + * the activities that is being used to create the array. */ - private Long[] createIdArrayFrom(Set activities) - { - if(activities == null) - throw new IllegalArgumentException("Fail to create id array" + - " from null activity set"); - - ArrayList activitiesIds = new ArrayList(); - for(Iterator i= activities.iterator();i.hasNext();) - { - Activity activity = (Activity)i.next(); - activitiesIds.add(activity.getActivityId()); - } - - return (Long [])activitiesIds.toArray(new Long[activitiesIds.size()]); + private Long[] createIdArrayFrom(Set activities) { + if (activities == null) + throw new IllegalArgumentException("Fail to create id array" + " from null activity set"); + + ArrayList activitiesIds = new ArrayList(); + for (Iterator i = activities.iterator(); i.hasNext();) { + Activity activity = (Activity) i.next(); + activitiesIds.add(activity.getActivityId()); + } + + return (Long[]) activitiesIds.toArray(new Long[activitiesIds.size()]); } - - private CompletedActivityDTO[] createCompletedActivityArrayFrom(Map activities) - { - if(activities == null) - throw new IllegalArgumentException("Fail to create id array" + - " from null activity set"); - - ArrayList activitiesCompleted = new ArrayList(); - - for(Iterator i= activities.keySet().iterator();i.hasNext();) - { - Activity activity = (Activity)i.next(); - Long completedTime = ((Date)activities.get(activity)).getTime() - startDate.getTime(); - activitiesCompleted.add(new CompletedActivityDTO(activity, completedTime)); - } - - return (CompletedActivityDTO [])activitiesCompleted.toArray(new CompletedActivityDTO[activitiesCompleted.size()]); + + //--------------------------------------------------------------------- + // Helper methods + //--------------------------------------------------------------------- + + private CompletedActivityDTO[] createCompletedActivityArrayFromMap( + Map completedActivityProgs) { + if (completedActivityProgs == null) + throw new IllegalArgumentException("Fail to create id array" + " from null activity set"); + + ArrayList activitiesCompleted = new ArrayList(); + + for (Entry ent : completedActivityProgs.entrySet() ) { + Activity activity = ent.getKey(); + CompletedActivityProgress compProg = ent.getValue(); + + if (compProg != null) { + Date end = compProg.getFinishDate(); + if (end != null && startDate != null) { + Long completedTime = end.getTime() - startDate.getTime(); + activitiesCompleted.add(new CompletedActivityDTO(activity, completedTime)); + } + } + } + + return (CompletedActivityDTO[]) activitiesCompleted + .toArray(new CompletedActivityDTO[activitiesCompleted.size()]); } - - - public Date getFinishDate() { - return finishDate; + + private CompletedActivityDTO[] createCompletedActivityArrayFrom(Map activities) { + if (activities == null) + throw new IllegalArgumentException("Fail to create id array" + " from null activity set"); + + ArrayList activitiesCompleted = new ArrayList(); + + for (Iterator i = activities.keySet().iterator(); i.hasNext();) { + Activity activity = (Activity) i.next(); + + Date completedDate = (Date) activities.get(activity); + if (completedDate != null && startDate != null) { + Long completedTime = ((Date) activities.get(activity)).getTime() - startDate.getTime(); + activitiesCompleted.add(new CompletedActivityDTO(activity, completedTime)); + } } - public void setFinishDate(Date finishDate) { - this.finishDate = finishDate; - } - public Date getStartDate() { - return startDate; - } - public void setStartDate(Date startDate) { - this.startDate = startDate; - } + + return (CompletedActivityDTO[]) activitiesCompleted + .toArray(new CompletedActivityDTO[activitiesCompleted.size()]); + } + + public Date getFinishDate() { + return finishDate; + } + + public void setFinishDate(Date finishDate) { + this.finishDate = finishDate; + } + + public Date getStartDate() { + return startDate; + } + + public void setStartDate(Date startDate) { + this.startDate = startDate; + } } Index: lams_common/src/java/org/lamsfoundation/lams/lesson/dto/LearnerProgressCompletedDTO.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/lesson/dto/LearnerProgressCompletedDTO.java,v diff -u -r1.1 -r1.2 --- lams_common/src/java/org/lamsfoundation/lams/lesson/dto/LearnerProgressCompletedDTO.java 12 Mar 2009 01:30:52 -0000 1.1 +++ lams_common/src/java/org/lamsfoundation/lams/lesson/dto/LearnerProgressCompletedDTO.java 3 Apr 2009 04:42:06 -0000 1.2 @@ -22,109 +22,100 @@ /* $$Id$$ */ package org.lamsfoundation.lams.lesson.dto; - /** * The data transfer object for remoting data communication. + * * @author Jacky Fang - * @since 2005-3-11 + * @since 2005-3-11 * @version 1.1 * */ -public class LearnerProgressCompletedDTO -{ +public class LearnerProgressCompletedDTO { private Long lessonId; private String lessonName; private String userName; private String lastName; private String firstName; private Integer learnerId; - private CompletedActivityDTO [] completedActivities; + private CompletedActivityDTO[] completedActivities; private Boolean lessonComplete; - + private Long lessonStartTime; private Long learnerStartTime; - - + /** - * Full constructor + * Full constructor */ - public LearnerProgressCompletedDTO(Long lessonId, - String lessonName, - String userName, - String lastName, - String firstName, - Integer learnerId, - CompletedActivityDTO[] completedActivities, - Boolean lessonComplete, - Long lessonStartTime, - Long learnerStartTime) - { - this.lessonId = lessonId; - this.lessonName = lessonName; - this.userName = userName; - this.lastName = lastName; - this.firstName = firstName; - this.learnerId = learnerId; - this.completedActivities = completedActivities; - this.lessonComplete = lessonComplete; - this.lessonStartTime = lessonStartTime; - this.learnerStartTime = learnerStartTime; + public LearnerProgressCompletedDTO(Long lessonId, String lessonName, String userName, String lastName, + String firstName, Integer learnerId, CompletedActivityDTO[] completedActivities, Boolean lessonComplete, + Long lessonStartTime, Long learnerStartTime) { + this.lessonId = lessonId; + this.lessonName = lessonName; + this.userName = userName; + this.lastName = lastName; + this.firstName = firstName; + this.learnerId = learnerId; + this.completedActivities = completedActivities; + this.lessonComplete = lessonComplete; + this.lessonStartTime = lessonStartTime; + this.learnerStartTime = learnerStartTime; } /** * @return Returns the learnerId. */ - public Integer getLearnerId() - { - return learnerId; + public Integer getLearnerId() { + return learnerId; } + /** * @return Returns the lessonId. */ - public Long getLessonId() - { - return lessonId; + public Long getLessonId() { + return lessonId; } + /** * @return Returns the lessonName. */ - public String getLessonName() - { - return lessonName; + public String getLessonName() { + return lessonName; } + /** * @return Returns the userName. */ - public String getUserName() - { - return userName; + public String getUserName() { + return userName; } - + /** * @return Returns the completedActivities. */ - public CompletedActivityDTO[] getCompletedActivities() - { - return completedActivities; + public CompletedActivityDTO[] getCompletedActivities() { + return completedActivities; } - public String getFirstName() { - return firstName; - } - public String getLastName() { - return lastName; - } + public String getFirstName() { + return firstName; + } - public Boolean getLessonComplete() { - return lessonComplete; - } - - public Long getLessonStartTime() { - return lessonStartTime; - } - - public Long getLearnerStartTime() { - return learnerStartTime; - } + public String getLastName() { + return lastName; + } + + public Boolean getLessonComplete() { + return lessonComplete; + } + + public Long getLessonStartTime() { + return lessonStartTime; + } + + public Long getLearnerStartTime() { + return learnerStartTime; + } + } + Index: lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java,v diff -u -r1.35 -r1.36 --- lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java 12 Feb 2009 00:22:51 -0000 1.35 +++ lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java 3 Apr 2009 04:42:05 -0000 1.36 @@ -626,7 +626,7 @@ boolean recordUpdated = false; - boolean removed = progress.getAttemptedActivities().remove(activity); + boolean removed = (progress.getAttemptedActivities().remove(activity) != null); if (removed) { recordUpdated = true; LessonService.log.debug("Removed activity from attempted activities"); Index: lams_learning/src/java/org/lamsfoundation/lams/learning/export/service/PortfolioBuilder.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/export/service/PortfolioBuilder.java,v diff -u -r1.19 -r1.20 --- lams_learning/src/java/org/lamsfoundation/lams/learning/export/service/PortfolioBuilder.java 12 Feb 2009 00:23:17 -0000 1.19 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/export/service/PortfolioBuilder.java 3 Apr 2009 04:42:06 -0000 1.20 @@ -184,7 +184,7 @@ // if learner only include the attempted and completed activities if (accessMode == ToolAccessMode.LEARNER && !(progress.getCompletedActivities().containsKey(activity) || progress.getAttemptedActivities() - .contains(activity))) { + .containsKey(activity))) { return; } Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/LearningWebUtil.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/LearningWebUtil.java,v diff -u -r1.26 -r1.27 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/LearningWebUtil.java 12 Feb 2009 00:23:17 -0000 1.26 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/LearningWebUtil.java 3 Apr 2009 04:42:06 -0000 1.27 @@ -310,7 +310,7 @@ } else { progressSummary.append("attempted="); boolean first = true; - for (Object obj : learnerProgress.getAttemptedActivities()) { + for (Object obj : learnerProgress.getAttemptedActivities().keySet()) { Activity activity = (Activity ) obj; if ( ! first ) { progressSummary.append("_");