001    /**
002     * Copyright 2005-2015 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     */
016    package org.kuali.rice.kew.actionlist.web;
017    
018    import java.util.ArrayList;
019    import java.util.Collection;
020    import java.util.Collections;
021    import java.util.Comparator;
022    import java.util.List;
023    
024    import org.apache.commons.collections.comparators.ComparableComparator;
025    import org.kuali.rice.kew.actionrequest.Recipient;
026    import org.kuali.rice.kew.util.WebFriendlyRecipient;
027    
028    /**
029     * Internal Utility class for Action Lists.
030     * 
031     * @author Kuali Rice Team (rice.collab@kuali.org)
032     *
033     */
034    public final class ActionListUtil {
035            
036            private ActionListUtil() {
037                    throw new UnsupportedOperationException("do not call");
038            }
039    
040        /**
041         * Converts a collection of Recipients into a collection of WebFriendlyRecipients which can be displayed in the UI
042         * @param recipients recipients to convert
043         * @return a collection of WebFriendlyRecipients which can be displayed in the UI
044         */
045        public static List<WebFriendlyRecipient> getWebFriendlyRecipients(Collection<Recipient> recipients) {
046            Collection<WebFriendlyRecipient> newRecipients = new ArrayList<WebFriendlyRecipient>(recipients.size());
047            for (Recipient recipient : recipients) {
048                newRecipients.add(new WebFriendlyRecipient(recipient));
049            }
050            List<WebFriendlyRecipient> recipientList = new ArrayList<WebFriendlyRecipient>(newRecipients);
051            Collections.sort(recipientList, new Comparator<WebFriendlyRecipient>() {
052                Comparator<String> comp = new ComparableComparator();
053    
054                @Override
055                            public int compare(WebFriendlyRecipient o1, WebFriendlyRecipient o2) {
056                    return comp.compare(o1.getDisplayName().trim().toLowerCase(), o2.getDisplayName().trim().toLowerCase());
057                }
058            });
059            return recipientList;
060        }
061    }