use of alfio.model.result.ErrorCode in project alf.io by alfio-event.
the class Validator method performAdvancedValidation.
public static ValidationResult performAdvancedValidation(AdvancedTicketAssignmentValidator advancedValidator, AdvancedValidationContext context, Errors errors) {
if (errors == null) {
return ValidationResult.success();
}
Result<Void> advancedValidation = advancedValidator.apply(context);
if (!advancedValidation.isSuccess()) {
ErrorCode error = advancedValidation.getFirstErrorOrNull();
Validate.notNull(error, "unexpected error");
errors.rejectValue(StringUtils.defaultString(context.prefix) + error.getDescription(), error.getCode());
}
return evaluateValidationResult(errors);
}
use of alfio.model.result.ErrorCode in project alf.io by alfio-event.
the class AdminReservationManager method reduceResults.
private <T> Result<T> reduceResults(Result<T> r1, Result<T> r2, BinaryOperator<T> processData) {
boolean successful = r1.isSuccess() && r2.isSuccess();
ResultStatus global = r1.isSuccess() ? r2.getStatus() : r1.getStatus();
List<ErrorCode> errors = new ArrayList<>();
if (!successful) {
errors.addAll(r1.getErrors());
errors.addAll(r2.getErrors());
return new Result<>(global, null, errors);
} else {
return new Result<>(global, processData.apply(r1.getData(), r2.getData()), errors);
}
}
use of alfio.model.result.ErrorCode in project alf.io by alfio-event.
the class AdminReservationManager method reduceResults.
private <T> Result<T> reduceResults(Result<T> r1, Result<T> r2, BiFunction<T, T, T> processData) {
boolean successful = r1.isSuccess() && r2.isSuccess();
ResultStatus global = r1.isSuccess() ? r2.getStatus() : r1.getStatus();
List<ErrorCode> errors = new ArrayList<>();
if (!successful) {
errors.addAll(r1.getErrors());
errors.addAll(r2.getErrors());
return new Result<>(global, null, errors);
} else {
return new Result<>(global, processData.apply(r1.getData(), r2.getData()), errors);
}
}
use of alfio.model.result.ErrorCode in project alf.io by alfio-event.
the class GroupApiController method createNew.
@PostMapping("/for/{organizationId}/new")
public ResponseEntity<String> createNew(@PathVariable("organizationId") int organizationId, @RequestBody GroupModification request, Principal principal) {
if (notOwner(principal.getName(), organizationId)) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}
if (request.getOrganizationId() != organizationId) {
return ResponseEntity.badRequest().build();
}
Result<Integer> result = groupManager.createNew(request);
if (result.isSuccess()) {
return ResponseEntity.ok(String.valueOf(result.getData()));
}
ErrorCode error = result.getFirstErrorOrNull();
if (error != null && error.getCode().equals("value.duplicate")) {
return ResponseEntity.badRequest().body(error.getDescription());
}
return ResponseEntity.badRequest().build();
}
Aggregations