use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class BlackDuckProviderIssueHandler method retrieveExistingIssue.
private Optional<ProjectVersionIssuesView> retrieveExistingIssue(String projectVersionUrl, String blackDuckIssueId) throws IntegrationException {
HttpUrl projectVersionHttpUrl = new HttpUrl(projectVersionUrl);
ProjectVersionView projectVersion = blackDuckApiClient.getResponse(projectVersionHttpUrl, ProjectVersionView.class);
List<ProjectVersionIssuesView> bomComponentIssues = issueService.getIssuesForProjectVersion(projectVersion);
return bomComponentIssues.stream().filter(issue -> issue.getIssueId().equals(blackDuckIssueId)).findAny();
}
use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class AbstractBlackDuckComponentConcernMessageExtractor method extract.
@Override
protected final ProviderMessageHolder extract(NotificationContentWrapper notificationContentWrapper, T notificationContent) {
AlertNotificationModel notificationModel = notificationContentWrapper.getAlertNotificationModel();
Long providerConfigId = notificationModel.getProviderConfigId();
String providerUrl;
List<BomComponentDetails> bomComponentDetails;
try {
BlackDuckServicesFactory blackDuckServicesFactory = servicesFactoryCache.retrieveBlackDuckServicesFactory(providerConfigId);
providerUrl = blackDuckServicesFactory.getBlackDuckHttpClient().getBlackDuckUrl().string();
bomComponentDetails = createBomComponentDetails(notificationContent, blackDuckServicesFactory);
} catch (AlertConfigurationException e) {
logger.warn("Invalid BlackDuck configuration for notification. ID: {}. Name: {}", providerConfigId, notificationModel.getProviderConfigName(), e);
return ProviderMessageHolder.empty();
} catch (IntegrationException e) {
logger.warn("Failed to retrieve BOM Component(s) from BlackDuck", e);
return ProviderMessageHolder.empty();
}
LinkableItem providerItem = new LinkableItem(blackDuckProviderKey.getDisplayName(), notificationModel.getProviderConfigName(), providerUrl);
ProviderDetails providerDetails = new ProviderDetails(notificationModel.getProviderConfigId(), providerItem);
Optional<String> projectUrl = extractProjectUrl(notificationContent.getProjectVersionUrl());
LinkableItem project = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT, notificationContent.getProjectName(), projectUrl.orElse(null));
LinkableItem projectVersion = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT_VERSION, notificationContent.getProjectVersionName(), notificationContent.getProjectVersionUrl());
// FIXME this is where I should put the additional info
ProjectMessage projectMessage = createProjectMessage(providerDetails, project, projectVersion, bomComponentDetails);
return new ProviderMessageHolder(List.of(projectMessage), List.of());
}
use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class BlackDuckSystemValidator method validate.
public boolean validate(BlackDuckProperties blackDuckProperties) {
boolean valid = true;
String configName = blackDuckProperties.getConfigName();
logger.info("Validating Black Duck configuration '{}'...", configName);
try {
Optional<String> blackDuckUrlOptional = blackDuckProperties.getBlackDuckUrl();
removeOldConfigMessages(blackDuckProperties, SystemMessageType.BLACKDUCK_PROVIDER_CONNECTIVITY, SystemMessageType.BLACKDUCK_PROVIDER_LOCALHOST, SystemMessageType.BLACKDUCK_PROVIDER_URL_MISSING);
String errorMessage = String.format(MISSING_BLACKDUCK_URL_ERROR_W_CONFIG_FORMAT, configName);
String urlMissingType = createProviderSystemMessageType(blackDuckProperties, SystemMessageType.BLACKDUCK_PROVIDER_URL_MISSING);
boolean missingUrl = addSystemMessageForError(errorMessage, SystemMessageSeverity.WARNING, urlMissingType, blackDuckUrlOptional.isEmpty());
if (missingUrl) {
logger.error(" -> {}", String.format(MISSING_BLACKDUCK_CONFIG_ERROR_FORMAT, configName));
valid = false;
}
if (blackDuckUrlOptional.isPresent()) {
String blackDuckUrlString = blackDuckUrlOptional.get();
Integer timeout = blackDuckProperties.getBlackDuckTimeout();
logger.debug(" -> Black Duck configuration '{}' URL found validating: {}", configName, blackDuckUrlString);
logger.debug(" -> Black Duck configuration '{}' Timeout: {}", configName, timeout);
URL blackDuckUrl = new URL(blackDuckUrlString);
String localhostMissingType = createProviderSystemMessageType(blackDuckProperties, SystemMessageType.BLACKDUCK_PROVIDER_LOCALHOST);
boolean localHostError = addSystemMessageForError(String.format(BLACKDUCK_LOCALHOST_ERROR_FORMAT, configName), SystemMessageSeverity.WARNING, localhostMissingType, "localhost".equals(blackDuckUrl.getHost()));
if (localHostError) {
logger.warn(" -> {}", String.format(BLACKDUCK_LOCALHOST_ERROR_FORMAT, configName));
}
IntLogger intLogger = new Slf4jIntLogger(logger);
BlackDuckServerConfig blackDuckServerConfig = blackDuckProperties.createBlackDuckServerConfig(intLogger);
boolean canConnect = blackDuckServerConfig.canConnect(intLogger);
if (canConnect) {
logger.info(" -> Black Duck configuration '{}' is Valid!", configName);
} else {
String message = String.format("Can not connect to the Black Duck server with the configuration '%s'.", configName);
connectivityWarning(blackDuckProperties, message);
valid = false;
}
} else {
String message = String.format("The Black Duck configuration '%s' is not valid.", configName);
connectivityWarning(blackDuckProperties, message);
valid = false;
}
BlackDuckApiTokenValidator blackDuckAPITokenValidator = new BlackDuckApiTokenValidator(blackDuckProperties);
if (!blackDuckAPITokenValidator.isApiTokenValid()) {
connectivityWarning(blackDuckProperties, BLACKDUCK_API_PERMISSION_FORMAT);
valid = false;
}
} catch (MalformedURLException | IntegrationException | AlertRuntimeException ex) {
logger.error(" -> Black Duck configuration '{}' is invalid; cause: {}", configName, ex.getMessage());
logger.debug(String.format(" -> Black Duck configuration '%s' Stack Trace: ", configName), ex);
valid = false;
}
return valid;
}
use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class BlackDuckSSOConfigRetriever method retrieve.
public BlackDuckSSOConfigView retrieve() throws AlertException {
BlackDuckRequestBuilder requestBuilder = new BlackDuckRequestBuilder().acceptMimeType(SSO_CONFIGURATION_MIME_TYPE);
UrlSingleResponse<BlackDuckSSOConfigView> ssoConfigurationSingleResponse = apiDiscovery.metaSingleResponse(SSO_CONFIGURATION_PATH);
BlackDuckRequest<BlackDuckSSOConfigView, UrlSingleResponse<BlackDuckSSOConfigView>> ssoConfigurationRequest = new BlackDuckRequest<>(requestBuilder, ssoConfigurationSingleResponse);
try {
return blackDuckApiClient.getResponse(ssoConfigurationRequest);
} catch (IntegrationException e) {
String errorMessage = String.format("Unable to retrieve SSO configuration from Black Duck: %s", e.getMessage());
throw new AlertException(errorMessage, e);
}
}
use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class BlackDuckDataSyncTask method getEmailsPerProject.
private Map<ProviderProject, Set<String>> getEmailsPerProject(Map<ProjectView, ProviderProject> blackDuckToAlertProjects, ProjectUsersService projectUsersService) {
Map<ProviderProject, Set<String>> projectToEmailAddresses = new ConcurrentHashMap<>();
blackDuckToAlertProjects.entrySet().parallelStream().forEach(entry -> {
try {
ProjectView blackDuckProjectView = entry.getKey();
ProviderProject alertProject = entry.getValue();
Set<String> projectUserEmailAddresses = projectUsersService.getAllActiveUsersForProject(blackDuckProjectView).stream().filter(UserView::getActive).map(UserView::getEmail).filter(StringUtils::isNotBlank).collect(Collectors.toSet());
if (StringUtils.isNotBlank(alertProject.getProjectOwnerEmail())) {
projectUserEmailAddresses.add(alertProject.getProjectOwnerEmail());
}
projectToEmailAddresses.put(alertProject, projectUserEmailAddresses);
} catch (IntegrationException e) {
// We do this to break out of the stream
throw new AlertRuntimeException(e.getMessage(), e);
}
});
return projectToEmailAddresses;
}
Aggregations