Search in sources :

Example 31 with AlertException

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);
}
Also used : DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) IssueTrackerMessageSenderFactory(com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerMessageSenderFactory) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) IssueTrackerMessageSender(com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerMessageSender) IssueTrackerIssueResponseModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel) IssueOperation(com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation) FrequencyType(com.synopsys.integration.alert.common.enumeration.FrequencyType) UUID(java.util.UUID) DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) IssueTrackerModelHolder(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder) IssueTransitionModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ProcessingType(com.synopsys.integration.alert.common.enumeration.ProcessingType) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) IssueTrackerChannelKey(com.synopsys.integration.alert.descriptor.api.model.IssueTrackerChannelKey) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) Test(org.junit.jupiter.api.Test)

Example 32 with AlertException

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);
}
Also used : AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

Example 33 with AlertException

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);
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) PolicyRuleView(com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 34 with AlertException

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));
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 35 with AlertException

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);
    }
}
Also used : UrlSingleResponse(com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) BlackDuckRequest(com.synopsys.integration.blackduck.service.request.BlackDuckRequest) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Aggregations

AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)101 Test (org.junit.jupiter.api.Test)35 MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)22 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)18 List (java.util.List)18 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)17 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)16 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)16 Optional (java.util.Optional)13 IssueTrackerModelHolder (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder)12 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)12 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)11 HashMap (java.util.HashMap)11 IntegrationException (com.synopsys.integration.exception.IntegrationException)10 ArrayList (java.util.ArrayList)9 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)8 DistributionJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel)8 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)8 UUID (java.util.UUID)8 IssueOperation (com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation)7