Clover Coverage Report - Kuali Student 1.1-SNAPSHOT (Aggregated)
Coverage timestamp: Thu Mar 3 2011 04:02:59 EST
../../../../../../img/srcFileCovDistChart9.png 28% of files have more coverage
144   289   17   13.09
12   189   0.12   11
11     1.55  
1    
 
  NaturalLanguageUtil       Line # 40 144 0% 17 25 85% 0.8502994
 
  (24)
 
1    /**
2    * Copyright 2010 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   
16    package org.kuali.student.core.statement.naturallanguage;
17   
18    import java.util.ArrayList;
19    import java.util.Arrays;
20    import java.util.List;
21   
22    import org.kuali.student.core.statement.config.context.lu.MockCluInfo;
23    import org.kuali.student.core.statement.config.context.lu.MockCluSetInfo;
24    import org.kuali.student.core.statement.config.context.lu.CourseListContextImpl;
25    import org.kuali.student.core.statement.config.context.lu.GradeCheckContextImpl;
26    import org.kuali.student.core.statement.config.context.lu.CreditContextImpl;
27    import org.kuali.student.core.statement.dto.ReqComponentInfo;
28    import org.kuali.student.core.statement.dto.StatementOperatorTypeKey;
29    import org.kuali.student.core.statement.entity.ReqComponent;
30    import org.kuali.student.core.statement.entity.ReqComponentField;
31    import org.kuali.student.core.statement.entity.ReqComponentType;
32    import org.kuali.student.core.statement.entity.ReqComponentTypeNLTemplate;
33    import org.kuali.student.core.statement.entity.Statement;
34    import org.kuali.student.core.statement.entity.StatementType;
35    import org.kuali.student.core.statement.naturallanguage.ReqComponentFieldTypes;
36   
37    /**
38    * Utility class to support testing.
39    */
 
