Search in sources :

Example 1 with AssignedUserView

use of com.synopsys.integration.blackduck.api.manual.temporary.view.AssignedUserView in project blackduck-common by blackducksoftware.

the class ProjectAssignmentServiceTestIT method testGetAssignedUsersFromProjectView.

@Test
public void testGetAssignedUsersFromProjectView() throws IllegalArgumentException, IntegrationException {
    Long timestamp = (new Date()).getTime();
    String testProjectName = "hub-common-it-ProjectAssignmentServiceTest-" + timestamp;
    ProjectRequest projectRequest = new ProjectRequest();
    projectRequest.setName(testProjectName);
    ProjectVersionWrapper projectVersionWrapper = ProjectAssignmentServiceTestIT.blackDuckServicesFactory.createProjectService().createProject(projectRequest);
    ProjectAssignmentServiceTestIT.project = projectVersionWrapper.getProjectView();
    System.out.println("projectUrl: " + ProjectAssignmentServiceTestIT.project.getHref());
    List<AssignedUserView> assignedUsers = ProjectAssignmentServiceTestIT.blackDuckServicesFactory.createProjectUsersService().getAssignedUsersToProject(ProjectAssignmentServiceTestIT.project);
    assertFalse(assignedUsers.isEmpty());
    assertEquals(1, assignedUsers.size());
    assertEquals("sysadmin", assignedUsers.get(0).getName());
}
Also used : ProjectRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectRequest) AssignedUserView(com.synopsys.integration.blackduck.api.manual.temporary.view.AssignedUserView) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 2 with AssignedUserView

use of com.synopsys.integration.blackduck.api.manual.temporary.view.AssignedUserView in project blackduck-common by blackducksoftware.

the class ProjectUsersService method getAllActiveUsersForProject.

/**
 * This will get all explicitly assigned users for a project, as well as all users who are assigned to groups that are explicitly assigned to a project.
 */
public Set<UserView> getAllActiveUsersForProject(ProjectView projectView) throws IntegrationException {
    Set<UserView> users = new HashSet<>();
    List<AssignedUserGroupView> assignedGroups = getAssignedGroupsToProject(projectView);
    for (AssignedUserGroupView assignedUserGroupView : assignedGroups) {
        if (assignedUserGroupView.getActive()) {
            HttpUrl groupUrl = new HttpUrl(assignedUserGroupView.getGroup());
            UserGroupView userGroupView = blackDuckApiClient.getResponse(groupUrl, UserGroupView.class);
            if (userGroupView.getActive()) {
                List<UserView> groupUsers = blackDuckApiClient.getAllResponses(userGroupView.metaUsersLink());
                users.addAll(groupUsers);
            }
        }
    }
    List<AssignedUserView> assignedUsers = getAssignedUsersToProject(projectView);
    for (AssignedUserView assignedUser : assignedUsers) {
        HttpUrl userUrl = new HttpUrl(assignedUser.getUser());
        UserView userView = blackDuckApiClient.getResponse(userUrl, UserView.class);
        users.add(userView);
    }
    return users.stream().filter(UserView::getActive).collect(Collectors.toSet());
}
Also used : UserGroupView(com.synopsys.integration.blackduck.api.generated.view.UserGroupView) AssignedUserGroupView(com.synopsys.integration.blackduck.api.manual.temporary.response.AssignedUserGroupView) AssignedUserGroupView(com.synopsys.integration.blackduck.api.manual.temporary.response.AssignedUserGroupView) AssignedUserView(com.synopsys.integration.blackduck.api.manual.temporary.view.AssignedUserView) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) AssignedUserView(com.synopsys.integration.blackduck.api.manual.temporary.view.AssignedUserView) HttpUrl(com.synopsys.integration.rest.HttpUrl) HashSet(java.util.HashSet)

Example 3 with AssignedUserView

use of com.synopsys.integration.blackduck.api.manual.temporary.view.AssignedUserView in project blackduck-common by blackducksoftware.

the class ProjectUsersService method getUsersForProject.

public List<UserView> getUsersForProject(ProjectView project) throws IntegrationException {
    logger.debug("Attempting to get the assigned users for Project: " + project.getName());
    List<AssignedUserView> assignedUsers = getAssignedUsersToProject(project);
    List<UserView> resolvedUserViews = new ArrayList<>();
    for (AssignedUserView assigned : assignedUsers) {
        HttpUrl userUrl = new HttpUrl(assigned.getUser());
        UserView userView = blackDuckApiClient.getResponse(userUrl, UserView.class);
        if (userView != null) {
            resolvedUserViews.add(userView);
        }
    }
    return resolvedUserViews;
}
Also used : ArrayList(java.util.ArrayList) AssignedUserView(com.synopsys.integration.blackduck.api.manual.temporary.view.AssignedUserView) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) AssignedUserView(com.synopsys.integration.blackduck.api.manual.temporary.view.AssignedUserView) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Aggregations

AssignedUserView (com.synopsys.integration.blackduck.api.manual.temporary.view.AssignedUserView)3 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)2 HttpUrl (com.synopsys.integration.rest.HttpUrl)2 UserGroupView (com.synopsys.integration.blackduck.api.generated.view.UserGroupView)1 ProjectRequest (com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectRequest)1 AssignedUserGroupView (com.synopsys.integration.blackduck.api.manual.temporary.response.AssignedUserGroupView)1 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Test (org.junit.jupiter.api.Test)1