Search in sources :

Example 1 with RequestValidationException

use of com.nexblocks.authguard.rest.exceptions.RequestValidationException in project AuthGuard by AuthGuard.

the class CredentialsRoute method addIdentifiers.

public void addIdentifiers(final Context context) {
    final String credentialsId = context.pathParam("id");
    final UserIdentifiersRequestDTO request = userIdentifiersRequestBodyHandler.getValidated(context);
    if (request.getOldIdentifier() != null && request.getIdentifiers().size() != 1) {
        throw new RequestValidationException(Collections.singletonList(new Violation("identifier", ViolationType.EXCEEDS_LENGTH_BOUNDARIES)));
    }
    final List<UserIdentifierBO> identifiers = request.getIdentifiers().stream().map(restMapper::toBO).collect(Collectors.toList());
    if (request.getOldIdentifier() != null) {
        credentialsService.replaceIdentifier(credentialsId, request.getOldIdentifier(), identifiers.get(0)).map(restMapper::toDTO).ifPresentOrElse(context::json, () -> context.status(404));
    } else {
        credentialsService.addIdentifiers(credentialsId, identifiers).map(restMapper::toDTO).ifPresentOrElse(context::json, () -> context.status(404));
    }
}
Also used : Violation(com.nexblocks.authguard.api.dto.validation.violations.Violation) UserIdentifiersRequestDTO(com.nexblocks.authguard.api.dto.requests.UserIdentifiersRequestDTO) RequestValidationException(com.nexblocks.authguard.rest.exceptions.RequestValidationException)

Aggregations

UserIdentifiersRequestDTO (com.nexblocks.authguard.api.dto.requests.UserIdentifiersRequestDTO)1 Violation (com.nexblocks.authguard.api.dto.validation.violations.Violation)1 RequestValidationException (com.nexblocks.authguard.rest.exceptions.RequestValidationException)1