View Javadoc
1   /**
2    * Copyright 2014 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 delyea on 8/4/14
16   */
17  package org.kuali.student.lum.lu.ui.course.keyvalues;
18  
19  import org.kuali.rice.core.api.util.ConcreteKeyValue;
20  import org.kuali.rice.core.api.util.KeyValue;
21  import org.kuali.rice.kew.api.KewApiServiceLocator;
22  import org.kuali.rice.kew.api.document.WorkflowDocumentService;
23  import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
24  import org.kuali.rice.krad.uif.view.ViewModel;
25  import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  
29  import java.util.ArrayList;
30  import java.util.List;
31  
32  /**
33   * This class returns all the previous node names for a particular document in an ordered list. This
34   * class assumes the node list is sequential.
35   *
36   * @author Kuali Student Team
37   */
38  public class PreviousNodeNamesValuesFinder extends UifKeyValuesFinderBase {
39  
40      private static final Logger LOG = LoggerFactory.getLogger(PreviousNodeNamesValuesFinder.class);
41      private WorkflowDocumentService workflowDocumentService;
42  
43      @Override
44      public List<KeyValue> getKeyValues(ViewModel model) {
45          List<KeyValue> nodeNames = new ArrayList<KeyValue>();
46          final MaintenanceDocumentForm form = (MaintenanceDocumentForm) model;
47          // loop the node names from the workflow service to build the list
48          for (String nodeName : getWorkflowDocumentService().getPreviousRouteNodeNames(form.getDocument().getDocumentNumber())) {
49              // both the key and value should be set to the node name
50              nodeNames.add(new ConcreteKeyValue(nodeName, nodeName));
51          }
52          return nodeNames;
53      }
54  
55      public WorkflowDocumentService getWorkflowDocumentService() {
56          if (workflowDocumentService == null) {
57              workflowDocumentService = KewApiServiceLocator.getWorkflowDocumentService();
58          }
59          if (null == workflowDocumentService) {
60              throw new RuntimeException("Workflow Document Service is unavailable");
61          }
62          return workflowDocumentService;
63      }
64  
65  }