Search in sources :

Example 41 with AlertException

use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.

the class BlackDuckProjectExistencePopulator method populateJobProviderProjects.

private void populateJobProviderProjects(ConfigurationModel providerGlobalConfig, List<JobProviderProjectFieldModel> configuredProviderProjects) {
    BlackDuckApiClient blackDuckApiClient;
    try {
        blackDuckApiClient = createBlackDuckApiClient(providerGlobalConfig);
    } catch (AlertException e) {
        logger.debug("Failed to initialize BlackDuck services", e);
        return;
    }
    for (JobProviderProjectFieldModel project : configuredProviderProjects) {
        boolean exists = doesProjectExist(blackDuckApiClient, project);
        project.setMissing(!exists);
    }
}
Also used : BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 42 with AlertException

use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.

the class BlackDuckProperties method createBlackDuckServerConfig.

public BlackDuckServerConfig createBlackDuckServerConfig(IntLogger logger, int blackDuckTimeout, String blackDuckApiToken) throws AlertException {
    BlackDuckServerConfigBuilder blackDuckServerConfigBuilder = createServerConfigBuilderWithoutAuthentication(logger, blackDuckTimeout);
    blackDuckServerConfigBuilder.setApiToken(blackDuckApiToken);
    try {
        return blackDuckServerConfigBuilder.build();
    } catch (IllegalStateException e) {
        throw new AlertException(e.getMessage(), e);
    }
}
Also used : BlackDuckServerConfigBuilder(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfigBuilder) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 43 with AlertException

use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.

the class JiraCloudIssueCreator method retrieveProjectComponent.

private ProjectComponent retrieveProjectComponent() throws AlertException {
    String jiraProjectName = distributionDetails.getProjectNameOrKey();
    PageOfProjectsResponseModel projectsResponseModel;
    try {
        projectsResponseModel = projectService.getProjectsByName(jiraProjectName);
    } catch (IntegrationException e) {
        throw new AlertException("Failed to retrieve projects from Jira", e);
    }
    return projectsResponseModel.getProjects().stream().filter(project -> jiraProjectName.equals(project.getName()) || jiraProjectName.equals(project.getKey())).findAny().orElseThrow(() -> new AlertException(String.format("Unable to find project matching '%s'", jiraProjectName)));
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) PageOfProjectsResponseModel(com.synopsys.integration.jira.common.model.response.PageOfProjectsResponseModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 44 with AlertException

use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.

the class EmailGlobalFieldModelTestActionTest method testConfigITTest.

@Test
@Tags(value = { @Tag(TestTags.DEFAULT_INTEGRATION), @Tag(TestTags.CUSTOM_EXTERNAL_CONNECTION) })
public void testConfigITTest() {
    TestProperties testProperties = new TestProperties();
    String emailAddress = testProperties.getProperty(TestPropertyKey.TEST_EMAIL_RECIPIENT);
    FieldModel validFieldModel = createFieldModelToTest(emailAddress);
    JavamailPropertiesFactory javamailPropertiesFactory = new JavamailPropertiesFactory();
    EmailChannelMessagingService validEmailChannelMessagingService = createValidEmailChannelMessagingService(emailAddress);
    EmailGlobalFieldModelTestAction emailGlobalFieldModelTestAction = new EmailGlobalFieldModelTestAction(validEmailChannelMessagingService, javamailPropertiesFactory);
    FieldUtility validFieldUtility = createValidEmailGlobalFieldUtility(testProperties);
    try {
        MessageResult messageResult = emailGlobalFieldModelTestAction.testConfig("0", validFieldModel, validFieldUtility);
        assertFalse(messageResult.hasErrors(), "Expected the message result to not have errors");
        assertFalse(messageResult.hasWarnings(), "Expected the message result to not have warnings");
    } catch (AlertException e) {
        fail("An exception was thrown where none was expected", e);
    }
}
Also used : TestProperties(com.synopsys.integration.alert.test.common.TestProperties) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) JavamailPropertiesFactory(com.synopsys.integration.alert.service.email.JavamailPropertiesFactory) EmailChannelMessagingService(com.synopsys.integration.alert.channel.email.distribution.EmailChannelMessagingService) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test) TestTags(com.synopsys.integration.alert.test.common.TestTags) Tags(org.junit.jupiter.api.Tags)

Example 45 with AlertException

use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.

the class EmailGlobalFieldModelTestActionTest method testConfigInvalidDestinationTest.

@Test
public void testConfigInvalidDestinationTest() {
    EmailGlobalFieldModelTestAction emailGlobalFieldModelTestAction = new EmailGlobalFieldModelTestAction(null, null);
    FieldModel validFieldModel = createFieldModelToTest("not a valid email address");
    try {
        emailGlobalFieldModelTestAction.testConfig("0", validFieldModel, new FieldUtility(Map.of()));
        fail("Expected an exception to be thrown");
    } catch (AlertException e) {
    // Pass
    }
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

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