View Javadoc
1   /**
2    * Copyright 2005-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.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License 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.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   * This class created values for the term droplist in krms ui.
41   *
42   * @author Kuali Student Team
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