From ed01815cafeab2eaec9f4f11c721b5d37c24d9ab Mon Sep 17 00:00:00 2001 From: raviavhad Date: Sat, 24 Jul 2021 14:15:50 +0530 Subject: [PATCH] Update UserAccountService.java Reverting changes --- .../service/UserAccountService.java | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/spring-boot-modules/spring-boot-servicelayer-validation/src/main/java/com/baeldung/spring/servicevalidation/service/UserAccountService.java b/spring-boot-modules/spring-boot-servicelayer-validation/src/main/java/com/baeldung/spring/servicevalidation/service/UserAccountService.java index c438719d3a..417e9a32b7 100644 --- a/spring-boot-modules/spring-boot-servicelayer-validation/src/main/java/com/baeldung/spring/servicevalidation/service/UserAccountService.java +++ b/spring-boot-modules/spring-boot-servicelayer-validation/src/main/java/com/baeldung/spring/servicevalidation/service/UserAccountService.java @@ -15,25 +15,28 @@ import com.baeldung.spring.servicevalidation.domain.UserAccount; @Service public class UserAccountService { - @Autowired - private Validator validator; - - @Autowired - private UserAccountDao dao; - - public String addUserAccount(UserAccount useraccount) { - - Set> violations = validator.validate(useraccount); + @Autowired + private Validator validator; - if (!violations.isEmpty()) { - StringBuilder sb = new StringBuilder(); - for (ConstraintViolation constraintViolation : violations) { - sb.append(constraintViolation.getMessage()); - } - throw new ConstraintViolationException("Error occurred: " + sb.toString(), violations); - } - dao.addUserAccount(useraccount); - return "Account for " + useraccount.getName() + " Added!"; - } + @Autowired + private UserAccountDao dao; + + public String addUserAccount(UserAccount useraccount) { + + Set> violations = validator.validate(useraccount); + + if (!violations.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (ConstraintViolation constraintViolation : violations) { + sb.append(constraintViolation.getMessage()); + } + + dao.addUserAccount(useraccount); + + throw new ConstraintViolationException("Error occurred: " + sb.toString(), violations); + } + + return "Account for " + useraccount.getName() + " Added!"; + } }