diff --git a/spring-boot-modules/spring-boot-servicelayer-validation/.gitignore b/spring-boot-modules/spring-boot-servicelayer-validation/.gitignore deleted file mode 100644 index 8f5ee06047..0000000000 --- a/spring-boot-modules/spring-boot-servicelayer-validation/.gitignore +++ /dev/null @@ -1,63 +0,0 @@ -# Created by https://www.gitignore.io/api/eclipse - -### Eclipse ### - -.metadata -target/ -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.settings/ -.loadpath -.recommenders - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# PyDev specific (Python IDE for Eclipse) -*.pydevproject - -# CDT-specific (C/C++ Development Tooling) -.cproject - -# Java annotation processor (APT) -.factorypath - -# PDT-specific (PHP Development Tools) -.buildpath - -# sbteclipse plugin -.target - -# Tern plugin -.tern-project - -# TeXlipse plugin -.texlipse - -# STS (Spring Tool Suite) -.springBeans - -# Code Recommenders -.recommenders/ - -# Scala IDE specific (Scala & Java development for Eclipse) -.cache-main -.scala_dependencies -.worksheet - -### Eclipse Patch ### -# Eclipse Core -.project - -# JDT-specific (Eclipse Java Development Tools) -.classpath - -# End of https://www.gitignore.io/api/eclipse \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-servicelayer-validation/README.md b/spring-boot-modules/spring-boot-servicelayer-validation/README.md deleted file mode 100644 index 7c39135db6..0000000000 --- a/spring-boot-modules/spring-boot-servicelayer-validation/README.md +++ /dev/null @@ -1,4 +0,0 @@ -## Spring Service Layer Validation - -This module contains articles about validation in Service layer of Spring Boot project. - diff --git a/spring-boot-modules/spring-boot-servicelayer-validation/pom.xml b/spring-boot-modules/spring-boot-servicelayer-validation/pom.xml deleted file mode 100644 index 31ec757699..0000000000 --- a/spring-boot-modules/spring-boot-servicelayer-validation/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - 4.0.0 - - com.baeldung.spring-service-layer-validation - spring-service-layer-validation - 0.0.1-SNAPSHOT - - - UTF-8 - 12 - 12 - - - - org.springframework.boot - spring-boot-starter-parent - 2.4.5 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.hibernate.validator - hibernate-validator - - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - diff --git a/spring-boot-modules/spring-boot-servicelayer-validation/src/main/java/com/baeldung/spring/servicevalidation/SpringServiceLayerValidationApp.java b/spring-boot-modules/spring-boot-servicelayer-validation/src/main/java/com/baeldung/spring/servicevalidation/SpringServiceLayerValidationApp.java deleted file mode 100644 index ea80a5da33..0000000000 --- a/spring-boot-modules/spring-boot-servicelayer-validation/src/main/java/com/baeldung/spring/servicevalidation/SpringServiceLayerValidationApp.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.spring.servicevalidation; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SpringServiceLayerValidationApp { - - public static void main(String[] args) { - SpringApplication.run(SpringServiceLayerValidationApp.class, args); - } - -} diff --git a/spring-boot-modules/spring-boot-servicelayer-validation/src/main/java/com/baeldung/spring/servicevalidation/controller/UserAccountController.java b/spring-boot-modules/spring-boot-servicelayer-validation/src/main/java/com/baeldung/spring/servicevalidation/controller/UserAccountController.java deleted file mode 100644 index b558ed89c2..0000000000 --- a/spring-boot-modules/spring-boot-servicelayer-validation/src/main/java/com/baeldung/spring/servicevalidation/controller/UserAccountController.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.spring.servicevalidation.controller; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; - -import com.baeldung.spring.servicevalidation.domain.UserAccount; -import com.baeldung.spring.servicevalidation.service.UserAccountService; - -@RestController -public class UserAccountController { - - @Autowired - private UserAccountService service; - - @PostMapping("/addUserAccount") - public Object addUserAccount(@RequestBody UserAccount userAccount) { - return service.addUserAccount(userAccount); - } - -} diff --git a/spring-boot-modules/spring-boot-servicelayer-validation/src/main/java/com/baeldung/spring/servicevalidation/dao/UserAccountDao.java b/spring-boot-modules/spring-boot-servicelayer-validation/src/main/java/com/baeldung/spring/servicevalidation/dao/UserAccountDao.java deleted file mode 100644 index d170ceef58..0000000000 --- a/spring-boot-modules/spring-boot-servicelayer-validation/src/main/java/com/baeldung/spring/servicevalidation/dao/UserAccountDao.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.baeldung.spring.servicevalidation.dao; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.springframework.stereotype.Service; - -import com.baeldung.spring.servicevalidation.domain.UserAccount; - -@Service -public class UserAccountDao { - - private Map DB = new HashMap(); - - public String addUserAccount(UserAccount useraccount) { - DB.put(useraccount.getName(), useraccount); - return "success"; - } - - public Collection getAllUserAccounts() { - - Collection list = DB.values(); - if(list.isEmpty()) { - list.addAll(DB.values()); - } - return list; - - } - - -} diff --git a/spring-boot-modules/spring-boot-servicelayer-validation/src/main/java/com/baeldung/spring/servicevalidation/domain/UserAccount.java b/spring-boot-modules/spring-boot-servicelayer-validation/src/main/java/com/baeldung/spring/servicevalidation/domain/UserAccount.java deleted file mode 100644 index 5b0e795a8a..0000000000 --- a/spring-boot-modules/spring-boot-servicelayer-validation/src/main/java/com/baeldung/spring/servicevalidation/domain/UserAccount.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.baeldung.spring.servicevalidation.domain; - -import javax.validation.Valid; -import javax.validation.constraints.Min; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; - -public class UserAccount { - - @NotNull(message = "Password must be between 4 to 15 characters") - @Size(min = 4, max = 15) - private String password; - - @NotBlank(message = "Name must not be blank") - private String name; - - @Min(value = 18, message = "Age should not be less than 18") - private int age; - - @NotBlank(message = "Phone must not be blank") - private String phone; - - @Valid - @NotNull(message = "UserAddress must not be blank") - private UserAddress useraddress; - - public UserAddress getUseraddress() { - return useraddress; - } - - public void setUseraddress(UserAddress useraddress) { - this.useraddress = useraddress; - } - - public UserAccount() { - - } - - public UserAccount(String email, String password, String name, int age) { - this.password = password; - this.name = name; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public int getAge() { - return age; - } - - public void setAge(int age) { - this.age = age; - } - - public String getPhone() { - return phone; - } - - public void setPhone(String phone) { - this.phone = phone; - } - -} diff --git a/spring-boot-modules/spring-boot-servicelayer-validation/src/main/java/com/baeldung/spring/servicevalidation/domain/UserAddress.java b/spring-boot-modules/spring-boot-servicelayer-validation/src/main/java/com/baeldung/spring/servicevalidation/domain/UserAddress.java deleted file mode 100644 index 85e7dfc05c..0000000000 --- a/spring-boot-modules/spring-boot-servicelayer-validation/src/main/java/com/baeldung/spring/servicevalidation/domain/UserAddress.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.spring.servicevalidation.domain; - -import javax.validation.constraints.NotBlank; -public class UserAddress { - - @NotBlank - private String countryCode; - - public String getCountryCode() { - return countryCode; - } - - public void setCountryCode(String countryCode) { - this.countryCode = countryCode; - } - -} 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 deleted file mode 100644 index 417e9a32b7..0000000000 --- a/spring-boot-modules/spring-boot-servicelayer-validation/src/main/java/com/baeldung/spring/servicevalidation/service/UserAccountService.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.baeldung.spring.servicevalidation.service; - -import java.util.Set; - -import javax.validation.ConstraintViolation; -import javax.validation.ConstraintViolationException; -import javax.validation.Validator; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import com.baeldung.spring.servicevalidation.dao.UserAccountDao; -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); - - 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!"; - } - -}