use of com.synopsys.integration.blackduck.api.generated.view.UserGroupView 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.generated.view.UserGroupView in project blackduck-common by blackducksoftware.
the class ProjectUsersService method addGroupToProject.
public void addGroupToProject(ProjectView projectView, String groupName) throws IntegrationException {
Optional<UserGroupView> optionalUserGroupView = userGroupService.getGroupByName(groupName);
UserGroupView userGroupView = optionalUserGroupView.orElseThrow(() -> new IntegrationException(String.format("The supplied group name (%s) does not exist.", groupName)));
HttpUrl userGroupUrl = userGroupView.getHref();
HttpUrl createUrl = projectView.getFirstLink(ProjectView.USERGROUPS_LINK);
AssignedUserGroupRequest userGroupRequest = new AssignedUserGroupRequest();
userGroupRequest.setGroup(userGroupUrl.string());
blackDuckApiClient.post(createUrl, userGroupRequest);
}
use of com.synopsys.integration.blackduck.api.generated.view.UserGroupView in project blackduck-common by blackducksoftware.
the class ProjectUsersService method getGroupsForProject.
public List<UserGroupView> getGroupsForProject(ProjectView project) throws IntegrationException {
logger.debug("Attempting to get the assigned users for Project: " + project.getName());
List<AssignedUserGroupView> assignedGroups = getAssignedGroupsToProject(project);
List<UserGroupView> resolvedGroupViews = new ArrayList<>();
for (AssignedUserGroupView assigned : assignedGroups) {
HttpUrl groupUrl = new HttpUrl(assigned.getGroup());
UserGroupView groupView = blackDuckApiClient.getResponse(groupUrl, UserGroupView.class);
if (groupView != null) {
resolvedGroupViews.add(groupView);
}
}
return resolvedGroupViews;
}
use of com.synopsys.integration.blackduck.api.generated.view.UserGroupView in project synopsys-detect by blackducksoftware.
the class BlackDuckConnectivityChecker method determineConnectivity.
public BlackDuckConnectivityResult determineConnectivity(BlackDuckServerConfig blackDuckServerConfig) throws DetectUserFriendlyException {
logger.debug("Detect will check communication with the Black Duck server.");
ConnectionResult connectionResult = blackDuckServerConfig.attemptConnection(new SilentIntLogger());
if (connectionResult.isFailure()) {
// TODO: For the logs, when connection result returns the client, can drop this.
blackDuckServerConfig.attemptConnection(new Slf4jIntLogger(logger));
logger.error("Failed to connect to the Black Duck server");
return BlackDuckConnectivityResult.failure(connectionResult.getFailureMessage().orElse("Could not reach the Black Duck server or the credentials were invalid."));
}
BlackDuckServicesFactory blackDuckServicesFactory = blackDuckServerConfig.createBlackDuckServicesFactory(new Slf4jIntLogger(logger));
BlackDuckRegistrationService blackDuckRegistrationService = blackDuckServicesFactory.createBlackDuckRegistrationService();
UserService userService = blackDuckServicesFactory.createUserService();
try {
String version = blackDuckRegistrationService.getBlackDuckServerData().getVersion();
logger.info(String.format("Successfully connected to Black Duck (version %s)!", version));
if (logger.isDebugEnabled()) {
// These (particularly fetching roles) can be very slow operations
UserView userView = userService.findCurrentUser();
logger.debug("Connected as: " + userView.getUserName());
UserGroupService userGroupService = blackDuckServicesFactory.createUserGroupService();
List<RoleAssignmentView> roles = userGroupService.getRolesForUser(userView);
logger.debug("Roles: " + roles.stream().map(RoleAssignmentView::getName).distinct().collect(Collectors.joining(", ")));
BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
List<UserGroupView> groups = blackDuckApiClient.getAllResponses(userView.metaMultipleResponses(USERGROUPS));
logger.debug("Group: " + groups.stream().map(UserGroupView::getName).distinct().collect(Collectors.joining(", ")));
}
} catch (IntegrationException e) {
throw new DetectUserFriendlyException("Could not determine which version of Black Duck detect connected to or which user is connecting.", e, ExitCodeType.FAILURE_BLACKDUCK_CONNECTIVITY);
}
return BlackDuckConnectivityResult.success(blackDuckServicesFactory, blackDuckServerConfig);
}
use of com.synopsys.integration.blackduck.api.generated.view.UserGroupView in project blackduck-common by blackducksoftware.
the class UserGroupService method getGroupByName.
public Optional<UserGroupView> getGroupByName(String groupName) throws IntegrationException {
List<UserGroupView> allGroups = blackDuckApiClient.getAllResponses(apiDiscovery.metaUsergroupsLink());
for (UserGroupView group : allGroups) {
if (group.getName().equalsIgnoreCase(groupName)) {
return Optional.of(group);
}
}
logger.error(String.format("The group (%s) does not exist.", groupName));
return Optional.empty();
}
Aggregations