source: src/main/java/it/finki/tinki/service/impl/WorkServiceImpl.java@ f067338

Last change on this file since f067338 was f067338, checked in by Vzdra <vladko.zdravkovski@…>, 3 years ago

added full text search on work

  • Property mode set to 100644
File size: 7.1 KB
RevLine 
[509cb95]1package it.finki.tinki.service.impl;
2
[297bd16]3import it.finki.tinki.model.Users.User;
[bd46dbb]4import it.finki.tinki.model.Work.Internship;
5import it.finki.tinki.model.Work.Job;
6import it.finki.tinki.model.Work.Project;
[509cb95]7import it.finki.tinki.model.Skill;
8import it.finki.tinki.model.Users.Account;
[f067338]9import it.finki.tinki.model.Work.Work;
10import it.finki.tinki.model.dto.response.work.InternshipResponseDTO;
11import it.finki.tinki.model.dto.response.work.JobResponseDTO;
12import it.finki.tinki.model.dto.response.work.ProjectResponseDTO;
13import it.finki.tinki.model.dto.response.work.WorkResponseDTO;
[509cb95]14import it.finki.tinki.model.enumerator.AccountType;
[297bd16]15import it.finki.tinki.repository.*;
[509cb95]16import it.finki.tinki.service.AccountService;
[297bd16]17import it.finki.tinki.service.MatchmakerService;
[509cb95]18import it.finki.tinki.service.SkillService;
19import it.finki.tinki.service.WorkService;
20import org.springframework.stereotype.Service;
21
[f067338]22import java.util.*;
[509cb95]23
24@Service
25public class WorkServiceImpl implements WorkService {
26
27 JobRepository jobRepository;
28 InternshipRepository internshipRepository;
29 ProjectRepository projectRepository;
30 MatchRepository matchRepository;
[297bd16]31 MatchmakerService matchmakerService;
[509cb95]32 SkillService skillService;
33 AccountService accountService;
[297bd16]34 UserRepository userRepository;
[509cb95]35
36 public WorkServiceImpl(JobRepository jobRepository,
37 InternshipRepository internshipRepository,
38 ProjectRepository projectRepository,
39 MatchRepository matchRepository,
40 SkillService skillService,
[297bd16]41 AccountService accountService,
42 UserRepository userRepository,
43 MatchmakerService matchmakerService) {
[509cb95]44 this.jobRepository = jobRepository;
45 this.internshipRepository = internshipRepository;
46 this.projectRepository = projectRepository;
47 this.matchRepository = matchRepository;
48 this.skillService = skillService;
49 this.accountService = accountService;
[297bd16]50 this.userRepository = userRepository;
51 this.matchmakerService = matchmakerService;
[509cb95]52 }
53
54 @Override
55 public List<Job> getAllJobsByAccount(Long accId) {
56 return this.jobRepository.findAllByAccount_Id(accId);
57 }
58
59 @Override
60 public List<Internship> getAllInternshipsByAccount(Long accId) {
61 return this.internshipRepository.findAllByAccount_Id(accId);
62 }
63
64 @Override
65 public List<Project> getAllProjectsByAccount(Long accId) {
66 return this.projectRepository.findAllByAccount_Id(accId);
67 }
68
69 @Override
70 public List<Job> getAllJobs() {
71 return this.jobRepository.findAll();
72 }
73
74 @Override
75 public List<Internship> getAllInternships() {
76 return this.internshipRepository.findAll();
77 }
78
79 @Override
80 public List<Project> getAllProjects() {
81 return this.projectRepository.findAll();
82 }
83
84 @Override
[a8e8545]85 public Job insertJob(String title, String description, Long adccId, int salary, List<Long> skillsRequired, AccountType type) {
[509cb95]86 List<Skill> skills = this.skillService.returnSkillsBasedOnId(skillsRequired);
87 Account account = this.accountService.findByIdAndType(adccId, type);
88 Job j = new Job(title, description, account, salary, skills);
[297bd16]89 Job jb = this.jobRepository.save(j);
90
91 List<User> users = this.userRepository.findAll();
92
93 users.forEach(user -> {
94 this.matchmakerService.setUpUserJobMatches(jb, user);
95 });
96
97 return jb;
[509cb95]98 }
99
100 @Override
[a8e8545]101 public Internship insertInternship(String title, String description, Long adccId, int salary, List<Long> skillsTrained, int openSpots, AccountType type) {
[509cb95]102 List<Skill> skills = this.skillService.returnSkillsBasedOnId(skillsTrained);
103 Account account = this.accountService.findByIdAndType(adccId, type);
104 Internship j = new Internship(title, description, account, salary, skills, openSpots);
[297bd16]105 Internship jb = this.internshipRepository.save(j);
106
107 List<User> users = this.userRepository.findAll();
108
109 users.forEach(user -> {
110 this.matchmakerService.setUpUserInternshipMatches(jb, user);
111 });
112
113 return jb;
[509cb95]114 }
115
116 @Override
[a8e8545]117 public Project insertProject(String title, String description, Long adccId, int salary, List<Long> skillsRequired, Date validUntil, AccountType type) {
[509cb95]118 List<Skill> skills = this.skillService.returnSkillsBasedOnId(skillsRequired);
119 Account account = this.accountService.findByIdAndType(adccId, type);
120 Project j = new Project(title, description, account, salary, skills, validUntil);
[297bd16]121 Project jb = this.projectRepository.save(j);
122
123 List<User> users = this.userRepository.findAll();
124
125 users.forEach(user -> {
126 this.matchmakerService.setUpUserProjectMatches(jb, user);
127 });
128
129 return jb;
[509cb95]130 }
[f067338]131
132 @Override
133 public List<JobResponseDTO> fullTextJobSearch(String text) {
134 List<Skill> skills = this.skillService.returnBasedOnText(text);
135
136 List<Job> jobs = this.jobRepository.findAllByTitleContainsOrDescriptionContains(text,text);
137 List<Job> sjob = new ArrayList<>();
138
139 skills.forEach(skill -> {
140 sjob.addAll(this.jobRepository.findAllBySkillsRequiredContaining(skill));
141 });
142
143 sjob.forEach(job -> {
144 if(!jobs.contains(job)){
145 jobs.add(job);
146 }
147 });
148
149 List<JobResponseDTO> jobs2 = new ArrayList<>();
150
151 jobs.forEach(job -> {
152 jobs2.add(new JobResponseDTO(job));
153 });
154
155 return jobs2;
156 }
157
158 @Override
159 public List<InternshipResponseDTO> fullTextInternshipSearch(String text) {
160 List<Skill> skills = this.skillService.returnBasedOnText(text);
161
162 List<Internship> jobs = this.internshipRepository.findAllByTitleContainsOrDescriptionContains(text,text);
163 List<Internship> sjob = new ArrayList<>();
164
165 skills.forEach(skill -> {
166 sjob.addAll(this.internshipRepository.findAllBySkillsTrainedContaining(skill));
167 });
168
169 sjob.forEach(job -> {
170 if(!jobs.contains(job)){
171 jobs.add(job);
172 }
173 });
174
175 List<InternshipResponseDTO> jobs2 = new ArrayList<>();
176
177 jobs.forEach(job -> {
178 jobs2.add(new InternshipResponseDTO(job));
179 });
180
181 return jobs2;
182 }
183
184 @Override
185 public List<ProjectResponseDTO> fullTextProjectSearch(String text) {
186 List<Skill> skills = this.skillService.returnBasedOnText(text);
187
188 List<Project> jobs = this.projectRepository.findAllByTitleContainsOrDescriptionContains(text,text);
189 List<Project> sjob = new ArrayList<>();
190
191 skills.forEach(skill -> {
192 sjob.addAll(this.projectRepository.findAllBySkillsRequiredContaining(skill));
193 });
194
195 sjob.forEach(job -> {
196 if(!jobs.contains(job)){
197 jobs.add(job);
198 }
199 });
200
201 List<ProjectResponseDTO> jobs2 = new ArrayList<>();
202
203 jobs.forEach(job -> {
204 jobs2.add(new ProjectResponseDTO(job));
205 });
206
207 return jobs2;
208 }
[509cb95]209}
Note: See TracBrowser for help on using the repository browser.