View Javadoc

1   package org.kuali.student.enrollment.class1.check.keyvalues;
2   
3   import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
4   import org.kuali.rice.core.api.util.ConcreteKeyValue;
5   import org.kuali.rice.core.api.util.KeyValue;
6   import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
7   import org.kuali.rice.krad.uif.view.ViewModel;
8   import org.kuali.student.mock.utilities.TestHelper;
9   import org.kuali.student.r2.common.dto.ContextInfo;
10  import org.kuali.student.r2.core.class1.state.dto.StateInfo;
11  import org.kuali.student.r2.core.class1.state.service.StateService;
12  import org.kuali.student.r2.core.constants.ProcessServiceConstants;
13  import org.kuali.student.r2.core.constants.StateServiceConstants;
14  
15  import javax.xml.namespace.QName;
16  import java.io.Serializable;
17  import java.util.ArrayList;
18  import java.util.List;
19  
20  /**
21   * This class does the lookups for the states associated with HoldIssueInfo's lifecycle
22   *
23   * @author Kuali Student Team
24   */
25  public class CheckInfoStateKeyValues extends UifKeyValuesFinderBase implements Serializable {
26  
27      private static final long serialVersionUID = 1L;
28  
29      private transient StateService stateService;
30  
31      @Override
32      public List<KeyValue> getKeyValues(ViewModel model) {
33          List<KeyValue> keyValues = new ArrayList<KeyValue>();
34  
35          //TODO:Build real context.
36          ContextInfo context = TestHelper.getContext1();
37  
38          try {
39              List<StateInfo> states = getStateService().getStatesByLifecycle(ProcessServiceConstants.CHECK_LIFECYCLE_KEY, context);
40              for (StateInfo state : states) {
41                  if(state.getKey().startsWith("kuali.process.check.state")) { //TODO remove check after data is fixed
42                      ConcreteKeyValue keyValue = new ConcreteKeyValue();
43                      keyValue.setKey(state.getKey());
44                      keyValue.setValue(state.getName());
45                      keyValues.add(keyValue);
46                  }
47              }
48          } catch (Exception e) {
49              throw new RuntimeException(e);
50          }
51          return keyValues;
52      }
53  
54      public KeyValue getStateKeyValue(String stateKey) {
55          ConcreteKeyValue keyValue = new ConcreteKeyValue();
56  
57          ContextInfo context = TestHelper.getContext1();
58  
59          try {
60              List<StateInfo> states = getStateService().getStatesByLifecycle(ProcessServiceConstants.CHECK_LIFECYCLE_KEY, context);
61              for (StateInfo state : states) {
62                  if(state.getKey().equals(stateKey)) { //TODO remove check after data is fixed
63                      keyValue.setKey(state.getKey());
64                      keyValue.setValue(state.getName());
65                  }
66              }
67          } catch (Exception e) {
68              throw new RuntimeException(e);
69          }
70          return keyValue;
71      }
72  
73      protected StateService getStateService() {
74          if(stateService == null) {
75              stateService = (StateService) GlobalResourceLoader.getService(new QName(StateServiceConstants.NAMESPACE, StateServiceConstants.SERVICE_NAME_LOCAL_PART));
76          }
77          return this.stateService;
78      }
79  }