Search in sources :

Example 36 with ValidationResponseModel

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

the class AbstractJobResourceActions method validate.

public final ValidationActionResponse validate(JobFieldModel resource) {
    boolean hasPermissions = resource.getFieldModels().stream().allMatch(model -> authorizationManager.hasCreatePermission(model.getContext(), model.getDescriptorName()) || authorizationManager.hasWritePermission(model.getContext(), model.getDescriptorName()) || authorizationManager.hasExecutePermission(model.getContext(), model.getDescriptorName()));
    if (!hasPermissions) {
        ValidationResponseModel responseModel = ValidationResponseModel.generalError(ActionResponse.FORBIDDEN_MESSAGE);
        return new ValidationActionResponse(HttpStatus.FORBIDDEN, responseModel);
    }
    // Clean input
    correctProjectsField(resource);
    ValidationActionResponse response = validateWithoutChecks(resource);
    return ValidationActionResponse.createOKResponseWithContent(response);
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.api.common.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse)

Example 37 with ValidationResponseModel

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

the class AbstractResourceActions method validate.

public final ValidationActionResponse validate(T resource) {
    if (!authorizationManager.hasExecutePermission(context, descriptorKey)) {
        logger.debug(String.format(FORBIDDEN_ACTION_FORMAT, "Validate"));
        ValidationResponseModel responseModel = ValidationResponseModel.generalError(ActionResponse.FORBIDDEN_MESSAGE);
        return new ValidationActionResponse(HttpStatus.FORBIDDEN, responseModel);
    }
    ValidationActionResponse response = validateWithoutChecks(resource);
    return ValidationActionResponse.createOKResponseWithContent(response);
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.api.common.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse)

Example 38 with ValidationResponseModel

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

the class AbstractResourceActions method test.

public final ValidationActionResponse test(T resource) {
    if (!authorizationManager.hasExecutePermission(context, descriptorKey)) {
        logger.debug(String.format(FORBIDDEN_ACTION_FORMAT, "Test"));
        ValidationResponseModel responseModel = ValidationResponseModel.generalError(ActionResponse.FORBIDDEN_MESSAGE);
        return new ValidationActionResponse(HttpStatus.FORBIDDEN, responseModel);
    }
    ValidationActionResponse validationResponse = validateWithoutChecks(resource);
    if (validationResponse.isError()) {
        return ValidationActionResponse.createOKResponseWithContent(validationResponse);
    }
    return testWithoutChecks(resource);
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.api.common.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse)

Example 39 with ValidationResponseModel

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

the class GlobalConfigurationModelToConcreteConverter method convertAndValidate.

public Optional<T> convertAndValidate(ConfigurationModel globalConfigurationModel) {
    Optional<T> configModel = convert(globalConfigurationModel);
    if (configModel.isEmpty()) {
        return Optional.empty();
    }
    ValidationResponseModel validationResponseModel = validate(configModel.get());
    if (validationResponseModel.hasErrors()) {
        logger.error("Converted field model validation failed: {}", validationResponseModel.getMessage());
        for (AlertFieldStatus errorStatus : validationResponseModel.getErrors().values()) {
            logger.error("Field: '{}' failed with the error: {}", errorStatus.getFieldName(), errorStatus.getFieldMessage());
        }
        return Optional.empty();
    }
    return configModel;
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.api.common.model.ValidationResponseModel) AlertFieldStatus(com.synopsys.integration.alert.api.common.model.errors.AlertFieldStatus)

Example 40 with ValidationResponseModel

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

the class RoleActions method validateWithoutChecks.

@Override
protected ValidationActionResponse validateWithoutChecks(RolePermissionModel resource) {
    ValidationResponseModel responseModel;
    List<AlertFieldStatus> alertFieldStatus = fullyValidateRoleNameField(resource);
    if (alertFieldStatus.isEmpty()) {
        responseModel = ValidationResponseModel.success("The role name is valid");
        return new ValidationActionResponse(HttpStatus.OK, responseModel);
    }
    responseModel = ValidationResponseModel.fromStatusCollection("There were problems with the role configuration", alertFieldStatus);
    return new ValidationActionResponse(HttpStatus.BAD_REQUEST, responseModel);
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.api.common.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) AlertFieldStatus(com.synopsys.integration.alert.api.common.model.errors.AlertFieldStatus)

Aggregations

ValidationResponseModel (com.synopsys.integration.alert.api.common.model.ValidationResponseModel)179 Test (org.junit.jupiter.api.Test)139 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)66 AlertFieldStatus (com.synopsys.integration.alert.api.common.model.errors.AlertFieldStatus)54 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)50 SettingsProxyModel (com.synopsys.integration.alert.common.rest.model.SettingsProxyModel)36 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)29 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)26 JiraServerGlobalConfigAccessor (com.synopsys.integration.alert.channel.jira.server.database.accessor.JiraServerGlobalConfigAccessor)20 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)18 SettingsProxyTestAction (com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyTestAction)18 IntegrationException (com.synopsys.integration.exception.IntegrationException)16 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)14 EmailGlobalConfigurationValidator (com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator)14 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)14 AlertFieldException (com.synopsys.integration.alert.common.exception.AlertFieldException)14 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)14 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)14 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)14 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)12