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