1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.enrollment.class1.krms.keyvalue;
17
18 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
19 import org.kuali.rice.core.api.util.ConcreteKeyValue;
20 import org.kuali.rice.core.api.util.KeyValue;
21 import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
22 import org.kuali.rice.krad.uif.view.ViewModel;
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.common.util.security.ContextUtils;
29 import org.kuali.student.r2.core.class1.type.dto.TypeInfo;
30 import org.kuali.student.r2.core.class1.type.service.TypeService;
31 import org.kuali.student.r2.core.constants.AtpServiceConstants;
32 import org.kuali.student.r2.core.constants.TypeServiceConstants;
33
34 import javax.xml.namespace.QName;
35 import java.io.Serializable;
36 import java.util.ArrayList;
37 import java.util.List;
38
39
40
41
42
43
44 public class TermKeyValueFinder extends UifKeyValuesFinderBase implements Serializable {
45
46 private static final long serialVersionUID = 1L;
47
48 private transient TypeService typeService;
49
50 @Override
51 public List<KeyValue> getKeyValues(ViewModel model) {
52
53 List<KeyValue> keyValues = new ArrayList<KeyValue>();
54 try {
55
56 keyValues.add(new ConcreteKeyValue("", "Select Term Type"));
57
58 for (TypeInfo type : getAcalTermTypes()) {
59
60 ConcreteKeyValue keyValue = new ConcreteKeyValue();
61 keyValue.setKey(type.getKey());
62 keyValue.setValue(type.getName());
63 keyValues.add(keyValue);
64 }
65
66 } catch (Exception e) {
67 throw new RuntimeException("Error getting term key values.", e);
68 }
69
70 return keyValues;
71 }
72
73 private List<TypeInfo> getAcalTermTypes() throws InvalidParameterException, MissingParameterException, DoesNotExistException, PermissionDeniedException, OperationFailedException {
74 return getTypeService().getTypesForGroupType(AtpServiceConstants.ATP_TERM_GROUPING_TYPE_KEY, ContextUtils.createDefaultContextInfo());
75 }
76
77 public TypeService getTypeService() {
78 if (typeService == null) {
79 typeService = (TypeService) GlobalResourceLoader.getService(new QName(TypeServiceConstants.NAMESPACE, TypeServiceConstants.SERVICE_NAME_LOCAL_PART));
80 }
81 return this.typeService;
82 }
83
84 }
85