View Javadoc
1   /*
2    * Copyright 2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * 	http://www.osedu.org/licenses/ECL-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the Lic+ense 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.r2.lum.coursebundle.service.impl;
17  
18  
19  import org.kuali.student.common.test.mock.data.AbstractMockServicesAwareDataLoader;
20  import org.kuali.student.lum.coursebundle.dto.CourseBundleInfo;
21  import org.kuali.student.lum.coursebundle.service.CourseBundleService;
22  import org.kuali.student.r2.common.exceptions.DataValidationErrorException;
23  import org.kuali.student.r2.common.exceptions.DoesNotExistException;
24  import org.kuali.student.r2.common.exceptions.InvalidParameterException;
25  import org.kuali.student.r2.common.exceptions.MissingParameterException;
26  import org.kuali.student.r2.common.exceptions.OperationFailedException;
27  import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
28  import org.kuali.student.r2.common.exceptions.ReadOnlyException;
29  import org.kuali.student.r2.common.util.RichTextHelper;
30  
31  import javax.annotation.Resource;
32  import java.text.ParseException;
33  import java.text.SimpleDateFormat;
34  import java.util.ArrayList;
35  import java.util.List;
36  
37  public class CourseBundleDataLoader extends AbstractMockServicesAwareDataLoader {
38  
39      public static final String COURSE_BUNDLE_ACTIVE_STATE_KEY = "kuali.course.bundle.state.course.bundle.active";
40      public static final String COURSE_BUNDLE_INACTIVE_STATE_KEY = "kuali.course.bundle.state.course.bundle.inactive";
41      public static final String COURSE_BUNDLE_TYPE_KEY = "kuali.course.bundle.type.course.bundle";
42  
43      private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
44  
45      @Resource
46      private CourseBundleService courseBundleService;
47  
48  
49      @Override
50      protected void initializeData() throws Exception {
51          createCourseBundles();
52      }
53  
54  
55      public void createCourseBundles() throws ParseException, DoesNotExistException, PermissionDeniedException,
56              OperationFailedException, InvalidParameterException, ReadOnlyException,
57              MissingParameterException, DataValidationErrorException {
58          for (int i = 0; i < 10; i++) {
59              CourseBundleInfo courseBundleInfo = new CourseBundleInfo();
60              courseBundleInfo.setStateKey(COURSE_BUNDLE_ACTIVE_STATE_KEY);
61              courseBundleInfo.setTypeKey(COURSE_BUNDLE_TYPE_KEY);
62              List<String> ids = new ArrayList<String>();
63              for(int j = 0; j <= i; j++) {
64                  ids.add(String.valueOf(j));
65              }
66              courseBundleInfo.setAdminOrgIds(ids);
67              courseBundleInfo.setName("NAME" + i);
68              courseBundleInfo.setDescr(RichTextHelper.buildRichTextInfo("PLAIN_DESCR" + i, "FORMATTED_DESCR" + i));
69              courseBundleInfo.setSubjectAreaOrgId("SUBJECT_AREA_ORG_ID" + i);
70              courseBundleInfo.setCourseBundleCode("CB_CODE" + i);
71              courseBundleInfo.setCourseBundleCodeSuffix("CODE_SUFFIX" + i);
72              courseBundleInfo.setCourseIds(ids);
73              courseBundleInfo.setEndTermId(String.valueOf(i + 1));
74              courseBundleInfo.setStartTermId(String.valueOf(i));
75              courseBundleInfo.setEffectiveDate(dateFormat.parse("20130611"));
76              courseBundleInfo.setExpirationDate(dateFormat.parse("20500101"));
77  
78              courseBundleService.createCourseBundle(courseBundleInfo.getTypeKey(), courseBundleInfo, context);
79          }
80      }
81  }