View Javadoc

1   /*
2    * Copyright 2012 The Kuali Foundation
3    *
4    * Licensed under the the Educational Community License, Version 1.0
5    * (the "License"); you may not use this file except in compliance
6    * with the License.  You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl1.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.student.enrollment.class2.courseoffering.service.impl;
17  
18  import org.joda.time.DateTime;
19  import org.kuali.student.common.test.mock.data.AbstractMockServicesAwareDataLoader;
20  import org.kuali.student.common.test.spring.log4j.KSLog4JConfigurer;
21  import org.kuali.student.enrollment.class2.acal.util.AcalTestDataLoader;
22  import org.kuali.student.enrollment.class2.courseoffering.service.CourseOfferingCodeGenerator;
23  import org.kuali.student.enrollment.class2.courseoffering.service.transformer.RegistrationGroupCodeGeneratorFactory;
24  import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingClusterInfo;
25  import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
26  import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingSetInfo;
27  import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
28  import org.kuali.student.enrollment.courseoffering.dto.FormatOfferingInfo;
29  import org.kuali.student.enrollment.courseoffering.dto.OfferingInstructorInfo;
30  import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
31  import org.kuali.student.r2.common.assembler.AssemblyException;
32  import org.kuali.student.r2.common.dto.AttributeInfo;
33  import org.kuali.student.r2.common.dto.BulkStatusInfo;
34  import org.kuali.student.r2.common.dto.ContextInfo;
35  import org.kuali.student.r2.common.dto.DtoConstants;
36  import org.kuali.student.r2.common.dto.RichTextInfo;
37  import org.kuali.student.r2.common.exceptions.AlreadyExistsException;
38  import org.kuali.student.r2.common.exceptions.CircularRelationshipException;
39  import org.kuali.student.r2.common.exceptions.DataValidationErrorException;
40  import org.kuali.student.r2.common.exceptions.DependentObjectsExistException;
41  import org.kuali.student.r2.common.exceptions.DoesNotExistException;
42  import org.kuali.student.r2.common.exceptions.InvalidParameterException;
43  import org.kuali.student.r2.common.exceptions.MissingParameterException;
44  import org.kuali.student.r2.common.exceptions.OperationFailedException;
45  import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
46  import org.kuali.student.r2.common.exceptions.ReadOnlyException;
47  import org.kuali.student.r2.common.exceptions.UnsupportedActionException;
48  import org.kuali.student.r2.common.exceptions.VersionMismatchException;
49  import org.kuali.student.r2.common.util.RichTextHelper;
50  import org.kuali.student.r2.common.util.constants.CourseOfferingServiceConstants;
51  import org.kuali.student.r2.common.util.constants.LuServiceConstants;
52  import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
53  import org.kuali.student.r2.common.util.date.DateFormatters;
54  import org.kuali.student.r2.core.acal.dto.TermInfo;
55  import org.kuali.student.r2.core.acal.service.AcademicCalendarService;
56  import org.kuali.student.r2.core.acal.service.assembler.TermAssembler;
57  import org.kuali.student.r2.core.acal.service.impl.TermCodeGeneratorMockImpl;
58  import org.kuali.student.r2.core.atp.dto.AtpInfo;
59  import org.kuali.student.r2.core.atp.service.AtpService;
60  import org.kuali.student.r2.core.class1.state.dto.LifecycleInfo;
61  import org.kuali.student.r2.core.class1.state.dto.StateInfo;
62  import org.kuali.student.r2.core.class1.state.service.StateService;
63  import org.kuali.student.r2.core.constants.AtpServiceConstants;
64  import org.kuali.student.r2.lum.course.dto.ActivityInfo;
65  import org.kuali.student.r2.lum.course.dto.CourseInfo;
66  import org.kuali.student.r2.lum.course.dto.FormatInfo;
67  import org.kuali.student.r2.lum.course.service.CourseService;
68  import org.kuali.student.r2.lum.lrc.dto.ResultValuesGroupInfo;
69  import org.kuali.student.r2.lum.util.constants.LrcServiceConstants;
70  import org.slf4j.Logger;
71  
72  import javax.annotation.Resource;
73  import java.util.ArrayList;
74  import java.util.Calendar;
75  import java.util.Date;
76  import java.util.HashMap;
77  import java.util.List;
78  import java.util.Map;
79  
80  
81  /**
82   * This class is expected to be configured as a spring bean in order to have the resources loaded.
83   * <p/>
84   * The {@link org.kuali.student.common.test.TestAwareDataLoader}  api is used by the TestCourseOfferingServiceMockImpl to coordinate the data clear and load operations.
85   * <p/>
86   * The data modeled here probably should have come from this picture in the CourseOfferingService documentation :
87   * <p/>
88   * <a href="https://wiki.kuali.org/display/STUDENT/KS+ENR+HLDS+-+Seat+Pools+-+Reg+Groups#KSENRHLDS-SeatPools-RegGroups-DiagramofSeatPoolandRegGroupExamples">Documentation</a>
89   * <p/>
90   * We also define some methods that can be used to insert specific kinds of data into various spots for each example CourseOffering.
91   *
92   * @author Kuali Student Team
93   */
94  public class CourseOfferingServiceTestDataLoader extends AbstractMockServicesAwareDataLoader {
95  
96      private static final Logger log = KSLog4JConfigurer.getLogger(CourseOfferingServiceTestDataLoader.class);
97      
98      public static final String CHEM123_COURSE_ID = "CLU-1";
99      
100     public static final String CHEM123_COURSE_OFFERING_ID = "CO-1";
101     
102     public static final String CHEM123_LEC_AND_LAB_FORMAT_OFFERING_ID = "CO-1:LEC-AND-LAB";
103     
104     public static final String ENG101_COURSE_ID = "CLU-2";
105     
106     public static final String ENG101_COURSE_OFFERING_ID = "CO-2";
107     
108     public static final String ENG101_LEC_ONLY_FORMAT_OFFERING_ID = "CO-2:LEC-ONLY";
109     
110     public static final String FALL_2012_TERM_ID = "2012FA";
111     
112     @Resource
113     protected AcademicCalendarService acalService;
114 
115     @Resource
116     protected CourseOfferingService coService;
117 
118     @Resource
119     protected CourseService courseService;
120 
121     @Resource
122     protected AtpService atpService;
123 
124     @Resource
125     protected StateService stateService;
126 
127     @Resource
128     protected CourseOfferingCodeGenerator courseCodeGenerator;
129 
130     @Resource
131     protected RegistrationGroupCodeGeneratorFactory registrationGroupCodeGeneratorFactory;
132 
133     protected AcalTestDataLoader acalDataLoader;
134 
135     TermInfo fall2012 = null;
136     TermInfo spring2012 = null;
137 
138     private boolean loadBaseData = true;
139 
140 
141     /**
142      */
143     public CourseOfferingServiceTestDataLoader() {
144         super();
145     }
146 
147 
148     public void beforeTest(boolean loadInstructors) throws Exception {
149         initializeData(loadInstructors);
150         initialized = true;
151     }
152 
153 
154     /* (non-Javadoc)
155     * @see org.kuali.student.common.test.mock.data.AbstractMockServicesAwareDataLoader#initializeData()
156     */
157     @Override
158     protected void initializeData() throws Exception {
159         initializeData(true);
160     }
161 
162     protected void initializeData(boolean loadInstructors) throws Exception {
163         this.acalDataLoader = new AcalTestDataLoader(atpService);
164 
165         acalDataLoader.loadData();
166 
167         // this provides a way for users of the data loader to not to load the base data.
168         // we may want to externalize the base data into the TestCourseOfferingServiceWithClass2Mocks
169         if (!loadBaseData)
170             return;
171 
172         loadTerms();
173 
174         // load the canonical course data
175 
176         createCourse(fall2012, "CHEM", "123", context);
177         createCourseCHEM123(fall2012, loadInstructors, context);
178 
179         createCourseENG101(spring2012, loadInstructors, context);
180     }
181 
182     public void createStateTestData() throws Exception {
183 
184         // ActivityOffering state
185         LifecycleInfo aoLifecycle = addLifecycle( LuiServiceConstants.ACTIVITY_OFFERING_LIFECYCLE_KEY );
186         addState( aoLifecycle, LuiServiceConstants.LUI_AO_STATE_DRAFT_KEY, true );
187 
188         // FormatOffering state
189         LifecycleInfo foLifecycle = addLifecycle( LuiServiceConstants.FORMAT_OFFERING_LIFECYCLE_KEY );
190         addState( foLifecycle, LuiServiceConstants.LUI_FO_STATE_PLANNED_KEY, true );
191 
192         // CourseOffering state
193         LifecycleInfo coLifecycle = addLifecycle( LuiServiceConstants.COURSE_OFFERING_LIFECYCLE_KEY );
194         addState( coLifecycle, LuiServiceConstants.LUI_CO_STATE_DRAFT_KEY, true );
195 
196         LifecycleInfo rgLifecycle = addLifecycle( LuiServiceConstants.REGISTRATION_GROUP_LIFECYCLE_KEY );
197         addState(rgLifecycle, LuiServiceConstants.REGISTRATION_GROUP_PENDING_STATE_KEY, true);
198     }
199 
200     private LifecycleInfo addLifecycle( String name ) throws Exception {
201 
202         LifecycleInfo origLife = new LifecycleInfo();
203         RichTextInfo rti = new RichTextInfo();
204         rti.setFormatted("<b>Formatted</b> lifecycle for testing purposes");
205         rti.setPlain("Plain lifecycle for testing purposes");
206         origLife.setDescr(rti);
207         origLife.setKey(name);
208         origLife.setName( "TEST_NAME" );
209         origLife.setRefObjectUri("TEST_URI");
210         AttributeInfo attr = new AttributeInfo();
211         attr.setKey("attribute.key");
212         attr.setValue("attribute value");
213         origLife.getAttributes().add(attr);
214 
215         return stateService.createLifecycle(origLife.getKey(), origLife, context);
216     }
217 
218     private StateInfo addState( LifecycleInfo lifecycleInfo, String state, boolean isInitialState ) throws Exception {
219 
220         StateInfo orig = new StateInfo();
221         orig.setKey(state);
222         orig.setLifecycleKey(lifecycleInfo.getKey());
223         RichTextInfo rti = new RichTextInfo();
224         rti.setFormatted("<b>Formatted again</b> state for testing purposes");
225         rti.setPlain("Plain state again for testing purposes");
226         orig.setDescr(rti);
227         orig.setName("Testing state");
228         Date effDate = new Date();
229         orig.setEffectiveDate(effDate);
230         Calendar cal = Calendar.getInstance();
231         cal.set(2022, 8, 23);
232         orig.setExpirationDate(cal.getTime());
233         AttributeInfo attr = new AttributeInfo();
234         attr.setKey("attribute.key");
235         attr.setValue("attribute value");
236         orig.getAttributes().add(attr);
237         orig.setIsInitialState(isInitialState);
238 
239         return stateService.createState(orig.getLifecycleKey(), orig.getKey(), orig, context);
240     }
241 
242     public void loadTerms() throws PermissionDeniedException, OperationFailedException, InvalidParameterException, ReadOnlyException, MissingParameterException, DataValidationErrorException {
243         // load in custom dates for use in the courses
244         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);
245 
246         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);
247     }
248 
249    
250 
251 
252     public TermInfo createTerm(String id, String name, String atpTypeKey, Date startDate, Date endDate, ContextInfo context) throws OperationFailedException, DataValidationErrorException, InvalidParameterException, MissingParameterException, PermissionDeniedException, ReadOnlyException {
253 
254         AtpInfo atpInfo = new AtpInfo();
255         atpInfo.setId(id);
256         atpInfo.setName(name);
257         atpInfo.setTypeKey(atpTypeKey);
258         atpInfo.setStateKey(AtpServiceConstants.ATP_OFFICIAL_STATE_KEY);
259         atpInfo.setStartDate(startDate);
260         atpInfo.setEndDate(endDate);
261         atpInfo.setDescr(new RichTextHelper().fromPlain(name));
262 
263         try {
264             TermInfo term = new TermAssembler().assemble(atpInfo, context);
265             TermCodeGeneratorMockImpl tcg = new TermCodeGeneratorMockImpl();
266             atpInfo.setCode(tcg.generateTermCode(term));
267         } catch (AssemblyException e) {
268             throw new OperationFailedException("Assembly of TermInfo failed", e);
269         }
270 
271         AtpInfo saved = atpService.createAtp(atpInfo.getTypeKey(), atpInfo, context);
272         
273         TermInfo term = new TermInfo();
274 
275         term.setId(saved.getId());
276         term.setAttributes(saved.getAttributes());
277         term.setCode(saved.getCode());
278         term.setStartDate(saved.getStartDate());
279         term.setEndDate(saved.getEndDate());
280         term.setMeta(saved.getMeta());
281         term.setDescr(saved.getDescr());
282         term.setStateKey(saved.getStateKey());
283         term.setTypeKey(saved.getTypeKey());
284 
285         return term;
286     }
287 
288 
289     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 {
290 
291         String courseCode = subjectCode + courseNumberCode;
292         String courseId = courseCode + "-ID";
293 
294         CourseInfo canonicalCourse = buildCanonicalCourse(courseId, term.getId(), subjectCode, courseCode, subjectCode + " " + courseCode, courseCode + " description 1");
295 
296         FormatInfo canonicalLectureOnlyFormat = buildCanonicalFormat(courseCode + ":LEC-ONLY", canonicalCourse);
297 
298         ActivityInfo canonicalLectureOnlyLectureActivity = buildCanonicalActivity(LuServiceConstants.COURSE_ACTIVITY_LECTURE_TYPE_KEY, canonicalLectureOnlyFormat);
299 
300         FormatInfo canonicalLectureAndLabFormat = buildCanonicalFormat(courseCode + ":LEC-AND-LAB", canonicalCourse);
301 
302         ActivityInfo canonicalLectureAndLabFormatLectureActivity = buildCanonicalActivity(LuServiceConstants.COURSE_ACTIVITY_LECTURE_TYPE_KEY, canonicalLectureAndLabFormat);
303         ActivityInfo canonicalLectureAndLabFormatLabActivity = buildCanonicalActivity(LuServiceConstants.COURSE_ACTIVITY_LAB_TYPE_KEY, canonicalLectureAndLabFormat);
304 
305         courseService.createCourse(canonicalCourse, context);
306 
307 
308         // course offering
309         CourseOfferingInfo courseOffering = CourseOfferingServiceTestDataUtils.createCourseOffering(canonicalCourse, term.getId());
310 
311         courseOffering.setId(courseId);
312 
313         coService.createCourseOffering(canonicalCourse.getId(), term.getId(), LuiServiceConstants.COURSE_OFFERING_TYPE_KEY, courseOffering, new ArrayList<String>(), context);
314 
315         // FO-1: lecture only format
316         FormatOfferingInfo lectureOnlyFormatOffering = CourseOfferingServiceTestDataUtils.createFormatOffering(courseOffering.getId(), canonicalLectureOnlyFormat.getId(), term.getId(), "Lecture", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY);
317 
318         lectureOnlyFormatOffering.setId(courseId + ":LEC-ONLY");
319 
320         coService.createFormatOffering(courseOffering.getId(), canonicalLectureOnlyFormat.getId(), LuiServiceConstants.FORMAT_OFFERING_TYPE_KEY, lectureOnlyFormatOffering, context);
321 
322         // FO-2: lab and lecture format
323         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});
324 
325         lectureAndLabFormatOffering.setId(courseId + ":LEC-AND-LAB");
326 
327         coService.createFormatOffering(courseOffering.getId(), canonicalLectureAndLabFormat.getId(), LuiServiceConstants.FORMAT_OFFERING_TYPE_KEY, lectureAndLabFormatOffering, context);
328 
329         List<OfferingInstructorInfo> instructors = new ArrayList<OfferingInstructorInfo>();
330 
331         instructors.add(CourseOfferingServiceTestDataUtils.createInstructor("p1", "Instructor", 100.00F));
332 
333 
334         // Format 1 Lecture offering A
335         ActivityOfferingInfo lectureOnlyFormatLectureA = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureOnlyFormatOffering.getId(), null, canonicalLectureOnlyLectureActivity.getId(), "Lecture A", "A", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, instructors);
336 
337         lectureOnlyFormatLectureA.setId(courseId + ":LEC-ONLY:LEC-A");
338 
339         coService.createActivityOffering(lectureOnlyFormatOffering.getId(), canonicalLectureOnlyLectureActivity.getId(), LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, lectureOnlyFormatLectureA, context);
340 
341         // Format 1 Lecture Offering B
342         ActivityOfferingInfo lectureOnlyFormatLectureB = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureOnlyFormatOffering.getId(), null, canonicalLectureOnlyLectureActivity.getId(), "Lecture B", "B", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, instructors);
343 
344         lectureOnlyFormatLectureB.setId(courseId + ":LEC-ONLY:LEC-B");
345 
346         coService.createActivityOffering(lectureOnlyFormatOffering.getId(), canonicalLectureOnlyLectureActivity.getId(), LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, lectureOnlyFormatLectureB, context);
347 
348         // Format 2:
349 
350         // Lecture A
351         ActivityOfferingInfo lectureAndLabFormatLectureA = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureAndLabFormatOffering.getId(), null, canonicalLectureAndLabFormatLectureActivity.getId(), "Lecture A", "C", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, instructors);
352 
353         lectureAndLabFormatLectureA.setId(courseId + ":LEC-AND-LAB:LEC-A");
354 
355         coService.createActivityOffering(lectureAndLabFormatOffering.getId(), canonicalLectureAndLabFormatLectureActivity.getId(), LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, lectureAndLabFormatLectureA, context);
356 
357         // Lecture B
358         ActivityOfferingInfo lectureAndLabFormatLectureB = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureAndLabFormatOffering.getId(), null, canonicalLectureAndLabFormatLectureActivity.getId(), "Lecture B", "D", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, instructors);
359 
360         lectureAndLabFormatLectureB.setId(courseId + ":LEC-AND-LAB:LEC-B");
361 
362         coService.createActivityOffering(lectureAndLabFormatOffering.getId(), canonicalLectureAndLabFormatLectureActivity.getId(), LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, lectureAndLabFormatLectureB, context);
363 
364 
365         // Lab A
366         ActivityOfferingInfo lectureAndLabFormatLabA = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureAndLabFormatOffering.getId(), null, canonicalLectureAndLabFormatLabActivity.getId(), "Lab A", "E", LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, instructors);
367 
368         lectureAndLabFormatLabA.setId(courseId + ":LEC-AND-LAB:LAB-A");
369 
370         coService.createActivityOffering(lectureAndLabFormatOffering.getId(), canonicalLectureAndLabFormatLabActivity.getId(), LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, lectureAndLabFormatLabA, context);
371 
372 
373         // Lab B
374         ActivityOfferingInfo lectureAndLabFormatLabB = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureAndLabFormatOffering.getId(), null, canonicalLectureAndLabFormatLabActivity.getId(), "Lab B", "F", LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, instructors);
375 
376         lectureAndLabFormatLabB.setId(courseId + ":LEC-AND-LAB:LAB-B");
377 
378         coService.createActivityOffering(lectureAndLabFormatOffering.getId(), canonicalLectureAndLabFormatLabActivity.getId(), LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, lectureAndLabFormatLabB, context);
379 
380         // Lab C
381 
382 
383         ActivityOfferingInfo lectureAndLabFormatLabC = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureAndLabFormatOffering.getId(), null, canonicalLectureAndLabFormatLabActivity.getId(), "Lab C", "G", LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, instructors);
384 
385         lectureAndLabFormatLabC.setId(courseId + ":LEC-AND-LAB:LAB-C");
386 
387         coService.createActivityOffering(lectureAndLabFormatOffering.getId(), canonicalLectureAndLabFormatLabActivity.getId(), LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, lectureAndLabFormatLabC, context);
388 
389 
390     }
391 
392     public String createCourse(TermInfo term, String subjectCode, String courseNumberCode, ContextInfo context) throws AlreadyExistsException, VersionMismatchException, CircularRelationshipException, DependentObjectsExistException, UnsupportedActionException, DoesNotExistException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException {
393 
394         String courseCode = subjectCode + courseNumberCode;
395         String courseId = courseCode + "-ID";
396 
397         CourseInfo canonicalCourse = buildCanonicalCourse(courseId, term.getId(), subjectCode, courseCode, subjectCode + " " + courseCode, courseCode + " description 1");
398         courseService.createCourse(canonicalCourse, context);
399 
400         return courseId;
401     }
402 
403     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 {
404         // course offering
405         CourseOfferingInfo courseOffering = CourseOfferingServiceTestDataUtils.createCourseOffering(canonicalCourse, term.getId());
406 
407         courseOffering.setId("CO:" + canonicalCourse.getId());
408 
409         coService.createCourseOffering(canonicalCourse.getId(), term.getId(), LuiServiceConstants.COURSE_OFFERING_TYPE_KEY, courseOffering, new ArrayList<String>(), context);
410 
411 
412     }
413 
414     protected void createCourseCHEM123(TermInfo term, boolean loadInstructors, ContextInfo context) throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException, DoesNotExistException, CircularRelationshipException, DependentObjectsExistException, UnsupportedActionException, DoesNotExistException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException {
415 
416         CourseInfo canonicalCourse = buildCanonicalCourse("CLU-1", term.getId(), "CHEM", "CHEM123", "Chemistry 123", "description 1");
417 
418         FormatInfo canonicalLectureOnlyFormat = buildCanonicalFormat("CHEM123:LEC-ONLY", canonicalCourse);
419 
420         ActivityInfo canonicalLectureOnlyLectureActivity = buildCanonicalActivity(LuServiceConstants.COURSE_ACTIVITY_LECTURE_TYPE_KEY, canonicalLectureOnlyFormat);
421 
422         FormatInfo canonicalLectureAndLabFormat = buildCanonicalFormat("CHEM123:LEC-AND-LAB", canonicalCourse);
423 
424         ActivityInfo canonicalLectureAndLabFormatLectureActivity = buildCanonicalActivity(LuServiceConstants.COURSE_ACTIVITY_LECTURE_TYPE_KEY, canonicalLectureAndLabFormat);
425         ActivityInfo canonicalLectureAndLabFormatLabActivity = buildCanonicalActivity(LuServiceConstants.COURSE_ACTIVITY_LAB_TYPE_KEY, canonicalLectureAndLabFormat);
426 
427         courseService.createCourse(canonicalCourse, context);
428 
429 
430         // course offering
431         CourseOfferingInfo courseOffering = CourseOfferingServiceTestDataUtils.createCourseOffering(canonicalCourse, term.getId());
432 
433         courseOffering.setId("CO-1");
434 
435         coService.createCourseOffering(canonicalCourse.getId(), term.getId(), LuiServiceConstants.COURSE_OFFERING_TYPE_KEY, courseOffering, new ArrayList<String>(), context);
436 
437         // FO-1: lecture only format
438         FormatOfferingInfo lectureOnlyFormatOffering = CourseOfferingServiceTestDataUtils.createFormatOffering(courseOffering.getId(), canonicalLectureOnlyFormat.getId(), term.getId(), "Lecture", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY);
439 
440         lectureOnlyFormatOffering.setId("CO-1:LEC-ONLY");
441 
442         coService.createFormatOffering(courseOffering.getId(), canonicalLectureOnlyFormat.getId(), LuiServiceConstants.FORMAT_OFFERING_TYPE_KEY, lectureOnlyFormatOffering, context);
443 
444         // FO-2: lab and lecture format
445         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});
446 
447         lectureAndLabFormatOffering.setId("CO-1:LEC-AND-LAB");
448 
449         coService.createFormatOffering(courseOffering.getId(), canonicalLectureAndLabFormat.getId(), LuiServiceConstants.FORMAT_OFFERING_TYPE_KEY, lectureAndLabFormatOffering, context);
450 
451         List<OfferingInstructorInfo> instructors = new ArrayList<OfferingInstructorInfo>();
452 
453         if(loadInstructors) {
454             instructors.add(CourseOfferingServiceTestDataUtils.createInstructor("p1", "Instructor", 100.00F));
455         }
456 
457         // Format 1 Lecture offering A
458         ActivityOfferingInfo lectureOnlyFormatLectureA = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureOnlyFormatOffering.getId(), null, canonicalLectureOnlyLectureActivity.getId(), "Lecture A", "A", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, instructors);
459 
460         lectureOnlyFormatLectureA.setId("CO-1:LEC-ONLY:LEC-A");
461 
462         coService.createActivityOffering(lectureOnlyFormatOffering.getId(), canonicalLectureOnlyLectureActivity.getId(), LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, lectureOnlyFormatLectureA, context);
463 
464         // Format 1 Lecture Offering B
465         ActivityOfferingInfo lectureOnlyFormatLectureB = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureOnlyFormatOffering.getId(), null, canonicalLectureOnlyLectureActivity.getId(), "Lecture B", "B", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, instructors);
466 
467         lectureOnlyFormatLectureB.setId("CO-1:LEC-ONLY:LEC-B");
468 
469         coService.createActivityOffering(lectureOnlyFormatOffering.getId(), canonicalLectureOnlyLectureActivity.getId(), LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, lectureOnlyFormatLectureB, context);
470 
471         // Format 2:
472 
473         // Lecture A
474         ActivityOfferingInfo lectureAndLabFormatLectureA = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureAndLabFormatOffering.getId(), null, canonicalLectureAndLabFormatLectureActivity.getId(), "Lecture A", "C", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, instructors);
475 
476         lectureAndLabFormatLectureA.setId("CO-1:LEC-AND-LAB:LEC-A");
477 
478         coService.createActivityOffering(lectureAndLabFormatOffering.getId(), canonicalLectureAndLabFormatLectureActivity.getId(), LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, lectureAndLabFormatLectureA, context);
479 
480         // Lecture B
481         ActivityOfferingInfo lectureAndLabFormatLectureB = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureAndLabFormatOffering.getId(), null, canonicalLectureAndLabFormatLectureActivity.getId(), "Lecture B", "D", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, instructors);
482 
483         lectureAndLabFormatLectureB.setId("CO-1:LEC-AND-LAB:LEC-B");
484 
485         coService.createActivityOffering(lectureAndLabFormatOffering.getId(), canonicalLectureAndLabFormatLectureActivity.getId(), LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, lectureAndLabFormatLectureB, context);
486 
487 
488         // Lab A
489         ActivityOfferingInfo lectureAndLabFormatLabA = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureAndLabFormatOffering.getId(), null, canonicalLectureAndLabFormatLabActivity.getId(), "Lab A", "E", LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, instructors);
490 
491         lectureAndLabFormatLabA.setId("CO-1:LEC-AND-LAB:LAB-A");
492 
493         coService.createActivityOffering(lectureAndLabFormatOffering.getId(), canonicalLectureAndLabFormatLabActivity.getId(), LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, lectureAndLabFormatLabA, context);
494 
495 
496         // Lab B
497         ActivityOfferingInfo lectureAndLabFormatLabB = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureAndLabFormatOffering.getId(), null, canonicalLectureAndLabFormatLabActivity.getId(), "Lab B", "F", LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, instructors);
498 
499         lectureAndLabFormatLabB.setId("CO-1:LEC-AND-LAB:LAB-B");
500 
501         coService.createActivityOffering(lectureAndLabFormatOffering.getId(), canonicalLectureAndLabFormatLabActivity.getId(), LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, lectureAndLabFormatLabB, context);
502 
503         // Lab C
504 
505 
506         ActivityOfferingInfo lectureAndLabFormatLabC = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), courseOffering, lectureAndLabFormatOffering.getId(), null, canonicalLectureAndLabFormatLabActivity.getId(), "Lab C", "G", LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, instructors);
507 
508         lectureAndLabFormatLabC.setId("CO-1:LEC-AND-LAB:LAB-C");
509 
510         coService.createActivityOffering(lectureAndLabFormatOffering.getId(), canonicalLectureAndLabFormatLabActivity.getId(), LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, lectureAndLabFormatLabC, context);
511 
512 
513     }
514 
515     public static interface CourseOfferingCreationDetails {
516 
517         public void storeCourseId(String id);
518         
519         public void storeCourseOfferingId(String id);
520         
521         String getSubjectArea();
522 
523         String getCourseCode();
524 
525         String getCourseTitle();
526 
527         String getCourseDescription();
528 
529         /**
530          * Get the type keys for the format given.
531          * 
532          * @param format
533          * @return
534          */
535         List<String> getCanonicalActivityTypeKeys(int format);
536 
537         String getFormatOfferingName(int format);
538 
539         String[] getFormatOfferingActivityTypeKeys(int format);
540 
541         String getActivityOfferingTypeKey(int format, String activityTypeKey);
542 
543         String getActivityOfferingCode(int format, String activityTypeKey, int activity);
544 
545         String getActivityOfferingName(int format, String activityTypeKey, int activity);
546 
547         int getNumberOfFormats();
548 
549         int getNumberOfActivityOfferings(int format, String activityType);
550 
551         public int getActivityOfferingMaxEnrollment(int i, String typeKey, int j);
552 
553     }
554     
555     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 {
556 
557         String courseOfferingId = null;
558         
559         CourseInfo canonicalCourse = buildCanonicalCourse(null, term.getId(), details.getSubjectArea(), details.getCourseCode(), details.getCourseTitle(), details.getCourseDescription());
560         
561         int formats = details.getNumberOfFormats();
562         
563        for (int i = 0; i < formats; i++) {
564         
565             FormatInfo canonicalFormat = buildCanonicalFormat(null, canonicalCourse);
566 
567             for (String canonicalActivityTypeKey : details.getCanonicalActivityTypeKeys(i)) {
568                 
569                buildCanonicalActivity(canonicalActivityTypeKey, canonicalFormat);
570             
571             }
572         }
573         
574        canonicalCourse = courseService.createCourse(canonicalCourse, context);
575        
576        details.storeCourseId(canonicalCourse.getId());
577 
578 
579         // course offering
580         CourseOfferingInfo courseOffering = CourseOfferingServiceTestDataUtils.createCourseOffering(canonicalCourse, term.getId());
581 
582         CourseOfferingInfo co = coService.createCourseOffering(canonicalCourse.getId(), term.getId(), LuiServiceConstants.COURSE_OFFERING_TYPE_KEY, courseOffering, new ArrayList<String>(), context);
583 
584         courseOfferingId = co.getId();
585         
586         details.storeCourseOfferingId(co.getId());
587         
588         // create format offerings
589         for (int i = 0; i < formats; i++) {
590             
591             FormatInfo canonicalFormat = canonicalCourse.getFormats().get(i);
592             
593             String canonicalFormatId = canonicalCourse.getFormats().get(i).getId();
594             
595             FormatOfferingInfo formatOffering = CourseOfferingServiceTestDataUtils.createFormatOffering(co.getId(), canonicalFormatId, term.getId(), details.getFormatOfferingName (i), details.getFormatOfferingActivityTypeKeys(i));
596 
597             FormatOfferingInfo fo = coService.createFormatOffering(co.getId(), canonicalFormatId, LuiServiceConstants.FORMAT_OFFERING_TYPE_KEY, formatOffering, context);
598             
599             
600             // create activity offerings
601             for (ActivityInfo activity : canonicalFormat.getActivities()) {
602                 
603                 int numberOfEachActivityType = details.getNumberOfActivityOfferings(i, activity.getTypeKey());
604                 
605                 for (int j = 0; j < numberOfEachActivityType; j++) {
606                     
607                     List<OfferingInstructorInfo> instructors = new ArrayList<OfferingInstructorInfo>();
608 
609                     instructors.add(CourseOfferingServiceTestDataUtils
610                             .createInstructor("p1", "Instructor", 100.00F));
611 
612                     ActivityOfferingInfo ao = CourseOfferingServiceTestDataUtils
613                             .createActivityOffering(term.getId(),
614                                     co, fo.getId(),
615                                     null, activity.getId(), details
616                                             .getActivityOfferingName(i,
617                                                     activity.getTypeKey(), j), details
618                                             .getActivityOfferingCode(i,
619                                                     activity.getTypeKey(), j), details
620                                             .getActivityOfferingTypeKey(i,
621                                                     activity.getTypeKey()), instructors);
622                     
623                     int maxEnrollment = details.getActivityOfferingMaxEnrollment(i, activity.getTypeKey(), j);
624 
625                     ao.setMaximumEnrollment(maxEnrollment);
626                     
627                     coService.createActivityOffering(fo.getId(), activity.getId(), details.getActivityOfferingTypeKey(i, activity.getTypeKey()), ao, context);
628 
629                 }
630                 
631                
632             }
633             
634             // create a default aoc
635             ActivityOfferingClusterInfo aoc = CourseOfferingServiceTestDataUtils.createActivityOfferingCluster(fo.getId(), "Default", coService.getActivityOfferingsByFormatOffering(fo.getId(), context));
636 
637             // add in all AO's
638             List<ActivityOfferingInfo> aos = coService.getActivityOfferingsWithoutClusterByFormatOffering(fo.getId(), context);
639             
640             Map<String, ActivityOfferingSetInfo>aoSetMap = new HashMap<String, ActivityOfferingSetInfo>();
641             
642             for (ActivityOfferingInfo activityOfferingInfo : aos) {
643             
644                 ActivityOfferingSetInfo aoset = aoSetMap.get(activityOfferingInfo.getTypeKey());
645             
646                 if (aoset == null) {
647                     aoset = new ActivityOfferingSetInfo();
648                     aoSetMap.put(activityOfferingInfo.getTypeKey(), aoset);
649                 }
650                 
651                 aoset.getActivityOfferingIds().add(activityOfferingInfo.getId());
652                 
653                 
654             }
655             
656             aoc = coService.createActivityOfferingCluster(fo.getId(), CourseOfferingServiceConstants.AOC_ROOT_TYPE_KEY, aoc, context);
657             
658             
659             // generate reg groups
660             
661             List<BulkStatusInfo> results = coService.generateRegistrationGroupsForFormatOffering(fo.getId(), context);
662             
663             log.debug("generated " + results + " reg groups");
664             
665         }
666         
667         return courseOfferingId;
668     }
669 
670     public void createLabActivityOfferingForCHEM123(String labCode, ContextInfo context) throws DoesNotExistException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
671 
672 
673         CourseOfferingInfo co = coService.getCourseOffering("CO-1", context);
674 
675         CourseInfo c = courseService.getCourse(co.getCourseId(), context);
676 
677         // create the new activity offering
678 
679         FormatInfo targetFormat = null;
680 
681         for (FormatInfo format : c.getFormats()) {
682 
683             if (format.getId().equals("CHEM123:LEC-AND-LAB")) {
684                 targetFormat = format;
685                 break;
686             }
687         }
688 
689         List<OfferingInstructorInfo> instructors = new ArrayList<OfferingInstructorInfo>();
690 
691         instructors.add(CourseOfferingServiceTestDataUtils.createInstructor("p1", "Instructor", 100.00F));
692 
693         String canonicalActivityId = CourseOfferingServiceTestDataUtils.createCanonicalActivityId(targetFormat.getId(), LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY);
694 
695         ActivityOfferingInfo lectureAndLabFormatLabC = CourseOfferingServiceTestDataUtils.createActivityOffering(co.getTermId(), co, "CO-1:LEC-AND-LAB", null, canonicalActivityId, labCode, "A", LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, instructors);
696 
697         lectureAndLabFormatLabC.setId("CO-1:LEC-AND-LAB:" + labCode);
698 
699 
700         coService.createActivityOffering("CO-1:LEC-AND-LAB", canonicalActivityId, LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY, lectureAndLabFormatLabC, context);
701 
702 
703     }
704 
705 
706     protected void createCourseENG101(TermInfo term, boolean loadInstructors, ContextInfo context) throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException, DoesNotExistException, CircularRelationshipException, DependentObjectsExistException, UnsupportedActionException, DoesNotExistException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException {
707 
708         CourseInfo canonicalCourse = buildCanonicalCourse("CLU-2", term.getId(), "ENG", "ENG101", "Intro English", "Description of Intoroductory English");
709 
710         FormatInfo canonicalLectureOnlyFormat = buildCanonicalFormat("ENG101:LEC-ONLY", canonicalCourse);
711 
712         ActivityInfo canonicalLectureOnlyFormatLectureActivity = buildCanonicalActivity(LuServiceConstants.COURSE_ACTIVITY_LECTURE_TYPE_KEY, canonicalLectureOnlyFormat);
713 
714         courseService.createCourse(canonicalCourse, context);
715 
716         // create offerings
717         CourseOfferingInfo co = CourseOfferingServiceTestDataUtils.createCourseOffering(canonicalCourse, term.getId());
718 
719         co.setId("CO-2");
720 
721         coService.createCourseOffering(canonicalCourse.getId(), term.getId(), LuiServiceConstants.COURSE_OFFERING_TYPE_KEY, co, new ArrayList<String>(), context);
722 
723         // create format offering
724         // FO-1: lecture only format
725         FormatOfferingInfo fo1 = CourseOfferingServiceTestDataUtils.createFormatOffering(co.getId(), canonicalLectureOnlyFormat.getId(), term.getId(), "Lecture", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY);
726 
727         fo1.setId("CO-2:LEC-ONLY");
728 
729         coService.createFormatOffering(co.getId(), canonicalLectureOnlyFormat.getId(), LuiServiceConstants.FORMAT_OFFERING_TYPE_KEY, fo1, context);
730 
731         // create lecture activity
732         List<OfferingInstructorInfo> instructors = new ArrayList<OfferingInstructorInfo>();
733 
734         if(loadInstructors) {
735             instructors.add(CourseOfferingServiceTestDataUtils.createInstructor("p2", "Instructor", 100.00F));
736         }
737 
738         // Lecture A
739         ActivityOfferingInfo lectureOnlyFormatLectureA = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), co, fo1.getId(), null, canonicalLectureOnlyFormatLectureActivity.getId(), "Lecture", "A", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, instructors);
740 
741         lectureOnlyFormatLectureA.setId("CO-2:LEC-ONLY:LEC-A");
742 
743         coService.createActivityOffering(fo1.getId(), canonicalLectureOnlyFormatLectureActivity.getId(), LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, lectureOnlyFormatLectureA, context);
744 
745         // Lecture B
746         ActivityOfferingInfo lectureOnlyFormatLectureB = CourseOfferingServiceTestDataUtils.createActivityOffering(term.getId(), co, fo1.getId(), null, canonicalLectureOnlyFormatLectureActivity.getId(), "Lecture", "B", LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, instructors);
747 
748         lectureOnlyFormatLectureB.setId("CO-2:LEC-ONLY:LEC-B");
749 
750         coService.createActivityOffering(fo1.getId(), canonicalLectureOnlyFormatLectureActivity.getId(), LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, lectureOnlyFormatLectureB, context);
751 
752         // create a default cluster
753         List<ActivityOfferingInfo> activities = coService.getActivityOfferingsByFormatOffering("CO-2:LEC-ONLY", context);
754 
755         ActivityOfferingClusterInfo defaultAoc = CourseOfferingServiceTestDataUtils.createActivityOfferingCluster("CO-2:LEC-ONLY", "Default Cluster", activities);
756 
757         defaultAoc = coService.createActivityOfferingCluster("CO-2:LEC-ONLY", CourseOfferingServiceConstants.AOC_ROOT_TYPE_KEY, defaultAoc, context);
758 
759         // Create a Registration Group
760         coService.generateRegistrationGroupsForFormatOffering("CO-2:LEC-ONLY", context);
761 
762 
763     }
764 
765 
766   
767 
768 
769 
770    
771     private CourseInfo buildCanonicalCourse(String id, String startTermId, String subjectArea, String code, String title, String description) {
772         CourseInfo info = new CourseInfo();
773         info.setStartTerm(startTermId);
774         info.setEffectiveDate(calcEffectiveDateForTerm(startTermId, id));
775         info.setId(id);
776         info.setSubjectArea(subjectArea);
777         info.setCode(code);
778         info.setCourseNumberSuffix(code.substring(subjectArea.length()));
779         info.setCourseTitle(title);
780         RichTextInfo rt = new RichTextInfo();
781         rt.setPlain(description);
782         info.setDescr(rt);
783         info.setTypeKey(LuServiceConstants.CREDIT_COURSE_LU_TYPE_KEY);
784         info.setStateKey(DtoConstants.STATE_ACTIVE);
785         info.setFormats(new ArrayList<FormatInfo>());
786         ResultValuesGroupInfo rvg = new ResultValuesGroupInfo();
787         rvg.setKey(LrcServiceConstants.RESULT_GROUP_KEY_KUALI_CREDITTYPE_CREDIT_1_0);
788         info.getCreditOptions().add(rvg);
789         info.getGradingOptions().add(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_LETTER);
790         return info;
791     }
792 
793 
794     private ActivityInfo buildCanonicalActivity(String activityTypeKey, FormatInfo format) {
795 
796         ActivityInfo info = new ActivityInfo();
797         info.setId(CourseOfferingServiceTestDataUtils.createCanonicalActivityId(format.getId(), activityTypeKey));
798         info.setTypeKey(activityTypeKey);
799         info.setStateKey(DtoConstants.STATE_ACTIVE);
800 
801         format.getActivities().add(info);
802 
803         return info;
804 
805     }
806 
807     private FormatInfo buildCanonicalFormat(String formatId, CourseInfo course) {
808 
809         FormatInfo info = new FormatInfo();
810         info.setId(formatId);
811         info.setTypeKey(LuServiceConstants.COURSE_FORMAT_TYPE_KEY);
812         info.setStateKey(DtoConstants.STATE_ACTIVE);
813         info.setActivities(new ArrayList<ActivityInfo>());
814 
815         course.getFormats().add(info);
816 
817         return info;
818     }
819 
820     private Date calcEffectiveDateForTerm(String termId, String context) {
821         String year = termId.substring(0, 4);
822         String mmdd = "09-01";
823         if (termId.endsWith("FA")) {
824             mmdd = "09-01";
825         } else if (termId.endsWith("WI")) {
826             mmdd = "01-01";
827         } else if (termId.endsWith("SP")) {
828             mmdd = "03-01";
829         } else if (termId.endsWith("SU")) {
830             mmdd = "06-01";
831         }
832         return str2Date(year + "-" + mmdd + " 00:00:00.0", context);
833     }
834 
835     private Date str2Date(String str, String context) {
836         if (str == null) {
837             return null;
838         }
839         try {
840             Date date = DateFormatters.DEFAULT_YEAR_MONTH_24HOUR_MILLISECONDS_FORMATTER.parse(str);
841             return date;
842         } catch (IllegalArgumentException ex) {
843             throw new IllegalArgumentException("Bad date " + str + " in " + context);
844         }
845     }
846 
847     public TermInfo getFall2012() {
848         return fall2012;
849     }
850 
851     public void setFall2012(TermInfo fall2012) {
852         this.fall2012 = fall2012;
853     }
854 
855     public TermInfo getSpring2012() {
856         return spring2012;
857     }
858 
859     public void setSpring2012(TermInfo spring2012) {
860         this.spring2012 = spring2012;
861     }
862 
863 
864 
865     /**
866      * @param acalService the acalService to set
867      */
868     public void setAcalService(AcademicCalendarService acalService) {
869         this.acalService = acalService;
870     }
871 
872 
873     /**
874      * @param coService the coService to set
875      */
876     public void setCoService(CourseOfferingService coService) {
877         this.coService = coService;
878     }
879 
880 
881     /**
882      * @param courseService the courseService to set
883      */
884     public void setCourseService(CourseService courseService) {
885         this.courseService = courseService;
886     }
887 
888 
889     /**
890      * @param atpService the atpService to set
891      */
892     public void setAtpService(AtpService atpService) {
893         this.atpService = atpService;
894     }
895 
896     public StateService getStateService() {
897         return stateService;
898     }
899 
900     public void setStateService(StateService stateService) {
901         this.stateService = stateService;
902     }
903 
904     /**
905      * @param courseCodeGenerator the courseCodeGenerator to set
906      */
907     public void setCourseCodeGenerator(
908             CourseOfferingCodeGenerator courseCodeGenerator) {
909         this.courseCodeGenerator = courseCodeGenerator;
910     }
911 
912 
913     /**
914      * @param registrationGroupCodeGeneratorFactory the registrationGroupCodeGeneratorFactory to set
915      */
916     public void setRegistrationGroupCodeGeneratorFactory(
917             RegistrationGroupCodeGeneratorFactory registrationGroupCodeGeneratorFactory) {
918         this.registrationGroupCodeGeneratorFactory = registrationGroupCodeGeneratorFactory;
919     }
920 
921 
922     /**
923      * @param acalDataLoader the acalDataLoader to set
924      */
925     public void setAcalDataLoader(AcalTestDataLoader acalDataLoader) {
926         this.acalDataLoader = acalDataLoader;
927     }
928 
929 
930     /**
931      * If set to false then the base data will not be loaded.
932      * 
933      * @param loadBaseData the loadBaseData to set
934      */
935     public void setLoadBaseData(boolean loadBaseData) {
936         this.loadBaseData = loadBaseData;
937     }
938     
939     
940 
941     
942 }