source: src/main/java/it/finki/tinki/service/impl/MatchmakerServiceImpl.java@ 509cb95

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

finalized register and login and added insert options for jobs

  • Property mode set to 100644
File size: 3.5 KB
Line 
1package it.finki.tinki.service.impl;
2
3import it.finki.tinki.helper.Matchmaker;
4import it.finki.tinki.model.EmbeddedMatchId;
5import it.finki.tinki.model.Jobs.Internship;
6import it.finki.tinki.model.Jobs.Job;
7import it.finki.tinki.model.Jobs.Project;
8import it.finki.tinki.model.Jobs.Work;
9import it.finki.tinki.model.Match;
10import it.finki.tinki.model.Skill;
11import it.finki.tinki.model.Users.User;
12import it.finki.tinki.model.enumerator.WorkType;
13import it.finki.tinki.repository.MatchRepository;
14import it.finki.tinki.service.MatchmakerService;
15import org.springframework.stereotype.Service;
16
17import java.util.ArrayList;
18import java.util.List;
19
20
21@Service
22public class MatchmakerServiceImpl implements MatchmakerService {
23
24 MatchRepository matchRepository;
25
26 public MatchmakerServiceImpl(MatchRepository matchRepository) {
27 this.matchRepository = matchRepository;
28 }
29
30 @Override
31 public List<Internship> getMatchingInternshipsForUser(User user) {
32 List<Match> matches = this.matchRepository.getAllByCombinedId_User_IdAndTypeOrderByCoefficientDesc(user.getId(), WorkType.INTERNSHIP);
33
34 List<Internship> internships = new ArrayList<>();
35 matches.forEach(match -> {
36 internships.add((Internship) match.getCombinedId().getWork());
37 });
38
39 return internships;
40 }
41
42 @Override
43 public List<Job> getMatchingJobsForUser(User user) {
44 List<Match> matches = this.matchRepository.getAllByCombinedId_User_IdAndTypeOrderByCoefficientDesc(user.getId(), WorkType.JOB);
45
46 List<Job> jobs = new ArrayList<>();
47 matches.forEach(match -> {
48 jobs.add((Job) match.getCombinedId().getWork());
49 });
50
51 return jobs;
52 }
53
54 @Override
55 public List<Project> getMatchingProjectsForUser(User user) {
56 List<Match> matches = this.matchRepository.getAllByCombinedId_User_IdAndTypeOrderByCoefficientDesc(user.getId(), WorkType.PROJECT);
57
58 List<Project> projects = new ArrayList<>();
59 matches.forEach(match -> {
60 projects.add((Project) match.getCombinedId().getWork());
61 });
62
63 return projects;
64 }
65
66 @Override
67 public void setUpUserJobMatches(Job job, User user) {
68 List<Skill> jobSkill = job.getSkillsRequired();
69 List<Skill> userSkill = user.getRetainedSkills();
70
71 float coef = Matchmaker.match(jobSkill, userSkill);
72
73 if(coef!=0){
74 EmbeddedMatchId matchId = new EmbeddedMatchId(job, user);
75 Match m = new Match(matchId, coef, WorkType.JOB);
76 this.matchRepository.save(m);
77 }
78 }
79
80 @Override
81 public void setUpUserProjectMatches(Project project, User user) {
82 List<Skill> projectSkills = project.getSkillsRequired();
83 List<Skill> userSkill = user.getRetainedSkills();
84
85 float coef = Matchmaker.match(projectSkills, userSkill);
86
87 if(coef!=0){
88 EmbeddedMatchId matchId = new EmbeddedMatchId(project, user);
89 Match m = new Match(matchId, coef, WorkType.PROJECT);
90 this.matchRepository.save(m);
91 }
92 }
93
94 @Override
95 public void setUpUserInternshipMatches(Internship internship, User user) {
96 List<Skill> internshipSkills = internship.getSkillsTrained();
97 List<Skill> userSkill = user.getSkillsToLearn();
98
99 float coef = Matchmaker.match(internshipSkills, userSkill);
100
101 if(coef!=0){
102 EmbeddedMatchId matchId = new EmbeddedMatchId(internship, user);
103 Match m = new Match(matchId, coef, WorkType.INTERNSHIP);
104 this.matchRepository.save(m);
105 }
106 }
107
108
109}
Note: See TracBrowser for help on using the repository browser.