Search in sources :

Example 51 with AlertException

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

the class AzureBoardsComponentIssueFinder method findExistingIssuesByProjectIssueModel.

@Override
public List<ExistingIssueDetails<Integer>> findExistingIssuesByProjectIssueModel(ProjectIssueModel projectIssueModel) throws AlertException {
    LinkableItem projectVersion = projectIssueModel.getProjectVersion().orElseThrow(() -> new AlertRuntimeException("Missing project-version"));
    String categoryKey = AzureBoardsAlertIssuePropertiesManager.CATEGORY_TYPE_VULNERABILITY_COMPATIBILITY_LABEL;
    AzureSearchFieldMappingBuilder fieldRefNameToValue = createBomFieldReferenceToValueMap(projectVersion, projectIssueModel.getBomComponentDetails());
    Optional<IssuePolicyDetails> policyDetails = projectIssueModel.getPolicyDetails();
    Optional<String> optionalPolicyName = policyDetails.map(IssuePolicyDetails::getName);
    if (optionalPolicyName.isPresent()) {
        categoryKey = AzureBoardsAlertIssuePropertiesManager.CATEGORY_TYPE_POLICY_COMPATIBILITY_LABEL;
        String additionalInfoKey = AzureBoardsAlertIssuePropertiesManager.POLICY_ADDITIONAL_KEY_COMPATIBILITY_LABEL + optionalPolicyName.get();
        fieldRefNameToValue.addAdditionalInfoKey(additionalInfoKey);
    }
    if (projectIssueModel.getComponentUnknownVersionDetails().isPresent()) {
        categoryKey = AzureBoardsAlertIssuePropertiesManager.CATEGORY_TYPE_COMPONENT_UNKNOWN_VERSION_COMPATIBILITY_LABEL;
    }
    fieldRefNameToValue.addCategoryKey(categoryKey);
    return workItemFinder.findWorkItems(projectIssueModel.getProvider(), projectIssueModel.getProject(), fieldRefNameToValue).stream().map(workItemResponseModel -> createIssueDetails(workItemResponseModel, projectIssueModel)).collect(Collectors.toList());
}
Also used : ExactIssueFinder(com.synopsys.integration.alert.api.channel.issue.search.ExactIssueFinder) WorkItemResponseModel(com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemResponseModel) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) Collectors(java.util.stream.Collectors) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) ArrayList(java.util.ArrayList) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) ProjectVersionComponentIssueFinder(com.synopsys.integration.alert.api.channel.issue.search.ProjectVersionComponentIssueFinder) AzureBoardsSearchPropertiesUtils(com.synopsys.integration.alert.channel.azure.boards.distribution.util.AzureBoardsSearchPropertiesUtils) List(java.util.List) AbstractBomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.AbstractBomComponentDetails) Gson(com.google.gson.Gson) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) Optional(java.util.Optional) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) ProjectIssueSearchResult(com.synopsys.integration.alert.api.channel.issue.search.ProjectIssueSearchResult) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)

Example 52 with AlertException

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

the class EmailGlobalTestAction method testConfigModelContent.

public ConfigurationTestResult testConfigModelContent(String testAddress, EmailGlobalConfigModel emailGlobalConfigModel) {
    if (StringUtils.isBlank(testAddress)) {
        return ConfigurationTestResult.failure("Could not determine what email address to send this content to. testAddress was not provided or was blank. Please provide a valid email address to test the configuration.");
    }
    try {
        InternetAddress emailAddress = new InternetAddress(testAddress);
        emailAddress.validate();
    } catch (AddressException ex) {
        return ConfigurationTestResult.failure(String.format("%s is not a valid email address. %s", testAddress, ex.getMessage()));
    }
    EmailChannelMessageModel testMessage = EmailChannelMessageModel.simple(TEST_SUBJECT_LINE, TEST_MESSAGE_CONTENT, "", "");
    SmtpConfigBuilder smtpConfigBuilder = SmtpConfig.builder();
    smtpConfigBuilder.setJavamailProperties(javamailPropertiesFactory.createJavaMailProperties(emailGlobalConfigModel));
    emailGlobalConfigModel.getSmtpFrom().ifPresent(smtpConfigBuilder::setSmtpFrom);
    emailGlobalConfigModel.getSmtpHost().ifPresent(smtpConfigBuilder::setSmtpHost);
    emailGlobalConfigModel.getSmtpPort().ifPresent(smtpConfigBuilder::setSmtpPort);
    emailGlobalConfigModel.getSmtpAuth().ifPresent(smtpConfigBuilder::setSmtpAuth);
    emailGlobalConfigModel.getSmtpUsername().ifPresent(smtpConfigBuilder::setSmtpUsername);
    if (BooleanUtils.toBoolean(emailGlobalConfigModel.getIsSmtpPasswordSet()) && emailGlobalConfigModel.getSmtpPassword().isEmpty()) {
        // TODO: This assumes if the password is saved but not provided we only test using the default configuration password.
        // If the UI supports multiple configurations in the future we should determine which configuration to get the password from.
        configurationAccessor.getConfiguration().flatMap(EmailGlobalConfigModel::getSmtpPassword).ifPresent(emailGlobalConfigModel::setSmtpPassword);
    }
    emailGlobalConfigModel.getSmtpPassword().ifPresent(smtpConfigBuilder::setSmtpPassword);
    SmtpConfig smtpConfig = smtpConfigBuilder.build();
    try {
        EmailTarget emailTarget = emailChannelMessagingService.createTarget(testMessage, testAddress);
        MessageResult messageResult = emailChannelMessagingService.sendMessage(smtpConfig, emailTarget);
        return ConfigurationTestResult.success(messageResult.getStatusMessage());
    } catch (AlertException ex) {
        return ConfigurationTestResult.failure(ex.getMessage());
    }
}
Also used : SmtpConfigBuilder(com.synopsys.integration.alert.service.email.SmtpConfigBuilder) SmtpConfig(com.synopsys.integration.alert.service.email.SmtpConfig) InternetAddress(javax.mail.internet.InternetAddress) AddressException(javax.mail.internet.AddressException) EmailChannelMessageModel(com.synopsys.integration.alert.channel.email.distribution.EmailChannelMessageModel) EmailTarget(com.synopsys.integration.alert.service.email.EmailTarget) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 53 with AlertException

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

