Search in sources :

Example 6 with AlertFieldException

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: "));
}
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 7 with AlertFieldException

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;
}
Also used : JsonObject(com.google.gson.JsonObject) AlertFieldException(com.synopsys.integration.alert.common.exception.AlertFieldException) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) JiraCustomFieldResolver(com.synopsys.integration.alert.api.channel.jira.distribution.custom.JiraCustomFieldResolver) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) ArrayList(java.util.ArrayList) JsonElement(com.google.gson.JsonElement) List(java.util.List) JsonArray(com.google.gson.JsonArray) Gson(com.google.gson.Gson) IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) Optional(java.util.Optional) JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) AlertFieldException(com.synopsys.integration.alert.common.exception.AlertFieldException)

Example 8 with AlertFieldException

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);
    }
}
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)

Aggregations

AlertFieldException (com.synopsys.integration.alert.common.exception.AlertFieldException)8 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)6 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)5 IntegrationException (com.synopsys.integration.exception.IntegrationException)4 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)4 ArrayList (java.util.ArrayList)4 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)3 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)3 Gson (com.google.gson.Gson)2 JiraCustomFieldResolver (com.synopsys.integration.alert.api.channel.jira.distribution.custom.JiraCustomFieldResolver)2 FieldModelTestAction (com.synopsys.integration.alert.common.action.FieldModelTestAction)2 MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)2 FieldUtility (com.synopsys.integration.alert.common.persistence.accessor.FieldUtility)2 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)2 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 IssueCreationModel (com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel)1 IssueTrackerIssueResponseModel (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel)1