Search in sources :

Example 41 with AlertFieldStatus

use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.

the class BlackDuckProjectCustomFunctionAction method validateRelatedFields.

@Override
protected Collection<AlertFieldStatus> validateRelatedFields(FieldModel fieldModel) {
    Optional<String> providerName = fieldModel.getFieldValue(ChannelDescriptor.KEY_PROVIDER_TYPE);
    Optional<String> providerConfigId = fieldModel.getFieldValue(ProviderDescriptor.KEY_PROVIDER_CONFIG_ID);
    Set<AlertFieldStatus> errors = new HashSet<>();
    if (providerName.isEmpty()) {
        AlertFieldStatus missingProviderName = AlertFieldStatus.error(ProviderDescriptor.KEY_CONFIGURED_PROJECT, String.format("Missing %s", ChannelDescriptor.KEY_PROVIDER_TYPE));
        errors.add(missingProviderName);
    }
    if (providerConfigId.isEmpty()) {
        AlertFieldStatus missingProviderConfigId = AlertFieldStatus.error(ProviderDescriptor.KEY_CONFIGURED_PROJECT, MISSING_PROVIDER_ERROR);
        errors.add(missingProviderConfigId);
    }
    return errors;
}
Also used : AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) HashSet(java.util.HashSet)

Example 42 with AlertFieldStatus

use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.

the class JiraFieldMappingValidator method validateFieldMappings.

public Optional<AlertFieldStatus> validateFieldMappings(String fieldMappingFieldKey, FieldValueModel fieldMappingField) {
    List<JiraJobCustomFieldModel> customFields = fieldMappingField.getValues().stream().map(fieldMappingString -> gson.fromJson(fieldMappingString, JiraJobCustomFieldModel.class)).collect(Collectors.toList());
    Set<String> fieldNames = new HashSet<>();
    List<String> duplicateNameList = new ArrayList<>();
    for (JiraJobCustomFieldModel jiraJobCustomFieldModel : customFields) {
        String currentFieldName = jiraJobCustomFieldModel.getFieldName();
        if (fieldNames.contains(currentFieldName)) {
            duplicateNameList.add(currentFieldName);
        }
        fieldNames.add(currentFieldName);
    }
    if (!duplicateNameList.isEmpty()) {
        String duplicateNames = StringUtils.join(duplicateNameList, ", ");
        String errorMessage = String.format("Duplicate field name(s): %s", duplicateNames);
        AlertFieldStatus fieldMappingError = AlertFieldStatus.error(fieldMappingFieldKey, errorMessage);
        return Optional.of(fieldMappingError);
    }
    return Optional.empty();
}
Also used : AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) JiraJobCustomFieldModel(com.synopsys.integration.alert.common.persistence.model.job.details.JiraJobCustomFieldModel) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Component(org.springframework.stereotype.Component) Gson(com.google.gson.Gson) Optional(java.util.Optional) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) JiraJobCustomFieldModel(com.synopsys.integration.alert.common.persistence.model.job.details.JiraJobCustomFieldModel) ArrayList(java.util.ArrayList) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) HashSet(java.util.HashSet)

Example 43 with AlertFieldStatus

use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.

the class JiraErrorMessageUtilityTest method verifyReporterRestExceptionTest.

@Test
void verifyReporterRestExceptionTest() throws IntegrationException, IOException {
    JiraCustomFieldResolver jiraCustomFieldResolver = new JiraCustomFieldResolver(() -> List.of());
    JiraErrorMessageUtility jiraErrorMessageUtility = new JiraErrorMessageUtility(new Gson(), jiraCustomFieldResolver);
    IntegrationRestException integrationRestException = createRestException(JsonTestResource.REPORTER_ERROR);
    String issueCreatorKey = "issueCreatorFieldKey";
    String issueCreatorEmail = "issueCreatorEmail";
    AlertException alertException = jiraErrorMessageUtility.improveRestException(integrationRestException, issueCreatorKey, issueCreatorEmail);
    assertTrue(alertException instanceof AlertFieldException);
    AlertFieldException alertFieldException = (AlertFieldException) alertException;
    List<AlertFieldStatus> fieldErrors = alertFieldException.getFieldErrors();
    assertEquals(1, fieldErrors.size());
    AlertFieldStatus alertFieldStatus = fieldErrors.get(0);
    assertEquals(issueCreatorKey, alertFieldStatus.getFieldName());
    assertEquals(FieldStatusSeverity.ERROR, alertFieldStatus.getSeverity());
    String fieldMessage = alertFieldStatus.getFieldMessage();
    assertTrue(fieldMessage.contains(issueCreatorEmail));
    assertTrue(fieldMessage.contains("It'sa me, Mario"));
    assertFalse(fieldMessage.contains(" | Details: "));
}
Also used : JiraCustomFieldResolver(com.synopsys.integration.alert.api.channel.jira.distribution.custom.JiraCustomFieldResolver) IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) Gson(com.google.gson.Gson) AlertFieldException(com.synopsys.integration.alert.common.exception.AlertFieldException) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

