001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sections/tags/sakai_2-4-1/sections-impl/standalone/src/java/org/sakaiproject/component/section/CourseSectionImpl.java $
003: * $Id: CourseSectionImpl.java 21967 2007-02-27 19:51:10Z 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;
021:
022: import java.io.Serializable;
023: import java.sql.Time;
024: import java.util.ArrayList;
025: import java.util.List;
026:
027: import org.sakaiproject.section.api.coursemanagement.Course;
028: import org.sakaiproject.section.api.coursemanagement.CourseSection;
029:
030: /**
031: * A detachable CourseSection for persistent storage.
032: *
033: * @author <a href="mailto:jholtzman@berkeley.edu">Josh Holtzman</a>
034: *
035: */
036: public class CourseSectionImpl extends LearningContextImpl implements
037: CourseSection, Comparable, Serializable {
038:
039: private static final long serialVersionUID = 1L;
040:
041: protected Course course;
042: protected String category;
043: protected Integer maxEnrollments;
044:
045: protected List meetings;
046:
047: /** Default constructor needed by hibernate */
048: public CourseSectionImpl() {
049: }
050:
051: /** Converts an arbitrary CourseSection into an instance of this class */
052: public CourseSectionImpl(CourseSection section) {
053: this .course = section.getCourse();
054: this .category = section.getCategory();
055: this .maxEnrollments = section.getMaxEnrollments();
056: this .meetings = section.getMeetings();
057: this .title = section.getTitle();
058: this .uuid = section.getUuid();
059: }
060:
061: /**
062: * Convenience constructor to create a CourseSection with a single meeting.
063: *
064: * @param course
065: * @param title
066: * @param uuid
067: * @param category
068: * @param maxEnrollments
069: * @param location
070: * @param startTime
071: * @param endTime
072: * @param monday
073: * @param tuesday
074: * @param wednesday
075: * @param thursday
076: * @param friday
077: * @param saturday
078: * @param sunday
079: */
080: public CourseSectionImpl(Course course, String title, String uuid,
081: String category, Integer maxEnrollments, String location,
082: Time startTime, Time endTime, boolean monday,
083: boolean tuesday, boolean wednesday, boolean thursday,
084: boolean friday, boolean saturday, boolean sunday) {
085:
086: this .course = course;
087: this .title = title;
088: this .uuid = uuid;
089: this .category = category;
090: this .maxEnrollments = maxEnrollments;
091: this .meetings = new ArrayList();
092: MeetingImpl meeting = new MeetingImpl(location, startTime,
093: endTime, monday, tuesday, wednesday, thursday, friday,
094: saturday, sunday);
095: meetings.add(meeting);
096: }
097:
098: public CourseSectionImpl(Course course, String title, String uuid,
099: String category, Integer maxEnrollments, List meetings) {
100: this .course = course;
101: this .title = title;
102: this .uuid = uuid;
103: this .category = category;
104: this .maxEnrollments = maxEnrollments;
105: this .meetings = meetings;
106: }
107:
108: public String getCategory() {
109: return category;
110: }
111:
112: public void setCategory(String category) {
113: this .category = category;
114: }
115:
116: public Course getCourse() {
117: return course;
118: }
119:
120: public void setCourse(Course course) {
121: this .course = course;
122: }
123:
124: public Integer getMaxEnrollments() {
125: return maxEnrollments;
126: }
127:
128: public void setMaxEnrollments(Integer maxEnrollments) {
129: this .maxEnrollments = maxEnrollments;
130: }
131:
132: public List getMeetings() {
133: return meetings;
134: }
135:
136: public void setMeetings(List meetings) {
137: this .meetings = meetings;
138: }
139:
140: /**
141: * Compares CourseSectionImpls based on their category ID and title. Sections
142: * without a category are sorted last.
143: */
144: public int compareTo(Object o) {
145: if (o == this ) {
146: return 0;
147: }
148: if (o instanceof CourseSectionImpl) {
149: CourseSectionImpl other = (CourseSectionImpl) o;
150: if (this .category != null && other.category == null) {
151: return -1;
152: } else if (this .category == null && other.category != null) {
153: return 1;
154: }
155: if (this .category == null && other.category == null) {
156: return this .title.compareTo(other.title);
157: }
158: int categoryComparison = this .category
159: .compareTo(other.category);
160: if (categoryComparison == 0) {
161: return this .title.compareTo(other.title);
162: } else {
163: return categoryComparison;
164: }
165: } else {
166: throw new ClassCastException(
167: "Can not compare CourseSectionImpl to "
168: + o.getClass());
169: }
170:
171: }
172:
173: /**
174: * Standalone does not support the notion of enterprise-defined CourseSections.
175: */
176: public String getEid() {
177: return null;
178: }
179: }
|