001: /**********************************************************************************
002: *
003: * $Id: StandaloneSectionsDataLoader.java 18134 2006-11-14 18:59:25Z jholtzman@berkeley.edu $
004: *
005: ***********************************************************************************
006: *
007: * Copyright (c) 2005 The Regents of the University of California, The Regents of the University of Michigan,
008: * Board of Trustees of the Leland Stanford, Jr., University, and The MIT Corporation
009: *
010: * Licensed under the Educational Community License, Version 1.0 (the "License");
011: * you may not use this file except in compliance with the License.
012: * You may obtain a copy of the License at
013: *
014: * http://www.opensource.org/licenses/ecl1.php
015: *
016: * Unless required by applicable law or agreed to in writing, software
017: * distributed under the License is distributed on an "AS IS" BASIS,
018: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019: * See the License for the specific language governing permissions and
020: * limitations under the License.
021: *
022: **********************************************************************************/package org.sakaiproject.tool.gradebook.test;
023:
024: import java.util.*;
025:
026: import org.apache.commons.logging.Log;
027: import org.apache.commons.logging.LogFactory;
028:
029: import org.sakaiproject.section.api.coursemanagement.Course;
030: import org.sakaiproject.section.api.coursemanagement.CourseSection;
031: import org.sakaiproject.section.api.coursemanagement.User;
032: import org.sakaiproject.section.api.coursemanagement.EnrollmentRecord;
033: import org.sakaiproject.section.api.facade.Role;
034:
035: public class StandaloneSectionsDataLoader extends GradebookTestBase {
036: private static Log log = LogFactory
037: .getLog(StandaloneSectionsDataLoader.class);
038:
039: public static final String[] SITE_UIDS = { "QA_1", "QA_2", "QA_3",
040: "QA_4", "QA_5", "QA_6", "QA_7", "QA_8", };
041: public static final String[] SITE_NAMES = {
042: "QA Site #1 [no students, 1 instructor, no self reg, no self switch, external]",
043: "QA Site #2 [10 students, 1 instructor, no self reg, no self switch, internal]",
044: "QA Site #3 [10 students, 2 instructors, no self reg, no self switch, internal]",
045: "QA Site #4 [10 students, 1 instructor, no self reg, no self switch, internal]",
046: "QA Site #5 [50 students, 1 instructor, no self reg, no self switch, internal]",
047: "QA Site #6 [50 students, 1 instructor, no self reg, no self switch, internal]",
048: "QA Site #7 [150 students, 1 instructor, no self reg, no self switch, internal]",
049: "QA Site #8 [400 students, 1 instructor, no self reg, no self switch, internal]", };
050: public static boolean[] SITE_SELF_REG = { false, false, false,
051: false, false, false, false, false, };
052: public static boolean[] SITE_SELF_SWITCH = { false, false, false,
053: false, false, false, false, false, };
054: public static boolean[] SITE_EXTERNALLY_MANAGED = { true, false,
055: false, false, false, false, false, false, };
056:
057: /** Special users */
058: public final static String AUTHID_TEACHER_ALL = "authid_teacher";
059: public final static String AUTHID_TEACHER_AND_STUDENT = "authid_teacher_student";
060: public final static String AUTHID_STUDENT_ALL = "stu_0";
061: public final static String AUTHID_NO_SITE = "authid_nowhere";
062: public final static String AUTHID_STUDENT_PREFIX = "stu_";
063: public static final String AUTHID_WITHOUT_GRADES_1 = "stu_16";
064: public static final String AUTHID_WITHOUT_GRADES_2 = "stu_17";
065: public static final String AUTHID_TA = "authid_ta";
066:
067: /** Special sites */
068: public static int SITE_AMBIGUOUS_TEACHER = 2;
069: public static int SITE_AMBIGUOUS_STUDENT = 5;
070: public static int SITE_LOADED_UP = 5;
071:
072: public StandaloneSectionsDataLoader() {
073: // Don't roll these tests back, since they are intended to load data
074: setDefaultRollback(false);
075: }
076:
077: public void testLoadData() {
078: // Load courses. (No sections yet!)
079: List sites = new ArrayList(SITE_UIDS.length);
080: for (int i = 0; i < SITE_UIDS.length; i++) {
081: Course courseSite = integrationSupport.createCourse(
082: SITE_UIDS[i], SITE_NAMES[i],
083: SITE_EXTERNALLY_MANAGED[i], SITE_SELF_REG[i],
084: SITE_SELF_SWITCH[i]);
085: sites.add(courseSite);
086: }
087:
088: // Load users.
089: User teacherAll = userManager.createUser(AUTHID_TEACHER_ALL,
090: "Bizzy Teacher", "Teacher, Bizzy", "uTeacher");
091: User teacherStudent = userManager.createUser(
092: AUTHID_TEACHER_AND_STUDENT, "Teaching Student",
093: "Student, Teaching", "uTeSt");
094: List students = new ArrayList(400);
095:
096: for (int i = 0; i < 400; i++) {
097: String firstName;
098: String lastName;
099: switch (i) {
100: case 0:
101: firstName = "Abby Lynn";
102: lastName = "Astudent";
103: break;
104: case 1:
105: firstName = "Mary";
106: lastName = "LongLastNameThatExceedsTheMaximumInTheGradebook";
107: break;
108: case 3:
109: firstName = "Susan";
110: lastName = "Smith-Morris";
111: break;
112: case 4:
113: firstName = "Nathan Q., Jr.";
114: lastName = "Brewster";
115: break;
116: case 5:
117: firstName = "Carol Lee";
118: lastName = "Williams";
119: break;
120: case 6:
121: firstName = "Kim";
122: lastName = "Jones Parker";
123: break;
124: case 7:
125: firstName = "Joe";
126: lastName = "Brown";
127: break;
128: case 8:
129: firstName = "Joe";
130: lastName = "Brown";
131: break;
132: case 9:
133: firstName = "Sarah Jane";
134: lastName = "Miller";
135: break;
136: case 10:
137: firstName = "Rachel";
138: lastName = "Wilson";
139: break;
140: case 11:
141: firstName = "Ali";
142: lastName = "Moore";
143: break;
144: case 12:
145: firstName = "Chen-Wai";
146: lastName = "Taylor";
147: break;
148: case 13:
149: firstName = "Samuel Taylor Coleridge";
150: lastName = "Ascot";
151: break;
152: case 14:
153: firstName = "Jane Quincy";
154: lastName = "Brandenburg";
155: break;
156: case 15:
157: firstName = "Thor";
158: lastName = "Mj\u00F8lner";
159: break;
160: case 16:
161: firstName = "Lazy";
162: lastName = "Etudient1";
163: break;
164: case 17:
165: firstName = "Lazy";
166: lastName = "Etudient2";
167: break;
168: default:
169: firstName = "First Middle";
170: lastName = "LastName" + i;
171: }
172: String uidPrefix = (i != 3) ? "uid_" : "uID_";
173: students.add(userManager.createUser(AUTHID_STUDENT_PREFIX
174: + i, firstName + " " + lastName, lastName + ", "
175: + firstName, uidPrefix + i));
176: }
177: userManager.createUser(AUTHID_NO_SITE, "Johnny Nobody",
178: "Nobody, Johnny", AUTHID_NO_SITE);
179:
180: // Load enrollments into the courses.
181: for (int i = 0; i < students.size(); i++) {
182: // Everyone is added to Site 8.
183: integrationSupport.addSiteMembership(((User) students
184: .get(i)).getUserUid(), SITE_UIDS[7], Role.STUDENT);
185:
186: // The first 150 students are added to Site 7.
187: if (i < 150) {
188: integrationSupport.addSiteMembership(((User) students
189: .get(i)).getUserUid(), SITE_UIDS[6],
190: Role.STUDENT);
191:
192: // The first 50 students are added to Site 5 and 6, but 6 contains a special student....
193: if (i < 50) {
194: integrationSupport.addSiteMembership(
195: ((User) students.get(i)).getUserUid(),
196: SITE_UIDS[4], Role.STUDENT);
197: if (i < 49) {
198: integrationSupport.addSiteMembership(
199: ((User) students.get(i)).getUserUid(),
200: SITE_UIDS[5], Role.STUDENT);
201:
202: // The first 10 students are added to Site 2, 3, and 4.
203: if (i < 10) {
204: integrationSupport.addSiteMembership(
205: ((User) students.get(i))
206: .getUserUid(),
207: SITE_UIDS[3], Role.STUDENT);
208: integrationSupport.addSiteMembership(
209: ((User) students.get(i))
210: .getUserUid(),
211: SITE_UIDS[2], Role.STUDENT);
212: integrationSupport.addSiteMembership(
213: ((User) students.get(i))
214: .getUserUid(),
215: SITE_UIDS[1], Role.STUDENT);
216: }
217: }
218: }
219: }
220: }
221:
222: // Load instructors into the courses.
223: for (int i = 0; i < SITE_UIDS.length; i++) {
224: integrationSupport.addSiteMembership(teacherAll
225: .getUserUid(), SITE_UIDS[i], Role.INSTRUCTOR);
226: }
227:
228: // Load the ambiguous one.
229: integrationSupport.addSiteMembership(teacherStudent
230: .getUserUid(), SITE_UIDS[SITE_AMBIGUOUS_TEACHER],
231: Role.INSTRUCTOR);
232: integrationSupport.addSiteMembership(teacherStudent
233: .getUserUid(), SITE_UIDS[SITE_AMBIGUOUS_STUDENT],
234: Role.STUDENT);
235:
236: // Define and load sections for the assignment-loaded site.
237: String loadedSiteUid = ((Course) sites.get(SITE_LOADED_UP))
238: .getUuid();
239: List sectionCategories = sectionAwareness
240: .getSectionCategories(loadedSiteUid);
241:
242: // We'd better have more than one category for this to work....
243: String catId = (String) sectionCategories.get(1);
244: String catName = sectionAwareness.getCategoryName(catId,
245: Locale.US);
246: List catASectionUuids = new ArrayList();
247: for (int i = 0; i < 4; i++) {
248: String sectionName;
249: if (i != 2) {
250: sectionName = catName + " " + (i + 1);
251: } else {
252: sectionName = "Abe's " + catName;
253: }
254: CourseSection section = integrationSupport.createSection(
255: loadedSiteUid, sectionName, catId, new Integer(40),
256: "Room 2" + i, null, null, true, false, true, false,
257: false, false, false);
258: catASectionUuids.add(section.getUuid());
259: }
260: catId = (String) sectionCategories.get(0);
261: catName = sectionAwareness.getCategoryName(catId, Locale.US);
262: List catBSectionUuids = new ArrayList();
263: for (int i = 0; i < 2; i++) {
264: String sectionName = catName + " " + (i + 1);
265: CourseSection section = integrationSupport.createSection(
266: loadedSiteUid, sectionName, catId, new Integer(40),
267: "Room 3" + i, null, null, true, false, true, false,
268: false, false, false);
269: catBSectionUuids.add(section.getUuid());
270: }
271:
272: // Populate the sections. Not all students will end up in a Category A section.
273: List enrollments = sectionAwareness.getSiteMembersInRole(
274: SITE_UIDS[SITE_LOADED_UP], Role.STUDENT);
275: for (int i = 0; i < enrollments.size(); i++) {
276: String userUid = ((EnrollmentRecord) enrollments.get(i))
277: .getUser().getUserUid();
278: String sectionUuid = (String) catBSectionUuids.get(i
279: % catBSectionUuids.size());
280: integrationSupport.addSectionMembership(userUid,
281: sectionUuid, Role.STUDENT);
282: if (i < (enrollments.size() - 5)) {
283: sectionUuid = (String) catASectionUuids.get(i
284: % catASectionUuids.size());
285: integrationSupport.addSectionMembership(userUid,
286: sectionUuid, Role.STUDENT);
287: }
288: }
289:
290: // Add a TA to the site and two sections.
291: userManager.createUser(AUTHID_TA, "Teech N. Assist",
292: "Assist, Teech N.", "uTA");
293: integrationSupport.addSiteMembership(AUTHID_TA,
294: SITE_UIDS[SITE_LOADED_UP], Role.TA);
295: integrationSupport.addSectionMembership(AUTHID_TA,
296: (String) catASectionUuids.get(2), Role.TA);
297: integrationSupport.addSectionMembership(AUTHID_TA,
298: (String) catBSectionUuids.get(1), Role.TA);
299: }
300: }
301:
302: /**********************************************************************************
303: * $Id: StandaloneSectionsDataLoader.java 18134 2006-11-14 18:59:25Z jholtzman@berkeley.edu $
304: *********************************************************************************/
|