1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.kuali.student.enrollment.class2.population.keyvalue;
16
17 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
18 import org.kuali.rice.core.api.util.ConcreteKeyValue;
19 import org.kuali.rice.core.api.util.KeyValue;
20 import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
21 import org.kuali.rice.krad.uif.view.ViewModel;
22 import org.kuali.student.r2.common.util.ContextUtils;
23 import org.kuali.student.r2.core.constants.PopulationServiceConstants;
24 import org.kuali.student.r2.core.population.dto.PopulationRuleInfo;
25 import org.kuali.student.r2.core.population.service.PopulationService;
26
27 import javax.xml.namespace.QName;
28 import java.io.Serializable;
29 import java.util.ArrayList;
30 import java.util.List;
31
32
33
34
35
36
37 public class PopulationRuleAgendaKeyValues extends UifKeyValuesFinderBase implements Serializable {
38 private static final long serialVersionUID = 1L;
39
40 private transient PopulationService populationService = null;
41
42
43
44
45
46
47
48
49 @Override
50 public List<KeyValue> getKeyValues(ViewModel model) {
51
52 List<KeyValue> keyValues = new ArrayList<KeyValue>();
53
54
55 String ruleTypes[] = PopulationServiceConstants.POPULATION_RULE_TYPE_KEYS;
56
57
58 for (int j = 0; j < ruleTypes.length; j++) {
59 try {
60
61
62 ArrayList<String> populationRules = (ArrayList<String>) getPopulationService().getPopulationRuleIdsByType(ruleTypes[j], ContextUtils.createDefaultContextInfo());
63 for (int i = 0; i < populationRules.size(); i++) {
64 PopulationRuleInfo ruleInfo = getPopulationService().getPopulationRule(populationRules.get(i), ContextUtils.createDefaultContextInfo());
65 if (ruleInfo.getAgendaIds() != null && ruleInfo.getAgendaIds().size() > 0)
66 keyValues.add(new ConcreteKeyValue(ruleInfo.getAgendaIds().get(0), ruleInfo.getName()));
67 }
68
69 } catch (Exception e) {
70 throw new RuntimeException("Error getting PopulationRuleInfo", e);
71 }
72 }
73
74 return keyValues;
75 }
76
77
78
79
80
81
82 private PopulationService getPopulationService() {
83 if (populationService == null) {
84 populationService = (PopulationService) GlobalResourceLoader.getService(new QName(PopulationServiceConstants.NAMESPACE, "PopulationService"));
85 }
86 return this.populationService;
87 }
88 }