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