use of com.synopsys.integration.alert.common.exception.AlertFieldException 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.exception.AlertFieldException in project hub-alert by blackducksoftware.
the class JiraErrorMessageUtility method extractSpecificErrorsFromErrorsObject.
private List<String> extractSpecificErrorsFromErrorsObject(JsonObject errors, String issueCreatorFieldKey, String issueCreatorEmail) throws AlertFieldException {
List<String> responseErrors = new ArrayList<>();
if (errors.has("reporter")) {
throw new AlertFieldException(List.of(AlertFieldStatus.error(issueCreatorFieldKey, String.format("There was a problem assigning '%s' to the issue. Please ensure that the user is assigned to the project and has permission to transition issues. Error: %s", issueCreatorEmail, errors.get("reporter")))));
} else {
List<String> fieldErrors = errors.entrySet().stream().map(entry -> String.format("Field '%s' has error %s", entry.getKey(), entry.getValue())).collect(Collectors.toList());
responseErrors.addAll(fieldErrors);
}
if (errors.has("errorMessages")) {
JsonArray errorMessages = errors.getAsJsonArray("errorMessages");
for (JsonElement errorMessage : errorMessages) {
responseErrors.add(errorMessage.getAsString());
}
}
return responseErrors;
}
use of com.synopsys.integration.alert.common.exception.AlertFieldException 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);
}
}
Aggregations