the class AzureBoardsProperties method createAzureHttpRequestCreator.

public AzureHttpRequestCreator createAzureHttpRequestCreator(ProxyInfo proxyInfo, Gson gson) throws AlertException {
    HttpTransport httpTransport = createHttpTransport(proxyInfo);
    try {
        AuthorizationCodeFlow oAuthFlow = createOAuthFlow(httpTransport);
        Credential oAuthCredential = getExistingOAuthCredential(oAuthFlow).orElseThrow(() -> new AlertException(String.format("No existing Azure OAuth credential associated with '%s'", oauthUserId)));
        return AzureHttpRequestCreatorFactory.withCredential(httpTransport, oAuthCredential, gson);
    } catch (IOException e) {
        throw new AlertException("Cannot read OAuth credentials", e);
    }
}
Also used : HttpTransport(com.google.api.client.http.HttpTransport) ApacheHttpTransport(com.google.api.client.http.apache.v2.ApacheHttpTransport) Credential(com.google.api.client.auth.oauth2.Credential) StoredCredential(com.google.api.client.auth.oauth2.StoredCredential) IOException(java.io.IOException) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) AuthorizationCodeFlow(com.google.api.client.auth.oauth2.AuthorizationCodeFlow) AzureAuthorizationCodeFlow(com.synopsys.integration.azure.boards.common.oauth.AzureAuthorizationCodeFlow)

Example 54 with AlertException

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

the class EmailGlobalFieldModelTestAction method testConfig.

@Override
public MessageResult testConfig(String configId, FieldModel fieldModel, FieldUtility registeredFieldValues) throws AlertException {
    String addressString = fieldModel.getFieldValue(FieldModelTestAction.KEY_DESTINATION_NAME).orElse("");
    if (StringUtils.isBlank(addressString)) {
        throw new AlertException(String.format("Could not determine what email address to send this content to. %s was not provided or was blank. Please provide a valid email address to test the configuration.", FieldModelTestAction.KEY_DESTINATION_NAME));
    }
    try {
        InternetAddress emailAddress = new InternetAddress(addressString);
        emailAddress.validate();
    } catch (AddressException ex) {
        throw new AlertException(String.format("%s is not a valid email address. %s", addressString, ex.getMessage()));
    }
    EmailChannelMessageModel testMessage = EmailChannelMessageModel.simple(TEST_SUBJECT_LINE, TEST_MESSAGE_CONTENT, "", "");
    EmailTarget emailTarget = emailChannelMessagingService.createTarget(testMessage, addressString);
    SmtpConfig smtpConfig = SmtpConfig.builder().setJavamailProperties(javamailPropertiesFactory.createJavaMailProperties(registeredFieldValues)).setSmtpFrom(registeredFieldValues.getString(EmailPropertyKeys.JAVAMAIL_FROM_KEY.getPropertyKey()).orElse(null)).setSmtpHost(registeredFieldValues.getString(EmailPropertyKeys.JAVAMAIL_HOST_KEY.getPropertyKey()).orElse(null)).setSmtpPort(registeredFieldValues.getInteger(EmailPropertyKeys.JAVAMAIL_PORT_KEY.getPropertyKey()).orElse(-1)).setSmtpAuth(registeredFieldValues.getBooleanOrFalse(EmailPropertyKeys.JAVAMAIL_AUTH_KEY.getPropertyKey())).setSmtpUsername(registeredFieldValues.getString(EmailPropertyKeys.JAVAMAIL_USER_KEY.name()).orElse(null)).setSmtpPassword(registeredFieldValues.getString(EmailPropertyKeys.JAVAMAIL_PASSWORD_KEY.getPropertyKey()).orElse(null)).build();
    return emailChannelMessagingService.sendMessage(smtpConfig, emailTarget);
}
Also used : SmtpConfig(com.synopsys.integration.alert.service.email.SmtpConfig) InternetAddress(javax.mail.internet.InternetAddress) AddressException(javax.mail.internet.AddressException) EmailChannelMessageModel(com.synopsys.integration.alert.channel.email.distribution.EmailChannelMessageModel) EmailTarget(com.synopsys.integration.alert.service.email.EmailTarget) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 55 with AlertException

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

the class AzureBoardsGlobalApiAction method beforeUpdateAction.

@Override
public FieldModel beforeUpdateAction(FieldModel fieldModel) throws AlertException {
    FieldModel updatedFieldModel = super.beforeUpdateAction(fieldModel);
    Optional<ConfigurationModel> existingConfig = configurationModelConfigurationAccessor.getConfigurationById(Long.valueOf(fieldModel.getId()));
    return existingConfig.map(config -> updateTokenFields(updatedFieldModel, config)).orElse(updatedFieldModel);
}
Also used : ApiAction(com.synopsys.integration.alert.common.action.ApiAction) OAuthRequestValidator(com.synopsys.integration.alert.channel.azure.boards.oauth.OAuthRequestValidator) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) List(java.util.List) Component(org.springframework.stereotype.Component) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) Map(java.util.Map) AzureBoardsDescriptor(com.synopsys.integration.alert.channel.azure.boards.descriptor.AzureBoardsDescriptor) Optional(java.util.Optional) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel)

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