View Javadoc

1   /**
2    * Copyright 2012 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   *
15   * Created by mharmath on 12/20/12
16   */
17  package org.kuali.student.lum.lrc.service.util;
18  
19  import org.kuali.student.common.test.mock.data.AbstractMockServicesAwareDataLoader;
20  import org.kuali.student.r2.common.dto.ContextInfo;
21  import org.kuali.student.r2.common.util.RichTextHelper;
22  import org.kuali.student.r2.lum.lrc.dto.ResultValueRangeInfo;
23  import org.kuali.student.r2.lum.lrc.dto.ResultValuesGroupInfo;
24  import org.kuali.student.r2.lum.lrc.infc.ResultValueRange;
25  import org.kuali.student.r2.lum.lrc.service.LRCService;
26  
27  import java.text.DateFormat;
28  import java.text.ParseException;
29  import java.text.SimpleDateFormat;
30  import java.util.Date;
31  
32  /**
33   * This class //TODO ...
34   *
35   * @author Kuali Student Team
36   */
37  public class MockLrcTestDataLoader  {
38  
39      private LRCService lrcService;
40      private static String principalId = MockLrcTestDataLoader.class.getSimpleName();
41  
42      public LRCService getLrcService() {
43          return lrcService;
44      }
45  
46      public void setLrcService(LRCService lrcService) {
47          this.lrcService = lrcService;
48      }
49  
50      public MockLrcTestDataLoader(LRCService lrcService) {
51          this.lrcService = lrcService;
52      }
53  
54      public void loadData() {
55          loadResultValuesGroupInfo("kuali.creditType.credit.degree.1.0", "kuali.result.values.group.type.fixed", "kuali.result.values.group.state.approved", "1 Credit", "1 Academic Credit", "kuali.result.scale.credit.degree", "1", "1");
56          loadResultValuesGroupInfo("kuali.creditType.credit.degree.2.0", "kuali.result.values.group.type.fixed", "kuali.result.values.group.state.approved", "1 Credit", "1 Academic Credit", "kuali.result.scale.credit.degree", "1", "1");
57      }
58  
59      public void loadResultValuesGroupInfo(String id, String type, String state, String name, String description, String resultScaleKey, String maxValue, String minValue) {
60  
61          ResultValuesGroupInfo info = new ResultValuesGroupInfo();
62          ResultValueRangeInfo resultValueRange = new ResultValueRangeInfo();
63          ContextInfo context = new ContextInfo();
64          context.setPrincipalId(principalId);
65          context.setCurrentDate(new Date());
66          info.setKey(id);
67          info.setTypeKey(type);// use id for code
68          info.setStateKey(state);
69          info.setName(name);
70          info.setDescr(new RichTextHelper().fromPlain(description));
71          info.setResultScaleKey(resultScaleKey);
72          resultValueRange.setMaxValue(maxValue);
73          resultValueRange.setMinValue(minValue);
74          info.setResultValueRange(resultValueRange);
75          boolean dataExists = true;
76          try {
77              lrcService.deleteResultValuesGroup(id,context);
78  //            lrcService.getResultValuesGroup(id,context);
79          } catch (Exception e) {
80              dataExists = true;
81          }
82          try {
83              if (dataExists) {
84                  lrcService.createResultValuesGroup(resultScaleKey, id, info, context);
85              }
86          } catch (Exception e) {
87              throw new RuntimeException("error assigning to services: "+e);
88          }
89      }
90  
91  }