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