use of com.synopsys.integration.blackduck.service.dataservice.UserGroupService 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);
}
Aggregations