View Javadoc
1   /**
2    * Copyright 2005-2016 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.rice.kew.actionlist;
17  
18  import java.util.ArrayList;
19  import java.util.Collections;
20  import java.util.List;
21  import org.kuali.rice.core.api.util.ConcreteKeyValue;
22  import org.kuali.rice.core.api.util.KeyValue;
23  import org.kuali.rice.kew.api.KewApiConstants;
24  import org.kuali.rice.kim.api.group.Group;
25  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
26  import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
27  import org.kuali.rice.krad.uif.view.ViewModel;
28  import org.kuali.rice.kew.actionlist.ActionListForm;
29  
30  public class UserWorkgroupsKeyValues extends UifKeyValuesFinderBase {
31  
32      private boolean blankOption;
33  
34  
35      @Override
36      public List<KeyValue> getKeyValues(ViewModel model) {
37          ActionListForm actionListForm = (ActionListForm)model;
38          List<String> userWorkgroups =
39                  KimApiServiceLocator.getGroupService().getGroupIdsByPrincipalId(actionListForm.getUser());
40  
41          //note that userWorkgroups is unmodifiable so we need to create a new list that we can sort
42          List<String> userGroupsToSort = new ArrayList<String>(userWorkgroups);
43  
44          List<KeyValue> sortedUserWorkgroups = new ArrayList<KeyValue>();
45          KeyValue keyValue = null;
46          keyValue = new ConcreteKeyValue(KewApiConstants.NO_FILTERING, KewApiConstants.NO_FILTERING);
47          sortedUserWorkgroups.add(keyValue);
48  
49          if (userGroupsToSort != null && userGroupsToSort.size() > 0) {
50              Collections.sort(userGroupsToSort);
51              Group group;
52  
53              for (String groupId : userGroupsToSort)
54              {
55                  group = KimApiServiceLocator.getGroupService().getGroup(groupId);
56                  keyValue = new ConcreteKeyValue(groupId, group.getName());
57                  sortedUserWorkgroups.add(keyValue);
58              }
59          }
60  
61          return sortedUserWorkgroups;
62      }
63  
64      /**
65       * @return the blankOption
66       */
67      public boolean isBlankOption() {
68          return this.blankOption;
69      }
70  
71      /**
72       * @param blankOption the blankOption to set
73       */
74      public void setBlankOption(boolean blankOption) {
75          this.blankOption = blankOption;
76      }
77  
78  //    private List<? extends KeyValue> getUserWorkgroupsDropDownList(String principalId) {
79  //        List<String> userWorkgroups =
80  //                KimApiServiceLocator.getGroupService().getGroupIdsByPrincipalId(principalId);
81  //
82  //        //note that userWorkgroups is unmodifiable so we need to create a new list that we can sort
83  //        List<String> userGroupsToSort = new ArrayList<String>(userWorkgroups);
84  //
85  //        List<KeyValue> sortedUserWorkgroups = new ArrayList<KeyValue>();
86  //        KeyValue keyValue = null;
87  //        keyValue = new ConcreteKeyValue(KewApiConstants.NO_FILTERING, KewApiConstants.NO_FILTERING);
88  //        sortedUserWorkgroups.add(keyValue);
89  //        if (userGroupsToSort != null && userGroupsToSort.size() > 0) {
90  //            Collections.sort(userGroupsToSort);
91  //
92  //            Group group;
93  //            for (String groupId : userGroupsToSort)
94  //            {
95  //                group = KimApiServiceLocator.getGroupService().getGroup(groupId);
96  //                keyValue = new ConcreteKeyValue(groupId, group.getName());
97  //                sortedUserWorkgroups.add(keyValue);
98  //            }
99  //        }
100 //        return sortedUserWorkgroups;
101 //    }
102 
103 
104 }