/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2019 Lachlan Dowding
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package permafrost.tundra.server;

import com.wm.app.b2b.server.InvokeState;
import com.wm.app.b2b.server.User;
import com.wm.app.b2b.server.UserManager;

/**
 * Convenience methods for working with Integration Server user objects.
 */
public class UserHelper {
    /**
     * Disallow instantiation of this class.
     */
    private UserHelper() {}

    /**
     * Returns the user associated with the given name.
     *
     * @param name  The name of the user.
     * @return      The user associated with the given name.
     */
    public static User get(String name) {
        return UserManager.getUser(name);
    }

    /**
     * Returns the current user, or null if there is no current user.
     *
     * @return the current user, or null if there is no current user.
     */
    public static User getCurrent() {
        User currentUser = null;
        InvokeState currentState = InvokeState.getCurrentState();
        if (currentState != null) {
            currentUser = currentState.getUser();
        }

        return currentUser;
    }

    /**
     * Returns the current user name, or null if there is no current user.
     *
     * @return the current user name, or null if there is no current user.
     */
    public static String getCurrentName() {
        String currentName = null;
        User currentUser = getCurrent();

        if (currentUser != null) {
            currentName = currentUser.getName();
        }

        return currentName;
    }
}

@@ -1295,16 +1295,129 @@
 Manager;
+%0Aimport java.util.Comparator;%0Aimport java.util.Enumeration;%0Aimport java.util.SortedSet;%0Aimport java.util.TreeSet;
 %0A%0A/**%0A *
@@ -2734,11 +2734,1267 @@
 e;%0A    %7D
+%0A%0A    /**%0A     * Returns the list of all users defined on this Integration Server.%0A     *%0A     * @return The list of all users defined on this Integration Server.%0A     */%0A    public static User%5B%5D list() %7B%0A        Enumeration enumeration = UserManager.listUsers(true);%0A        SortedSet%3CUser%3E set = new TreeSet%3CUser%3E(new UserComparator());%0A        while(enumeration.hasMoreElements()) %7B%0A            Object element = enumeration.nextElement();%0A            if (element instanceof String) %7B%0A                User user = get((String)element);%0A                if (user != null) %7B%0A                    set.add(user);%0A                %7D%0A            %7D%0A        %7D%0A        return set.toArray(new User%5B0%5D);%0A    %7D%0A%0A    /**%0A     * Compares instance of User class.%0A     */%0A    private static class UserComparator implements Comparator%3CUser%3E %7B%0A        /**%0A         * Compares two instances of the User class.%0A         *%0A         * @param thisUser  The first object to be compared.%0A         * @param otherUser The second object to be compared.%0A         * @return          The result of the comparison.%0A         */%0A        @Override%0A        public int compare(User thisUser, User otherUser) %7B%0A            return thisUser.getName().compareTo(otherUser.getName());%0A        %7D%0A    %7D
 %0A%7D%0A

Add UserHelper.list() method to return a list of all IS users