From 4fc66833dc21ad56794a1f5e1f4b3d5faaa283c1 Mon Sep 17 00:00:00 2001 From: Ryan Doherty Date: Mon, 5 Aug 2024 12:36:12 -0400 Subject: [PATCH] Use validation bundle formatting for user errors during user profile initial submission or edit --- .../wdk/service/service/user/ProfileService.java | 7 +++++-- .../wdk/service/service/user/UserUtilityServices.java | 11 +++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Service/src/main/java/org/gusdb/wdk/service/service/user/ProfileService.java b/Service/src/main/java/org/gusdb/wdk/service/service/user/ProfileService.java index f2bdd3c46..65cbc1e2d 100644 --- a/Service/src/main/java/org/gusdb/wdk/service/service/user/ProfileService.java +++ b/Service/src/main/java/org/gusdb/wdk/service/service/user/ProfileService.java @@ -21,6 +21,7 @@ import org.gusdb.wdk.model.user.UserPreferences; import org.gusdb.wdk.service.UserBundle; import org.gusdb.wdk.service.formatter.UserFormatter; +import org.gusdb.wdk.service.formatter.ValidationFormatter; import org.gusdb.wdk.service.request.exception.ConflictException; import org.gusdb.wdk.service.request.exception.DataValidationException; import org.gusdb.wdk.service.request.exception.RequestMisformatException; @@ -91,10 +92,12 @@ public Response setUserProfile(String body) throw new BadRequestException(e); } catch (InvalidPropertiesException e) { - throw new DataValidationException(e.getMessage()); + // convert to use validation bundle JSON formatting + throw new DataValidationException(ValidationFormatter.getValidationBundleJson(e.getMessage()).toString()); } catch (InvalidUsernameOrEmailException e) { - throw new ConflictException(e.getMessage()); + // convert to use validation bundle JSON formatting + throw new ConflictException(ValidationFormatter.getValidationBundleJson(e.getMessage()).toString()); } } } diff --git a/Service/src/main/java/org/gusdb/wdk/service/service/user/UserUtilityServices.java b/Service/src/main/java/org/gusdb/wdk/service/service/user/UserUtilityServices.java index c6282e63f..cbc1c0312 100644 --- a/Service/src/main/java/org/gusdb/wdk/service/service/user/UserUtilityServices.java +++ b/Service/src/main/java/org/gusdb/wdk/service/service/user/UserUtilityServices.java @@ -27,6 +27,7 @@ import org.gusdb.wdk.model.user.User; import org.gusdb.wdk.model.user.UserPreferenceFactory; import org.gusdb.wdk.model.user.UserPreferences; +import org.gusdb.wdk.service.formatter.ValidationFormatter; import org.gusdb.wdk.service.request.exception.ConflictException; import org.gusdb.wdk.service.request.exception.DataValidationException; import org.gusdb.wdk.service.request.exception.RequestMisformatException; @@ -77,11 +78,13 @@ public Response createNewUser(String body) throws RequestMisformatException, Dat .location(getUriInfo().getAbsolutePathBuilder().build(newUser.getUserId())) .build(); } - catch (InvalidUsernameOrEmailException e) { - throw new ConflictException(e.getMessage()); - } catch (InvalidPropertiesException e) { - throw new DataValidationException(e.getMessage()); + // convert to use validation bundle JSON formatting + throw new DataValidationException(ValidationFormatter.getValidationBundleJson(e.getMessage()).toString()); + } + catch (InvalidUsernameOrEmailException e) { + // convert to use validation bundle JSON formatting + throw new ConflictException(ValidationFormatter.getValidationBundleJson(e.getMessage()).toString()); } catch (JSONException e) { throw new RequestMisformatException(e.getMessage(), e);