[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;
|
---|
| 8 | import it.finki.tinki.model.Match;
|
---|
[509cb95] | 9 | import it.finki.tinki.model.Skill;
|
---|
[723994f] | 10 | import it.finki.tinki.model.Users.User;
|
---|
| 11 | import it.finki.tinki.model.enumerator.WorkType;
|
---|
[a8e8545] | 12 | import it.finki.tinki.repository.InternshipRepository;
|
---|
| 13 | import it.finki.tinki.repository.JobRepository;
|
---|
[723994f] | 14 | import it.finki.tinki.repository.MatchRepository;
|
---|
[a8e8545] | 15 | import it.finki.tinki.repository.ProjectRepository;
|
---|
[723994f] | 16 | import it.finki.tinki.service.MatchmakerService;
|
---|
| 17 | import org.springframework.stereotype.Service;
|
---|
| 18 |
|
---|
| 19 | import java.util.ArrayList;
|
---|
| 20 | import java.util.List;
|
---|
| 21 |
|
---|
| 22 |
|
---|
| 23 | @Service
|
---|
| 24 | public class MatchmakerServiceImpl implements MatchmakerService {
|
---|
| 25 |
|
---|
| 26 | MatchRepository matchRepository;
|
---|
[a8e8545] | 27 | JobRepository jobRepository;
|
---|
| 28 | InternshipRepository internshipRepository;
|
---|
| 29 | ProjectRepository projectRepository;
|
---|
| 30 |
|
---|
| 31 | public MatchmakerServiceImpl(MatchRepository matchRepository,
|
---|
| 32 | JobRepository jobRepository,
|
---|
| 33 | InternshipRepository internshipRepository,
|
---|
| 34 | ProjectRepository projectRepository) {
|
---|
[723994f] | 35 | this.matchRepository = matchRepository;
|
---|
[a8e8545] | 36 | this.jobRepository = jobRepository;
|
---|
| 37 | this.internshipRepository = internshipRepository;
|
---|
| 38 | this.projectRepository = projectRepository;
|
---|
[723994f] | 39 | }
|
---|
| 40 |
|
---|
| 41 | @Override
|
---|
| 42 | public List<Internship> getMatchingInternshipsForUser(User user) {
|
---|
[4cec0a3] | 43 | List<Match> matches = this.matchRepository.findAllByEmbeddedMatchIdUserAndTypeOrderByCoefficientDesc(user, WorkType.INTERNSHIP);
|
---|
[723994f] | 44 |
|
---|
| 45 | List<Internship> internships = new ArrayList<>();
|
---|
[4cec0a3] | 46 | if(matches.size()!=0){
|
---|
| 47 | matches.forEach(match -> {
|
---|
| 48 | internships.add((Internship) match.getEmbeddedMatchId().getWork());
|
---|
| 49 | });
|
---|
| 50 | }
|
---|
[723994f] | 51 |
|
---|
| 52 | return internships;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | @Override
|
---|
| 56 | public List<Job> getMatchingJobsForUser(User user) {
|
---|
[4cec0a3] | 57 | List<Match> matches = this.matchRepository.findAllByEmbeddedMatchIdUserAndTypeOrderByCoefficientDesc(user, WorkType.JOB);
|
---|
[723994f] | 58 |
|
---|
| 59 | List<Job> jobs = new ArrayList<>();
|
---|
[4cec0a3] | 60 | if(matches.size()!=0) {
|
---|
| 61 | matches.forEach(match -> {
|
---|
| 62 | jobs.add((Job) match.getEmbeddedMatchId().getWork());
|
---|
| 63 | });
|
---|
| 64 | }
|
---|
[723994f] | 65 |
|
---|
| 66 | return jobs;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | @Override
|
---|
| 70 | public List<Project> getMatchingProjectsForUser(User user) {
|
---|
[4cec0a3] | 71 | List<Match> matches = this.matchRepository.findAllByEmbeddedMatchIdUserAndTypeOrderByCoefficientDesc(user, WorkType.PROJECT);
|
---|
[723994f] | 72 |
|
---|
| 73 | List<Project> projects = new ArrayList<>();
|
---|
[4cec0a3] | 74 | if(matches.size()!=0) {
|
---|
| 75 | matches.forEach(match -> {
|
---|
| 76 | projects.add((Project) match.getEmbeddedMatchId().getWork());
|
---|
| 77 | });
|
---|
| 78 | }
|
---|
[723994f] | 79 |
|
---|
| 80 | return projects;
|
---|
| 81 | }
|
---|
[509cb95] | 82 |
|
---|
| 83 | @Override
|
---|
| 84 | public void setUpUserJobMatches(Job job, User user) {
|
---|
| 85 | List<Skill> jobSkill = job.getSkillsRequired();
|
---|
| 86 | List<Skill> userSkill = user.getRetainedSkills();
|
---|
| 87 |
|
---|
| 88 | float coef = Matchmaker.match(jobSkill, userSkill);
|
---|
| 89 |
|
---|
| 90 | if(coef!=0){
|
---|
[a8e8545] | 91 | EmbeddedMatchId embeddedMatchId = new EmbeddedMatchId(job, user);
|
---|
| 92 | Match m = new Match(embeddedMatchId, coef, WorkType.JOB);
|
---|
[509cb95] | 93 | this.matchRepository.save(m);
|
---|
| 94 | }
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | @Override
|
---|
| 98 | public void setUpUserProjectMatches(Project project, User user) {
|
---|
| 99 | List<Skill> projectSkills = project.getSkillsRequired();
|
---|
| 100 | List<Skill> userSkill = user.getRetainedSkills();
|
---|
| 101 |
|
---|
| 102 | float coef = Matchmaker.match(projectSkills, userSkill);
|
---|
| 103 |
|
---|
| 104 | if(coef!=0){
|
---|
[a8e8545] | 105 | EmbeddedMatchId embeddedMatchId = new EmbeddedMatchId(project, user);
|
---|
| 106 | Match m = new Match(embeddedMatchId, coef, WorkType.PROJECT);
|
---|
[509cb95] | 107 | this.matchRepository.save(m);
|
---|
| 108 | }
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | @Override
|
---|
| 112 | public void setUpUserInternshipMatches(Internship internship, User user) {
|
---|
| 113 | List<Skill> internshipSkills = internship.getSkillsTrained();
|
---|
| 114 | List<Skill> userSkill = user.getSkillsToLearn();
|
---|
| 115 |
|
---|
| 116 | float coef = Matchmaker.match(internshipSkills, userSkill);
|
---|
| 117 |
|
---|
| 118 | if(coef!=0){
|
---|
[a8e8545] | 119 | EmbeddedMatchId embeddedMatchId = new EmbeddedMatchId(internship, user);
|
---|
| 120 | Match m = new Match(embeddedMatchId, coef, WorkType.PROJECT);
|
---|
[509cb95] | 121 | this.matchRepository.save(m);
|
---|
| 122 | }
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 |
|
---|
[723994f] | 126 | }
|
---|