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 Adi Rajesh on 4/12/12
16   */
17  package org.kuali.student.enrollment.class2.appointment.keyvalue;
18  
19  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
20  import org.kuali.rice.core.api.util.ConcreteKeyValue;
21  import org.kuali.rice.core.api.util.KeyValue;
22  import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
23  import org.kuali.rice.krad.uif.view.ViewModel;
24  import org.kuali.student.r2.common.util.ContextUtils;
25  import org.kuali.student.r2.core.enumerationmanagement.dto.EnumeratedValueInfo;
26  import org.kuali.student.r2.core.enumerationmanagement.dto.EnumerationInfo;
27  import org.kuali.student.r2.core.enumerationmanagement.service.EnumerationManagementService;
28  
29  import org.kuali.student.mock.utilities.TestHelper;
30  import org.kuali.student.r2.common.constants.CommonServiceConstants;
31  import org.kuali.student.r2.common.dto.ContextInfo;
32  
33  import javax.xml.namespace.QName;
34  import java.io.Serializable;
35  import java.util.ArrayList;
36  import java.util.List;
37  
38  /**
39   * This class //TODO ...
40   *
41   * @author Kuali Student Team
42   */
43  public class SlotRuleForAppWindowKeyValuesFinder extends UifKeyValuesFinderBase implements Serializable {
44      private static final long serialVersionUID = 1L;
45      private transient EnumerationManagementService enumerationService;
46  
47      private String enumerationKey;
48  
49      private ContextInfo contextInfo;
50  
51      //this method returns the enumeration values as key value pairs to the UI for appoint rule type which is passed as enumerationKey to the
52      // enumeration management service.
53      @Override
54      public List<KeyValue> getKeyValues(ViewModel model) {
55  
56          List<KeyValue> keyValues = new ArrayList<KeyValue>();
57  
58          try {
59              List<EnumeratedValueInfo> slotRuleTypeCodes = getEnumerationService().getEnumeratedValues(getEnumerationKey(),null,null,null, this.getContextInfo());
60              if(slotRuleTypeCodes!=null)  {
61                  for (EnumeratedValueInfo slotRuleTypeCode : slotRuleTypeCodes) {
62                      ConcreteKeyValue keyValue = new ConcreteKeyValue();
63                      keyValue.setKey(slotRuleTypeCode.getValue());
64                      keyValue.setValue(slotRuleTypeCode.getAbbrevValue());
65                      keyValues.add(keyValue);
66                  }
67              }
68          } catch (Exception e) {
69              throw new RuntimeException(e);
70          }
71  
72          return keyValues;
73      }
74  
75      public String getEnumerationKey() {
76          return enumerationKey;
77      }
78  
79      public void setEnumerationKey(String enumerationKey){
80          this.enumerationKey = enumerationKey;
81      }
82  
83      //returns the enumerationmangement service
84      public EnumerationManagementService getEnumerationService() {
85          if(enumerationService == null) {
86              enumerationService = GlobalResourceLoader.getService(new QName(CommonServiceConstants.REF_OBJECT_URI_GLOBAL_PREFIX+"enumerationmanagement", "EnumerationManagementService"));
87          }
88          return this.enumerationService;
89      }
90  
91      public ContextInfo getContextInfo() {
92          if (contextInfo == null){
93              contextInfo = org.kuali.student.enrollment.common.util.ContextBuilder.loadContextInfo();
94          }
95          return contextInfo;
96      }
97  }