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.enrollment.class2.bundledoffering.service.impl;
17  
18  
19  import org.kuali.student.common.test.mock.data.AbstractMockServicesAwareDataLoader;
20  import org.kuali.student.enrollment.bundledoffering.dto.BundledOfferingInfo;
21  import org.kuali.student.enrollment.bundledoffering.infc.BundledOffering;
22  import org.kuali.student.enrollment.bundledoffering.service.BundledOfferingService;
23  import org.kuali.student.enrollment.constants.BundledOfferingServiceConstants;
24  import org.kuali.student.r2.common.exceptions.DataValidationErrorException;
25  import org.kuali.student.r2.common.exceptions.DoesNotExistException;
26  import org.kuali.student.r2.common.exceptions.InvalidParameterException;
27  import org.kuali.student.r2.common.exceptions.MissingParameterException;
28  import org.kuali.student.r2.common.exceptions.OperationFailedException;
29  import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
30  import org.kuali.student.r2.common.exceptions.ReadOnlyException;
31  import org.kuali.student.r2.common.util.RichTextHelper;
32  
33  import javax.annotation.Resource;
34  import java.text.ParseException;
35  import java.util.ArrayList;
36  import java.util.List;
37  
38  public class BundledOfferingDataLoader extends AbstractMockServicesAwareDataLoader {
39  
40      public static final String BUNDLED_OFFERING_ACTIVE_STATE_KEY = "kuali.bundled.offering.state.bundled.offering.active";
41      public static final String BUNDLED_OFFERING_INACTIVE_STATE_KEY = "kuali.bundled.offering.state.bundled.offering.inactive";
42      public static final String BUNDLED_OFFERING_TYPE_KEY = "kuali.bundled.offering.type.bundled.offering";
43  
44      @Resource
45      private BundledOfferingService bundledOfferingService;
46  
47  
48      @Override
49      protected void initializeData() throws Exception {
50          createBundledOfferings();
51      }
52  
53  
54      public void createBundledOfferings() throws ParseException, DoesNotExistException, PermissionDeniedException,
55              OperationFailedException, InvalidParameterException, ReadOnlyException,
56              MissingParameterException, DataValidationErrorException {
57          for (int i = 0; i < 10; i++) {
58              BundledOfferingInfo bundledOffering = new BundledOfferingInfo();
59              bundledOffering.setStateKey(BUNDLED_OFFERING_ACTIVE_STATE_KEY);
60              bundledOffering.setTypeKey(BUNDLED_OFFERING_TYPE_KEY);
61              List<String> ids = new ArrayList<String>();
62              for(int j = 0; j <= i; j++) {
63                  ids.add(String.valueOf(j));
64              }
65              bundledOffering.setAdminOrgIds(ids);
66              bundledOffering.setBundledOfferingCode("BO_CODE" + i);
67              bundledOffering.setCourseBundleId("COURSE_BUNDLE" + i);
68              bundledOffering.setFormatOfferingIds(ids);
69              bundledOffering.setRegistrationGroupIds(ids);
70              bundledOffering.setBundledOfferingCodeSuffix("CODE_SUFFIX" + i);
71              bundledOffering.setName("NAME" + i);
72              bundledOffering.setDescr(RichTextHelper.buildRichTextInfo("PLAIN_DESCR" + i, "FORMATTED_DESCR" + i));
73              bundledOffering.setSubjectAreaOrgId("SUBJECT_AREA_ORG_ID" + i);
74              bundledOffering.setTermId(String.valueOf(i));
75  
76              bundledOfferingService.createBundledOffering(bundledOffering.getCourseBundleId(), bundledOffering.getTermId(), bundledOffering.getTypeKey(), bundledOffering, context);
77          }
78      }
79  }