/**
 * hub-common
 *
 * Copyright (C) 2018 Black Duck Software, Inc.
 * http://www.blackducksoftware.com/
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package com.blackducksoftware.integration.hub.service;

import java.util.ArrayList;
import java.util.List;

import com.blackducksoftware.integration.exception.IntegrationException;
import com.blackducksoftware.integration.hub.api.generated.discovery.ApiDiscovery;
import com.blackducksoftware.integration.hub.api.generated.response.AssignedProjectView;
import com.blackducksoftware.integration.hub.api.generated.view.ProjectView;
import com.blackducksoftware.integration.hub.api.generated.view.RoleAssignmentView;
import com.blackducksoftware.integration.hub.api.generated.view.UserGroupView;
import com.blackducksoftware.integration.hub.api.generated.view.UserView;
import com.blackducksoftware.integration.hub.exception.DoesNotExistException;
import com.blackducksoftware.integration.log.IntLogger;

public class UserGroupService {
    private final IntLogger logger;
    private final HubService hubService;

    public UserGroupService(final HubService hubService, final IntLogger logger) {
        this.logger = logger;
        this.hubService = hubService;
    }

    public UserView getUserByUserName(final String userName) throws IntegrationException {
        final List<UserView> allUsers = hubService.getAllResponses(ApiDiscovery.USERS_LINK_RESPONSE);
        for (final UserView user : allUsers) {
            if (user.userName.equalsIgnoreCase(userName)) {
                return user;
            }
        }
        throw new DoesNotExistException("This User does not exist. UserName : " + userName);
    }

    public List<ProjectView> getProjectsForUser(final String userName) throws IntegrationException {
        final UserView user = getUserByUserName(userName);
        return getProjectsForUser(user);
    }

    public List<ProjectView> getProjectsForUser(final UserView userView) throws IntegrationException {
        logger.debug("Attempting to get the assigned projects for User: " + userView.userName);
        final List<AssignedProjectView> assignedProjectViews = hubService.getAllResponses(userView, UserView.PROJECTS_LINK_RESPONSE);

        final List<ProjectView> resolvedProjectViews = new ArrayList<>();
        for (final AssignedProjectView assigned : assignedProjectViews) {
            final ProjectView project = hubService.getResponse(assigned.project, ProjectView.class);
            if (project != null) {
                resolvedProjectViews.add(project);
            }
        }

        return resolvedProjectViews;
    }

    public List<RoleAssignmentView> getRolesForUser(final String userName) throws IntegrationException {
        final UserView user = getUserByUserName(userName);
        return getRolesForUser(user);
    }

    public List<RoleAssignmentView> getRolesForUser(final UserView userView) throws IntegrationException {
        return hubService.getAllResponses(userView, UserView.ROLES_LINK_RESPONSE);
    }

    public UserGroupView getGroupByName(final String groupName) throws IntegrationException {
        final List<UserGroupView> allGroups = hubService.getAllResponses(ApiDiscovery.USERGROUPS_LINK_RESPONSE);
        for (final UserGroupView group : allGroups) {
            if (group.name.equalsIgnoreCase(groupName)) {
                return group;
            }
        }
        throw new DoesNotExistException("This Group does not exist. Group name : " + groupName);
    }

}

@@ -1004,18 +1004,108 @@
 .util.Li
+nkedHashSet;%0Aimport java.util.List;%0Aimport java.util.Set;%0Aimport java.util.stream.Collector
 s
-t
 ;%0A%0Aimpor
@@ -3858,32 +3858,1045 @@
 SPONSE);%0A    %7D%0A%0A
+    public List%3CRoleAssignmentView%3E getInheritedRolesForUser(final String userName) throws IntegrationException %7B%0A        final UserView user = getUserByUserName(userName);%0A        return getInheritedRolesForUser(user);%0A    %7D%0A%0A    public List%3CRoleAssignmentView%3E getInheritedRolesForUser(final UserView userView) throws IntegrationException %7B%0A        return hubService.getAllResponses(userView, UserView.INHERITED_ROLES_LINK_RESPONSE);%0A    %7D%0A%0A    public List%3CRoleAssignmentView%3E getAllRolesForUser(final String userName) throws IntegrationException %7B%0A        final UserView user = getUserByUserName(userName);%0A        return getAllRolesForUser(user);%0A    %7D%0A%0A    public List%3CRoleAssignmentView%3E getAllRolesForUser(final UserView userView) throws IntegrationException %7B%0A        Set%3CRoleAssignmentView%3E roleSet = new LinkedHashSet%3C%3E();%0A        roleSet.addAll(getRolesForUser(userView));%0A        roleSet.addAll(getInheritedRolesForUser(userView));%0A        return roleSet.stream().collect(Collectors.toList());%0A    %7D%0A%0A
     public UserG

Add methods to get inherited roles for the user groups