[723994f] | 1 | package it.finki.tinki.service.impl;
|
---|
| 2 |
|
---|
[509cb95] | 3 | import it.finki.tinki.helper.Matchmaker;
|
---|
| 4 | import it.finki.tinki.model.EmbeddedMatchId;
|
---|
[723994f] | 5 | import it.finki.tinki.model.Jobs.Internship;
|
---|
| 6 | import it.finki.tinki.model.Jobs.Job;
|
---|
| 7 | import it.finki.tinki.model.Jobs.Project;
|
---|
[509cb95] | 8 | import it.finki.tinki.model.Jobs.Work;
|
---|
[723994f] | 9 | import it.finki.tinki.model.Match;
|
---|
[509cb95] | 10 | import it.finki.tinki.model.Skill;
|
---|
[723994f] | 11 | import it.finki.tinki.model.Users.User;
|
---|
| 12 | import it.finki.tinki.model.enumerator.WorkType;
|
---|
| 13 | import it.finki.tinki.repository.MatchRepository;
|
---|
| 14 | import it.finki.tinki.service.MatchmakerService;
|
---|
| 15 | import org.springframework.stereotype.Service;
|
---|
| 16 |
|
---|
| 17 | import java.util.ArrayList;
|
---|
| 18 | import java.util.List;
|
---|
| 19 |
|
---|
| 20 |
|
---|
| 21 | @Service
|
---|
| 22 | public 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) {
|
---|
[509cb95] | 32 | List<Match> matches = this.matchRepository.getAllByCombinedId_User_IdAndTypeOrderByCoefficientDesc(user.getId(), WorkType.INTERNSHIP);
|
---|
[723994f] | 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) {
|
---|
[509cb95] | 44 | List<Match> matches = this.matchRepository.getAllByCombinedId_User_IdAndTypeOrderByCoefficientDesc(user.getId(), WorkType.JOB);
|
---|
[723994f] | 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) {
|
---|
[509cb95] | 56 | List<Match> matches = this.matchRepository.getAllByCombinedId_User_IdAndTypeOrderByCoefficientDesc(user.getId(), WorkType.PROJECT);
|
---|
[723994f] | 57 |
|
---|
| 58 | List<Project> projects = new ArrayList<>();
|
---|
| 59 | matches.forEach(match -> {
|
---|
| 60 | projects.add((Project) match.getCombinedId().getWork());
|
---|
| 61 | });
|
---|
| 62 |
|
---|
| 63 | return projects;
|
---|
| 64 | }
|
---|
[509cb95] | 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 |
|
---|
[723994f] | 109 | }
|
---|