Index: lams_build/lib/lams/lams.jar
===================================================================
diff -u -raf5a6d9874421d5f5bb335259ae58b23116b0bf5 -r7e8b71604044e851c877e918e7d6570a9942a356
Binary files differ
Index: lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/lesson/Lesson.hbm.xml
===================================================================
diff -u -r8d7fbb9d04178c47476596b238655bf8ce2214ca -r7e8b71604044e851c877e918e7d6570a9942a356
--- lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/lesson/Lesson.hbm.xml (.../Lesson.hbm.xml) (revision 8d7fbb9d04178c47476596b238655bf8ce2214ca)
+++ lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/lesson/Lesson.hbm.xml (.../Lesson.hbm.xml) (revision 7e8b71604044e851c877e918e7d6570a9942a356)
@@ -167,4 +167,13 @@
WHERE ({learner}.user_id = lams_learner_progress.user_id)
AND (lams_learner_progress.lesson_id = :lessonId)
+
+
+
+ SELECT COUNT(DISTINCT {learner.user_id})
+ FROM lams_user {learner},
+ lams_learner_progress
+ WHERE ({learner}.user_id = lams_learner_progress.user_id)
+ AND (lams_learner_progress.lesson_id = :lessonId)
+
Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/GateActivityStrategy.java
===================================================================
diff -u -r049f9b1332a5f65c5de9d5b4f891b93fe429ae63 -r7e8b71604044e851c877e918e7d6570a9942a356
--- lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/GateActivityStrategy.java (.../GateActivityStrategy.java) (revision 049f9b1332a5f65c5de9d5b4f891b93fe429ae63)
+++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/GateActivityStrategy.java (.../GateActivityStrategy.java) (revision 7e8b71604044e851c877e918e7d6570a9942a356)
@@ -60,7 +60,7 @@
*
* @param learner the learner who just arrived at the gate.
* @param activity the gate activity.
- * @param lessonLearners all learners who are currently in the lesson.
+ * @param lessonLearners all learners who have started the lesson
* @return whether we should open it or not.
*/
public boolean shouldOpenGateFor(User learner,List lessonLearners)
Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/SynchGateActivityStrategy.java
===================================================================
diff -u -r049f9b1332a5f65c5de9d5b4f891b93fe429ae63 -r7e8b71604044e851c877e918e7d6570a9942a356
--- lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/SynchGateActivityStrategy.java (.../SynchGateActivityStrategy.java) (revision 049f9b1332a5f65c5de9d5b4f891b93fe429ae63)
+++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/SynchGateActivityStrategy.java (.../SynchGateActivityStrategy.java) (revision 7e8b71604044e851c877e918e7d6570a9942a356)
@@ -23,12 +23,10 @@
package org.lamsfoundation.lams.learningdesign.strategy;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import org.lamsfoundation.lams.learningdesign.ContributionTypes;
import org.lamsfoundation.lams.learningdesign.GateActivity;
-import org.lamsfoundation.lams.usermanagement.User;
/**
@@ -37,9 +35,7 @@
* defined in the abstract level.
*
* @author Jacky Fang
- * @since 2005-4-6
- * @version 1.1
- *
+ * @author Fiona Malikoff
*/
public class SynchGateActivityStrategy extends GateActivityStrategy
{
@@ -54,24 +50,23 @@
*
Check up the waiting learners list and lesson learner list. If all
* lesson learner appears in the waiting list, we assume the open condition
* for the sync gate is met.
+ *
+ * Given that the list of lessonLearners is everyone who has started
+ * the lesson, we can assume that # waiting is less than or equal to # in lesson.
+ * So if the two sets have some number of users, then open the gate. Small
+ * chance that the two sets won't match due to a bug elsewhere but not
+ * worth testing for here
.
*
- * Note, simply compares the size of two list might be proper. Waiting
- * learners might not want to wait any more and exit the lesson, who will
- * be removed from current lesson learner list. Therefore, it is possible
- * that the waiting learner list is larger than the current lesson learner
- * list.
- *
* @see org.lamsfoundation.lams.learningdesign.strategy.GateActivityStrategy#isOpenConditionMet()
*/
protected boolean isOpenConditionMet(List lessonLearners)
{
if ( gateActivity != null ) {
- for(Iterator i = lessonLearners.iterator();i.hasNext();)
- {
- User learner = (User)i.next();
- if (!gateActivity.getWaitingLearners().contains(learner))
- return false;
- }
+ int numWaiting = gateActivity.getWaitingLearners().size();
+ int numLesson = lessonLearners!=null?lessonLearners.size():0;
+ if ( numWaiting < numLesson ) {
+ return false;
+ }
}
return true;
}
Index: lams_common/src/java/org/lamsfoundation/lams/lesson/Lesson.java
===================================================================
diff -u -r98fd1a25fe48b3eb229c4992f728b0f90f0fa7e0 -r7e8b71604044e851c877e918e7d6570a9942a356
--- lams_common/src/java/org/lamsfoundation/lams/lesson/Lesson.java (.../Lesson.java) (revision 98fd1a25fe48b3eb229c4992f728b0f90f0fa7e0)
+++ lams_common/src/java/org/lamsfoundation/lams/lesson/Lesson.java (.../Lesson.java) (revision 7e8b71604044e851c877e918e7d6570a9942a356)
@@ -429,20 +429,21 @@
// Domain service methods
//---------------------------------------------------------------------
/**
- * Create lesson data transfer object for flash and java interaction.
+ * Create lesson data transfer object for flash and java learner interaction.
+ * Does not include the counts of the users.
+ *
* @return the lesson data transfer object.
*/
public LessonDTO getLessonData()
{
- return new LessonDTO(this.lessonId,
- this.getLessonName(),
- this.getLessonDescription(),
- this.lessonStateId,
- this.organisation!=null?this.organisation.getOrganisationId():null,
- this.learningDesign!=null?this.learningDesign.getLearningDesignId():null,
- this.createDateTime,
- this.startDateTime);
+ return new LessonDTO(this);
}
+ /**
+ * Create lesson data transfer object for flash and java monitoring interaction.
+ * Includes counts of the learners.
+ *
+ * @return the monitoring lesson data transfer object.
+ */
public LessonDetailsDTO getLessonDetails(){
return new LessonDetailsDTO(this);
}
Index: lams_common/src/java/org/lamsfoundation/lams/lesson/dao/ILessonDAO.java
===================================================================
diff -u -r8d7fbb9d04178c47476596b238655bf8ce2214ca -r7e8b71604044e851c877e918e7d6570a9942a356
--- lams_common/src/java/org/lamsfoundation/lams/lesson/dao/ILessonDAO.java (.../ILessonDAO.java) (revision 8d7fbb9d04178c47476596b238655bf8ce2214ca)
+++ lams_common/src/java/org/lamsfoundation/lams/lesson/dao/ILessonDAO.java (.../ILessonDAO.java) (revision 7e8b71604044e851c877e918e7d6570a9942a356)
@@ -115,6 +115,14 @@
public List getActiveLearnerByLesson(final long lessonId);
/**
+ * Returns the count of all the learners that have started the requested lesson.
+ *
+ * @param lessonId the id of the requested lesson.
+ * @return the count of the learners.
+ */
+ public Integer getCountActiveLearnerByLesson(final long lessonId);
+
+ /**
* Get all the preview lessons more with the creation date before the given date.
*
* @param startDate UTC date
Index: lams_common/src/java/org/lamsfoundation/lams/lesson/dao/hibernate/LessonDAO.java
===================================================================
diff -u -r8d7fbb9d04178c47476596b238655bf8ce2214ca -r7e8b71604044e851c877e918e7d6570a9942a356
--- lams_common/src/java/org/lamsfoundation/lams/lesson/dao/hibernate/LessonDAO.java (.../LessonDAO.java) (revision 8d7fbb9d04178c47476596b238655bf8ce2214ca)
+++ lams_common/src/java/org/lamsfoundation/lams/lesson/dao/hibernate/LessonDAO.java (.../LessonDAO.java) (revision 7e8b71604044e851c877e918e7d6570a9942a356)
@@ -23,6 +23,7 @@
/* $$Id$$ */
package org.lamsfoundation.lams.lesson.dao.hibernate;
+import java.sql.SQLException;
import java.util.Date;
import java.util.List;
@@ -159,7 +160,23 @@
);
return learners;
}
+
/**
+ * @see org.lamsfoundation.lams.lesson.dao.ILessonDAO#getActiveLearnerByLesson(long)
+ */
+ public Integer getCountActiveLearnerByLesson(final long lessonId)
+ {
+ HibernateTemplate hibernateTemplate = new HibernateTemplate(this.getSessionFactory());
+ return (Integer) hibernateTemplate.execute(new HibernateCallback() {
+ public Object doInHibernate(Session session)
+ throws HibernateException {
+ Query query = session.getNamedQuery("countActiveLearners");
+ query.setLong("lessonId", lessonId);
+ return query.uniqueResult();
+ }
+ });
+ }
+/**
* Saves or Updates a Lesson.
* @param lesson
*/
Index: lams_common/src/java/org/lamsfoundation/lams/lesson/dto/LessonDTO.java
===================================================================
diff -u -r98fd1a25fe48b3eb229c4992f728b0f90f0fa7e0 -r7e8b71604044e851c877e918e7d6570a9942a356
--- lams_common/src/java/org/lamsfoundation/lams/lesson/dto/LessonDTO.java (.../LessonDTO.java) (revision 98fd1a25fe48b3eb229c4992f728b0f90f0fa7e0)
+++ lams_common/src/java/org/lamsfoundation/lams/lesson/dto/LessonDTO.java (.../LessonDTO.java) (revision 7e8b71604044e851c877e918e7d6570a9942a356)
@@ -24,7 +24,11 @@
import java.util.Date;
+import org.lamsfoundation.lams.learningdesign.LearningDesign;
+import org.lamsfoundation.lams.lesson.Lesson;
+import org.lamsfoundation.lams.usermanagement.Organisation;
+
/**
* This is a cut down version of Lesson domain object. This data transfer object
* is design for the data interaction between flash and java. As the flash and
@@ -58,23 +62,18 @@
/**
* Full constructor
*/
- public LessonDTO(Long lessonId,
- String lessonName,
- String lessonDescription,
- Integer lessonStateId,
- Integer organisationId,
- Long learningDesignId,
- Date createDateTime,
- Date startDateTime)
+ public LessonDTO(Lesson lesson)
{
- this.lessonID = lessonId;
- this.lessonName = lessonName;
- this.lessonDescription = lessonDescription;
- this.lessonStateID = lessonStateId;
- this.learningDesignID = learningDesignId;
- this.organisationID = organisationId;
- this.createDateTime = createDateTime;
- this.startDateTime = startDateTime;
+ this.lessonID = lesson.getLessonId();
+ this.lessonName = lesson.getLessonName();
+ this.lessonDescription = lesson.getLessonDescription();
+ this.lessonStateID = lesson.getLessonStateId();
+ LearningDesign design = lesson.getLearningDesign();
+ this.learningDesignID = design != null ? design.getLearningDesignId() : null;
+ Organisation org = lesson.getOrganisation();
+ this.organisationID = org != null ? org.getOrganisationId() : null;
+ this.createDateTime = lesson.getCreateDateTime();
+ this.startDateTime = lesson.getStartDateTime();
}
//---------------------------------------------------------------------
Index: lams_common/src/java/org/lamsfoundation/lams/lesson/dto/LessonDetailsDTO.java
===================================================================
diff -u -r34b959260a0f8f8285793a4481a95ca3580eabc5 -r7e8b71604044e851c877e918e7d6570a9942a356
--- lams_common/src/java/org/lamsfoundation/lams/lesson/dto/LessonDetailsDTO.java (.../LessonDetailsDTO.java) (revision 34b959260a0f8f8285793a4481a95ca3580eabc5)
+++ lams_common/src/java/org/lamsfoundation/lams/lesson/dto/LessonDetailsDTO.java (.../LessonDetailsDTO.java) (revision 7e8b71604044e851c877e918e7d6570a9942a356)
@@ -24,6 +24,8 @@
package org.lamsfoundation.lams.lesson.dto;
import java.util.Date;
+import java.util.Set;
+
import org.lamsfoundation.lams.lesson.Lesson;
import org.lamsfoundation.lams.util.wddx.WDDXTAGS;
@@ -33,6 +35,8 @@
public class LessonDetailsDTO {
private Long lessonID;
+ private String lessonName;
+ private String lessonDescription;
private Integer lessonStateID;
private Date createDateTime;
private Date startDateTime;
@@ -43,38 +47,22 @@
private Integer workspaceFolderID;
private Long licenseID;
private String licenseText;
-
private Long learningDesignID;
+ private Integer numberPossibleLearners;
+ private Integer numberStartedLearners;
-
- /** Full constructor */
- public LessonDetailsDTO(Long lessonID, Long duration, Date createDateTime,
- Date startDateTime, Integer organisationID,
- String organisationName, String organisationDescription,
- Integer workspaceFolderID, Long licenseID, String licenseText,
- Integer lessonStateID, Long learningDesignID) {
- this.lessonID = lessonID;
- this.duration = duration;
- this.createDateTime = createDateTime;
- this.startDateTime = startDateTime;
- this.organisationID = organisationID;
- this.organisationName = organisationName;
- this.organisationDescription = organisationDescription;
- this.workspaceFolderID = workspaceFolderID;
- this.licenseID = licenseID;
- this.licenseText = licenseText;
- this.lessonStateID = lessonStateID;
- this.learningDesignID = learningDesignID;
- }
+ /** Create the DTO based on the lesson. Sets up all the fields except numberStartedLearners */
public LessonDetailsDTO(Lesson lesson){
this.lessonID = lesson.getLessonId();
-
- this.duration = lesson.getLearningDesign().getDuration();
-
+ this.lessonName = lesson.getLessonName();
+ this.lessonDescription = lesson.getLessonDescription();
+
+ this.lessonStateID = lesson.getLessonStateId();
this.createDateTime = lesson.getCreateDateTime();
-
this.startDateTime = lesson.getStartDateTime();
+ this.duration = lesson.getLearningDesign().getDuration();
+
this.organisationID = lesson.getOrganisation()!=null?
lesson.getOrganisation().getOrganisationId():
WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER;
@@ -99,9 +87,11 @@
lesson.getLearningDesign().getLicenseText():
WDDXTAGS.STRING_NULL_VALUE;
- this.lessonStateID = lesson.getLessonStateId();
-
this.learningDesignID = lesson.getLearningDesign().getLearningDesignId();
+
+ Set allLearners = lesson.getAllLearners();
+ this.numberPossibleLearners = new Integer(allLearners !=null ? allLearners.size() : 0);
+ this.numberStartedLearners = new Integer(0);
}
/**
* @return Returns the createDateTime.
@@ -175,4 +165,19 @@
public Integer getWorkspaceFolderID() {
return workspaceFolderID!=null?workspaceFolderID:WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER;
}
+ public Integer getNumberStartedLearners() {
+ return numberStartedLearners;
+ }
+ public void setNumberStartedLearners(Integer numberStartedLearners) {
+ this.numberStartedLearners = numberStartedLearners;
+ }
+ public String getLessonDescription() {
+ return lessonDescription;
+ }
+ public String getLessonName() {
+ return lessonName;
+ }
+ public Integer getNumberPossibleLearners() {
+ return numberPossibleLearners;
+ }
}
Index: lams_common/src/java/org/lamsfoundation/lams/lesson/lessonApplicationContext.xml
===================================================================
diff -u -r0b2737221177ec6fb88f447aa647f9413f4373f8 -r7e8b71604044e851c877e918e7d6570a9942a356
--- lams_common/src/java/org/lamsfoundation/lams/lesson/lessonApplicationContext.xml (.../lessonApplicationContext.xml) (revision 0b2737221177ec6fb88f447aa647f9413f4373f8)
+++ lams_common/src/java/org/lamsfoundation/lams/lesson/lessonApplicationContext.xml (.../lessonApplicationContext.xml) (revision 7e8b71604044e851c877e918e7d6570a9942a356)
@@ -22,4 +22,22 @@
+
+
+
+
+
+
+
+
+ true
+
+
+ PROPAGATION_REQUIRED
+ PROPAGATION_REQUIRED
+ PROPAGATION_REQUIRED
+
+
+
+
Index: lams_common/src/java/org/lamsfoundation/lams/lesson/service/ILessonService.java
===================================================================
diff -u
--- lams_common/src/java/org/lamsfoundation/lams/lesson/service/ILessonService.java (revision 0)
+++ lams_common/src/java/org/lamsfoundation/lams/lesson/service/ILessonService.java (revision 7e8b71604044e851c877e918e7d6570a9942a356)
@@ -0,0 +1,85 @@
+/****************************************************************
+ * Copyright (C) 2005 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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+/* $Id$ */
+
+package org.lamsfoundation.lams.lesson.service;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.lamsfoundation.lams.lesson.Lesson;
+import org.lamsfoundation.lams.lesson.dto.LessonDTO;
+import org.lamsfoundation.lams.lesson.dto.LessonDetailsDTO;
+import org.lamsfoundation.lams.usermanagement.User;
+
+/**
+ * Access the general lesson details.
+ *
+ * A lesson has three different "lists" of learners.
+ *
+ * - The learners who are in the learner group attached to the lesson. This is fixed
+ * when the lesson is started and is a list of all the learners who could ever participate in
+ * to the lesson. This is available via lesson.getAllLearners()
+ *
- The learners who have started the lesson. They may or may not be logged in currently,
+ * or if they are logged in they may or may not be doing this lesson. This is available
+ * via getActiveLessonLearners().
+ *
- The learners who are currently logged in and doing this lesson. This is available
+ * via getLoggedInLessonLearners(). Note - learners in this list may actually have left but
+ * we don't know unless they use the actual logout/exit buttons.
+ *
+ */
+public interface ILessonService {
+
+ /**
+ * Cache the user in the list of "currently logged in users"
+ */
+ public abstract void cacheLessonUser(Lesson lesson, User learner);
+
+ /**
+ * Remove the user from the list of "currently logged in users"
+ */
+ public abstract void removeLessonUserFromCache(Lesson lesson, User learner);
+
+ /** Get all the learners who are currently using the lesson */
+ public abstract Collection getLoggedInLessonLearners(Long lessonId);
+
+ /** Get all the learners who have started the lesson. They may not be currently online.*/
+ public abstract List getActiveLessonLearners(Long lessonId);
+
+ /** Get the lesson details for the LAMS client. Suitable for the monitoring client.
+ * Contains a count of the total number of learners in the lesson and the number of active learners.
+ * This is a pretty intensive call as it counts all the learners in the
+ * lessons' learner group, and determines the number of active learners.
+ * @param lessonId
+ * @return lesson details
+ */
+ public abstract LessonDetailsDTO getLessonDetails(Long lessonId);
+
+ /** Get the lesson details for the LAMS client. Suitable for the learner client.
+ * Contains a reduced number of fields compared to getLessonDetails.
+ * @param lessonId
+ * @return lesson details
+ */
+ public abstract LessonDTO getLessonData(Long lessonId);
+
+}
\ No newline at end of file
Index: lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java
===================================================================
diff -u
--- lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java (revision 0)
+++ lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java (revision 7e8b71604044e851c877e918e7d6570a9942a356)
@@ -0,0 +1,152 @@
+/****************************************************************
+ * Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+package org.lamsfoundation.lams.lesson.service;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+
+import org.lamsfoundation.lams.lesson.Lesson;
+import org.lamsfoundation.lams.lesson.dao.ILessonDAO;
+import org.lamsfoundation.lams.lesson.dto.LessonDTO;
+import org.lamsfoundation.lams.lesson.dto.LessonDetailsDTO;
+import org.lamsfoundation.lams.usermanagement.User;
+
+
+/**
+ * Access the general lesson details.
+ *
+ * A lesson has three different "lists" of learners.
+ *
+ * - The learners who are in the learner group attached to the lesson. This is fixed
+ * when the lesson is started and is a list of all the learners who could ever participate in
+ * to the lesson. This is available via lesson.getAllLearners()
+ *
- The learners who have started the lesson. They may or may not be logged in currently,
+ * or if they are logged in they may or may not be doing this lesson. This is available
+ * via getActiveLessonLearners().
+ *
- The learners who are currently logged in and doing this lesson. This is available
+ * via getLoggedInLessonLearners(). Note - learners in this list may actually have left but
+ * we don't know unless they use the actual logout/exit buttons.
+ *
+ */
+/* TODO improve caching of current learners.
+ * The caching is based on the LearnerDataManager cache written by Jacky Fang
+ * but it has been moved out of the servlet context to this singleton.
+ */
+public class LessonService implements ILessonService
+{
+ private ILessonDAO lessonDAO;
+ private HashMap lessonMaps = new HashMap(); // contains maps of lesson users
+
+ /* (non-Javadoc)
+ * @see org.lamsfoundation.lams.lesson.service.ILessonService#cacheLessonUser(org.lamsfoundation.lams.lesson.Lesson, org.lamsfoundation.lams.usermanagement.User)
+ */
+ public void cacheLessonUser(Lesson lesson, User learner)
+ {
+ synchronized (lesson)
+ {
+ //retrieve the map for this lesson
+ HashMap lessonUsersMap = lessonMaps.get(lesson.getLessonId());
+ //create new if never created before
+ if (lessonUsersMap == null) {
+ lessonUsersMap = new HashMap();
+ lessonMaps.put(lesson.getLessonId(),lessonUsersMap);
+ }
+ if (!lessonUsersMap.containsKey(learner.getUserId())) {
+ lessonUsersMap.put(learner.getUserId(), learner);
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.lamsfoundation.lams.lesson.service.ILessonService#removeLessonUserFromCache(org.lamsfoundation.lams.lesson.Lesson, org.lamsfoundation.lams.usermanagement.User)
+ */
+ public void removeLessonUserFromCache(Lesson lesson, User learner)
+ {
+ synchronized (lesson)
+ {
+ HashMap lessonUsersMap = lessonMaps.get(lesson.getLessonId());
+ if (lessonUsersMap != null) {
+ lessonUsersMap.remove(learner.getUserId());
+ }
+ if (lessonUsersMap.size()==0) {
+ // no one active in lesson? get rid of lesson from cache
+ lessonMaps.remove(lesson.getLessonId());
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.lamsfoundation.lams.lesson.service.ILessonService#getLoggedInLessonLearners(java.lang.Long)
+ */
+ public Collection getLoggedInLessonLearners(Long lessonId)
+ {
+ HashMap lessonUsersMap = lessonMaps.get(lessonId);
+ if ( lessonUsersMap != null )
+ return lessonUsersMap.values();
+ return new ArrayList();
+ }
+
+ /* (non-Javadoc)
+ * @see org.lamsfoundation.lams.lesson.service.ILessonService#getActiveLessonLearners(java.lang.Long)
+ */
+ public List getActiveLessonLearners(Long lessonId)
+ {
+ return lessonDAO.getActiveLearnerByLesson(lessonId);
+ }
+
+
+ public void setLessonDAO(ILessonDAO lessonDAO) {
+ this.lessonDAO = lessonDAO;
+ }
+
+ /* (non-Javadoc)
+ * @see org.lamsfoundation.lams.lesson.service.ILessonService#getLessonDetails(java.lang.Long)
+ */
+ public LessonDetailsDTO getLessonDetails(Long lessonId) {
+ Lesson lesson = lessonDAO.getLesson(lessonId);
+ LessonDetailsDTO dto = null;
+ if ( lesson != null ) {
+ dto = lesson.getLessonDetails();
+ Integer active = lessonDAO.getCountActiveLearnerByLesson(lessonId);
+ dto.setNumberStartedLearners(active!=null?active:new Integer(0));
+ }
+ return dto;
+ }
+
+ /* (non-Javadoc)
+ * @see org.lamsfoundation.lams.lesson.service.ILessonService#getLessonData(java.lang.Long)
+ */
+ public LessonDTO getLessonData(Long lessonId) {
+ Lesson lesson = lessonDAO.getLesson(lessonId);
+ LessonDTO dto = null;
+ if ( lesson != null ) {
+ dto = lesson.getLessonData();
+ }
+ return dto;
+ }
+
+}
Index: lams_common/src/java/org/lamsfoundation/lams/usermanagement/service/IUserManagementService.java
===================================================================
diff -u -r8d7fbb9d04178c47476596b238655bf8ce2214ca -r7e8b71604044e851c877e918e7d6570a9942a356
--- lams_common/src/java/org/lamsfoundation/lams/usermanagement/service/IUserManagementService.java (.../IUserManagementService.java) (revision 8d7fbb9d04178c47476596b238655bf8ce2214ca)
+++ lams_common/src/java/org/lamsfoundation/lams/usermanagement/service/IUserManagementService.java (.../IUserManagementService.java) (revision 7e8b71604044e851c877e918e7d6570a9942a356)
@@ -185,22 +185,29 @@
* given roles. If restrictToRoleNames is null/empty then till return all organisations
* to which the user belongs.
*
- * @param user the user
+ * @param user mandatory
* @param restrictToRoleNames role names to which to restrict the user
* @return List of organisationDTOs
*/
public OrganisationDTO getOrganisationsForUserByRole(User user, List restrictToRoleNames);
/**
- * Retrieves a tree of child organisations for this user/organisation. The top of the
- * tree is a "dummy" root organisation, just so that we have a real tree. This makes life easier for Flash.
- *
+ * Retrieves a tree of child of organisations in which the user has the specified role.
+ * If courseID only is set, then return course organisationDTO and its children as its nodes
+ * If courseID && restrictToClassIds are set, then course organisationDTO and its the nominated class
+ * organisationDTOs - most cases will have only single classID
+ *
* If restrictToRoleNames contains any role names (ie not null and size > 0 )
* then it will restrict the organisations to those in which the user has one of the
- * given roles. If restrictToRoleNames is null/empty then till return all organisations
- * to which the user belongs.
+ * given roles.
+ *
+ * @param user mandatory
+ * @param roles optional
+ * @param courseID mandatory
+ * @param restrictToClassIds optional
+ * @return organisationDTO hierarchy, in WDDX format.
*/
- public OrganisationDTO getOrganisationsForUserByRole(User user, List restrictToRoleNames, Integer organisationId);
+ public OrganisationDTO getOrganisationsForUserByRole(User user, List restrictToRoleNames, Integer courseId, List restrictToClassIds);
/**
* Gets an organisation for a user, with the user's roles. Doesn't not return a tree of organisations
Index: lams_common/src/java/org/lamsfoundation/lams/usermanagement/service/UserManagementService.java
===================================================================
diff -u -r8d7fbb9d04178c47476596b238655bf8ce2214ca -r7e8b71604044e851c877e918e7d6570a9942a356
--- lams_common/src/java/org/lamsfoundation/lams/usermanagement/service/UserManagementService.java (.../UserManagementService.java) (revision 8d7fbb9d04178c47476596b238655bf8ce2214ca)
+++ lams_common/src/java/org/lamsfoundation/lams/usermanagement/service/UserManagementService.java (.../UserManagementService.java) (revision 7e8b71604044e851c877e918e7d6570a9942a356)
@@ -319,29 +319,38 @@
/**
* @see org.lamsfoundation.lams.usermanagement.service.IUserManagementService#getOrganisationRolesForUser(org.lamsfoundation.lams.usermanagement.User, java.util.List, java.util.Integer)
*/
- public OrganisationDTO getOrganisationsForUserByRole(User user, List restrictToRoleNames, Integer organisationId) {
+ public OrganisationDTO getOrganisationsForUserByRole(User user, List restrictToRoleNames, Integer courseId, List restrictToClassIds) {
// TODO optimise db access
List dtolist = new ArrayList();
- Organisation org = organisationDAO.getOrganisationById(organisationId);
- getChildOrganisations(user, org, restrictToRoleNames, dtolist);
- return OrganisationDTOFactory.createTree(dtolist);
+ Organisation org = organisationDAO.getOrganisationById(courseId);
+ dtolist.add(org.getOrganisationDTO());
+ getChildOrganisations(user, org, restrictToRoleNames, restrictToClassIds, dtolist);
+ OrganisationDTO dtoTree = OrganisationDTOFactory.createTree(dtolist);
+
+ // Want to return the course as the main node, not the dummy root.
+ Vector nodes = dtoTree.getNodes();
+ return (OrganisationDTO) nodes.get(0);
+
}
- private void getChildOrganisations(User user, Organisation org, List restrictToRoleNames, List dtolist) {
+ private void getChildOrganisations(User user, Organisation org, List restrictToRoleNames, List restrictToClassIds, List dtolist) {
if ( org != null ) {
+ boolean notCheckClassId = restrictToClassIds == null || restrictToClassIds.size() == 0;
List childOrgs = userOrganisationDAO.getChildUserOrganisationsByUser(user, org);
for ( UserOrganisation userOrganisation : childOrgs) {
OrganisationDTO dto = userOrganisation.getOrganisation().getOrganisationDTO();
- boolean aRoleFound = addRolesToDTO(restrictToRoleNames, userOrganisation, dto);
- if ( aRoleFound ) {
- dtolist.add(dto);
+ if ( notCheckClassId || restrictToClassIds.contains(dto.getOrganisationID()) ) {
+ boolean aRoleFound = addRolesToDTO(restrictToRoleNames, userOrganisation, dto);
+ if ( aRoleFound ) {
+ dtolist.add(dto);
+ }
+
+ // now, process any children of this org
+ Organisation childOrganisation = userOrganisation.getOrganisation();
+ if ( org.getChildOrganisations().size() > 0 ) {
+ getChildOrganisations(user, childOrganisation, restrictToRoleNames, restrictToClassIds, dtolist);
+ }
}
-
- // now, process any children of this org
- Organisation childOrganisation = userOrganisation.getOrganisation();
- if ( org.getChildOrganisations().size() > 0 ) {
- getChildOrganisations(user, childOrganisation, restrictToRoleNames, dtolist);
- }
}
}
}