Search in sources :

Example 21 with AlertRuntimeException

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

the class JiraCustomFieldResolver method convertValueToRequestObject.

protected Object convertValueToRequestObject(CustomFieldDefinitionModel fieldDefinition, JiraCustomFieldConfig jiraCustomFieldConfig) {
    String fieldType = fieldDefinition.getFieldType();
    String innerFieldValue = extractUsableInnerValue(jiraCustomFieldConfig);
    switch(fieldType) {
        case CUSTOM_FIELD_TYPE_STRING_VALUE:
            return innerFieldValue;
        case CUSTOM_FIELD_TYPE_ARRAY_VALUE:
            return createJsonArray(innerFieldValue, fieldDefinition.getFieldArrayItems());
        case CUSTOM_FIELD_TYPE_OPTION_VALUE:
            return createJsonObject("value", innerFieldValue);
        case CUSTOM_FIELD_TYPE_PRIORITY_VALUE:
            return createJsonObject("name", innerFieldValue);
        case CUSTOM_FIELD_TYPE_USER_VALUE:
            // "name" is used for Jira Server (ignored on Jira Cloud)
            JsonObject createUserObject = createJsonObject("name", innerFieldValue);
            // "accountId" is used for Jira Cloud (ignored on Jira Server)
            createUserObject.addProperty("accountId", innerFieldValue);
            // TODO consider separating this functionality depending on which Jira channel is being used
            return createUserObject;
        default:
            throw new AlertRuntimeException(String.format("Unsupported field type '%s' for field: %s", fieldType, jiraCustomFieldConfig.getFieldName()));
    }
}
Also used : JsonObject(com.google.gson.JsonObject) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)

Example 22 with AlertRuntimeException

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

the class JobNotificationMapper method createRequestModelFromNotifications.

private FilteredDistributionJobRequestModel createRequestModelFromNotifications(List<DetailedNotificationContent> detailedContents, List<FrequencyType> frequencies) {
    Long commonProviderConfigId = detailedContents.stream().map(DetailedNotificationContent::getProviderConfigId).findAny().orElseThrow(() -> new AlertRuntimeException("Notification(s) missing provider configuration id"));
    FilteredDistributionJobRequestModel filteredDistributionJobRequestModel = new FilteredDistributionJobRequestModel(commonProviderConfigId, frequencies);
    for (DetailedNotificationContent detailedNotificationContent : detailedContents) {
        detailedNotificationContent.getProjectName().ifPresent(filteredDistributionJobRequestModel::addProjectName);
        filteredDistributionJobRequestModel.addNotificationType(detailedNotificationContent.getNotificationContentWrapper().extractNotificationType());
        filteredDistributionJobRequestModel.addVulnerabilitySeverities(detailedNotificationContent.getVulnerabilitySeverities());
        detailedNotificationContent.getPolicyName().ifPresent(filteredDistributionJobRequestModel::addPolicyName);
    }
    return filteredDistributionJobRequestModel;
}
Also used : DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) FilteredDistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobRequestModel)

Aggregations

AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)22 ConfigurationModelMutable (com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable)4 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)3 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)3 RegisteredDescriptorModel (com.synopsys.integration.alert.common.persistence.model.RegisteredDescriptorModel)3 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)3 IntegrationException (com.synopsys.integration.exception.IntegrationException)3 ArrayList (java.util.ArrayList)3 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)2 IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)2 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)2 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)2 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)2 DefinedFieldModel (com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel)2 ProviderProject (com.synopsys.integration.alert.common.persistence.model.ProviderProject)2 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)2 FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)2 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)2 HashMap (java.util.HashMap)2 List (java.util.List)2