40    public class NaturalLanguageUtil {
41   
42    private final static List<MockCluInfo> cluList = new ArrayList<MockCluInfo>();
43    private final static List<MockCluSetInfo> cluSetList = new ArrayList<MockCluSetInfo>();
44   
 
45  11 toggle public static void createData() {
46  11 MockCluInfo clu1 = new MockCluInfo();
47  11 clu1.setId("CLU-NL-1");
48  11 clu1.setCode("MATH152");
49  11 clu1.setShortName("MATH 152");
50  11 clu1.setLongName("MATH 152 Linear Systems");
51  11 cluList.add(clu1);
52   
53  11 MockCluInfo clu2 = new MockCluInfo();
54  11 clu2.setId("CLU-NL-2");
55  11 clu2.setCode("MATH221");
56  11 clu2.setShortName("MATH 221");
57  11 clu2.setLongName("MATH 221 Matrix Algebra");
58  11 cluList.add(clu2);
59   
60  11 MockCluInfo clu3 = new MockCluInfo();
61  11 clu3.setId("CLU-NL-3");
62  11 clu3.setCode("MATH180");
63  11 clu3.setShortName("MATH 180");
64  11 clu3.setLongName("MATH 180 Differential Calculus with Physical Applications");
65  11 cluList.add(clu3);
66   
67  11 MockCluSetInfo cluSet1 = new MockCluSetInfo();
68  11 cluSet1.setId("CLUSET-NL-1");
69  11 cluSet1.setCluIds(Arrays.asList(new String[] {clu1.getId(), clu3.getId()}));
70  11 cluSet1.setCluList(Arrays.asList(new MockCluInfo[] {clu1, clu3}));
71  11 cluSetList.add(cluSet1);
72   
73  11 MockCluSetInfo cluSet2 = new MockCluSetInfo();
74  11 cluSet2.setId("CLUSET-NL-2");
75  11 cluSet2.setCluIds(Arrays.asList(new String[] {clu1.getId(), clu2.getId(), clu3.getId()}));
76  11 cluSet2.setCluList(Arrays.asList(new MockCluInfo[] {clu1, clu2, clu3}));
77  11 cluSetList.add(cluSet2);
78   
79  11 MockCluSetInfo cluSet3 = new MockCluSetInfo();
80  11 cluSet3.setId("CLUSET-NL-3");
81  11 cluSet3.setCluIds(Arrays.asList(new String[] {clu1.getId(), clu2.getId()}));
82  11 cluSet3.setCluList(Arrays.asList(new MockCluInfo[] {clu1, clu2}));
83  11 cluSetList.add(cluSet3);
84    }
85   
 
86  0 toggle public static ReqComponentType createReqComponentType(String reqComponentType) {
87  0 ReqComponentType reqCompType = new ReqComponentType();
88  0 reqCompType.setId(reqComponentType);
89  0 return reqCompType;
90    }
91   
 
92  37 toggle public static ReqComponentType createDefaultReqComponentType(String nlUsageTypeKey, String reqComponentType) {
93  37 ReqComponentType reqCompType = new ReqComponentType();
94  37 reqCompType.setId(reqComponentType);
95   
96  37 List<ReqComponentTypeNLTemplate> templateList = new ArrayList<ReqComponentTypeNLTemplate>();
97  37 ReqComponentTypeNLTemplate templateEn = new ReqComponentTypeNLTemplate();
98  37 templateEn.setLanguage("en");
99  37 templateEn.setNlUsageTypeKey(nlUsageTypeKey);
100   
101  37 ReqComponentTypeNLTemplate templateDe = new ReqComponentTypeNLTemplate();
102  37 templateDe.setLanguage("de");
103  37 templateDe.setNlUsageTypeKey(nlUsageTypeKey);
104   
105  37 if(reqComponentType.equals("kuali.reqComponent.type.courseList.nof")) {
106  31 templateEn.setTemplate("Student must have completed $expectedValue of $cluSet.getCluSetAsShortName()");
107  31 templateDe.setTemplate("Student muss abgeschlossen $expectedValue von $cluSet.getCluSetAsShortName()");
108  6 } else if(reqComponentType.equals("kuali.reqComponent.type.courseList.all")) {
109  2 templateEn.setTemplate("Student must have completed all of $cluSet.getCluSetAsShortName()");
110  2 templateDe.setTemplate("Student must have completed all of $cluSet.getCluSetAsShortName()");
111  4 } else if(reqComponentType.equals("kuali.reqComponent.type.courseList.none")) {
112  2 templateEn.setTemplate("Student must have completed none of $cluSet.getCluSetAsShortName()");
113  2 templateDe.setTemplate("Student must have completed none of $cluSet.getCluSetAsShortName()");
114  2 } else if(reqComponentType.equals("kuali.reqComponent.type.courseList.1of2")) {
115  0 templateEn.setTemplate("Student must have completed $cluSet.getCluAsShortName(0) or $cluSet.getCluAsShortName(1)");
116  0 templateDe.setTemplate("Student must have completed $cluSet.getCluAsShortName(0) or $cluSet.getCluAsShortName(1)");
117  2 } else if(reqComponentType.equals("kuali.reqComponent.type.grdCondCourseList")) {
118  1 templateEn.setTemplate("Students must take $totalCredits credits from $cluSet.getCluSetAsShortName()");
119  1 templateDe.setTemplate("Students must take $totalCredits credits from $cluSet.getCluSetAsShortName()");
120  1 } else if(reqComponentType.equals("kuali.reqComponent.type.gradecheck")) {
121  1 templateEn.setTemplate("Student needs a minimum GPA of $gpa");
122  1 templateDe.setTemplate("Student needs a minimum GPA of $gpa");
123    }
124   
125  37 templateList.add(templateEn);
126  37 templateList.add(templateDe);
127  37 reqCompType.setNlUsageTemplates(templateList);
128   
129  37 return reqCompType;
130    }
131   
 
132  37 toggle public static ReqComponent createReqComponent(String nlUsageTypeKey, String reqComponentType) throws Exception {
133  37 ReqComponent reqComponent = new ReqComponent();
134  37 ReqComponentType reqCompType = createDefaultReqComponentType(nlUsageTypeKey, reqComponentType);
135  37 reqComponent.setRequiredComponentType(reqCompType);
136  37 return reqComponent;
137    }
138   
 
139  0 toggle public static ReqComponent createReqComponent(String reqComponentType, List<ReqComponentField> fieldList) {
140  0 ReqComponentType reqCompType = createDefaultReqComponentType("KUALI.RULE", reqComponentType);
141   
142  0 ReqComponent reqComp = new ReqComponent();
143  0 reqComp.setReqComponentFields(fieldList);
144  0 reqComp.setRequiredComponentType(reqCompType);
145   
146  0 return reqComp;
147    }
148   
 
149  35 toggle public static List<ReqComponentField> createReqComponentFieldsForCluSet(String expectedValue, String operator, String target) {
150  35 List<ReqComponentField> fieldList = new ArrayList<ReqComponentField>();
151  35 ReqComponentField field1 = new ReqComponentField();
152  35 field1.setId("1");
153  35 field1.setType(ReqComponentFieldTypes.REQUIRED_COUNT_KEY.getType());
154  35 field1.setValue(expectedValue);
155  35 fieldList.add(field1);
156   
157  35 ReqComponentField field2 = new ReqComponentField();
158  35 field2.setId("2");
159  35 field2.setType(ReqComponentFieldTypes.OPERATOR_KEY.getType());
160  35 field2.setValue(operator);
161  35 fieldList.add(field2);
162   
163  35 ReqComponentField field3 = new ReqComponentField();
164  35 field3.setId("3");
165  35 field3.setType(ReqComponentFieldTypes.CLUSET_KEY.getType());
166  35 field3.setValue(target);
167  35 fieldList.add(field3);
168   
169  35 return fieldList;
170    }
171   
 
172  2 toggle public static List<ReqComponentField> createReqComponentFieldsForClu(String expectedValue, String operator, String cluIds) {
173  2 List<ReqComponentField> fieldList = new ArrayList<ReqComponentField>();
174  2 ReqComponentField field1 = new ReqComponentField();
175  2 field1.setId("4");
176  2 field1.setType(ReqComponentFieldTypes.REQUIRED_COUNT_KEY.getType());
177  2 field1.setValue(expectedValue);
178  2 fieldList.add(field1);
179   
180  2 ReqComponentField field2 = new ReqComponentField();
181  2 field2.setId("5");
182  2 field2.setType(ReqComponentFieldTypes.OPERATOR_KEY.getType());
183  2 field2.setValue(operator);
184  2 fieldList.add(field2);
185   
186  2 ReqComponentField field3 = new ReqComponentField();
187  2 field3.setId("6");
188  2 field3.setType(ReqComponentFieldTypes.CLU_KEY.getType());
189  2 field3.setValue(cluIds);
190  2 fieldList.add(field3);
191   
192  2 return fieldList;
193    }
194   
195    /*public static List<ReqComponentField> createReqComponentFields(String expectedValue, String operator, String reqCompFieldType, String id) {
196    List<ReqComponentField> fieldList = new ArrayList<ReqComponentField>();
197    ReqComponentField field1 = new ReqComponentField();
198    field1.setId("7");
199    field1.setType(ReqComponentFieldTypes.REQUIRED_COUNT_KEY.getType());
200    field1.setValue(expectedValue);
201    fieldList.add(field1);
202   
203    ReqComponentField field2 = new ReqComponentField();
204    field2.setId("8");
205    field2.setType(ReqComponentFieldTypes.OPERATOR_KEY.getType());
206    field2.setValue(operator);
207    fieldList.add(field2);
208   
209    ReqComponentField field3 = new ReqComponentField();
210    field3.setId("9");
211    field3.setType(reqCompFieldType);
212    field3.setValue(id);
213    fieldList.add(field3);
214   
215    return fieldList;
216    }*/
217   
 
218  8 toggle public static Statement createStatement(StatementOperatorTypeKey operator) throws Exception {
219  8 Statement stmt = new Statement();
220  8 stmt.setOperator(operator);
221  8 StatementType type = new StatementType();
222  8 type.setId("kuali.statement.type.course.academicReadiness.prereq");
223    //type.setStatementHeaders(createHeaders());
224  8 stmt.setStatementType(type);
225  8 return stmt;
226    }
227   
 
228  0 toggle public static Statement createLuStatementInfo(String id, StatementOperatorTypeKey operator) throws Exception {
229  0 Statement stmt = new Statement();
230  0 stmt.setId(id);
231  0 stmt.setOperator(operator);
232    // LuStatementTypeInfo type = new LuStatementTypeInfo();
233    // type.setId("kuali.statement.type.course.academicReadiness.prereq");
234    // type.setHeaders(createHeaders());
235  0 StatementType type = createLuStatementTypeInfo("kuali.statement.type.course.academicReadiness.prereq");
236  0 stmt.setStatementType(type);
237  0 return stmt;
238    }
239   
 
240  0 toggle public static StatementType createLuStatementTypeInfo(String id) throws Exception {
241  0 StatementType type = new StatementType();
242  0 type.setId(id);
243    //type.setStatementHeaders(createHeaders());
244  0 return type;
245    }
246   
247    // public static List<StatementTypeHeaderTemplate> createHeaders() {
248    // List<StatementTypeHeaderTemplate> headerList = new ArrayList<StatementTypeHeaderTemplate>();
249    // StatementTypeHeaderTemplate header1 = new StatementTypeHeaderTemplate();
250    // header1.setLanguage("en");
251    // header1.setNlUsageTypeKey("KUALI.RULE");
252    // header1.setTemplate("Requirement for $clu.getOfficialIdentifier().getLongName(): ");
253    // headerList.add(header1);
254    // StatementTypeHeaderTemplate header2 = new StatementTypeHeaderTemplate();
255    // header2.setLanguage("de");
256    // header2.setNlUsageTypeKey("KUALI.RULE");
257    // header2.setTemplate("Voraussetzung fur die $clu.getOfficialIdentifier().getLongName(): ");
258    // headerList.add(header2);
259    //
260    // return headerList;
261    // }
262   
 
263  11 toggle public static ContextRegistry<Context<ReqComponentInfo>> getReqComponentContextRegistry() {
264  11 ContextRegistry<Context<ReqComponentInfo>> contextRegistry = new ContextRegistry<Context<ReqComponentInfo>>();
265   
266  11 createData();
267  11 CourseListContextImpl.setCluInfo(cluList);
268  11 CourseListContextImpl.setCluSetInfo(cluSetList);
269  11 CourseListContextImpl courseListContext = new CourseListContextImpl();
270   
271  11 contextRegistry.add("kuali.reqComponent.type.courseList.none", courseListContext);
272  11 contextRegistry.add("kuali.reqComponent.type.courseList.all", courseListContext);
273  11 contextRegistry.add("kuali.reqComponent.type.courseList.nof", courseListContext);
274  11 contextRegistry.add("kuali.reqComponent.type.courseList.1of2", courseListContext);
275   
276  11 CreditContextImpl.setCluInfo(cluList);
277  11 CreditContextImpl.setCluSetInfo(cluSetList);
278  11 CreditContextImpl gradeConditionCourseListContext = new CreditContextImpl();
279  11 contextRegistry.add("kuali.reqComponent.type.grdCondCourseList", gradeConditionCourseListContext);
280  11 contextRegistry.add("kuali.reqComponent.type.grdCondCourseList", courseListContext);
281   
282  11 GradeCheckContextImpl.setCluInfo(cluList);
283  11 GradeCheckContextImpl.setCluSetInfo(cluSetList);
284  11 GradeCheckContextImpl gradeCheckContext = new GradeCheckContextImpl();
285  11 contextRegistry.add("kuali.reqComponent.type.gradecheck", gradeCheckContext);
286   
287  11 return contextRegistry;
288    }
289    }