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