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