Index: lams_build/lib/lams/lams-monitoring.jar
===================================================================
diff -u -r7bf7065d902a3645561f57c779b86721eedc27a5 -r568197820cd33d3fb1bab3ea4ec180a58800fd65
Binary files differ
Index: lams_common/src/java/org/lamsfoundation/lams/lesson/LessonClass.java
===================================================================
diff -u -r34b959260a0f8f8285793a4481a95ca3580eabc5 -r568197820cd33d3fb1bab3ea4ec180a58800fd65
--- lams_common/src/java/org/lamsfoundation/lams/lesson/LessonClass.java (.../LessonClass.java) (revision 34b959260a0f8f8285793a4481a95ca3580eabc5)
+++ lams_common/src/java/org/lamsfoundation/lams/lesson/LessonClass.java (.../LessonClass.java) (revision 568197820cd33d3fb1bab3ea4ec180a58800fd65)
@@ -27,6 +27,7 @@
import org.lamsfoundation.lams.learningdesign.Group;
import org.lamsfoundation.lams.learningdesign.Grouping;
+import org.lamsfoundation.lams.usermanagement.User;
/**
* A type of Grouping that represents all the Learners in a Lesson. The
@@ -70,12 +71,12 @@
/**
* @see org.lamsfoundation.lams.learningdesign.Grouping#isLearnerGroup(org.lamsfoundation.lams.learningdesign.Group)
+ * Returns false if group is null
*/
public boolean isLearnerGroup(Group group)
{
if(group.getGroupId()==null||staffGroup.getGroupId()==null)
- throw new IllegalArgumentException("Can't check up whether group" +
- " is learner group without group id.");
+ return false;
return staffGroup.getGroupId()!=group.getGroupId();
}
@@ -92,4 +93,15 @@
return lessonClass;
}
+ /**
+ * Is this user a staff member for this lesson class? Returns false if the userID is null.
+ */
+ public boolean isStaffMember(User user) {
+ if ( user == null )
+ return false;
+
+ Group staff = getStaffGroup();
+ return staff!=null && staff.hasLearner(user);
+ }
+
}
\ No newline at end of file
Index: lams_common/src/java/org/lamsfoundation/lams/usermanagement/exception/UserAccessDeniedException.java
===================================================================
diff -u -r34b959260a0f8f8285793a4481a95ca3580eabc5 -r568197820cd33d3fb1bab3ea4ec180a58800fd65
--- lams_common/src/java/org/lamsfoundation/lams/usermanagement/exception/UserAccessDeniedException.java (.../UserAccessDeniedException.java) (revision 34b959260a0f8f8285793a4481a95ca3580eabc5)
+++ lams_common/src/java/org/lamsfoundation/lams/usermanagement/exception/UserAccessDeniedException.java (.../UserAccessDeniedException.java) (revision 568197820cd33d3fb1bab3ea4ec180a58800fd65)
@@ -28,9 +28,14 @@
/**
* The current ticket doesn't have sufficient rights for the requested action.
*/
-public class UserAccessDeniedException extends Exception {
+public class UserAccessDeniedException extends RuntimeException {
/**
+ *
+ */
+ private static final long serialVersionUID = 456802622742034527L;
+
+ /**
* Constructs a new instance of this class.
*/
public UserAccessDeniedException() {
@@ -84,4 +89,19 @@
super("Access Denied for user userID="+user.getUserId().toString(), cause);
}
+ /**
+ * Constructs a new instance of this class.
+ */
+ public UserAccessDeniedException(Integer userId) {
+ super("Access Denied for user userID="+userId);
+ }
+
+/**
+ * Constructs a new instance of this class given a root throwable.
+ *
+ * @param cause root failure cause
+ */
+public UserAccessDeniedException(Integer userId, Throwable cause) {
+ super("Access Denied for user userID="+userId, cause);
+ }
}
Index: lams_monitoring/conf/language/ApplicationResources.properties
===================================================================
diff -u -r5b215ed05d720a4cb7edc7f412dc2e234eef304f -r568197820cd33d3fb1bab3ea4ec180a58800fd65
--- lams_monitoring/conf/language/ApplicationResources.properties (.../ApplicationResources.properties) (revision 5b215ed05d720a4cb7edc7f412dc2e234eef304f)
+++ lams_monitoring/conf/language/ApplicationResources.properties (.../ApplicationResources.properties) (revision 568197820cd33d3fb1bab3ea4ec180a58800fd65)
@@ -21,4 +21,8 @@
# Message for monitoring client (Flash) - Invalid type of activity
INVALID.ACTIVITYID.TYPE=Invalid Activity type: {0}. Only ToolActivity allowed.
# Message for monitoring client (Flash) - Invalid Lesson ID
-INVALID.ACTIVITYID.LESSONID=Invalid activityID/lessonID : {0} : {1}.
\ No newline at end of file
+INVALID.ACTIVITYID.LESSONID=Invalid activityID/lessonID : {0} : {1}.
+# General system error message.
+error.system.error=An error has occurred. Please start again. Reason for error: {0}
+# User is not allowed to do whatever they just tried to do
+error.user.noprivilege=Sorry, you do not have the privilege to do this action.
\ No newline at end of file
Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/MonitoringConstants.java
===================================================================
diff -u -rd9c7ddef141d19423b6ab2914d153c2cb748f187 -r568197820cd33d3fb1bab3ea4ec180a58800fd65
--- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/MonitoringConstants.java (.../MonitoringConstants.java) (revision d9c7ddef141d19423b6ab2914d153c2cb748f187)
+++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/MonitoringConstants.java (.../MonitoringConstants.java) (revision 568197820cd33d3fb1bab3ea4ec180a58800fd65)
@@ -24,7 +24,6 @@
/* $$Id$$ */
package org.lamsfoundation.lams.monitoring;
-import java.util.Hashtable;
public class MonitoringConstants {
@@ -34,6 +33,7 @@
public static final String PERFORM_CHOSEN_GROUPING_KEY = "performChosenGrouping";
public static final String KEY_ORGANISATION_ID = "organisationID";
public static final String KEY_LESSON_ID = "lessonID";
+ public static final String KEY_USER_ID = "userID";
public static final String KEY_STAFF = "staff";
public static final String KEY_LEARNER = "learners";
public static final String JOB_START_LESSON = "startScheduleLessonJob";
Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/quartz/job/FinishScheduleLessonJob.java
===================================================================
diff -u -rd9c7ddef141d19423b6ab2914d153c2cb748f187 -r568197820cd33d3fb1bab3ea4ec180a58800fd65
--- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/quartz/job/FinishScheduleLessonJob.java (.../FinishScheduleLessonJob.java) (revision d9c7ddef141d19423b6ab2914d153c2cb748f187)
+++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/quartz/job/FinishScheduleLessonJob.java (.../FinishScheduleLessonJob.java) (revision 568197820cd33d3fb1bab3ea4ec180a58800fd65)
@@ -44,12 +44,12 @@
//getting gate id set from scheduler
Map properties = context.getJobDetail().getJobDataMap();
long lessonId = ((Long)properties.get(MonitoringConstants.KEY_LESSON_ID)).longValue();
-
+ Integer userId = (Integer)properties.get(MonitoringConstants.KEY_USER_ID);
if(log.isDebugEnabled())
log.debug("Lesson ["+lessonId+"] is stopping...");
- monitoringService.finishLesson(lessonId);
+ monitoringService.finishLesson(lessonId,userId);
if(log.isDebugEnabled())
log.debug("Lesson ["+lessonId+"] stopped");
Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/quartz/job/StartScheduleLessonJob.java
===================================================================
diff -u -rd9c7ddef141d19423b6ab2914d153c2cb748f187 -r568197820cd33d3fb1bab3ea4ec180a58800fd65
--- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/quartz/job/StartScheduleLessonJob.java (.../StartScheduleLessonJob.java) (revision d9c7ddef141d19423b6ab2914d153c2cb748f187)
+++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/quartz/job/StartScheduleLessonJob.java (.../StartScheduleLessonJob.java) (revision 568197820cd33d3fb1bab3ea4ec180a58800fd65)
@@ -44,12 +44,13 @@
//getting gate id set from scheduler
Map properties = context.getJobDetail().getJobDataMap();
long lessonId = ((Long)properties.get(MonitoringConstants.KEY_LESSON_ID)).longValue();
+ Integer userId = (Integer)properties.get(MonitoringConstants.KEY_USER_ID);
if(log.isDebugEnabled())
log.debug("Lesson ["+lessonId+"] is starting...");
- monitoringService.startLesson(lessonId);
+ monitoringService.startLesson(lessonId, userId);
if(log.isDebugEnabled())
log.debug("Lesson ["+lessonId+"] started");
Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java
===================================================================
diff -u -rd9c7ddef141d19423b6ab2914d153c2cb748f187 -r568197820cd33d3fb1bab3ea4ec180a58800fd65
--- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java (.../IMonitoringService.java) (revision d9c7ddef141d19423b6ab2914d153c2cb748f187)
+++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java (.../IMonitoringService.java) (revision 568197820cd33d3fb1bab3ea4ec180a58800fd65)
@@ -34,9 +34,8 @@
import org.lamsfoundation.lams.lesson.Lesson;
import org.lamsfoundation.lams.tool.exception.LamsToolServiceException;
import org.lamsfoundation.lams.usermanagement.Organisation;
-import org.lamsfoundation.lams.usermanagement.User;
-import org.lamsfoundation.lams.usermanagement.dto.UserDTO;
import org.lamsfoundation.lams.usermanagement.exception.UserAccessDeniedException;
+import org.lamsfoundation.lams.util.MessageService;
/**
@@ -51,6 +50,9 @@
public interface IMonitoringService
{
+ /** Get the message service, which gives access to the I18N text */
+ public MessageService getMessageService();
+
/**
* Initialize a new lesson so as to start the learning process. It needs to
* notify lams which learning design it belongs to. The initialize process
@@ -89,7 +91,7 @@
* @param lessionPackage
* @return
*/
- public String createLessonClassForLessonWDDX(Integer creatorUserId,String lessionPackage);
+ public String createLessonClassForLessonWDDX(Integer creatorUserId,String lessionPackage) throws UserAccessDeniedException;
/**
* Setup the lesson class and organization for a lesson according to the
@@ -103,40 +105,44 @@
* @param staffs a list of staffs who will be in charge of this lesson.
* @return the lesson with lesson class and organization
*/
- public Lesson createLessonClassForLesson(long lessonId, Organisation organisation,String leanerGroupName, List organizationUsers,String staffGroupName, List staffs);
+ public Lesson createLessonClassForLesson(long lessonId, Organisation organisation,String leanerGroupName, List organizationUsers,String staffGroupName, List staffs, Integer userID) throws UserAccessDeniedException;
/**
* Start the specified the lesson. It must be created before calling this
* service.
* @param lessonId the specified the lesson id.
+ * @param userId checks that the user is a staff member for this lesson
* @throws LamsToolServiceException the exception occurred during the
* lams and tool interaction to start a
* lesson.
*/
- public void startLesson(long lessonId);
+ public void startLesson(long lessonId, Integer userId) throws UserAccessDeniedException;
/**
* Start a lesson on schedule datetime.
* @param lessonId
* @param startDate the lesson start date and time.
+ * @param userId checks that the user is a staff member for this lesson
* @see org.lamsfoundation.lams.monitoring.service#startLesson(long)
*/
- public void startLessonOnSchedule(long lessonId, Date startDate);
+ public void startLessonOnSchedule(long lessonId, Date startDate, Integer userId) throws UserAccessDeniedException;
/**
* Finish a lesson on schedule datetime.
* @param lessonId
- * @param endDate teh lesson end date and time.
+ * @param endDate the lesson end date and time.
+ * @param userId checks that the user is a staff member for this lesson
*/
- public void finishLessonOnSchedule(long lessonId, Date endDate);
+ public void finishLessonOnSchedule(long lessonId, Date endDate, Integer userId) throws UserAccessDeniedException;
/**
* Finish a lesson.A Finished lesson can be viewed on the monitoring interface.
* It should be an "inactive" lesson. A Finished lesson is listed on the learner
* interface but all the learner can do is view the progress bar and do an
* export portfolio - they cannot access any of the tool screens.
*
* @param lessonId
+ * @param userId checks that the user is a staff member for this lesson
* @param endDate teh lesson end date and time.
*/
- public void finishLesson(long lessonId);
+ public void finishLesson(long lessonId, Integer userId) throws UserAccessDeniedException;
/**
* Force Complete works on an individual user. The teacher may complete it up to a particular activity,
@@ -155,37 +161,34 @@
* Archive the specified lesson. When archived, the data is retained
* but the learners cannot access the details.
* @param lessonId the specified the lesson id.
+ * @param userId checks that the user is a staff member for this lesson
*/
- public void archiveLesson(long lessonId);
+ public void archiveLesson(long lessonId, Integer userId) throws UserAccessDeniedException;
/**
* A lesson can only be suspended if it is started. The purpose of suspending is
* to hide the lesson from learners temporarily. If the teacher tries to suspend a lesson that
* is not in the STARTED_STATE, then an error should be returned.
* @param lessonId the lesson ID which will be suspended.
+ * @param userId checks that the user is a staff member for this lesson
*/
- public void suspendLesson(long lessonId);
+ public void suspendLesson(long lessonId, Integer userId) throws UserAccessDeniedException;
/**
* Unsuspend a lesson, which state must be Lesson.SUSPEND_STATE. Otherwise an exception will be thrown.
* @param lessonId
+ * @param userId checks that the user is a staff member for this lesson
*/
- public void unsuspendLesson(long lessonId);
+ public void unsuspendLesson(long lessonId, Integer userId) throws UserAccessDeniedException;
/**
*
* Teachers sometimes find that there are just too many "old" designs and
* wish to remove them and never access them again. This function disables
* the lesson - it does not remove the contents from the database
*
- * @param lessonId
- * the specified the lesson id.
+ * @param lessonId the specified the lesson id.
+ * @param userId checks that the user is a staff member for this lesson
*/
- public void removeLesson(long lessonId);
- /**
- *
- * Permanently remove a lesson from the database. This can not be undone - once deleted the
- * data is gone forever.
- */
- public void deleteLesson(Lesson lesson);
+ public void removeLesson(long lessonId, Integer userId) throws UserAccessDeniedException;
/**
* Set the gate to open to let all the learners through. This learning service
* is triggerred by the system scheduler. Will return true GateActivity (or subclass)
@@ -203,50 +206,29 @@
public GateActivity closeGate(Long gateId);
/**
- * This method returns a A list of all available Lessons.
- * Note - this is all the lessons (for all users, for all states, including disabled).
- * If the data is to be sent to Flash, then use getAllLessonsWDDX()
+ * This method returns a string representing a list of all lessons
+ * for the current user. See getAllLessons().
*
- * @return List The requested list of Lessons
- * @throws IOException
- */
- public List getAllLessons() throws IOException;
-
- /**
- * This method returns a string representing a list of all
- * Note - this is all the lessons (for all users, for all states, including disabled).
- * available Lessons in the WDDX format
- *
* @return String The requested list of Lessons in wddx format
* @throws IOException
*/
- public String getAllLessonsWDDX() throws IOException;
+ public String getAllLessonsWDDX(Integer userID) throws IOException;
/**
- * This method returns a string representing a list of all
- * available Lessons for a given user. If the data is to be
- * sent to Flash, then use getAllLessonsWDDX(Integer userID)
+ * This method returns a list of all available Lessons. This is all the lessons
+ * created by the current user and all the lessons for which the user is in the
+ * staff group. It does not return removed lessons.
*
+ * If the data is to be sent to Flash, then use getAllLessonsWDDX()
+ *
* @param userID The user_id of the user for whom the lessons
* are being fetched.
* @return List The requested list of Lessons
* @throws IOException
*/
- public List getAllLessons(Integer userID)throws IOException;
+ public List getAllLessons(Integer userID) throws IOException;
-
/**
- * This method returns a string representing a list of all
- * available Lessons for a given user in the WDDX format
- *
- * @param userID The user_id of the user for whom the lessons
- * are being fetched.
- * @return String The requested list of Lessons in wddx format
- * @throws IOException
- */
- public String getAllLessonsWDDX(Integer userID)throws IOException;
-
- /**
* This method returns the details for the given Lesson in
* WDDX format
*
Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java
===================================================================
diff -u -r0493011805035201766e67898a94bdf9f797d573 -r568197820cd33d3fb1bab3ea4ec180a58800fd65
--- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision 0493011805035201766e67898a94bdf9f797d573)
+++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision 568197820cd33d3fb1bab3ea4ec180a58800fd65)
@@ -61,6 +61,7 @@
import org.lamsfoundation.lams.lesson.LessonClass;
import org.lamsfoundation.lams.lesson.dao.ILessonClassDAO;
import org.lamsfoundation.lams.lesson.dao.ILessonDAO;
+import org.lamsfoundation.lams.lesson.dto.LessonDTO;
import org.lamsfoundation.lams.monitoring.MonitoringConstants;
import org.lamsfoundation.lams.tool.ToolSession;
import org.lamsfoundation.lams.tool.exception.DataMissingException;
@@ -143,6 +144,9 @@
public void setMessageService(MessageService messageService) {
this.messageService = messageService;
}
+ public MessageService getMessageService() {
+ return messageService;
+ }
/**
* @param userManagementService The userManagementService to set.
*/
@@ -249,6 +253,21 @@
//---------------------------------------------------------------------
// Service Methods
//---------------------------------------------------------------------
+
+ /** Checks whether the user is a staff member for the lesson or the creator of the lesson.
+ * If not, throws a UserAccessDeniedException exception */
+ private void checkOwnerOrStaffMember(Integer userId, Lesson lesson, String actionDescription) {
+ User user = userManagementService.getUserById(userId);
+
+ if ( lesson.getUser() != null && lesson.getUser().getUserId().equals(userId) ) {
+ return;
+ }
+
+ if ( lesson == null || lesson.getLessonClass()==null || !lesson.getLessonClass().isStaffMember(user) ) {
+ throw new UserAccessDeniedException("User "+userId+" may not "+actionDescription+" for lesson "+lesson.getLessonId());
+ }
+ }
+
/**
* Create new lesson according to the learning design specified by the
* user. This involves following major steps:
@@ -356,10 +375,11 @@
}
/**
- * @see org.lamsfoundation.lams.monitoring.service.IMonitoringService#createLessonClassForLessonWDDX(Integer, String)
+ * @see org.lamsfoundation.lams.monitoring.service.IMonitoringService#createLessonClassForLessonWDDX(Integer, String, java.util.Integer)
*/
- public String createLessonClassForLessonWDDX(Integer creatorUserId, String lessonPacket){
+ public String createLessonClassForLessonWDDX(Integer creatorUserId, String lessonPacket) throws UserAccessDeniedException {
FlashMessage flashMessage = null;
+
try{
Hashtable table = (Hashtable)WDDXProcessor.deserialize(lessonPacket);
//todo: convert:data type:
@@ -383,9 +403,10 @@
Organisation organisation = organisationDAO.getOrganisationById(orgId);
User creator = userDAO.getUserById(creatorUserId);
+
// create the lesson class - add all the users in this organisation to the lesson class
// add user as staff
- List learnerList = new LinkedList();
+ List learnerList = new LinkedList();
learnerList.add(creator);
Iterator iter = learners.iterator();
while (iter.hasNext()) {
@@ -398,7 +419,7 @@
}
}
//get staff user info
- List staffList = new LinkedList();
+ List staffList = new LinkedList();
staffList.add(creator);
iter = staffs.iterator();
while (iter.hasNext()) {
@@ -411,13 +432,14 @@
}
}
- //Create Lesson!
+ //Create Lesson class
createLessonClassForLesson(lessonId,
organisation,
learnerGroupName,
learnerList,
staffGroupName,
- staffList);
+ staffList,
+ creatorUserId);
flashMessage = new FlashMessage("createLesson",Boolean.TRUE);
} catch (Exception e) {
@@ -443,18 +465,19 @@
* @param staffGroupName
* @param learnerGroupName
*
- * @see org.lamsfoundation.lams.monitoring.service.IMonitoringService#createLessonClassForLesson(long, org.lamsfoundation.lams.usermanagement.Organisation, java.util.List, java.util.List)
+ * @see org.lamsfoundation.lams.monitoring.service.IMonitoringService#createLessonClassForLesson(long, org.lamsfoundation.lams.usermanagement.Organisation, java.util.List, java.util.List, java.util.Integer)
*/
public Lesson createLessonClassForLesson(long lessonId,
Organisation organisation,
String learnerGroupName, List organizationUsers,
- String staffGroupName, List staffs)
+ String staffGroupName, List staffs, Integer userId)
{
Lesson newLesson = lessonDAO.getLesson(new Long(lessonId));
if ( newLesson == null) {
throw new MonitoringServiceException("Lesson for id="+lessonId+" is missing. Unable to create class for lesson.");
}
-
+ checkOwnerOrStaffMember(userId, newLesson, "create lesson class");
+
LessonClass newLessonClass = this.createLessonClass(organisation,
learnerGroupName,
organizationUsers,
@@ -473,15 +496,17 @@
* Start lesson on schedule.
* @param lessonId
* @param startDate
+ * @param userID: checks that this user is a staff member for this lesson
* @see org.lamsfoundation.lams.monitoring.service.IMonitoringService#startLessonOnSchedule(long , Date, User)
*/
- public void startLessonOnSchedule(long lessonId, Date startDate){
+ public void startLessonOnSchedule(long lessonId, Date startDate, Integer userId){
//we get the lesson just created
Lesson requestedLesson = lessonDAO.getLesson(new Long(lessonId));
if ( requestedLesson == null) {
throw new MonitoringServiceException("Lesson for id="+lessonId+" is missing. Unable to start lesson.");
}
+ checkOwnerOrStaffMember(userId, requestedLesson, "start lesson on schedule");
JobDetail startLessonJob = getStartScheduleLessonJob();
//setup the message for scheduling job
@@ -490,6 +515,8 @@
startLessonJob.setDescription(requestedLesson.getLessonName()+":"
+ (requestedLesson.getUser() == null?"":requestedLesson.getUser().getFullName()));
startLessonJob.getJobDataMap().put(MonitoringConstants.KEY_LESSON_ID,new Long(lessonId));
+ startLessonJob.getJobDataMap().put(MonitoringConstants.KEY_USER_ID,new Integer(userId));
+
//create customized triggers
Trigger startLessonTrigger = new SimpleTrigger("startLessonOnScheduleTrigger:"+ lessonId,
Scheduler.DEFAULT_GROUP,
@@ -518,19 +545,21 @@
* @param endDate
* @see org.lamsfoundation.lams.monitoring.service.IMonitoringService#finishLessonOnSchedule(long , Date , User)
*/
- public void finishLessonOnSchedule(long lessonId, Date endDate) {
+ public void finishLessonOnSchedule(long lessonId, Date endDate, Integer userId) {
//we get the lesson want to finish
Lesson requestedLesson = lessonDAO.getLesson(new Long(lessonId));
if ( requestedLesson == null) {
throw new MonitoringServiceException("Lesson for id="+lessonId+" is missing. Unable to start lesson.");
}
+ checkOwnerOrStaffMember(userId, requestedLesson, "finish lesson on schedule");
JobDetail finishLessonJob = getFinishScheduleLessonJob();
//setup the message for scheduling job
finishLessonJob.setName("finishLessonOnSchedule:"+lessonId);
finishLessonJob.setDescription(requestedLesson.getLessonName()+":"
+ (requestedLesson.getUser() == null?"":requestedLesson.getUser().getFullName()));
finishLessonJob.getJobDataMap().put(MonitoringConstants.KEY_LESSON_ID,new Long(lessonId));
+ finishLessonJob.getJobDataMap().put(MonitoringConstants.KEY_USER_ID,new Integer(userId));
//create customized triggers
Trigger finishLessonTrigger = new SimpleTrigger("finishLessonOnScheduleTrigger:"+lessonId,
Scheduler.DEFAULT_GROUP,
@@ -554,7 +583,7 @@
/**
* @see org.lamsfoundation.lams.monitoring.service.IMonitoringService#startlesson(long)
*/
- public void startLesson(long lessonId)
+ public void startLesson(long lessonId, Integer userId)
{
// System.out.println(messageService.getMessage("NO.SUCH.LESSON",new Object[]{new Long(lessonId)}));
// System.out.println(messageService.getMessage("INVALID.ACTIVITYID.USER", new Object[]{ "activityID","userID" }));
@@ -569,6 +598,7 @@
if ( requestedLesson == null) {
throw new MonitoringServiceException("Lesson for id="+lessonId+" is missing. Unable to start lesson.");
}
+ checkOwnerOrStaffMember(userId, requestedLesson, "create lesson class");
Date lessonStartTime = new Date();
//initialize tool sessions if necessary
@@ -598,24 +628,35 @@
/**
* @see org.lamsfoundation.lams.monitoring.service.IMonitoringService#finishLesson(long)
*/
- public void finishLesson(long lessonId) {
- setLessonState(lessonId,Lesson.FINISHED_STATE);
+ public void finishLesson(long lessonId, Integer userId) {
+ Lesson requestedLesson = lessonDAO.getLesson(new Long(lessonId));
+ if ( requestedLesson == null ) {
+ throw new MonitoringServiceException("Lesson for id="+lessonId+" is missing. Unable to set lesson to finished");
+ }
+ checkOwnerOrStaffMember(userId, requestedLesson, "finish lesson");
+ setLessonState(requestedLesson,Lesson.FINISHED_STATE);
}
/**
* Archive the specified the lesson. When archived, the data is retained
* but the learners cannot access the details.
* @param lessonId the specified the lesson id.
*/
- public void archiveLesson(long lessonId) {
- setLessonState(lessonId,Lesson.ARCHIVED_STATE);
+ public void archiveLesson(long lessonId, Integer userId) {
+ Lesson requestedLesson = lessonDAO.getLesson(new Long(lessonId));
+ if ( requestedLesson == null ) {
+ throw new MonitoringServiceException("Lesson for id="+lessonId+" is missing. Unable to set lesson to archived");
+ }
+ checkOwnerOrStaffMember(userId, requestedLesson, "archive lesson");
+ setLessonState(requestedLesson,Lesson.ARCHIVED_STATE);
}
/**
*
* @see org.lamsfoundation.lams.monitoring.service.IMonitoringService#suspendLesson(long)
*/
- public void suspendLesson(long lessonId) {
+ public void suspendLesson(long lessonId, Integer userId) {
Lesson lesson = lessonDAO.getLesson(new Long(lessonId));
+ checkOwnerOrStaffMember(userId, lesson, "suspend lesson");
Integer state = lesson.getLessonStateId();
//only suspend started lesson
if(!Lesson.STARTED_STATE.equals(state)){
@@ -630,8 +671,9 @@
*
* @see org.lamsfoundation.lams.monitoring.service.IMonitoringService#unsuspendLesson(long)
*/
- public void unsuspendLesson(long lessonId) {
+ public void unsuspendLesson(long lessonId, Integer userId) {
Lesson lesson = lessonDAO.getLesson(new Long(lessonId));
+ checkOwnerOrStaffMember(userId, lesson, "unsuspend lesson");
Integer state = lesson.getLessonStateId();
//only suspend started lesson
if(!Lesson.SUSPENDED_STATE.equals(state)){
@@ -644,26 +686,6 @@
}
/**
- * Set lesson status to given status value. The stauts value will be one value of class level in
- * org.lamsfoundation.lams.lesson.Lesson.
- *
- * @param lessonId
- * @param status
- */
- private void setLessonState(long lessonId,Integer status) {
-
- Lesson requestedLesson = lessonDAO.getLesson(new Long(lessonId));
- if( status == null ){
- throw new MonitoringServiceException("Lesson status is required");
- }
- if ( requestedLesson == null ) {
- throw new MonitoringServiceException("Lesson for id="+lessonId+" is missing. Unable to set lesson status to "+ status.intValue());
- }
-
- setLessonState(requestedLesson,status);
-
- }
- /**
* @see setLessonState(long,Integer)
* @param requestedLesson
* @param status
@@ -677,42 +699,16 @@
/**
* @see org.lamsfoundation.lams.monitoring.service.IMonitoringService#removeLesson(long)
*/
- public void removeLesson(long lessonId) {
+ public void removeLesson(long lessonId, Integer userId) {
Lesson requestedLesson = lessonDAO.getLesson(new Long(lessonId));
if ( requestedLesson == null) {
throw new MonitoringServiceException("Lesson for id="+lessonId+" is missing. Unable to remove lesson.");
}
-
- requestedLesson.setLessonStateId(Lesson.REMOVED_STATE);
- lessonDAO.updateLesson(requestedLesson);
-
+ checkOwnerOrStaffMember(userId, requestedLesson, "remove lesson");
+ setLessonState(requestedLesson,Lesson.REMOVED_STATE);
}
/**
- * Delete a lesson and all its contents. Warning: at the moment, this should only be done to preview lessons.
- * Can't guarentee data integrity if it is done to any other type of lesson. See removeLesson() for hiding
- * lessons from a teacher's view without removing them from the database.
- *
- * This code actually checks that the lesson is a preview lesson - writes out a warning message if it is not
- * a preview lesson.
- *
- * @see org.lamsfoundation.lams.monitoring.service.IMonitoringService#deleteLesson(org.lamsfoundation.lams.lesson.Lesson)
- * TODO remove the related tool data.
- */
- public void deleteLesson(Lesson lesson) {
-
- if ( lesson != null && lesson.getLearningDesign()!= null && lesson.getLearningDesign().getCopyTypeID() != null &&
- LearningDesign.COPY_TYPE_PREVIEW == lesson.getLearningDesign().getCopyTypeID().intValue() ) {
- lessonDAO.deleteLesson(lesson);
- } else {
- log.warn("Unable to delete lesson as lesson is not a preview lesson. Learning design copy type was "
- +(lesson != null && lesson.getLearningDesign()!= null ? lesson.getLearningDesign().getCopyTypeID() : null)
- +" Lesson is "+lesson);
- }
-
- }
-
- /**
* @see org.lamsfoundation.lams.monitoring.service.IMonitoringService#openGate(org.lamsfoundation.lams.learningdesign.GateActivity)
*/
public GateActivity openGate(Long gateId)
@@ -834,22 +830,6 @@
/**
* (non-Javadoc)
- * @see org.lamsfoundation.lams.monitoring.service.IMonitoringService#getAllLessons()
- */
- public List getAllLessons() throws IOException{
- return lessonDAO.getAllLessons();
- }
-
- /**
- * (non-Javadoc)
- * @see org.lamsfoundation.lams.monitoring.service.IMonitoringService#getAllLessonsWDDX()
- */
- public String getAllLessonsWDDX() throws IOException{
- return requestLessonList(getAllLessons());
- }
-
- /**
- * (non-Javadoc)
* @see org.lamsfoundation.lams.monitoring.service.IMonitoringService#getAllLessons(java.lang.Integer)
*/
public List getAllLessons(Integer userID)throws IOException{
@@ -1234,9 +1214,9 @@
*/
private LessonClass createLessonClass(Organisation organisation,
String learnerGroupName,
- List organizationUsers,
+ List organizationUsers,
String staffGroupName,
- List staffs,
+ List staffs,
Lesson newLesson)
{
//create a new lesson class object
@@ -1348,7 +1328,7 @@
* @throws IOException
*/
private String requestLessonList(List lessons)throws IOException{
- Vector lessonObjects = new Vector();
+ Vector lessonObjects = new Vector();
Iterator lessonIterator = lessons.iterator();
while(lessonIterator.hasNext()){
Lesson lesson = (Lesson)lessonIterator.next();
@@ -1368,7 +1348,7 @@
private Vector getOrderedActivityTree(LearningDesign learningDesign){
int order = 0;
HashMap activityTree = learningDesign.getActivityTree();
- Vector activityVector = new Vector();
+ Vector activityVector = new Vector();
Activity nextActivity = learningDesign.getFirstActivity();
while(nextActivity!=null){
@@ -1501,7 +1481,7 @@
private Hashtable createGateStatusInfo(Long activityID, GateActivity gate)
{
- Hashtable table = new Hashtable();
+ Hashtable table = new Hashtable();
table.put("activityID", activityID);
table.put("activityTypeID", gate.getActivityTypeId());
table.put("gateOpen", gate.getGateOpen());
@@ -1555,29 +1535,33 @@
Organisation organisation = user.getBaseOrganisation();
// create the lesson class - add the teacher as the learner and as staff
- LinkedList learners = new LinkedList();
+ LinkedList learners = new LinkedList();
learners.add(user);
- LinkedList staffs = new LinkedList();
+ LinkedList staffs = new LinkedList();
staffs.add(user);
return createLessonClassForLesson(lessonID,
organisation,
"Learner Group",
learners,
"Staff Group",
- staffs);
+ staffs,
+ userID);
}
- /* (non-Javadoc)
- * @see org.lamsfoundation.lams.preview.service.IMonitoringService#deletePreviewSession(long)
- */
+ /**
+ * Delete a preview lesson and all its contents. Warning: can only delete preview lessons.
+ * Can't guarentee data integrity if it is done to any other type of lesson. See removeLesson() for hiding
+ * lessons from a teacher's view without removing them from the database.
+ * TODO remove the related tool data.
+ */
public void deletePreviewLesson(long lessonID) {
Lesson lesson = lessonDAO.getLesson(new Long(lessonID));
deletePreviewLesson(lesson);
}
-
+
private void deletePreviewLesson(Lesson lesson) {
if ( lesson != null ) {
if ( lesson.getLearningDesign().getCopyTypeID() != null &&
@@ -1597,7 +1581,7 @@
// lesson has learning design as a foriegn key, so need to remove lesson before learning design
LearningDesign ld = lesson.getLearningDesign();
- deleteLesson(lesson);
+ lessonDAO.deleteLesson(lesson);
authoringService.deleteLearningDesign(ld);
} else {
Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/DummyMonitoringAction.java
===================================================================
diff -u -rc5da4a357670347bcb3af134be8e7de02eabecdb -r568197820cd33d3fb1bab3ea4ec180a58800fd65
--- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/DummyMonitoringAction.java (.../DummyMonitoringAction.java) (revision c5da4a357670347bcb3af134be8e7de02eabecdb)
+++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/DummyMonitoringAction.java (.../DummyMonitoringAction.java) (revision 568197820cd33d3fb1bab3ea4ec180a58800fd65)
@@ -111,8 +111,7 @@
setupServices();
- User user = getUser();
- List lessons = monitoringService.getAllLessons(user.getUserId());
+ List lessons = monitoringService.getAllLessons(getUserId());
request.getSession().setAttribute(LESSONS_PARAMETER,lessons);
return mapping.findForward(CONTROL_FORWARD);
@@ -125,12 +124,10 @@
HttpServletResponse response)throws IOException{
setupServices();
- User user = getUser();
-
- List designs = monitoringService.getLearningDesigns(new Long(user.getUserId().longValue()));
+ List designs = monitoringService.getLearningDesigns(new Long(getUserId().longValue()));
request.getSession().setAttribute(DESIGNS_PARAMETER,designs);
- List organisations = monitoringService.getOrganisationsUsers(user.getUserId());
+ List organisations = monitoringService.getOrganisationsUsers(getUserId());
request.getSession().setAttribute(ORGS_PARAMETER,organisations);
return mapping.findForward(START_LESSON_FORWARD);
@@ -168,7 +165,7 @@
// Must have User, rather than UserDTO as the createLessonClassForLesson must have
// a proper user objcet in the staffs list.
- User user = getUser();
+ User user = usermanageService.getUserById(getUserId());
Long ldId = dummyForm.getLearningDesignId();
if ( ldId == null )
@@ -207,14 +204,15 @@
"Learner Group",
learners,
"Staff Group",
- staffs);
+ staffs,
+ getUserId());
// start the lesson.
Calendar startDate = dummyForm.getStartDate();
if ( startDate == null ) {
- monitoringService.startLesson(testLesson.getLessonId().longValue());
+ monitoringService.startLesson(testLesson.getLessonId().longValue(),getUserId());
} else {
- monitoringService.startLessonOnSchedule(testLesson.getLessonId().longValue(),startDate.getTime());
+ monitoringService.startLessonOnSchedule(testLesson.getLessonId().longValue(),startDate.getTime(),getUserId());
}
return mapping.findForward(LESSON_STARTED_FORWARD);
@@ -250,7 +248,7 @@
// cal.add(Calendar.MILLISECOND, 5000);
// monitoringService.finishLessonOnSchedule(lessonId,cal.getTime());
- monitoringService.archiveLesson(lessonId);
+ monitoringService.archiveLesson(lessonId,getUserId());
return unspecified(mapping, form, request, response);
}
@@ -281,7 +279,7 @@
this.monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext());
long lessonId = WebUtil.readLongParam(request,AttributeNames.PARAM_LESSON_ID);
- monitoringService.removeLesson(lessonId);
+ monitoringService.removeLesson(lessonId,getUserId());
return unspecified(mapping, form, request, response);
}
@@ -309,9 +307,8 @@
setupServices();
- User user = getUser();
Long lessonId = new Long(WebUtil.readLongParam(request,AttributeNames.PARAM_LESSON_ID));
- List lessons = monitoringService.getAllLessons(user.getUserId());
+ List lessons = monitoringService.getAllLessons(getUserId());
Iterator iter = lessons.iterator();
boolean found = false;
@@ -359,14 +356,11 @@
this.usermanageService= (IUserManagementService) wac.getBean("userManagementService");
}
- private User getUser() throws IOException {
- HttpSession ss = SessionManager.getSession();
- UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
- if ( user != null ) {
- return usermanageService.getUserById(user.getUserID());
- }
- throw new IOException("Unable to get user. User in session manager is "+user);
- }
+ private Integer getUserId() {
+ HttpSession ss = SessionManager.getSession();
+ UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
+ return user != null ? user.getUserID() : null;
+ }
public ActionForward gotoLearnerActivityURL(ActionMapping mapping,
ActionForm form,
Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/MonitoringAction.java
===================================================================
diff -u -r958bc4dadb70cd846b28bf9256704f7a8162ac94 -r568197820cd33d3fb1bab3ea4ec180a58800fd65
--- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/MonitoringAction.java (.../MonitoringAction.java) (revision 958bc4dadb70cd846b28bf9256704f7a8162ac94)
+++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/MonitoringAction.java (.../MonitoringAction.java) (revision 568197820cd33d3fb1bab3ea4ec180a58800fd65)
@@ -27,12 +27,12 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.text.DateFormat;
-import java.text.ParseException;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
@@ -42,10 +42,12 @@
import org.lamsfoundation.lams.monitoring.service.IMonitoringService;
import org.lamsfoundation.lams.monitoring.service.MonitoringServiceProxy;
import org.lamsfoundation.lams.tool.exception.LamsToolServiceException;
-import org.lamsfoundation.lams.usermanagement.service.UserManagementService;
+import org.lamsfoundation.lams.usermanagement.dto.UserDTO;
+import org.lamsfoundation.lams.usermanagement.exception.UserAccessDeniedException;
import org.lamsfoundation.lams.util.WebUtil;
import org.lamsfoundation.lams.util.wddx.FlashMessage;
import org.lamsfoundation.lams.web.action.LamsDispatchAction;
+import org.lamsfoundation.lams.web.session.SessionManager;
import org.lamsfoundation.lams.web.util.AttributeNames;
import org.lamsfoundation.lams.web.util.HttpSessionManager;
import org.springframework.web.context.WebApplicationContext;
@@ -76,7 +78,6 @@
public class MonitoringAction extends LamsDispatchAction
{
WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(HttpSessionManager.getInstance().getServletContext());
- UserManagementService userManagementService = (UserManagementService) ctx.getBean("userManagementServiceTarget");
//---------------------------------------------------------------------
// Instance variables
@@ -90,6 +91,12 @@
/** See deleteOldPreviewLessons */
public static final String NUM_DELETED = "numDeleted";
+ private Integer getUserId() {
+ HttpSession ss = SessionManager.getSession();
+ UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
+ return user != null ? user.getUserID() : null;
+ }
+
/**
* @param wddxPacket
* @return
@@ -110,7 +117,29 @@
return url;
}
-
+ private FlashMessage handleException(Exception e, String methodKey, IMonitoringService monitoringService) {
+ log.error("Exception thrown "+methodKey,e);
+ if ( e instanceof UserAccessDeniedException ) {
+ return new FlashMessage(methodKey,
+ monitoringService.getMessageService().getMessage("error.user.noprivilege"),
+ FlashMessage.ERROR);
+ } else {
+ String[] msg = new String[1];
+ msg[0] = e.getMessage();
+ return new FlashMessage(methodKey,
+ monitoringService.getMessageService().getMessage("error.system.error", msg),
+ FlashMessage.CRITICAL_ERROR);
+ }
+ }
+
+ private FlashMessage handleCriticalError(String methodKey, String messageKey, IMonitoringService monitoringService) {
+ String message = monitoringService.getMessageService().getMessage(messageKey);
+ log.error("Error occured "+methodKey+" error ");
+ return new FlashMessage(methodKey,
+ message,
+ FlashMessage.CRITICAL_ERROR);
+ }
+
//---------------------------------------------------------------------
// Struts Dispatch Method
//---------------------------------------------------------------------
@@ -147,14 +176,11 @@
String desc = WebUtil.readStrParam(request,"lessonDescription");
if ( desc == null ) desc = "description";
long ldId = WebUtil.readLongParam(request, AttributeNames.PARAM_LEARNINGDESIGN_ID);
- Integer userId = new Integer(WebUtil.readIntParam(request, AttributeNames.PARAM_USER_ID));
- Lesson newLesson = monitoringService.initializeLesson(title,desc,ldId,userId);
+ Lesson newLesson = monitoringService.initializeLesson(title,desc,ldId,getUserId());
flashMessage = new FlashMessage("initializeLesson",newLesson.getLessonId());
} catch (Exception e) {
- flashMessage = new FlashMessage("initializeLesson",
- e.getMessage(),
- FlashMessage.ERROR);
+ flashMessage = handleException(e, "initializeLesson", monitoringService);
}
String message = flashMessage.serializeMessage();
@@ -164,6 +190,7 @@
return null;
}
+
/**
* The Struts dispatch method that starts a lesson that has been created
* beforehand. Most likely, the request to start lesson should be triggered
@@ -191,16 +218,14 @@
ServletException
{
IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext());
- long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID);
FlashMessage flashMessage = null;
try {
- monitoringService.startLesson(lessonId);
+ long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID);
+ monitoringService.startLesson(lessonId, getUserId());
flashMessage = new FlashMessage("startLesson",Boolean.TRUE);
} catch (Exception e) {
- flashMessage = new FlashMessage("startLesson",
- "Invalid lessonID :" + lessonId,
- FlashMessage.ERROR);
+ flashMessage = handleException(e, "startLesson", monitoringService);
}
String message = flashMessage.serializeMessage();
@@ -233,22 +258,16 @@
ServletException
{
IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext());
- long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID);
- String dateStr = WebUtil.readStrParam(request, MonitoringConstants.PARAM_LESSON_START_DATE);
FlashMessage flashMessage = null;
try {
+ long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID);
+ String dateStr = WebUtil.readStrParam(request, MonitoringConstants.PARAM_LESSON_START_DATE);
Date startDate = DateFormat.getInstance().parse(dateStr);
- monitoringService.startLessonOnSchedule(lessonId,startDate);
+ monitoringService.startLessonOnSchedule(lessonId,startDate,getUserId());
flashMessage = new FlashMessage("startOnScheduleLesson",Boolean.TRUE);
- } catch(ParseException e){
- flashMessage = new FlashMessage("startOnScheduleLesson",
- "Invalid lesson start datetime format:" + dateStr,
- FlashMessage.ERROR);
}catch (Exception e) {
- flashMessage = new FlashMessage("startOnScheduleLesson",
- "Invalid lessonID :" + lessonId,
- FlashMessage.ERROR);
+ flashMessage = handleException(e, "startOnScheduleLesson", monitoringService);
}
String message = flashMessage.serializeMessage();
@@ -283,22 +302,16 @@
ServletException
{
IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext());
- long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID);
- String dateStr = WebUtil.readStrParam(request, MonitoringConstants.PARAM_LESSON_FINISH_DATE);
FlashMessage flashMessage = null;
try {
+ long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID);
+ String dateStr = WebUtil.readStrParam(request, MonitoringConstants.PARAM_LESSON_FINISH_DATE);
Date finishDate = DateFormat.getInstance().parse(dateStr);
- monitoringService.finishLessonOnSchedule(lessonId,finishDate);
+ monitoringService.finishLessonOnSchedule(lessonId,finishDate,getUserId());
flashMessage = new FlashMessage("finishOnScheduleLesson",Boolean.TRUE);
- } catch(ParseException e){
- flashMessage = new FlashMessage("finishOnScheduleLesson",
- "Invalid lesson finish datetime format:" + dateStr,
- FlashMessage.ERROR);
}catch (Exception e) {
- flashMessage = new FlashMessage("finishOnScheduleLesson",
- "Invalid lessonID :" + lessonId,
- FlashMessage.ERROR);
+ flashMessage = handleException(e, "finishOnScheduleLesson", monitoringService);
}
String message = flashMessage.serializeMessage();
@@ -333,15 +346,13 @@
{
FlashMessage flashMessage = null;
IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext());
- long lessonId = WebUtil.readLongParam(request,AttributeNames.PARAM_LESSON_ID);
try {
- monitoringService.archiveLesson(lessonId);
+ long lessonId = WebUtil.readLongParam(request,AttributeNames.PARAM_LESSON_ID);
+ monitoringService.archiveLesson(lessonId, getUserId());
flashMessage = new FlashMessage("archiveLesson",Boolean.TRUE);
} catch (Exception e) {
- flashMessage = new FlashMessage("archiveLesson",
- "Invalid lessonID :" + lessonId,
- FlashMessage.ERROR);
+ flashMessage = handleException(e, "archiveLesson", monitoringService);
}
String message = flashMessage.serializeMessage();
@@ -374,15 +385,13 @@
{
FlashMessage flashMessage = null;
IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext());
- long lessonId = WebUtil.readLongParam(request,AttributeNames.PARAM_LESSON_ID);
try {
- monitoringService.suspendLesson(lessonId);
+ long lessonId = WebUtil.readLongParam(request,AttributeNames.PARAM_LESSON_ID);
+ monitoringService.suspendLesson(lessonId, getUserId());
flashMessage = new FlashMessage("suspendLesson",Boolean.TRUE);
} catch (Exception e) {
- flashMessage = new FlashMessage("suspendLesson",
- "Error occurs :" + e.getMessage(),
- FlashMessage.ERROR);
+ flashMessage = handleException(e, "suspendLesson", monitoringService);
}
String message = flashMessage.serializeMessage();
@@ -412,15 +421,13 @@
{
FlashMessage flashMessage = null;
IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext());
- long lessonId = WebUtil.readLongParam(request,AttributeNames.PARAM_LESSON_ID);
try {
- monitoringService.unsuspendLesson(lessonId);
+ long lessonId = WebUtil.readLongParam(request,AttributeNames.PARAM_LESSON_ID);
+ monitoringService.unsuspendLesson(lessonId, getUserId());
flashMessage = new FlashMessage("unsuspendLesson",Boolean.TRUE);
} catch (Exception e) {
- flashMessage = new FlashMessage("unsuspendLesson",
- "Error occurs :" + e.getMessage(),
- FlashMessage.ERROR);
+ flashMessage = handleException(e, "unsuspendLesson", monitoringService);
}
String message = flashMessage.serializeMessage();
@@ -453,15 +460,13 @@
ServletException{
FlashMessage flashMessage = null;
IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext());
- long lessonId = WebUtil.readLongParam(request,AttributeNames.PARAM_LESSON_ID);
try {
- monitoringService.removeLesson(lessonId);
+ long lessonId = WebUtil.readLongParam(request,AttributeNames.PARAM_LESSON_ID);
+ monitoringService.removeLesson(lessonId, getUserId());
flashMessage = new FlashMessage("removeLesson",Boolean.TRUE);
} catch (Exception e) {
- flashMessage = new FlashMessage("removeLesson",
- "Invalid lessonID :" + lessonId,
- FlashMessage.ERROR);
+ flashMessage = handleException(e, "removeLesson", monitoringService);
}
String message = flashMessage.serializeMessage();
@@ -500,17 +505,15 @@
}catch(Exception e){
activityId = null;
}
- long lessonId = WebUtil.readLongParam(request,AttributeNames.PARAM_LESSON_ID);
- Integer learnerId = new Integer(WebUtil.readIntParam(request,MonitoringConstants.PARAM_LEARNER_ID));
//force complete
try {
+ long lessonId = WebUtil.readLongParam(request,AttributeNames.PARAM_LESSON_ID);
+ Integer learnerId = new Integer(WebUtil.readIntParam(request,MonitoringConstants.PARAM_LEARNER_ID));
String message = monitoringService.forceCompleteLessonByUser(learnerId,lessonId,activityId);
flashMessage = new FlashMessage("forceComplete",message);
} catch (Exception e) {
- flashMessage = new FlashMessage("forceComplete",
- "Error occurs :" + e.toString(),
- FlashMessage.ERROR);
+ flashMessage = handleException(e, "forceComplete", monitoringService);
}
String message = flashMessage.serializeMessage();
@@ -524,7 +527,7 @@
HttpServletRequest request,
HttpServletResponse response)throws IOException{
IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext());
- String wddxPacket = monitoringService.getAllLessonsWDDX();
+ String wddxPacket = monitoringService.getAllLessonsWDDX(getUserId());
PrintWriter writer = response.getWriter();
writer.println(wddxPacket);
return null;
@@ -685,23 +688,16 @@
long lessonID = previewLesson.getLessonId().longValue();
monitoringService.createPreviewClassForLesson(userID, lessonID);
- monitoringService.startLesson(lessonID);
+ monitoringService.startLesson(lessonID, getUserId());
flashMessage = new FlashMessage("startPreviewSession",new Long(lessonID));
} else {
-
- flashMessage = new FlashMessage("startPreviewSession",
- "Internal error - no lesson created.",
- FlashMessage.CRITICAL_ERROR);
+ flashMessage = handleCriticalError("startPreviewSession", "error.system.error", monitoringService);
}
} catch (Exception e) {
-
- flashMessage = new FlashMessage("startPreviewSession",
- e.getMessage(),
- FlashMessage.ERROR);
-
+ flashMessage = handleException(e, "startPreviewSession", monitoringService);
}
PrintWriter writer = response.getWriter();
Index: lams_monitoring/test/java/org/lamsfoundation/lams/monitoring/service/TestMonitoringService.java
===================================================================
diff -u -rad683fcaeabe83c702b599c5c866bb7d30cd7191 -r568197820cd33d3fb1bab3ea4ec180a58800fd65
--- lams_monitoring/test/java/org/lamsfoundation/lams/monitoring/service/TestMonitoringService.java (.../TestMonitoringService.java) (revision ad683fcaeabe83c702b599c5c866bb7d30cd7191)
+++ lams_monitoring/test/java/org/lamsfoundation/lams/monitoring/service/TestMonitoringService.java (.../TestMonitoringService.java) (revision 568197820cd33d3fb1bab3ea4ec180a58800fd65)
@@ -193,7 +193,8 @@
"leaner group",
learners,
"staff group",
- staffs);
+ staffs,
+ TEST_STAFF_ID);
Lesson createdLesson = lessonDao.getLesson(TEST_LESSON_ID);
assertEquals("verify the staff group",staffs.size(),createdLesson.getLessonClass().getStaffGroup().getUsers().size());
@@ -207,7 +208,7 @@
public void testStartlesson() throws LamsToolServiceException
{
- monitoringService.startLesson(TEST_LESSON_ID.longValue());
+ monitoringService.startLesson(TEST_LESSON_ID.longValue(),TEST_STAFF_ID);
assertTrue(true);
Lesson startedLesson = lessonDao.getLesson(TEST_LESSON_ID);
@@ -237,7 +238,7 @@
}
public void testGetAllLessons()throws IOException{
- String packet = monitoringService.getAllLessonsWDDX();
+ String packet = monitoringService.getAllLessonsWDDX(TEST_STAFF_ID);
System.out.print(packet);
}
public void testGetLessonDetails() throws IOException{
@@ -351,7 +352,7 @@
assertNotNull("Lesson returned from create class",newLesson);
assertSame("Lesson updated from create class", newLesson.getLessonId(),previewLesson.getLessonId());
- monitoringService.startLesson(previewLesson.getLessonId().longValue());
+ monitoringService.startLesson(previewLesson.getLessonId().longValue(),TEST_STAFF_ID);
return previewLesson;
} catch (UserAccessDeniedException e) {