Search in sources :

Example 41 with ValidationActionResponse

use of com.synopsys.integration.alert.common.action.ValidationActionResponse in project hub-alert by blackducksoftware.

the class AbstractJobResourceActions method update.

public final ActionResponse<JobFieldModel> update(UUID id, JobFieldModel resource) {
    boolean hasPermissions = hasRequiredPermissions(resource.getFieldModels(), authorizationManager::hasWritePermission);
    if (!hasPermissions) {
        return ActionResponse.createForbiddenResponse();
    }
    Optional<JobFieldModel> existingJob = findJobFieldModel(id);
    if (existingJob.isEmpty()) {
        return new ActionResponse<>(HttpStatus.NOT_FOUND);
    }
    // Clean input
    correctProjectsField(resource);
    ValidationActionResponse validationResponse = validateWithoutChecks(resource);
    if (validationResponse.isError()) {
        return new ActionResponse<>(validationResponse.getHttpStatus(), validationResponse.getMessage().orElse(null));
    }
    return updateWithoutChecks(id, resource);
}
Also used : ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) MultiJobFieldModel(com.synopsys.integration.alert.common.rest.model.MultiJobFieldModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 42 with ValidationActionResponse

use of com.synopsys.integration.alert.common.action.ValidationActionResponse in project hub-alert by blackducksoftware.

the class AbstractJobResourceActions method test.

public final ValidationActionResponse test(JobFieldModel resource) {
    boolean hasPermissions = hasRequiredPermissions(resource.getFieldModels(), authorizationManager::hasExecutePermission);
    if (!hasPermissions) {
        ValidationResponseModel responseModel = ValidationResponseModel.generalError(ActionResponse.FORBIDDEN_MESSAGE);
        return new ValidationActionResponse(HttpStatus.FORBIDDEN, responseModel);
    }
    // Clean input
    correctProjectsField(resource);
    ValidationActionResponse validationResponse = validateWithoutChecks(resource);
    if (validationResponse.isError()) {
        return ValidationActionResponse.createOKResponseWithContent(validationResponse);
    }
    return testWithoutChecks(resource);
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse)

Example 43 with ValidationActionResponse

use of com.synopsys.integration.alert.common.action.ValidationActionResponse in project hub-alert by blackducksoftware.

the class ConfigurationTestHelper method test.

public ValidationActionResponse test(Supplier<ValidationActionResponse> validationSupplier, Supplier<ConfigurationTestResult> testResultSupplier) {
    if (!authorizationManager.hasExecutePermission(context, descriptorKey)) {
        ValidationResponseModel responseModel = ValidationResponseModel.generalError(ActionResponse.FORBIDDEN_MESSAGE);
        return new ValidationActionResponse(HttpStatus.FORBIDDEN, responseModel);
    }
    ValidationActionResponse validationResponse = validationSupplier.get();
    // using different validation schemes, this should be removed.
    if (validationResponse.isError() || validationResponse.hasValidationErrors()) {
        return validationResponse;
    }
    ConfigurationTestResult testResult = testResultSupplier.get();
    if (testResult.isSuccess()) {
        return new ValidationActionResponse(HttpStatus.OK, ValidationResponseModel.success(testResult.getStatusMessage()));
    } else {
        return new ValidationActionResponse(HttpStatus.OK, ValidationResponseModel.generalError(testResult.getStatusMessage()));
    }
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ConfigurationTestResult(com.synopsys.integration.alert.common.message.model.ConfigurationTestResult)

Example 44 with ValidationActionResponse

use of com.synopsys.integration.alert.common.action.ValidationActionResponse in project hub-alert by blackducksoftware.

the class UserActions method validateWithoutChecks.

@Override
protected ValidationActionResponse validateWithoutChecks(UserConfig resource) {
    ValidationResponseModel responseModel;
    if (StringUtils.isNotBlank(resource.getId()) && !NumberUtils.isCreatable(resource.getId())) {
        responseModel = ValidationResponseModel.generalError("Invalid resource id");
        return new ValidationActionResponse(HttpStatus.BAD_REQUEST, responseModel);
    }
    List<AlertFieldStatus> fieldErrors = validateCreationRequiredFields(resource);
    validateUserRole(resource).ifPresent(fieldErrors::add);
    if (fieldErrors.isEmpty()) {
        responseModel = ValidationResponseModel.success("The user is valid");
        return new ValidationActionResponse(HttpStatus.OK, responseModel);
    }
    responseModel = ValidationResponseModel.fromStatusCollection("There were problems validating this user.", fieldErrors);
    return new ValidationActionResponse(HttpStatus.BAD_REQUEST, responseModel);
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)

Aggregations

ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)44 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)33 Test (org.junit.jupiter.api.Test)28 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)15 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)13 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)10 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)9 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)9 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)8 ChannelKey (com.synopsys.integration.alert.descriptor.api.model.ChannelKey)8 AuthenticationTestUtils (com.synopsys.integration.alert.test.common.AuthenticationTestUtils)8 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)7 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)7 AlertFieldException (com.synopsys.integration.alert.common.exception.AlertFieldException)7 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)7 FieldModelTestAction (com.synopsys.integration.alert.common.action.FieldModelTestAction)6 FieldUtility (com.synopsys.integration.alert.common.persistence.accessor.FieldUtility)6 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)6 IntegrationException (com.synopsys.integration.exception.IntegrationException)6 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)6