Example 44 with AlertFieldStatus

use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.

the class AuthenticationFieldModelTestAction method performSAMLTest.

private void performSAMLTest(FieldUtility registeredFieldValues) throws IntegrationException {
    List<AlertFieldStatus> errors = new ArrayList<>();
    Optional<String> registeredEntityId = registeredFieldValues.getString(AuthenticationDescriptor.KEY_SAML_ENTITY_ID);
    if (registeredEntityId.isEmpty()) {
        errors.add(AlertFieldStatus.error(AuthenticationDescriptor.KEY_SAML_ENTITY_ID, "Entity ID missing."));
    }
    logger.info("Testing SAML Metadata URL...");
    try {
        Optional<ExtendedMetadataDelegate> provider = samlManager.createHttpProvider(registeredFieldValues.getStringOrEmpty(AuthenticationDescriptor.KEY_SAML_METADATA_URL));
        if (provider.isPresent()) {
            ExtendedMetadataDelegate extendedMetadataDelegate = provider.get();
            extendedMetadataDelegate.initialize();
        }
    } catch (Exception ex) {
        logger.error("Testing SAML Metadata URL error: ", ex);
        errors.add(AlertFieldStatus.error(AuthenticationDescriptor.KEY_SAML_METADATA_URL, ex.getMessage()));
    }
    logger.info("Testing SAML Metadata File...");
    try {
        Optional<ExtendedMetadataDelegate> provider = samlManager.createFileProvider();
        if (provider.isPresent()) {
            ExtendedMetadataDelegate extendedMetadataDelegate = provider.get();
            extendedMetadataDelegate.initialize();
        }
    } catch (Exception ex) {
        logger.error("Testing SAML Metadata File error: ", ex);
        errors.add(AlertFieldStatus.error(AuthenticationDescriptor.KEY_SAML_METADATA_FILE, ex.getMessage()));
    }
    samlManager.initializeConfiguration();
    if (!errors.isEmpty()) {
        throw new AlertFieldException(errors);
    }
}
Also used : ArrayList(java.util.ArrayList) ExtendedMetadataDelegate(org.springframework.security.saml.metadata.ExtendedMetadataDelegate) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) AlertFieldException(com.synopsys.integration.alert.common.exception.AlertFieldException) AlertFieldException(com.synopsys.integration.alert.common.exception.AlertFieldException) IntegrationException(com.synopsys.integration.exception.IntegrationException)

Example 45 with AlertFieldStatus

use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.

the class SlackDistributionConfigurationValidatorTest method testValidate.

@MethodSource("getFieldsAndExpectedErrors")
@ParameterizedTest()
public void testValidate(Map<String, FieldValueModel> fieldModelMap, Set<AlertFieldStatus> expectedValidationErrors) {
    JobFieldModel testJobFieldModel = FieldModelUtils.createJobFieldModel(ValidationConstants.COMMON_CHANNEL_FIELDS, fieldModelMap);
    CommonChannelDistributionValidator commonChannelDistributionValidator = new CommonChannelDistributionValidator();
    SlackDistributionConfigurationValidator validator = new SlackDistributionConfigurationValidator(commonChannelDistributionValidator);
    Set<AlertFieldStatus> validationErrors = validator.validate(testJobFieldModel);
    Assertions.assertEquals(expectedValidationErrors, validationErrors);
}
Also used : CommonChannelDistributionValidator(com.synopsys.integration.alert.api.channel.CommonChannelDistributionValidator) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)50 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)23 Test (org.junit.jupiter.api.Test)23 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)11 ArrayList (java.util.ArrayList)11 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)10 FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)9 HashSet (java.util.HashSet)9 Set (java.util.Set)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 Component (org.springframework.stereotype.Component)9 AlertFieldException (com.synopsys.integration.alert.common.exception.AlertFieldException)8 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)8 IntegrationException (com.synopsys.integration.exception.IntegrationException)8 List (java.util.List)8 Optional (java.util.Optional)8 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)7 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)7 JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)7 FieldModelTestAction (com.synopsys.integration.alert.common.action.FieldModelTestAction)6