diff --git a/log/output.log b/log/output.log index 39f90af..6a5a61e 100644 --- a/log/output.log +++ b/log/output.log @@ -1 +1,66 @@ 2018-12-03 | 20:53:40 | INFO | MlHhApplication:30 | Start method | +2018-12-08 | 14:10:19 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-08 | 14:10:20 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-14 | 15:42:16 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-14 | 15:42:17 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-14 | 16:08:44 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-14 | 16:08:44 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-14 | 16:12:38 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-14 | 16:12:38 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 15:01:07 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 15:01:08 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 15:06:31 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 15:06:32 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 15:09:30 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 15:12:08 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 15:12:09 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 15:17:59 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 15:18:00 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 15:21:20 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 15:21:20 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 15:25:51 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 15:25:51 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 15:27:10 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 15:27:11 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 15:30:48 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 15:30:48 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 15:41:47 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 15:41:48 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 15:55:46 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 15:55:46 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 16:06:35 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 16:06:35 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 16:12:43 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 16:12:44 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 16:19:05 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 16:19:06 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 16:21:36 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 16:21:37 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 16:27:47 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 16:27:47 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 16:29:09 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 16:29:10 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 16:34:05 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 16:34:06 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 16:45:14 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 16:45:15 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 16:46:38 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 16:46:38 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 16:48:23 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 16:48:24 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 16:51:24 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 16:51:25 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 16:52:37 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 16:52:38 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 16:55:57 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 16:55:59 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 18:30:33 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 18:30:34 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 18:34:59 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 18:35:00 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 18:38:08 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 18:38:09 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 18:38:33 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 18:38:34 | INFO | MlHhApplication:39 | Add new candidates | +2018-12-17 | 18:39:03 | INFO | WebSecurityConfig:40 | user has successfully logged in | +2018-12-17 | 18:39:04 | INFO | MlHhApplication:39 | Add new candidates | diff --git a/src/main/java/learn/epam/mlhh/MlHhApplication.java b/src/main/java/learn/epam/mlhh/MlHhApplication.java index e504cb0..313962c 100644 --- a/src/main/java/learn/epam/mlhh/MlHhApplication.java +++ b/src/main/java/learn/epam/mlhh/MlHhApplication.java @@ -48,6 +48,40 @@ private void testJpaMethods(){ candidate.setKeyWord("Spring"); candidateService.createCandidate(candidate); + Candidate candidate1 = new Candidate(); + candidate1.setName("John"); + candidate1.setAge(30); + candidate1.setGender("М"); + candidate1.setRegion("Gorky"); + candidate1.setSalary(500.000); + candidate1.setDeveloper("Java Developer"); + candidate1.setExperience(3); + candidate1.setKeyWord("Spring"); + candidateService.createCandidate(candidate1); + + Candidate candidate2 = new Candidate(); + candidate2.setName("Poul"); + candidate2.setAge(40); + candidate2.setGender("М"); + candidate2.setRegion("Gorky"); + candidate2.setSalary(1000.000); + candidate2.setDeveloper("Java Developer"); + candidate2.setExperience(5); + candidate2.setKeyWord("Spring"); + candidateService.createCandidate(candidate2); + + + Candidate candidate3 = new Candidate(); + candidate3.setName("Anna"); + candidate3.setAge(25); + candidate3.setGender("Ж"); + candidate3.setRegion("Mos"); + candidate3.setSalary(500.000); + candidate3.setDeveloper("Java Developer"); + candidate3.setExperience(3); + candidate3.setKeyWord("Spring"); + candidateService.createCandidate(candidate3); + Candidate newCandidate = new Candidate(); newCandidate.setName("FIO"); newCandidate.setAge(20); diff --git a/src/main/java/learn/epam/mlhh/controllers/SearchController.java b/src/main/java/learn/epam/mlhh/controllers/SearchController.java new file mode 100644 index 0000000..a9fa0fa --- /dev/null +++ b/src/main/java/learn/epam/mlhh/controllers/SearchController.java @@ -0,0 +1,59 @@ +package learn.epam.mlhh.controllers; + + +import learn.epam.mlhh.entity.Candidate; +import learn.epam.mlhh.entity.Search; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.Errors; +import org.springframework.web.bind.annotation.*; +import learn.epam.mlhh.service.CandidateService; + +import javax.validation.Valid; +import java.util.*; + +@Controller +public class SearchController { + + @Autowired + private CandidateService candidateService; + + + @GetMapping("/search") + public String searchForm(Model model) { + model.addAttribute("search", new Search()); + return "search"; + } + + @PostMapping("/search") + public String searchSubmit(Search search, Map model) { + + double dSearchMin = search.getSalaryMin().doubleValue(); + double dSearchMax = search.getSalaryMax().doubleValue(); + + List forsearch = candidateService.findAll(); + + Iterator i = forsearch.iterator(); + while (i.hasNext()) { + Candidate c = i.next(); // must be called before you can call i.remove() + + if ( + c.getAge() < search.getAgeMin() || c.getAge() > search.getAgeMax() + || !(c.getGender().equals(search.getGender())) + || !(c.getRegion().equals(search.getRegion())) + || c.getSalary().compareTo(dSearchMin) < 0 || c.getSalary().compareTo(dSearchMax) > 0 + || !(c.getDeveloper().equals(search.getDeveloper())) + || c.getExperience() < search.getExperienceMin() || c.getExperience() > search.getExperienceMax() + || !(c.getKeyWord().equals(search.getKeywords()))) { + i.remove(); + } + } + model.put("searchPut", forsearch); + + return "searchresult"; + } +} + + + diff --git a/src/main/java/learn/epam/mlhh/entity/Search.java b/src/main/java/learn/epam/mlhh/entity/Search.java new file mode 100644 index 0000000..fe6f687 --- /dev/null +++ b/src/main/java/learn/epam/mlhh/entity/Search.java @@ -0,0 +1,129 @@ +package learn.epam.mlhh.entity; + + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; + +import java.math.BigDecimal; + +//@Data +public class Search { + +// @NotBlank(message="ageMin is required") + private Integer ageMin; + +// @NotBlank(message="ageMax is required") + private Integer ageMax; + +// @NotBlank(message="gender is required") +// @Size(max=1, message="You can select only one character") + private String gender; + +// @NotBlank(message="region is required") + private String region; + +// @NotBlank(message="salaryMin is required") + private BigDecimal salaryMin; + +// @NotBlank(message="salaryMax is required") + private BigDecimal salaryMax; + +// @NotBlank(message="developer is required") + private String developer; + +// @NotBlank(message="experienceMin is required") + private Integer experienceMin; + +// @NotBlank(message="experienceMax is required") + private Integer experienceMax; + +// @NotBlank(message="keywords is required") + private String keywords; + + public Search() { + } + + public Integer getAgeMin() { + return ageMin; + } + + public void setAgeMin(Integer ageMin) { + this.ageMin = ageMin; + } + + public Integer getAgeMax() { + return ageMax; + } + + public void setAgeMax(Integer ageMax) { + this.ageMax = ageMax; + } + + public String getGender() { + return gender; + } + + public void setGender(String gender) { + this.gender = gender; + } + + public String getRegion() { + return region; + } + + public void setRegion(String region) { + this.region = region; + } + + public BigDecimal getSalaryMin() { + return salaryMin; + } + + public void setSalaryMin(BigDecimal salaryMin) { + this.salaryMin = salaryMin; + } + + public BigDecimal getSalaryMax() { + return salaryMax; + } + + public void setSalaryMax(BigDecimal salaryMax) { + this.salaryMax = salaryMax; + } + + public String getDeveloper() { + return developer; + } + + public void setDeveloper(String developer) { + this.developer = developer; + } + + public Integer getExperienceMin() { + return experienceMin; + } + + public void setExperienceMin(Integer experienceMin) { + this.experienceMin = experienceMin; + } + + public Integer getExperienceMax() { + return experienceMax; + } + + public void setExperienceMax(Integer experienceMax) { + this.experienceMax = experienceMax; + } + + public String getKeywords() { + return keywords; + } + + public void setKeywords(String keywords) { + this.keywords = keywords; + } + + + + +} diff --git a/src/main/java/learn/epam/mlhh/repository/CandidateRepository.java b/src/main/java/learn/epam/mlhh/repository/CandidateRepository.java index be66726..c4a2f27 100644 --- a/src/main/java/learn/epam/mlhh/repository/CandidateRepository.java +++ b/src/main/java/learn/epam/mlhh/repository/CandidateRepository.java @@ -17,4 +17,5 @@ public interface CandidateRepository extends JpaRepository { /*@Query("SELECT u FROM Candidate u WHERE developer like 'Java'") //собственный запрос List findWhereDevelop();*/ + } diff --git a/src/main/java/learn/epam/mlhh/service/CandidateService.java b/src/main/java/learn/epam/mlhh/service/CandidateService.java index 9f807c0..e7b2221 100644 --- a/src/main/java/learn/epam/mlhh/service/CandidateService.java +++ b/src/main/java/learn/epam/mlhh/service/CandidateService.java @@ -14,6 +14,7 @@ public class CandidateService { private final CandidateRepository candidateRepository; public CandidateService(CandidateRepository candidateRepository){ + this.candidateRepository = candidateRepository; } @@ -32,4 +33,5 @@ public Candidate findById(Long candidateId){ public List findAllByName(String name){ return candidateRepository.findAllByName(name); } + } diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 98d5975..bef88f3 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -18,6 +18,10 @@

+
+
+ +
diff --git a/src/main/resources/templates/result.html b/src/main/resources/templates/result.html new file mode 100644 index 0000000..a9e1661 --- /dev/null +++ b/src/main/resources/templates/result.html @@ -0,0 +1,47 @@ + + + + Table + + + + +
+
+
+

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
IDNameAgegenderregionsalarydeveloperexperiencekeyword
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/search.html b/src/main/resources/templates/search.html new file mode 100644 index 0000000..a4bd754 --- /dev/null +++ b/src/main/resources/templates/search.html @@ -0,0 +1,30 @@ + + + + Getting Started: Handling Form Submission + + + +

Search form

+
+ +
+ +
+ +

Age min:

+

Age max:

+

Gender:

+

Region:

+

Salary min:

+

Salary max:

+

Dveloper:

+

Experience min:

+

Experience max:

+

Keyword:

+
+ +
+ + + diff --git a/src/main/resources/templates/searchresult.html b/src/main/resources/templates/searchresult.html new file mode 100644 index 0000000..830b9a7 --- /dev/null +++ b/src/main/resources/templates/searchresult.html @@ -0,0 +1,47 @@ + + + + Search Table + + + + +
+
+
+

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
IDNameAgegenderregionsalarydeveloperexperiencekeyword
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/table.html b/src/main/resources/templates/table.html index a824fbb..b1b54f7 100644 --- a/src/main/resources/templates/table.html +++ b/src/main/resources/templates/table.html @@ -9,7 +9,8 @@
-

+

+