Search in sources :

Example 1 with ErrorCode

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);
}
Also used : ErrorCode(alfio.model.result.ErrorCode)

Example 2 with ErrorCode

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);
    }
}
Also used : ResultStatus(alfio.model.result.Result.ResultStatus) ErrorCode(alfio.model.result.ErrorCode) MapBindingResult(org.springframework.validation.MapBindingResult) Result(alfio.model.result.Result)

Example 3 with ErrorCode

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);
    }
}
Also used : ResultStatus(alfio.model.result.Result.ResultStatus) ErrorCode(alfio.model.result.ErrorCode) Result(alfio.model.result.Result)

Example 4 with ErrorCode

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();
}
Also used : ErrorCode(alfio.model.result.ErrorCode)

Aggregations

ErrorCode (alfio.model.result.ErrorCode)4 Result (alfio.model.result.Result)2 ResultStatus (alfio.model.result.Result.ResultStatus)2 MapBindingResult (org.springframework.validation.MapBindingResult)1