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