001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sections/tags/sakai_2-4-1/sections-impl/sakai/model/src/java/org/sakaiproject/component/section/sakai/CourseImpl.java $
003: * $Id: CourseImpl.java 18493 2006-11-28 17:27:43Z 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 java.io.Serializable;
023:
024: import org.apache.commons.lang.builder.ToStringBuilder;
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027: import org.sakaiproject.section.api.coursemanagement.Course;
028: import org.sakaiproject.entity.api.ResourceProperties;
029: import org.sakaiproject.site.api.Site;
030:
031: public class CourseImpl implements Course, Serializable {
032: private static final Log log = LogFactory.getLog(CourseImpl.class);
033: private static final long serialVersionUID = 1L;
034:
035: public static final String EXTERNALLY_MAINTAINED = "sections_externally_maintained";
036: public static final String STUDENT_REGISTRATION_ALLOWED = "sections_student_registration_allowed";
037: public static final String STUDENT_SWITCHING_ALLOWED = "sections_student_switching_allowed";
038:
039: /**
040: * Creates a course from a sakai Site
041: *
042: * @param site The Sakai site
043: */
044: public CourseImpl(Site site) {
045: this .site = site;
046: this .uuid = site.getReference();
047: this .title = site.getTitle();
048: this .siteContext = site.getId();
049: this .externallyManaged = Boolean.valueOf(
050: site.getProperties().getProperty(
051: CourseImpl.EXTERNALLY_MAINTAINED))
052: .booleanValue();
053: this .selfRegistrationAllowed = Boolean.valueOf(
054: site.getProperties().getProperty(
055: CourseImpl.STUDENT_REGISTRATION_ALLOWED))
056: .booleanValue();
057: this .selfSwitchingAllowed = Boolean.valueOf(
058: site.getProperties().getProperty(
059: CourseImpl.STUDENT_SWITCHING_ALLOWED))
060: .booleanValue();
061: }
062:
063: protected String siteContext;
064: protected String uuid;
065: protected String title;
066: protected boolean externallyManaged;
067: protected boolean selfRegistrationAllowed;
068: protected boolean selfSwitchingAllowed;
069:
070: public void decorateSite(Site site) {
071: ResourceProperties props = site.getProperties();
072: if (log.isDebugEnabled())
073: log.debug("Decorating site " + site.getId()
074: + " with external = " + externallyManaged);
075: props.addProperty(CourseImpl.EXTERNALLY_MAINTAINED, Boolean
076: .toString(externallyManaged));
077: props.addProperty(CourseImpl.STUDENT_REGISTRATION_ALLOWED,
078: Boolean.toString(selfRegistrationAllowed));
079: props.addProperty(CourseImpl.STUDENT_SWITCHING_ALLOWED, Boolean
080: .toString(selfSwitchingAllowed));
081: }
082:
083: // Transient reference to the site being modeled
084: private transient Site site;
085:
086: public boolean isSelfSwitchingAllowed() {
087: return selfSwitchingAllowed;
088: }
089:
090: public void setSelfSwitchingAllowed(boolean selfSwitchingAllowed) {
091: this .selfSwitchingAllowed = selfSwitchingAllowed;
092: }
093:
094: public boolean isSelfRegistrationAllowed() {
095: return selfRegistrationAllowed;
096: }
097:
098: public void setSelfRegistrationAllowed(
099: boolean selfRegistrationAllowed) {
100: this .selfRegistrationAllowed = selfRegistrationAllowed;
101: }
102:
103: public String getSiteContext() {
104: return siteContext;
105: }
106:
107: public void setSiteContext(String siteContext) {
108: this .siteContext = siteContext;
109: }
110:
111: public boolean isExternallyManaged() {
112: return externallyManaged;
113: }
114:
115: public void setExternallyManaged(boolean externallyManaged) {
116: this .externallyManaged = externallyManaged;
117: }
118:
119: public String getTitle() {
120: return title;
121: }
122:
123: public void setTitle(String title) {
124: this .title = title;
125: }
126:
127: public String getUuid() {
128: return uuid;
129: }
130:
131: public void setUuid(String uuid) {
132: this .uuid = uuid;
133: }
134:
135: public String toString() {
136: return new ToStringBuilder(this ).append(title).append(
137: siteContext).append(uuid).toString();
138: }
139:
140: public Site getSite() {
141: return site;
142: }
143:
144: }
|