[509cb95] | 1 | package it.finki.tinki.service.impl;
|
---|
| 2 |
|
---|
[297bd16] | 3 | import it.finki.tinki.model.Users.User;
|
---|
[bd46dbb] | 4 | import it.finki.tinki.model.Work.Internship;
|
---|
| 5 | import it.finki.tinki.model.Work.Job;
|
---|
| 6 | import it.finki.tinki.model.Work.Project;
|
---|
[509cb95] | 7 | import it.finki.tinki.model.Skill;
|
---|
| 8 | import it.finki.tinki.model.Users.Account;
|
---|
[f067338] | 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;
|
---|
[509cb95] | 12 | import it.finki.tinki.model.enumerator.AccountType;
|
---|
[297bd16] | 13 | import it.finki.tinki.repository.*;
|
---|
[509cb95] | 14 | import it.finki.tinki.service.AccountService;
|
---|
[297bd16] | 15 | import it.finki.tinki.service.MatchmakerService;
|
---|
[509cb95] | 16 | import it.finki.tinki.service.SkillService;
|
---|
| 17 | import it.finki.tinki.service.WorkService;
|
---|
| 18 | import org.springframework.stereotype.Service;
|
---|
| 19 |
|
---|
[f067338] | 20 | import java.util.*;
|
---|
[509cb95] | 21 |
|
---|
| 22 | @Service
|
---|
| 23 | public class WorkServiceImpl implements WorkService {
|
---|
| 24 |
|
---|
| 25 | JobRepository jobRepository;
|
---|
| 26 | InternshipRepository internshipRepository;
|
---|
| 27 | ProjectRepository projectRepository;
|
---|
| 28 | MatchRepository matchRepository;
|
---|
[297bd16] | 29 | MatchmakerService matchmakerService;
|
---|
[509cb95] | 30 | SkillService skillService;
|
---|
| 31 | AccountService accountService;
|
---|
[297bd16] | 32 | UserRepository userRepository;
|
---|
[509cb95] | 33 |
|
---|
| 34 | public WorkServiceImpl(JobRepository jobRepository,
|
---|
| 35 | InternshipRepository internshipRepository,
|
---|
| 36 | ProjectRepository projectRepository,
|
---|
| 37 | MatchRepository matchRepository,
|
---|
| 38 | SkillService skillService,
|
---|
[297bd16] | 39 | AccountService accountService,
|
---|
| 40 | UserRepository userRepository,
|
---|
| 41 | MatchmakerService matchmakerService) {
|
---|
[509cb95] | 42 | this.jobRepository = jobRepository;
|
---|
| 43 | this.internshipRepository = internshipRepository;
|
---|
| 44 | this.projectRepository = projectRepository;
|
---|
| 45 | this.matchRepository = matchRepository;
|
---|
| 46 | this.skillService = skillService;
|
---|
| 47 | this.accountService = accountService;
|
---|
[297bd16] | 48 | this.userRepository = userRepository;
|
---|
| 49 | this.matchmakerService = matchmakerService;
|
---|
[509cb95] | 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
|
---|
[a8e8545] | 68 | public Job insertJob(String title, String description, Long adccId, int salary, List<Long> skillsRequired, AccountType type) {
|
---|
[509cb95] | 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);
|
---|
[297bd16] | 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;
|
---|
[509cb95] | 81 | }
|
---|
| 82 |
|
---|
| 83 | @Override
|
---|
[a8e8545] | 84 | public Internship insertInternship(String title, String description, Long adccId, int salary, List<Long> skillsTrained, int openSpots, AccountType type) {
|
---|
[509cb95] | 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);
|
---|
[297bd16] | 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;
|
---|
[509cb95] | 97 | }
|
---|
| 98 |
|
---|
| 99 | @Override
|
---|
[a8e8545] | 100 | public Project insertProject(String title, String description, Long adccId, int salary, List<Long> skillsRequired, Date validUntil, AccountType type) {
|
---|
[509cb95] | 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);
|
---|
[297bd16] | 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;
|
---|
[509cb95] | 113 | }
|
---|
[f067338] | 114 |
|
---|
[a3d2b0d] | 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 |
|
---|
[f067338] | 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 | }
|
---|
[a3d2b0d] | 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 | }
|
---|
[509cb95] | 240 | }
|
---|