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