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;
}
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();
}
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: "));
}
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);
}
}
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);
}
Aggregations