use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class IssueTrackerFieldModelTestActionTest method testConfigNoReopen.
@Test
public void testConfigNoReopen() throws AlertException {
IssueTrackerMessageSender<String> messageSender = Mockito.mock(IssueTrackerMessageSender.class);
Mockito.when(messageSender.sendMessages(Mockito.any())).thenReturn(List.of(TEST_ISSUE_RESPONSE_MODEL));
IssueTrackerMessageSenderFactory<TestJobDetails, String> messageSenderFactory = distributionDetails -> messageSender;
TestIssueTrackerTestAction issueTrackerTestAction = new TestIssueTrackerTestAction(messageSenderFactory, true, false);
MessageResult messageResult = issueTrackerTestAction.testConfig(TEST_JOB_MODEL, "jobName", null, null);
assertFalse(messageResult.hasErrors(), EXPECTED_NO_ERRORS);
assertFalse(messageResult.hasWarnings(), EXPECTED_NO_WARNINGS);
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class IssueTrackerTransitionFieldModelTestActionTest method messageSenderThrowsAlertException.
@Test
public void messageSenderThrowsAlertException() throws AlertException {
IssueTrackerMessageSender<String> messageSender = Mockito.mock(IssueTrackerMessageSender.class);
Mockito.when(messageSender.sendMessages(Mockito.any())).thenThrow(new AlertException("Processing exception"));
testAndAssertHasErrors(messageSender);
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class PolicyNotificationFilterCustomFunctionAction method createPagedActionResponse.
@Override
public ActionResponse<NotificationFilterModelOptions> createPagedActionResponse(FieldModel fieldModel, HttpServletContentWrapper servletContentWrapper, int pageNumber, int pageSize, String searchTerm) throws IntegrationException {
Optional<FieldValueModel> fieldValueModel = fieldModel.getFieldValueModel(ProviderDescriptor.KEY_NOTIFICATION_TYPES);
Collection<String> selectedNotificationTypes = fieldValueModel.map(FieldValueModel::getValues).orElse(List.of());
int totalPages = 1;
List<NotificationFilterModel> options = List.of();
if (isJobFilterableByPolicy(selectedNotificationTypes)) {
try {
Optional<BlackDuckServicesFactory> blackDuckServicesFactory = createBlackDuckServicesFactory(fieldModel);
if (blackDuckServicesFactory.isPresent()) {
BlackDuckPageResponse<PolicyRuleView> policyRulesPage = retrievePolicyRules(blackDuckServicesFactory.get(), pageNumber, pageSize, searchTerm);
totalPages = (policyRulesPage.getTotalCount() + (pageSize - 1)) / pageSize;
options = convertToNotificationFilterModel(policyRulesPage.getItems());
}
} catch (IntegrationException e) {
logger.errorAndDebug("There was an issue communicating with Black Duck. " + e.getMessage(), e);
throw new AlertException("Unable to communicate with Black Duck.", e);
}
}
NotificationFilterModelOptions notificationFilterModelOptions = new NotificationFilterModelOptions(totalPages, pageNumber, pageSize, options);
return new ActionResponse<>(HttpStatus.OK, notificationFilterModelOptions);
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class NotificationExtractorBlackDuckServicesFactoryCache method createBlackDuckServicesFactory.
private BlackDuckServicesFactory createBlackDuckServicesFactory(Long blackDuckConfigId) throws AlertConfigurationException {
Optional<BlackDuckProperties> optionalProperties = blackDuckPropertiesFactory.createProperties(blackDuckConfigId);
if (optionalProperties.isPresent()) {
BlackDuckProperties blackDuckProperties = optionalProperties.get();
Slf4jIntLogger intLogger = new Slf4jIntLogger(logger);
try {
BlackDuckHttpClient blackDuckHttpClient = blackDuckProperties.createBlackDuckCacheClient(intLogger);
return blackDuckProperties.createBlackDuckServicesFactory(blackDuckHttpClient, intLogger);
} catch (AlertException e) {
throw new AlertConfigurationException("The BlackDuck configuration is invalid", e);
}
}
throw new AlertConfigurationException(String.format("No BlackDuck configuration with id '%s' existed", blackDuckConfigId));
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException 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);
}
}
Aggregations