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());
}
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());
}
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;
}
Aggregations