001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sections/tags/sakai_2-4-1/sections-impl/sakai/impl/src/java/org/sakaiproject/component/section/sakai/CourseManagerImpl.java $
003: * $Id: CourseManagerImpl.java 18134 2006-11-14 18:59:25Z jholtzman@berkeley.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Regents of the University of California and The Regents of the University of Michigan
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.component.section.sakai;
021:
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024: import org.sakaiproject.section.api.CourseManager;
025: import org.sakaiproject.section.api.coursemanagement.Course;
026: import org.sakaiproject.section.api.coursemanagement.ParticipationRecord;
027: import org.sakaiproject.section.api.coursemanagement.User;
028: import org.sakaiproject.exception.IdUnusedException;
029: import org.sakaiproject.exception.PermissionException;
030: import org.sakaiproject.site.api.Site;
031: import org.sakaiproject.site.cover.SiteService;
032:
033: /**
034: * Sakai implementation of CourseManager. Uses Sakai Sites API to store
035: * all course metadata needed by the Section Info tool.
036: *
037: * @author <a href="mailto:jholtzman@berkeley.edu">Josh Holtzman</a>
038: *
039: */
040: public class CourseManagerImpl implements CourseManager {
041:
042: private static final Log log = LogFactory
043: .getLog(CourseManagerImpl.class);
044:
045: /**
046: * @inheritDoc
047: */
048: public Course createCourse(final String siteContext,
049: final String title, final boolean selfRegAllowed,
050: final boolean selfSwitchingAllowed,
051: final boolean externallyManaged) {
052:
053: log
054: .warn("There should be no need to call "
055: + "org.sakaiproject.section.api.CourseManager.createCourse() in "
056: + "sakai . This should only be called by a customized section "
057: + "data loader.");
058:
059: Site site;
060: try {
061: site = SiteService.getSite(siteContext);
062: } catch (IdUnusedException e) {
063: log.error("Not site with id = " + siteContext);
064: return null;
065: }
066: CourseImpl course = new CourseImpl(site);
067:
068: // Update the course with the new booleans passed to this method
069: course.setSelfRegistrationAllowed(selfRegAllowed);
070: course.setSelfSwitchingAllowed(selfSwitchingAllowed);
071: course.setExternallyManaged(externallyManaged);
072: course.decorateSite(site);
073:
074: // Save the modified site
075: try {
076: SiteService.save(site);
077: } catch (IdUnusedException e) {
078: log.error("Not site with id = " + siteContext);
079: return null;
080: } catch (PermissionException e) {
081: log.error("Not allowed to save site with id = "
082: + siteContext);
083: return null;
084: }
085: return course;
086: }
087:
088: /**
089: * The Sakai implementation uses the SiteService API, so if the site exists
090: * then the "Course" exists.
091: */
092: public boolean courseExists(final String siteContext) {
093: try {
094: SiteService.getSite(siteContext);
095: return true;
096: } catch (IdUnusedException e) {
097: return false;
098: }
099: }
100:
101: /**
102: * This is handled by the Site and AuthzGroup Services in Sakai. No need to
103: * do anything here.
104: */
105: public void removeOrphans(final String siteContext) {
106: }
107:
108: /**
109: * Not supported in sakai
110: */
111: public ParticipationRecord addInstructor(final User user,
112: final Course course) {
113: throw new RuntimeException("Operation not supported in sakai");
114: }
115:
116: /**
117: * Not supported in sakai
118: */
119: public ParticipationRecord addEnrollment(final User user,
120: final Course course) {
121: throw new RuntimeException("Operation not supported in sakai");
122: }
123:
124: /**
125: * Not supported in sakai
126: */
127: public ParticipationRecord addTA(final User user,
128: final Course course) {
129: throw new RuntimeException("Operation not supported in sakai");
130: }
131:
132: /**
133: * Not supported in sakai
134: */
135: public void removeCourseMembership(String userUid, Course course) {
136: throw new RuntimeException("Operation not supported in sakai");
137: }
138:
139: }
|