1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.enrollment.class2.courseoffering.service.impl;
17
18 import java.util.ArrayList;
19 import java.util.Date;
20 import java.util.HashMap;
21 import java.util.List;
22 import java.util.Map;
23
24 import javax.annotation.Resource;
25
26 import org.joda.time.DateTime;
27 import org.kuali.student.common.test.mock.data.AbstractMockServicesAwareDataLoader;
28 import org.kuali.student.common.test.spring.log4j.KSLog4JConfigurer;
29 import org.kuali.student.enrollment.class2.acal.util.AcalTestDataLoader;
30 import org.kuali.student.enrollment.class2.courseoffering.service.CourseOfferingCodeGenerator;
31 import org.kuali.student.enrollment.class2.courseoffering.service.transformer.RegistrationGroupCodeGeneratorFactory;
32 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingClusterInfo;
33 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
34 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingSetInfo;
35 import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
36 import org.kuali.student.enrollment.courseoffering.dto.FormatOfferingInfo;
37 import org.kuali.student.enrollment.courseoffering.dto.OfferingInstructorInfo;
38 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
39 import org.kuali.student.r2.common.assembler.AssemblyException;
40 import org.kuali.student.r2.common.dto.BulkStatusInfo;
41 import org.kuali.student.r2.common.dto.ContextInfo;
42 import org.kuali.student.r2.common.dto.DtoConstants;
43 import org.kuali.student.r2.common.dto.RichTextInfo;
44 import org.kuali.student.r2.common.exceptions.AlreadyExistsException;
45 import org.kuali.student.r2.common.exceptions.CircularRelationshipException;
46 import org.kuali.student.r2.common.exceptions.DataValidationErrorException;
47 import org.kuali.student.r2.common.exceptions.DependentObjectsExistException;
48 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
49 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
50 import org.kuali.student.r2.common.exceptions.MissingParameterException;
51 import org.kuali.student.r2.common.exceptions.OperationFailedException;
52 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
53 import org.kuali.student.r2.common.exceptions.ReadOnlyException;
54 import org.kuali.student.r2.common.exceptions.UnsupportedActionException;
55 import org.kuali.student.r2.common.exceptions.VersionMismatchException;
56 import org.kuali.student.r2.common.util.RichTextHelper;
57 import org.kuali.student.r2.common.util.constants.CourseOfferingServiceConstants;
58 import org.kuali.student.r2.common.util.constants.LuServiceConstants;
59 import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
60 import org.kuali.student.r2.common.util.date.DateFormatters;
61 import org.kuali.student.r2.core.acal.dto.TermInfo;
62 import org.kuali.student.r2.core.acal.service.AcademicCalendarService;
63 import org.kuali.student.r2.core.acal.service.TermCodeGenerator;
64 import org.kuali.student.r2.core.acal.service.assembler.TermAssembler;
65 import org.kuali.student.r2.core.acal.service.impl.TermCodeGeneratorImpl;
66 import org.kuali.student.r2.core.atp.dto.AtpInfo;
67 import org.kuali.student.r2.core.atp.service.AtpService;
68 import org.kuali.student.r2.core.constants.AtpServiceConstants;
69 import org.kuali.student.r2.lum.course.dto.ActivityInfo;
70 import org.kuali.student.r2.lum.course.dto.CourseInfo;
71 import org.kuali.student.r2.lum.course.dto.FormatInfo;
72 import org.kuali.student.r2.lum.course.service.CourseService;
73 import org.kuali.student.r2.lum.lrc.dto.ResultValuesGroupInfo;
74 import org.kuali.student.r2.lum.util.constants.LrcServiceConstants;
75 import org.slf4j.Logger;
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91 public class CourseOfferingServiceTestDataLoader extends AbstractMockServicesAwareDataLoader {
92
93 private static final Logger log = KSLog4JConfigurer.getLogger(CourseOfferingServiceTestDataLoader.class);
94
95 public static final String CHEM123_COURSE_ID = "CLU-1";
96
97 public static final String CHEM123_COURSE_OFFERING_ID = "CO-1";
98
99 public static final String CHEM123_LEC_AND_LAB_FORMAT_OFFERING_ID = "CO-1:LEC-AND-LAB";
100
101 public static final String ENG101_COURSE_ID = "CLU-2";
102
103 public static final String ENG101_COURSE_OFFERING_ID = "CO-2";
104
105 public static final String ENG101_LEC_ONLY_FORMAT_OFFERING_ID = "CO-2:LEC-ONLY";
106
107 public static final String FALL_2012_TERM_ID = "2012FA";
108
109 @Resource
110 protected AcademicCalendarService acalService;
111
112 @Resource
113 protected CourseOfferingService coService;
114
115 @Resource
116 protected CourseService courseService;
117
118 @Resource
119 protected AtpService atpService;
120
121 @Resource
122 protected CourseOfferingCodeGenerator courseCodeGenerator;
123
124 @Resource
125 protected RegistrationGroupCodeGeneratorFactory registrationGroupCodeGeneratorFactory;
126
127
128
129 protected AcalTestDataLoader acalDataLoader;
130
131 TermInfo fall2012 = null;
132 TermInfo spring2012 = null;
133
134 private boolean loadBaseData = true;
135
136
137
138
139 public CourseOfferingServiceTestDataLoader() {
140 super();
141 }
142
143
144
145
146
147
148
149 @Override
150 protected void initializeData() throws Exception {
151
152 this.acalDataLoader = new AcalTestDataLoader(atpService);
153
154 acalDataLoader.loadData();
155
156
157
158 if (!loadBaseData)
159 return;
160
161
162 fall2012 = createTerm(FALL_2012_TERM_ID, "Fall 2012", AtpServiceConstants.ATP_FALL_TYPE_KEY, new DateTime().withDate(2012, 9, 1).toDate(), new DateTime().withDate(2012, 12, 31).toDate(), context);
163
164 spring2012 = createTerm("2012SP", "Spring 2012", AtpServiceConstants.ATP_SPRING_TYPE_KEY, new DateTime().withDate(2012, 1, 1).toDate(), new DateTime().withDate(2012, 4, 30).toDate(), context);
165
166
167
168 createCourse(fall2012, "CHEM", "123", context);
169 createCourseCHEM123(fall2012, context);
170
171 createCourseENG101(spring2012, context);
172
173 }
174
175
176
177
178 public TermInfo createTerm(String id, String name, String atpTypeKey, Date startDate, Date endDate, ContextInfo context) throws OperationFailedException, DataValidationErrorException, InvalidParameterException, MissingParameterException, PermissionDeniedException, ReadOnlyException {
179
180 AtpInfo atpInfo = new AtpInfo();
181 atpInfo.setId(id);
182 atpInfo.setName(name);
183 atpInfo.setTypeKey(atpTypeKey);
184 atpInfo.setStateKey(AtpServiceConstants.ATP_OFFICIAL_STATE_KEY);
185 atpInfo.setStartDate(startDate);
186 atpInfo.setEndDate(endDate);
187 atpInfo.setDescr(new RichTextHelper().fromPlain(name));
188
189 try {
190 TermInfo term = new TermAssembler().assemble(atpInfo, context);
191 TermCodeGenerator tcg = new TermCodeGeneratorImpl();
192 atpInfo.setCode(tcg.generateTermCode(term));
193 } catch (AssemblyException e) {
194 throw new OperationFailedException("Assembly of TermInfo failed", e);
195 }
196
197 AtpInfo saved = atpService.createAtp(atpInfo.getTypeKey(), atpInfo, context);
198
199 TermInfo term = new TermInfo();
200
201 term.setId(saved.getId());
202 term.setAttributes(saved.getAttributes());
203 term.setCode(saved.getCode());
204 term.setStartDate(saved.getStartDate());
205 term.setEndDate(saved.getEndDate());
206 term.setMeta(saved.getMeta());
207 term.setDescr(saved.getDescr());
208 term.setStateKey(saved.getStateKey());
209 term.setTypeKey(saved.getTypeKey());
210
211 return term;
212 }
213
214
215 public void createCourseByTemplate(TermInfo term, String subjectCode, String courseNumberCode, ContextInfo context) throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException, DoesNotExistException, CircularRelationshipException, DependentObjectsExistException, UnsupportedActionException, DoesNotExistException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException {
216
217 String courseCode = subjectCode + courseNumberCode;
218 String courseId = courseCode + "-ID";
219
220 CourseInfo canonicalCourse = buildCanonicalCourse(courseId, term.getId(), subjectCode, courseCode, subjectCode + " " + courseCode, courseCode + " description 1");
221
222 FormatInfo canonicalLectureOnlyFormat = buildCanonicalFormat(courseCode + ":LEC-ONLY", canonicalCourse);
223
224 ActivityInfo canonicalLectureOnlyLectureActivity = buildCanonicalActivity(LuServiceConstants.COURSE_ACTIVITY_LECTURE_TYPE_KEY, canonicalLectureOnlyFormat);
225
226 FormatInfo canonicalLectureAndLabFormat = buildCanonicalFormat(courseCode + ":LEC-AND-LAB", canonicalCourse);
227
228 ActivityInfo canonicalLectureAndLabFormatLectureActivity = buildCanonicalActivity(LuServiceConstants.COURSE_ACTIVITY_LECTURE_TYPE_KEY, canonicalLectureAndLabFormat);
229 ActivityInfo canonicalLectureAndLabFormatLabActivity = buildCanonicalActivity(LuServiceConstants.COURSE_ACTIVITY_LAB_TYPE_KEY, canonicalLectureAndLabFormat);
230
231 courseService.createCourse(canonicalCourse, context);
232
233
234
235 CourseOfferingInfo courseOffering = CourseOfferingServiceTestDataUtils.createCourseOffering(canonicalCourse, term.getId());
236
237 courseOffering.setId(courseId);
238
239 coService.createCourseOffering(canonicalCourse.getId(), term.getId(), LuiServiceConstants.COURSE_OFFERING_TYPE_KEY, courseOffering, new ArrayList<String>(), context);
240
241
242 FormatOfferingInfo lectureOnlyFormatOffering = CourseOfferingServiceTestDataUtils.createFormatOffering(courseOffering.getId(), canonicalLectureOnlyFormat.getId(), term.getId(), "Lecture", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY);
243
244 lectureOnlyFormatOffering.setId(courseId + ":LEC-ONLY");
245
246 coService.createFormatOffering(courseOffering.getId(), canonicalLectureOnlyFormat.getId(), LuiServiceConstants.FORMAT_OFFERING_TYPE_KEY, lectureOnlyFormatOffering, context);
247
248
249 FormatOfferingInfo lectureAndLabFormatOffering = CourseOfferingServiceTestDataUtils.createFormatOffering(courseOffering.getId(), canonicalLectureAndLabFormat.getId(), term.getId(), "Lab & Lecture", new String[]{LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY});
250
251 lectureAndLabFormatOffering.setId(courseId + ":LEC-AND-LAB");
252
253 coService.createFormatOffering(courseOffering.getId(), canonicalLectureAndLabFormat.getId(), LuiServiceConstants.FORMAT_OFFERING_TYPE_KEY, lectureAndLabFormatOffering, context);
254
255 List<OfferingInstructorInfo> instructors = new ArrayList<OfferingInstructorInfo>();
256
257 instructors.add(CourseOfferingServiceTestDataUtils.createInstructor("p1", "Instructor", 100.00F));
258
259
260
261 ActivityOfferingInfo lectureOnlyFormatLectureA = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureOnlyFormatOffering.getId(), null, canonicalLectureOnlyLectureActivity.getId(), "Lecture A", "A", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, instructors);
262
263 lectureOnlyFormatLectureA.setId(courseId + ":LEC-ONLY:LEC-A");
264
265 coService.createActivityOffering(lectureOnlyFormatOffering.getId(), canonicalLectureOnlyLectureActivity.getId(), LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, lectureOnlyFormatLectureA, context);
266
267
268 ActivityOfferingInfo lectureOnlyFormatLectureB = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureOnlyFormatOffering.getId(), null, canonicalLectureOnlyLectureActivity.getId(), "Lecture B", "B", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, instructors);
269
270 lectureOnlyFormatLectureB.setId(courseId + ":LEC-ONLY:LEC-B");
271
272 coService.createActivityOffering(lectureOnlyFormatOffering.getId(), canonicalLectureOnlyLectureActivity.getId(), LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, lectureOnlyFormatLectureB, context);
273
274
275
276
277 ActivityOfferingInfo lectureAndLabFormatLectureA = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureAndLabFormatOffering.getId(), null, canonicalLectureAndLabFormatLectureActivity.getId(), "Lecture A", "C", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, instructors);
278
279 lectureAndLabFormatLectureA.setId(courseId + ":LEC-AND-LAB:LEC-A");
280
281 coService.createActivityOffering(lectureAndLabFormatOffering.getId(), canonicalLectureAndLabFormatLectureActivity.getId(), LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, lectureAndLabFormatLectureA, context);
282
283
284 ActivityOfferingInfo lectureAndLabFormatLectureB = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureAndLabFormatOffering.getId(), null, canonicalLectureAndLabFormatLectureActivity.getId(), "Lecture B", "D", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, instructors);
285
286 lectureAndLabFormatLectureB.setId(courseId + ":LEC-AND-LAB:LEC-B");
287
288 coService.createActivityOffering(lectureAndLabFormatOffering.getId(), canonicalLectureAndLabFormatLectureActivity.getId(), LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, lectureAndLabFormatLectureB, context);
289
290
291
292 ActivityOfferingInfo lectureAndLabFormatLabA = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureAndLabFormatOffering.getId(), null, canonicalLectureAndLabFormatLabActivity.getId(), "Lab A", "E", LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, instructors);
293
294 lectureAndLabFormatLabA.setId(courseId + ":LEC-AND-LAB:LAB-A");
295
296 coService.createActivityOffering(lectureAndLabFormatOffering.getId(), canonicalLectureAndLabFormatLabActivity.getId(), LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, lectureAndLabFormatLabA, context);
297
298
299
300 ActivityOfferingInfo lectureAndLabFormatLabB = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureAndLabFormatOffering.getId(), null, canonicalLectureAndLabFormatLabActivity.getId(), "Lab B", "F", LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, instructors);
301
302 lectureAndLabFormatLabB.setId(courseId + ":LEC-AND-LAB:LAB-B");
303
304 coService.createActivityOffering(lectureAndLabFormatOffering.getId(), canonicalLectureAndLabFormatLabActivity.getId(), LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, lectureAndLabFormatLabB, context);
305
306
307
308
309 ActivityOfferingInfo lectureAndLabFormatLabC = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureAndLabFormatOffering.getId(), null, canonicalLectureAndLabFormatLabActivity.getId(), "Lab C", "G", LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, instructors);
310
311 lectureAndLabFormatLabC.setId(courseId + ":LEC-AND-LAB:LAB-C");
312
313 coService.createActivityOffering(lectureAndLabFormatOffering.getId(), canonicalLectureAndLabFormatLabActivity.getId(), LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, lectureAndLabFormatLabC, context);
314
315
316 }
317
318 public String createCourse(TermInfo term, String subjectCode, String courseNumberCode, ContextInfo context) throws AlreadyExistsException, VersionMismatchException, CircularRelationshipException, DependentObjectsExistException, UnsupportedActionException, DoesNotExistException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException {
319
320 String courseCode = subjectCode + courseNumberCode;
321 String courseId = courseCode + "-ID";
322
323 CourseInfo canonicalCourse = buildCanonicalCourse(courseId, term.getId(), subjectCode, courseCode, subjectCode + " " + courseCode, courseCode + " description 1");
324 courseService.createCourse(canonicalCourse, context);
325
326 return courseId;
327 }
328
329 public void createCourseOffering(TermInfo term, CourseInfo canonicalCourse, ContextInfo context) throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException, DoesNotExistException, CircularRelationshipException, DependentObjectsExistException, UnsupportedActionException, DoesNotExistException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException {
330
331 CourseOfferingInfo courseOffering = CourseOfferingServiceTestDataUtils.createCourseOffering(canonicalCourse, term.getId());
332
333 courseOffering.setId("CO:" + canonicalCourse.getId());
334
335 coService.createCourseOffering(canonicalCourse.getId(), term.getId(), LuiServiceConstants.COURSE_OFFERING_TYPE_KEY, courseOffering, new ArrayList<String>(), context);
336
337
338 }
339
340 protected void createCourseCHEM123(TermInfo term, ContextInfo context) throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException, DoesNotExistException, CircularRelationshipException, DependentObjectsExistException, UnsupportedActionException, DoesNotExistException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException {
341
342 CourseInfo canonicalCourse = buildCanonicalCourse("CLU-1", term.getId(), "CHEM", "CHEM123", "Chemistry 123", "description 1");
343
344 FormatInfo canonicalLectureOnlyFormat = buildCanonicalFormat("CHEM123:LEC-ONLY", canonicalCourse);
345
346 ActivityInfo canonicalLectureOnlyLectureActivity = buildCanonicalActivity(LuServiceConstants.COURSE_ACTIVITY_LECTURE_TYPE_KEY, canonicalLectureOnlyFormat);
347
348 FormatInfo canonicalLectureAndLabFormat = buildCanonicalFormat("CHEM123:LEC-AND-LAB", canonicalCourse);
349
350 ActivityInfo canonicalLectureAndLabFormatLectureActivity = buildCanonicalActivity(LuServiceConstants.COURSE_ACTIVITY_LECTURE_TYPE_KEY, canonicalLectureAndLabFormat);
351 ActivityInfo canonicalLectureAndLabFormatLabActivity = buildCanonicalActivity(LuServiceConstants.COURSE_ACTIVITY_LAB_TYPE_KEY, canonicalLectureAndLabFormat);
352
353 courseService.createCourse(canonicalCourse, context);
354
355
356
357 CourseOfferingInfo courseOffering = CourseOfferingServiceTestDataUtils.createCourseOffering(canonicalCourse, term.getId());
358
359 courseOffering.setId("CO-1");
360
361 coService.createCourseOffering(canonicalCourse.getId(), term.getId(), LuiServiceConstants.COURSE_OFFERING_TYPE_KEY, courseOffering, new ArrayList<String>(), context);
362
363
364 FormatOfferingInfo lectureOnlyFormatOffering = CourseOfferingServiceTestDataUtils.createFormatOffering(courseOffering.getId(), canonicalLectureOnlyFormat.getId(), term.getId(), "Lecture", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY);
365
366 lectureOnlyFormatOffering.setId("CO-1:LEC-ONLY");
367
368 coService.createFormatOffering(courseOffering.getId(), canonicalLectureOnlyFormat.getId(), LuiServiceConstants.FORMAT_OFFERING_TYPE_KEY, lectureOnlyFormatOffering, context);
369
370
371 FormatOfferingInfo lectureAndLabFormatOffering = CourseOfferingServiceTestDataUtils.createFormatOffering(courseOffering.getId(), canonicalLectureAndLabFormat.getId(), term.getId(), "Lab & Lecture", new String[]{LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY});
372
373 lectureAndLabFormatOffering.setId("CO-1:LEC-AND-LAB");
374
375 coService.createFormatOffering(courseOffering.getId(), canonicalLectureAndLabFormat.getId(), LuiServiceConstants.FORMAT_OFFERING_TYPE_KEY, lectureAndLabFormatOffering, context);
376
377 List<OfferingInstructorInfo> instructors = new ArrayList<OfferingInstructorInfo>();
378
379 instructors.add(CourseOfferingServiceTestDataUtils.createInstructor("p1", "Instructor", 100.00F));
380
381
382
383 ActivityOfferingInfo lectureOnlyFormatLectureA = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureOnlyFormatOffering.getId(), null, canonicalLectureOnlyLectureActivity.getId(), "Lecture A", "A", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, instructors);
384
385 lectureOnlyFormatLectureA.setId("CO-1:LEC-ONLY:LEC-A");
386
387 coService.createActivityOffering(lectureOnlyFormatOffering.getId(), canonicalLectureOnlyLectureActivity.getId(), LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, lectureOnlyFormatLectureA, context);
388
389
390 ActivityOfferingInfo lectureOnlyFormatLectureB = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureOnlyFormatOffering.getId(), null, canonicalLectureOnlyLectureActivity.getId(), "Lecture B", "B", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, instructors);
391
392 lectureOnlyFormatLectureB.setId("CO-1:LEC-ONLY:LEC-B");
393
394 coService.createActivityOffering(lectureOnlyFormatOffering.getId(), canonicalLectureOnlyLectureActivity.getId(), LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, lectureOnlyFormatLectureB, context);
395
396
397
398
399 ActivityOfferingInfo lectureAndLabFormatLectureA = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureAndLabFormatOffering.getId(), null, canonicalLectureAndLabFormatLectureActivity.getId(), "Lecture A", "C", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, instructors);
400
401 lectureAndLabFormatLectureA.setId("CO-1:LEC-AND-LAB:LEC-A");
402
403 coService.createActivityOffering(lectureAndLabFormatOffering.getId(), canonicalLectureAndLabFormatLectureActivity.getId(), LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, lectureAndLabFormatLectureA, context);
404
405
406 ActivityOfferingInfo lectureAndLabFormatLectureB = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureAndLabFormatOffering.getId(), null, canonicalLectureAndLabFormatLectureActivity.getId(), "Lecture B", "D", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, instructors);
407
408 lectureAndLabFormatLectureB.setId("CO-1:LEC-AND-LAB:LEC-B");
409
410 coService.createActivityOffering(lectureAndLabFormatOffering.getId(), canonicalLectureAndLabFormatLectureActivity.getId(), LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, lectureAndLabFormatLectureB, context);
411
412
413
414 ActivityOfferingInfo lectureAndLabFormatLabA = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureAndLabFormatOffering.getId(), null, canonicalLectureAndLabFormatLabActivity.getId(), "Lab A", "E", LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, instructors);
415
416 lectureAndLabFormatLabA.setId("CO-1:LEC-AND-LAB:LAB-A");
417
418 coService.createActivityOffering(lectureAndLabFormatOffering.getId(), canonicalLectureAndLabFormatLabActivity.getId(), LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, lectureAndLabFormatLabA, context);
419
420
421
422 ActivityOfferingInfo lectureAndLabFormatLabB = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureAndLabFormatOffering.getId(), null, canonicalLectureAndLabFormatLabActivity.getId(), "Lab B", "F", LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, instructors);
423
424 lectureAndLabFormatLabB.setId("CO-1:LEC-AND-LAB:LAB-B");
425
426 coService.createActivityOffering(lectureAndLabFormatOffering.getId(), canonicalLectureAndLabFormatLabActivity.getId(), LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, lectureAndLabFormatLabB, context);
427
428
429
430
431 ActivityOfferingInfo lectureAndLabFormatLabC = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureAndLabFormatOffering.getId(), null, canonicalLectureAndLabFormatLabActivity.getId(), "Lab C", "G", LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, instructors);
432
433 lectureAndLabFormatLabC.setId("CO-1:LEC-AND-LAB:LAB-C");
434
435 coService.createActivityOffering(lectureAndLabFormatOffering.getId(), canonicalLectureAndLabFormatLabActivity.getId(), LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, lectureAndLabFormatLabC, context);
436
437
438 }
439
440 public static interface CourseOfferingCreationDetails {
441
442 public void storeCourseId(String id);
443
444 public void storeCourseOfferingId(String id);
445
446 String getSubjectArea();
447
448 String getCourseCode();
449
450 String getCourseTitle();
451
452 String getCourseDescription();
453
454
455
456
457
458
459
460 List<String> getCanonicalActivityTypeKeys(int format);
461
462 String getFormatOfferingName(int format);
463
464 String[] getFormatOfferingActivityTypeKeys(int format);
465
466 String getActivityOfferingTypeKey(int format, String activityTypeKey);
467
468 String getActivityOfferingCode(int format, String activityTypeKey, int activity);
469
470 String getActivityOfferingName(int format, String activityTypeKey, int activity);
471
472 int getNumberOfFormats();
473
474 int getNumberOfActivityOfferings(int format, String activityType);
475
476 public int getActivityOfferingMaxEnrollment(int i, String typeKey, int j);
477
478 }
479
480 public String createCourseOffering(TermInfo term, CourseOfferingCreationDetails details, ContextInfo context) throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException, DoesNotExistException, CircularRelationshipException, DependentObjectsExistException, UnsupportedActionException, DoesNotExistException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException {
481
482 String courseOfferingId = null;
483
484 CourseInfo canonicalCourse = buildCanonicalCourse(null, term.getId(), details.getSubjectArea(), details.getCourseCode(), details.getCourseTitle(), details.getCourseDescription());
485
486 int formats = details.getNumberOfFormats();
487
488 for (int i = 0; i < formats; i++) {
489
490 FormatInfo canonicalFormat = buildCanonicalFormat(null, canonicalCourse);
491
492 for (String canonicalActivityTypeKey : details.getCanonicalActivityTypeKeys(i)) {
493
494 buildCanonicalActivity(canonicalActivityTypeKey, canonicalFormat);
495
496 }
497 }
498
499 canonicalCourse = courseService.createCourse(canonicalCourse, context);
500
501 details.storeCourseId(canonicalCourse.getId());
502
503
504
505 CourseOfferingInfo courseOffering = CourseOfferingServiceTestDataUtils.createCourseOffering(canonicalCourse, term.getId());
506
507 CourseOfferingInfo co = coService.createCourseOffering(canonicalCourse.getId(), term.getId(), LuiServiceConstants.COURSE_OFFERING_TYPE_KEY, courseOffering, new ArrayList<String>(), context);
508
509 courseOfferingId = co.getId();
510
511 details.storeCourseOfferingId(co.getId());
512
513
514 for (int i = 0; i < formats; i++) {
515
516 FormatInfo canonicalFormat = canonicalCourse.getFormats().get(i);
517
518 String canonicalFormatId = canonicalCourse.getFormats().get(i).getId();
519
520 FormatOfferingInfo formatOffering = CourseOfferingServiceTestDataUtils.createFormatOffering(co.getId(), canonicalFormatId, term.getId(), details.getFormatOfferingName (i), details.getFormatOfferingActivityTypeKeys(i));
521
522 FormatOfferingInfo fo = coService.createFormatOffering(co.getId(), canonicalFormatId, LuiServiceConstants.FORMAT_OFFERING_TYPE_KEY, formatOffering, context);
523
524
525
526 for (ActivityInfo activity : canonicalFormat.getActivities()) {
527
528 int numberOfEachActivityType = details.getNumberOfActivityOfferings(i, activity.getTypeKey());
529
530 for (int j = 0; j < numberOfEachActivityType; j++) {
531
532 List<OfferingInstructorInfo> instructors = new ArrayList<OfferingInstructorInfo>();
533
534 instructors.add(CourseOfferingServiceTestDataUtils
535 .createInstructor("p1", "Instructor", 100.00F));
536
537 ActivityOfferingInfo ao = CourseOfferingServiceTestDataUtils
538 .createActivityOffering(term.getId(),
539 co, fo.getId(),
540 null, activity.getId(), details
541 .getActivityOfferingName(i,
542 activity.getTypeKey(), j), details
543 .getActivityOfferingCode(i,
544 activity.getTypeKey(), j), details
545 .getActivityOfferingTypeKey(i,
546 activity.getTypeKey()), instructors);
547
548 int maxEnrollment = details.getActivityOfferingMaxEnrollment(i, activity.getTypeKey(), j);
549
550 ao.setMaximumEnrollment(maxEnrollment);
551
552 coService.createActivityOffering(fo.getId(), activity.getId(), details.getActivityOfferingTypeKey(i, activity.getTypeKey()), ao, context);
553
554 }
555
556
557 }
558
559
560 ActivityOfferingClusterInfo aoc = CourseOfferingServiceTestDataUtils.createActivityOfferingCluster(fo.getId(), "Default", coService.getActivityOfferingsByFormatOffering(fo.getId(), context));
561
562
563 List<ActivityOfferingInfo> aos = coService.getActivityOfferingsWithoutClusterByFormatOffering(fo.getId(), context);
564
565 Map<String, ActivityOfferingSetInfo>aoSetMap = new HashMap<String, ActivityOfferingSetInfo>();
566
567 for (ActivityOfferingInfo activityOfferingInfo : aos) {
568
569 ActivityOfferingSetInfo aoset = aoSetMap.get(activityOfferingInfo.getTypeKey());
570
571 if (aoset == null) {
572 aoset = new ActivityOfferingSetInfo();
573 aoSetMap.put(activityOfferingInfo.getTypeKey(), aoset);
574 }
575
576 aoset.getActivityOfferingIds().add(activityOfferingInfo.getId());
577
578
579 }
580
581 aoc = coService.createActivityOfferingCluster(fo.getId(), CourseOfferingServiceConstants.AOC_ROOT_TYPE_KEY, aoc, context);
582
583
584
585
586 List<BulkStatusInfo> results = coService.generateRegistrationGroupsForFormatOffering(fo.getId(), context);
587
588 log.debug("generated " + results + " reg groups");
589
590 }
591
592 return courseOfferingId;
593 }
594
595 public void createLabActivityOfferingForCHEM123(String labCode, ContextInfo context) throws DoesNotExistException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
596
597
598 CourseOfferingInfo co = coService.getCourseOffering("CO-1", context);
599
600 CourseInfo c = courseService.getCourse(co.getCourseId(), context);
601
602
603
604 FormatInfo targetFormat = null;
605
606 for (FormatInfo format : c.getFormats()) {
607
608 if (format.getId().equals("CHEM123:LEC-AND-LAB")) {
609 targetFormat = format;
610 break;
611 }
612 }
613
614 List<OfferingInstructorInfo> instructors = new ArrayList<OfferingInstructorInfo>();
615
616 instructors.add(CourseOfferingServiceTestDataUtils.createInstructor("p1", "Instructor", 100.00F));
617
618 String canonicalActivityId = CourseOfferingServiceTestDataUtils.createCanonicalActivityId(targetFormat.getId(), LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY);
619
620 ActivityOfferingInfo lectureAndLabFormatLabC = CourseOfferingServiceTestDataUtils.createActivityOffering(co.getTermId(), co, "CO-1:LEC-AND-LAB", labCode, canonicalActivityId, labCode, "A", LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, instructors);
621
622 lectureAndLabFormatLabC.setId("CO-1:LEC-AND-LAB:" + labCode);
623
624
625 coService.createActivityOffering("CO-1:LEC-AND-LAB", canonicalActivityId, LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, lectureAndLabFormatLabC, context);
626
627
628 }
629
630
631 protected void createCourseENG101(TermInfo term, ContextInfo context) throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException, DoesNotExistException, CircularRelationshipException, DependentObjectsExistException, UnsupportedActionException, DoesNotExistException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException {
632
633 CourseInfo canonicalCourse = buildCanonicalCourse("CLU-2", term.getId(), "ENG", "ENG101", "Intro English", "Description of Intoroductory English");
634
635 FormatInfo canonicalLectureOnlyFormat = buildCanonicalFormat("ENG101:LEC-ONLY", canonicalCourse);
636
637 ActivityInfo canonicalLectureOnlyFormatLectureActivity = buildCanonicalActivity(LuServiceConstants.COURSE_ACTIVITY_LECTURE_TYPE_KEY, canonicalLectureOnlyFormat);
638
639 courseService.createCourse(canonicalCourse, context);
640
641
642 CourseOfferingInfo co = CourseOfferingServiceTestDataUtils.createCourseOffering(canonicalCourse, term.getId());
643
644 co.setId("CO-2");
645
646 coService.createCourseOffering(canonicalCourse.getId(), term.getId(), LuiServiceConstants.COURSE_OFFERING_TYPE_KEY, co, new ArrayList<String>(), context);
647
648
649
650 FormatOfferingInfo fo1 = CourseOfferingServiceTestDataUtils.createFormatOffering(co.getId(), canonicalLectureOnlyFormat.getId(), term.getId(), "Lecture", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY);
651
652 fo1.setId("CO-2:LEC-ONLY");
653
654 coService.createFormatOffering(co.getId(), canonicalLectureOnlyFormat.getId(), LuiServiceConstants.FORMAT_OFFERING_TYPE_KEY, fo1, context);
655
656
657 List<OfferingInstructorInfo> instructors = new ArrayList<OfferingInstructorInfo>();
658
659 instructors.add(CourseOfferingServiceTestDataUtils.createInstructor("p2", "Instructor", 100.00F));
660
661
662 ActivityOfferingInfo lectureOnlyFormatLectureA = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), co, fo1.getId(), null, canonicalLectureOnlyFormatLectureActivity.getId(), "Lecture", "A", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, instructors);
663
664 lectureOnlyFormatLectureA.setId("CO-2:LEC-ONLY:LEC-A");
665
666 coService.createActivityOffering(fo1.getId(), canonicalLectureOnlyFormatLectureActivity.getId(), LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, lectureOnlyFormatLectureA, context);
667
668
669 ActivityOfferingInfo lectureOnlyFormatLectureB = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), co, fo1.getId(), null, canonicalLectureOnlyFormatLectureActivity.getId(), "Lecture", "B", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, instructors);
670
671 lectureOnlyFormatLectureB.setId("CO-2:LEC-ONLY:LEC-B");
672
673 coService.createActivityOffering(fo1.getId(), canonicalLectureOnlyFormatLectureActivity.getId(), LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, lectureOnlyFormatLectureB, context);
674
675
676 List<ActivityOfferingInfo> activities = coService.getActivityOfferingsByFormatOffering("CO-2:LEC-ONLY", context);
677
678 ActivityOfferingClusterInfo defaultAoc = CourseOfferingServiceTestDataUtils.createActivityOfferingCluster("CO-2:LEC-ONLY", "Default Cluster", activities);
679
680 defaultAoc = coService.createActivityOfferingCluster("CO-2:LEC-ONLY", CourseOfferingServiceConstants.AOC_ROOT_TYPE_KEY, defaultAoc, context);
681
682
683 coService.generateRegistrationGroupsForFormatOffering("CO-2:LEC-ONLY", context);
684
685
686 }
687
688
689
690
691
692
693
694 private CourseInfo buildCanonicalCourse(String id, String startTermId, String subjectArea, String code, String title, String description) {
695 CourseInfo info = new CourseInfo();
696 info.setStartTerm(startTermId);
697 info.setEffectiveDate(calcEffectiveDateForTerm(startTermId, id));
698 info.setId(id);
699 info.setSubjectArea(subjectArea);
700 info.setCode(code);
701 info.setCourseNumberSuffix(code.substring(subjectArea.length()));
702 info.setCourseTitle(title);
703 RichTextInfo rt = new RichTextInfo();
704 rt.setPlain(description);
705 info.setDescr(rt);
706 info.setTypeKey(LuServiceConstants.CREDIT_COURSE_LU_TYPE_KEY);
707 info.setStateKey(DtoConstants.STATE_ACTIVE);
708 info.setFormats(new ArrayList<FormatInfo>());
709 ResultValuesGroupInfo rvg = new ResultValuesGroupInfo();
710 rvg.setKey(LrcServiceConstants.RESULT_GROUP_KEY_KUALI_CREDITTYPE_CREDIT_1_0);
711 info.getCreditOptions().add(rvg);
712 info.getGradingOptions().add(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_LETTER);
713 return info;
714 }
715
716
717 private ActivityInfo buildCanonicalActivity(String activityTypeKey, FormatInfo format) {
718
719 ActivityInfo info = new ActivityInfo();
720 info.setId(CourseOfferingServiceTestDataUtils.createCanonicalActivityId(format.getId(), activityTypeKey));
721 info.setTypeKey(activityTypeKey);
722 info.setStateKey(DtoConstants.STATE_ACTIVE);
723
724 format.getActivities().add(info);
725
726 return info;
727
728 }
729
730 private FormatInfo buildCanonicalFormat(String formatId, CourseInfo course) {
731
732 FormatInfo info = new FormatInfo();
733 info.setId(formatId);
734 info.setTypeKey(LuServiceConstants.COURSE_FORMAT_TYPE_KEY);
735 info.setStateKey(DtoConstants.STATE_ACTIVE);
736 info.setActivities(new ArrayList<ActivityInfo>());
737
738 course.getFormats().add(info);
739
740 return info;
741 }
742
743 private Date calcEffectiveDateForTerm(String termId, String context) {
744 String year = termId.substring(0, 4);
745 String mmdd = "09-01";
746 if (termId.endsWith("FA")) {
747 mmdd = "09-01";
748 } else if (termId.endsWith("WI")) {
749 mmdd = "01-01";
750 } else if (termId.endsWith("SP")) {
751 mmdd = "03-01";
752 } else if (termId.endsWith("SU")) {
753 mmdd = "06-01";
754 }
755 return str2Date(year + "-" + mmdd + " 00:00:00.0", context);
756 }
757
758 private Date str2Date(String str, String context) {
759 if (str == null) {
760 return null;
761 }
762 try {
763 Date date = DateFormatters.DEFAULT_YEAR_MONTH_24HOUR_MILLISECONDS_FORMATTER.parse(str);
764 return date;
765 } catch (IllegalArgumentException ex) {
766 throw new IllegalArgumentException("Bad date " + str + " in " + context);
767 }
768 }
769
770 public TermInfo getFall2012() {
771 return fall2012;
772 }
773
774 public void setFall2012(TermInfo fall2012) {
775 this.fall2012 = fall2012;
776 }
777
778 public TermInfo getSpring2012() {
779 return spring2012;
780 }
781
782 public void setSpring2012(TermInfo spring2012) {
783 this.spring2012 = spring2012;
784 }
785
786
787
788
789
790
791 public void setAcalService(AcademicCalendarService acalService) {
792 this.acalService = acalService;
793 }
794
795
796
797
798
799 public void setCoService(CourseOfferingService coService) {
800 this.coService = coService;
801 }
802
803
804
805
806
807 public void setCourseService(CourseService courseService) {
808 this.courseService = courseService;
809 }
810
811
812
813
814
815 public void setAtpService(AtpService atpService) {
816 this.atpService = atpService;
817 }
818
819
820
821
822
823 public void setCourseCodeGenerator(
824 CourseOfferingCodeGenerator courseCodeGenerator) {
825 this.courseCodeGenerator = courseCodeGenerator;
826 }
827
828
829
830
831
832 public void setRegistrationGroupCodeGeneratorFactory(
833 RegistrationGroupCodeGeneratorFactory registrationGroupCodeGeneratorFactory) {
834 this.registrationGroupCodeGeneratorFactory = registrationGroupCodeGeneratorFactory;
835 }
836
837
838
839
840
841 public void setAcalDataLoader(AcalTestDataLoader acalDataLoader) {
842 this.acalDataLoader = acalDataLoader;
843 }
844
845
846
847
848
849
850
851 public void setLoadBaseData(boolean loadBaseData) {
852 this.loadBaseData = loadBaseData;
853 }
854
855
856
857
858 }