use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class BlackDuckPhoneHomeHandler method populatePhoneHomeData.
@Override
public PhoneHomeRequestBodyBuilder populatePhoneHomeData(ConfigurationModel configurationModel, NameVersion alertArtifactInfo) {
String registrationId = null;
String blackDuckUrl = PhoneHomeRequestBody.UNKNOWN_FIELD_VALUE;
String blackDuckVersion = PhoneHomeRequestBody.UNKNOWN_FIELD_VALUE;
try {
descriptorAccessor.getRegisteredDescriptorById(configurationModel.getDescriptorId());
StatefulProvider statefulProvider = provider.createStatefulProvider(configurationModel);
BlackDuckProperties blackDuckProperties = (BlackDuckProperties) statefulProvider.getProperties();
BlackDuckHttpClient blackDuckHttpClient = blackDuckProperties.createBlackDuckHttpClient(logger);
BlackDuckServicesFactory blackDuckServicesFactory = blackDuckProperties.createBlackDuckServicesFactory(blackDuckHttpClient, new Slf4jIntLogger(logger));
BlackDuckRegistrationService blackDuckRegistrationService = blackDuckServicesFactory.createBlackDuckRegistrationService();
BlackDuckServerData blackDuckServerData = blackDuckRegistrationService.getBlackDuckServerData();
blackDuckVersion = blackDuckServerData.getVersion();
registrationId = blackDuckServerData.getRegistrationKey().orElse(null);
blackDuckUrl = blackDuckProperties.getBlackDuckUrl().orElse(PhoneHomeRequestBody.UNKNOWN_FIELD_VALUE);
} catch (IntegrationException ignored) {
// ignoring this exception
}
// We must check if the reg id is blank because of an edge case in which Black Duck can authenticate (while the webserver is coming up) without registration
if (StringUtils.isBlank(registrationId)) {
registrationId = PhoneHomeRequestBody.UNKNOWN_FIELD_VALUE;
}
PhoneHomeRequestBodyBuilder phoneHomeBuilder = new PhoneHomeRequestBodyBuilder(registrationId, blackDuckUrl, alertArtifactInfo, UniquePhoneHomeProduct.BLACK_DUCK, blackDuckVersion);
return phoneHomeBuilder;
}
use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class BlackDuckProviderDataAccessor method getProviderConfigUserById.
@Override
public ProviderUserModel getProviderConfigUserById(Long providerConfigId) throws AlertConfigurationException {
try {
Optional<ConfigurationModel> providerConfigOptional = configurationModelConfigurationAccessor.getConfigurationById(providerConfigId);
if (providerConfigOptional.isPresent()) {
BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(providerConfigOptional.get());
UserService userService = blackDuckServicesFactory.createUserService();
UserView providerConfigUser = userService.findCurrentUser();
return new ProviderUserModel(providerConfigUser.getEmail(), false);
}
} catch (IntegrationException e) {
throw new AlertConfigurationException(createUserNotFoundString(providerConfigId, e.getMessage()), e);
}
throw new AlertConfigurationException(String.format("The provider config with id '%s' is invalid", providerConfigId));
}
use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class BlackDuckProviderDataAccessor method getEmailAddressesForProjectHref.
@Override
public Set<String> getEmailAddressesForProjectHref(Long providerConfigId, String projectHref) {
Optional<ConfigurationModel> providerConfigOptional = configurationModelConfigurationAccessor.getConfigurationById(providerConfigId);
if (providerConfigOptional.isPresent()) {
try {
BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(providerConfigOptional.get());
BlackDuckApiClient blackDuckService = blackDuckServicesFactory.getBlackDuckApiClient();
ProjectView projectView = blackDuckService.getResponse(new HttpUrl(projectHref), ProjectView.class);
return getEmailAddressesForProject(projectView, blackDuckServicesFactory.createProjectUsersService());
} catch (IntegrationException e) {
logger.errorAndDebug(createProjectNotFoundString(providerConfigId, e.getMessage()), e);
}
}
return Set.of();
}
use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class BlackDuckProviderDataAccessor method getProjectByHref.
@Override
public Optional<ProviderProject> getProjectByHref(Long providerConfigId, String projectHref) {
try {
Optional<ConfigurationModel> providerConfigOptional = configurationModelConfigurationAccessor.getConfigurationById(providerConfigId);
if (providerConfigOptional.isPresent()) {
BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(providerConfigOptional.get());
BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
ProjectView foundProject = blackDuckApiClient.getResponse(new HttpUrl(projectHref), ProjectView.class);
return convertBlackDuckProjects(List.of(foundProject), blackDuckApiClient).stream().findFirst();
}
} catch (IntegrationException e) {
logger.errorAndDebug(createProjectNotFoundString(providerConfigId, e.getMessage()), e);
}
return Optional.empty();
}
use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class BlackDuckProviderDataAccessor method retrieveUsersForProvider.
private AlertPagedModel<ProviderUserModel> retrieveUsersForProvider(ConfigurationModel blackDuckConfigurationModel, int pageNumber, int pageSize, String searchTerm) throws IntegrationException {
BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(blackDuckConfigurationModel);
Predicate<UserView> searchFilter = userView -> StringUtils.isNotBlank(userView.getEmail());
if (StringUtils.isNotBlank(searchTerm)) {
searchFilter = searchFilter.and(userView -> StringUtils.containsIgnoreCase(userView.getEmail(), searchTerm));
}
ApiDiscovery apiDiscovery = blackDuckServicesFactory.getApiDiscovery();
BlackDuckPageResponse<UserView> pageOfUsers = retrieveBlackDuckPageResponse(blackDuckServicesFactory, apiDiscovery.metaUsersLink(), pageNumber, pageSize, searchFilter);
List<ProviderUserModel> foundUsers = pageOfUsers.getItems().stream().map(UserView::getEmail).map(email -> new ProviderUserModel(email, false)).collect(Collectors.toList());
// Due to a limitation in the blackduck-common library, the totalCount in the BlackDuckPageResponse does not represent the count the matches the searchFilter. It is the totalCount from Black Duck
int totalPageCount = computeTotalCount(pageOfUsers, pageSize);
return new AlertPagedModel<>(totalPageCount, pageNumber, pageSize, foundUsers);
}
Aggregations