[Building Sakai] coursemanagement service and Course vs CourseSection objects

Gross,Christopher ufchrisg at ufl.edu
Wed Sep 5 12:28:37 PDT 2012


I found where I need to make changes but I am curious about a few things, namely if this is something that the community may want upstream.

As a quick refresher: I need to include the section number for students in all exports from the gradebook.  An EnrollmentRecord is a LearningContext and LearningContext.getClass(), for this type of object, will either be a Course or CourseSection.  What I have seen is that it is almost always the former but I need it to be the latter in order to get the proper section title.  So, I turned on eclipse debug and traced through what Gradebook was doing and found where EnrollmentRecord objects are created and thus being linked to Course instead of CourseSection for all eternity.

The function in question is:

org.sakaiproject.component.section.sakai.SectionAwarenessImpl.getSiteEnrollments(String)

When this function adds an EnrollmentRecordImpl object to the list to be returned, it constructs it using Course, regardless of if CourseSection is more appropriate.  I have thought of two ways of tackling this.  The first can be rather expensive in very large courses with many sections and the second I'm not entirely sure will get all of the appropriate users.

First:

Here, I get the sections associated with this site context and for each user check if they are a student in one of those sections.  If they are, then the EnrollmentRecord is created using CourseSection and Course if they are not.  I do not like this method because for course sites with many students and a large set of sections this can mean a lot of looping.  We have sites with 1000+ students and 50+ sections.

       private List getSiteEnrollments(String siteContext) {
        Course course = getCourse(siteContext);
        if(course == null) {
              log.error("Could not find course site " + siteContext);
              return new ArrayList();
        }

              List sections = getSections(siteContext);

        List sakaiMembers = securityService.unlockUsers(SectionAwareness.STUDENT_MARKER, course.getUuid());
        if(log.isDebugEnabled()) log.debug("Site students size = " + sakaiMembers.size());
        List<EnrollmentRecordImpl> membersList = new ArrayList<EnrollmentRecordImpl>();
        for(Iterator iter = sakaiMembers.iterator(); iter.hasNext();) {
              org.sakaiproject.user.api.User sakaiUser = (org.sakaiproject.user.api.User)iter.next();
              User user = SakaiUtil.convertUser(sakaiUser);
              if (user != null) {

                     boolean userNotInSection = true; // for when the user is not found in a section or there are no sections

                     for(Object section : sections) {
                           if (isUserInRole(user.getUserUid(), Role.STUDENT, ((CourseSection) section).getUuid())) {
                                  userNotInSection = false;
                                  EnrollmentRecordImpl record = new EnrollmentRecordImpl((CourseSection) section, null, user);
                                  membersList.add(record);
                                  break;
                           }
                     }

                     if (userNotInSection) {
                                 EnrollmentRecordImpl record = new EnrollmentRecordImpl(course, null, user);
                                 membersList.add(record);
                     }

              }
        }
        return membersList;
       }


Second:

Here, I replaced securityService.unlockUsers() with other get member functions from within SectionAwareness and it is that part that I am unsure about.  I understand the difference between unlockUsers and getSectionMembersInRole/getUnassignedMembersInRole but would unlockUsers get any different a list than the combination of the other two?  Using the combination allows me to get enrollment records that are from the CM service and have sections as the proper learning context (CourseSection) and anyone not managed by the CM service (e.g. manually added students) should, in theory, be retrieved by getUnassignedMembersInRole.

       private List getSiteEnrollments(String siteContext) {
        Course course = getCourse(siteContext);
        if(course == null) {
              log.error("Could not find course site " + siteContext);
              return new ArrayList();
        }

        List<EnrollmentRecordImpl> membersList = new ArrayList<EnrollmentRecordImpl>();

        // get the list of sections and then for each section get the student enrollments
              List sections = getSections(siteContext);
              for(Object section : sections) {
                     membersList.addAll(getSectionMembersInRole(((CourseSection)section).getUuid(), Role.STUDENT));
              }
              // add any other students that may not be managed by CM service
              membersList.addAll(getUnassignedMembersInRole(siteContext, Role.STUDENT));

              if(log.isDebugEnabled()) log.debug("Site students size = " + membersList.size());

        return membersList;
       }


I know for certain that method 1 works as I have been able to test it, however I only know that method 2 compiles with the rest of gb as I have not yet had a chance to test it in action.

-Chris


From: Gross,Christopher
Sent: Friday, August 17, 2012 11:53 AM
To: 'sakai-dev at collab.sakaiproject.org'
Subject: coursemanagement service and Course vs CourseSection objects

Hello!

I have touched on this in the past but only get a chance to look at this every few months, which I am back on it.  We use the course management API extensively and at the same time have modified gradebook slightly so that exports include a few extra columns, one of them being the section information passed in by the CM API.  The problem I am encountering is that when I attempt to get the CourseSection object, using EnrollmentRecord.getLearningContext() the object being returned is of type Course and not CourseSection.  I need CourseSection objects to get the proper title.  I cannot determine if this is a problem in the code I am using or in how we are forming our XML for the CM API imports.  I pulled the method for doing this from the sample-course-grade-converter module located in the gradebook tool - ~line 112 of CourseGradesToSpreadsheetConverterSample.java.  An example of what our CM XML looks like is attached.

--
Chris Gross
University of Florida


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20120905/ef015a34/attachment.html 


More information about the sakai-dev mailing list