001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.kew.actionlist; 017 018import java.util.ArrayList; 019import java.util.Collections; 020import java.util.List; 021import org.kuali.rice.core.api.util.ConcreteKeyValue; 022import org.kuali.rice.core.api.util.KeyValue; 023import org.kuali.rice.kew.api.KewApiConstants; 024import org.kuali.rice.kim.api.group.Group; 025import org.kuali.rice.kim.api.services.KimApiServiceLocator; 026import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase; 027import org.kuali.rice.krad.uif.view.ViewModel; 028import org.kuali.rice.kew.actionlist.ActionListForm; 029 030public class UserWorkgroupsKeyValues extends UifKeyValuesFinderBase { 031 032 private boolean blankOption; 033 034 035 @Override 036 public List<KeyValue> getKeyValues(ViewModel model) { 037 ActionListForm actionListForm = (ActionListForm)model; 038 List<String> userWorkgroups = 039 KimApiServiceLocator.getGroupService().getGroupIdsByPrincipalId(actionListForm.getUser()); 040 041 //note that userWorkgroups is unmodifiable so we need to create a new list that we can sort 042 List<String> userGroupsToSort = new ArrayList<String>(userWorkgroups); 043 044 List<KeyValue> sortedUserWorkgroups = new ArrayList<KeyValue>(); 045 KeyValue keyValue = null; 046 keyValue = new ConcreteKeyValue(KewApiConstants.NO_FILTERING, KewApiConstants.NO_FILTERING); 047 sortedUserWorkgroups.add(keyValue); 048 049 if (userGroupsToSort != null && userGroupsToSort.size() > 0) { 050 Collections.sort(userGroupsToSort); 051 Group group; 052 053 for (String groupId : userGroupsToSort) 054 { 055 group = KimApiServiceLocator.getGroupService().getGroup(groupId); 056 keyValue = new ConcreteKeyValue(groupId, group.getName()); 057 sortedUserWorkgroups.add(keyValue); 058 } 059 } 060 061 return sortedUserWorkgroups; 062 } 063 064 /** 065 * @return the blankOption 066 */ 067 public boolean isBlankOption() { 068 return this.blankOption; 069 } 070 071 /** 072 * @param blankOption the blankOption to set 073 */ 074 public void setBlankOption(boolean blankOption) { 075 this.blankOption = blankOption; 076 } 077 078// private List<? extends KeyValue> getUserWorkgroupsDropDownList(String principalId) { 079// List<String> userWorkgroups = 080// KimApiServiceLocator.getGroupService().getGroupIdsByPrincipalId(principalId); 081// 082// //note that userWorkgroups is unmodifiable so we need to create a new list that we can sort 083// List<String> userGroupsToSort = new ArrayList<String>(userWorkgroups); 084// 085// List<KeyValue> sortedUserWorkgroups = new ArrayList<KeyValue>(); 086// KeyValue keyValue = null; 087// keyValue = new ConcreteKeyValue(KewApiConstants.NO_FILTERING, KewApiConstants.NO_FILTERING); 088// sortedUserWorkgroups.add(keyValue); 089// if (userGroupsToSort != null && userGroupsToSort.size() > 0) { 090// Collections.sort(userGroupsToSort); 091// 092// Group group; 093// for (String groupId : userGroupsToSort) 094// { 095// group = KimApiServiceLocator.getGroupService().getGroup(groupId); 096// keyValue = new ConcreteKeyValue(groupId, group.getName()); 097// sortedUserWorkgroups.add(keyValue); 098// } 099// } 100// return sortedUserWorkgroups; 101// } 102 103 104}