001 /*
002 * Copyright 2012 The Kuali Foundation
003 *
004 * Licensed under the the Educational Community License, Version 1.0
005 * (the "License"); you may not use this file except in compliance
006 * with the License. You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl1.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.student.enrollment.class2.courseoffering.service.impl;
017
018 import java.util.ArrayList;
019 import java.util.Date;
020 import java.util.HashMap;
021 import java.util.List;
022 import java.util.Map;
023
024 import javax.annotation.Resource;
025
026 import org.joda.time.DateTime;
027 import org.kuali.student.common.test.mock.data.AbstractMockServicesAwareDataLoader;
028 import org.kuali.student.common.test.spring.log4j.KSLog4JConfigurer;
029 import org.kuali.student.enrollment.class2.acal.util.AcalTestDataLoader;
030 import org.kuali.student.enrollment.class2.courseoffering.service.CourseOfferingCodeGenerator;
031 import org.kuali.student.enrollment.class2.courseoffering.service.transformer.RegistrationGroupCodeGeneratorFactory;
032 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingClusterInfo;
033 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
034 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingSetInfo;
035 import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
036 import org.kuali.student.enrollment.courseoffering.dto.FormatOfferingInfo;
037 import org.kuali.student.enrollment.courseoffering.dto.OfferingInstructorInfo;
038 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
039 import org.kuali.student.r2.common.assembler.AssemblyException;
040 import org.kuali.student.r2.common.dto.BulkStatusInfo;
041 import org.kuali.student.r2.common.dto.ContextInfo;
042 import org.kuali.student.r2.common.dto.DtoConstants;
043 import org.kuali.student.r2.common.dto.RichTextInfo;
044 import org.kuali.student.r2.common.exceptions.AlreadyExistsException;
045 import org.kuali.student.r2.common.exceptions.CircularRelationshipException;
046 import org.kuali.student.r2.common.exceptions.DataValidationErrorException;
047 import org.kuali.student.r2.common.exceptions.DependentObjectsExistException;
048 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
049 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
050 import org.kuali.student.r2.common.exceptions.MissingParameterException;
051 import org.kuali.student.r2.common.exceptions.OperationFailedException;
052 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
053 import org.kuali.student.r2.common.exceptions.ReadOnlyException;
054 import org.kuali.student.r2.common.exceptions.UnsupportedActionException;
055 import org.kuali.student.r2.common.exceptions.VersionMismatchException;
056 import org.kuali.student.r2.common.util.RichTextHelper;
057 import org.kuali.student.r2.common.util.constants.CourseOfferingServiceConstants;
058 import org.kuali.student.r2.common.util.constants.LuServiceConstants;
059 import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
060 import org.kuali.student.r2.common.util.date.DateFormatters;
061 import org.kuali.student.r2.core.acal.dto.TermInfo;
062 import org.kuali.student.r2.core.acal.service.AcademicCalendarService;
063 import org.kuali.student.r2.core.acal.service.TermCodeGenerator;
064 import org.kuali.student.r2.core.acal.service.assembler.TermAssembler;
065 import org.kuali.student.r2.core.acal.service.impl.TermCodeGeneratorImpl;
066 import org.kuali.student.r2.core.atp.dto.AtpInfo;
067 import org.kuali.student.r2.core.atp.service.AtpService;
068 import org.kuali.student.r2.core.constants.AtpServiceConstants;
069 import org.kuali.student.r2.lum.course.dto.ActivityInfo;
070 import org.kuali.student.r2.lum.course.dto.CourseInfo;
071 import org.kuali.student.r2.lum.course.dto.FormatInfo;
072 import org.kuali.student.r2.lum.course.service.CourseService;
073 import org.kuali.student.r2.lum.lrc.dto.ResultValuesGroupInfo;
074 import org.kuali.student.r2.lum.util.constants.LrcServiceConstants;
075 import org.slf4j.Logger;
076
077
078 /**
079 * This class is expected to be configured as a spring bean in order to have the resources loaded.
080 * <p/>
081 * The {@link org.kuali.student.common.test.TestAwareDataLoader} api is used by the TestCourseOfferingServiceMockImpl to coordinate the data clear and load operations.
082 * <p/>
083 * The data modeled here probably should have come from this picture in the CourseOfferingService documentation :
084 * <p/>
085 * <a href="https://wiki.kuali.org/display/STUDENT/KS+ENR+HLDS+-+Seat+Pools+-+Reg+Groups#KSENRHLDS-SeatPools-RegGroups-DiagramofSeatPoolandRegGroupExamples">Documentation</a>
086 * <p/>
087 * We also define some methods that can be used to insert specific kinds of data into various spots for each example CourseOffering.
088 *
089 * @author Kuali Student Team
090 */
091 public class CourseOfferingServiceTestDataLoader extends AbstractMockServicesAwareDataLoader {
092
093 private static final Logger log = KSLog4JConfigurer.getLogger(CourseOfferingServiceTestDataLoader.class);
094
095 public static final String CHEM123_COURSE_ID = "CLU-1";
096
097 public static final String CHEM123_COURSE_OFFERING_ID = "CO-1";
098
099 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 /* (non-Javadoc)
147 * @see org.kuali.student.common.test.mock.data.AbstractMockServicesAwareDataLoader#initializeData()
148 */
149 @Override
150 protected void initializeData() throws Exception {
151
152 this.acalDataLoader = new AcalTestDataLoader(atpService);
153
154 acalDataLoader.loadData();
155
156 // this provides a way for users of the data loader to not to load the base data.
157 // we may want to externalize the base data into the TestCourseOfferingServiceWithClass2Mocks
158 if (!loadBaseData)
159 return;
160
161 // load in custom dates for use in the courses
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 // load the canonical course data
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 // course offering
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 // FO-1: lecture only format
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 // FO-2: lab and lecture format
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 // Format 1 Lecture offering A
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 // Format 1 Lecture Offering B
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 // Format 2:
275
276 // Lecture A
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 // Lecture B
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 // Lab A
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 // Lab B
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 // Lab C
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 // course offering
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 // course offering
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 // FO-1: lecture only format
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 // FO-2: lab and lecture format
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 // Format 1 Lecture offering A
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 // Format 1 Lecture Offering B
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 // Format 2:
397
398 // Lecture A
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 // Lecture B
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 // Lab A
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 // Lab B
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 // Lab C
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 * Get the type keys for the format given.
456 *
457 * @param format
458 * @return
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 // course offering
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 // create format offerings
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 // create activity offerings
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 // create a default aoc
560 ActivityOfferingClusterInfo aoc = CourseOfferingServiceTestDataUtils.createActivityOfferingCluster(fo.getId(), "Default", coService.getActivityOfferingsByFormatOffering(fo.getId(), context));
561
562 // add in all AO's
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 // generate reg groups
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 // create the new activity offering
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 // create offerings
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 // create format offering
649 // FO-1: lecture only format
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 // create lecture activity
657 List<OfferingInstructorInfo> instructors = new ArrayList<OfferingInstructorInfo>();
658
659 instructors.add(CourseOfferingServiceTestDataUtils.createInstructor("p2", "Instructor", 100.00F));
660
661 // Lecture A
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 // Lecture B
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 // create a default cluster
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 // Create a Registration Group
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 * @param acalService the acalService to set
790 */
791 public void setAcalService(AcademicCalendarService acalService) {
792 this.acalService = acalService;
793 }
794
795
796 /**
797 * @param coService the coService to set
798 */
799 public void setCoService(CourseOfferingService coService) {
800 this.coService = coService;
801 }
802
803
804 /**
805 * @param courseService the courseService to set
806 */
807 public void setCourseService(CourseService courseService) {
808 this.courseService = courseService;
809 }
810
811
812 /**
813 * @param atpService the atpService to set
814 */
815 public void setAtpService(AtpService atpService) {
816 this.atpService = atpService;
817 }
818
819
820 /**
821 * @param courseCodeGenerator the courseCodeGenerator to set
822 */
823 public void setCourseCodeGenerator(
824 CourseOfferingCodeGenerator courseCodeGenerator) {
825 this.courseCodeGenerator = courseCodeGenerator;
826 }
827
828
829 /**
830 * @param registrationGroupCodeGeneratorFactory the registrationGroupCodeGeneratorFactory to set
831 */
832 public void setRegistrationGroupCodeGeneratorFactory(
833 RegistrationGroupCodeGeneratorFactory registrationGroupCodeGeneratorFactory) {
834 this.registrationGroupCodeGeneratorFactory = registrationGroupCodeGeneratorFactory;
835 }
836
837
838 /**
839 * @param acalDataLoader the acalDataLoader to set
840 */
841 public void setAcalDataLoader(AcalTestDataLoader acalDataLoader) {
842 this.acalDataLoader = acalDataLoader;
843 }
844
845
846 /**
847 * If set to false then the base data will not be loaded.
848 *
849 * @param loadBaseData the loadBaseData to set
850 */
851 public void setLoadBaseData(boolean loadBaseData) {
852 this.loadBaseData = loadBaseData;
853 }
854
855
856
857
858 }