Changeset a8e8545


Ignore:
Timestamp:
01/08/21 00:35:56 (3 years ago)
Author:
Vzdra <vladko.zdravkovski@…>
Branches:
master
Children:
4cec0a3
Parents:
509cb95
Message:

added dummy data for user skills and fixed bugs

Location:
src/main/java/it/finki/tinki
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/it/finki/tinki/bootstrap/DataHolder.java

    r509cb95 ra8e8545  
    22
    33import it.finki.tinki.model.Address;
     4import it.finki.tinki.model.EmbeddedMatchId;
     5import it.finki.tinki.model.Jobs.Job;
     6import it.finki.tinki.model.Jobs.Work;
     7import it.finki.tinki.model.Match;
    48import it.finki.tinki.model.Skill;
     9import it.finki.tinki.model.Users.Account;
    510import it.finki.tinki.model.Users.Company;
    611import it.finki.tinki.model.Users.User;
    712import it.finki.tinki.model.enumerator.AccountType;
     13import it.finki.tinki.model.enumerator.WorkType;
    814import it.finki.tinki.repository.*;
     15import it.finki.tinki.service.AccountService;
     16import it.finki.tinki.service.WorkService;
     17import org.springframework.beans.factory.annotation.Autowired;
    918import org.springframework.stereotype.Component;
    1019
     
    1726
    1827    SkillRepository skillRepository;
    19     UserRepository userRepository;
    20     CompanyRepository companyRepository;
    21     TeamRepository teamRepository;
    22     AddressRepository addressRepository;
     28    AccountService accountService;
     29    WorkService workService;
     30    MatchRepository matchRepository;
    2331
    24     public DataHolder(SkillRepository skillRepository, UserRepository userRepository, CompanyRepository companyRepository, TeamRepository teamRepository, AddressRepository addressRepository) {
     32    public DataHolder(SkillRepository skillRepository,
     33                      AccountService accountService,
     34                      WorkService workService,
     35                      MatchRepository matchRepository) {
    2536        this.skillRepository = skillRepository;
    26         this.userRepository = userRepository;
    27         this.companyRepository = companyRepository;
    28         this.teamRepository = teamRepository;
    29         this.addressRepository = addressRepository;
     37        this.accountService = accountService;
     38        this.workService = workService;
     39        this.matchRepository = matchRepository;
    3040    }
    3141
     
    5969        lista = skillRepository.findAll();
    6070
    61         userRepository.save(new User("asdf", "asdf", "Zoki", AccountType.USER, "Poki", lista, lista));
     71        List<Long> ids = new ArrayList<>();
     72        lista.forEach(item -> {
     73            ids.add(item.getId());
     74        });
    6275
    63         addressRepository.save(new Address("asdf", "asdf", "asdf"));
    64         companyRepository.save(new Company("asdf@asdf", "pass", "Co.co", AccountType.COMPANY, addressRepository.findAll().get(0)));
     76        Account c = this.accountService.registerCompany("asdf@asdf", "pass", "Co.co", "Macedonia", "Skopje", "Pero Nakov");
     77
     78        Job j = this.workService.insertJob("Asdf", "Asdfa", c.getId() ,5000, ids, AccountType.COMPANY);
     79
     80        Account u = this.accountService.registerUser("asdf", "asdf", "Zoki", "Poki", lista, lista);
     81
    6582    }
    6683
  • src/main/java/it/finki/tinki/model/EmbeddedMatchId.java

    r509cb95 ra8e8545  
    66
    77import javax.persistence.Embeddable;
     8import javax.persistence.FetchType;
    89import javax.persistence.OneToOne;
    910import java.io.Serializable;
     11import java.util.Objects;
    1012
    1113@Embeddable
     
    2527        this.user = user;
    2628    }
    27 
    2829}
  • src/main/java/it/finki/tinki/model/Jobs/Internship.java

    r509cb95 ra8e8545  
    1212public class Internship extends Work {
    1313
    14     @ManyToMany
     14    @ManyToMany(fetch = FetchType.EAGER)
    1515    List<Skill> skillsTrained;
    1616
  • src/main/java/it/finki/tinki/model/Jobs/Job.java

    r509cb95 ra8e8545  
    1212public class Job extends Work {
    1313
    14     @ManyToMany
     14    @ManyToMany(fetch = FetchType.EAGER)
    1515    List<Skill> skillsRequired;
    1616
  • src/main/java/it/finki/tinki/model/Jobs/Project.java

    r509cb95 ra8e8545  
    1313public class Project extends Work {
    1414
    15     @ManyToMany
     15    @ManyToMany(fetch = FetchType.EAGER)
    1616    List<Skill> skillsRequired;
    1717
  • src/main/java/it/finki/tinki/model/Match.java

    r509cb95 ra8e8545  
    11package it.finki.tinki.model;
    22
     3import com.sun.istack.NotNull;
     4import it.finki.tinki.model.Jobs.Work;
     5import it.finki.tinki.model.Users.User;
    36import it.finki.tinki.model.enumerator.WorkType;
    47import lombok.Data;
     
    1013public class Match {
    1114
     15//    @Id
     16//    @GeneratedValue(strategy = GenerationType.AUTO)
     17//    Long id;
     18//
     19//    @NotNull
     20//    Long workId;
     21//
     22//    @NotNull
     23//    Long userId;
     24
    1225    @Id
    13     EmbeddedMatchId combinedId;
     26    EmbeddedMatchId embeddedMatchId;
    1427
    1528    float coefficient;
     
    1932    public Match(){}
    2033
     34//    public Match(Long workId, Long userId, float coefficient, WorkType type) {
     35//        this.workId = workId;
     36//        this.userId = userId;
     37//        this.coefficient = coefficient;
     38//        this.type = type;
     39//    }
     40
    2141    public Match(EmbeddedMatchId embeddedMatchId, float coefficient, WorkType type) {
    22         this.combinedId = embeddedMatchId;
     42        this.embeddedMatchId = embeddedMatchId;
    2343        this.coefficient = coefficient;
    2444        this.type = type;
  • src/main/java/it/finki/tinki/repository/MatchRepository.java

    r509cb95 ra8e8545  
    11package it.finki.tinki.repository;
    22
     3import it.finki.tinki.model.EmbeddedMatchId;
    34import it.finki.tinki.model.Match;
    45import it.finki.tinki.model.Users.User;
     
    1011
    1112@Repository
    12 public interface MatchRepository extends JpaRepository<Match, Long> {
    13     List<Match> getAllByCombinedId_User_IdAndTypeOrderByCoefficientDesc(Long uId, WorkType type);
     13public interface MatchRepository extends JpaRepository<Match, EmbeddedMatchId> {
     14    List<Match> getAllByEmbeddedMatchIdUserAndTypeOrderByCoefficientDesc(Long uId, WorkType type);
     15//    List<Match> getAllByUserIdAndTypeOrderByCoefficientDesc(Long uId, WorkType type);
    1416}
  • src/main/java/it/finki/tinki/service/SkillService.java

    r509cb95 ra8e8545  
    66
    77public interface SkillService {
    8     List<Skill> returnSkillsBasedOnId(List<Integer> skillIds);
     8    List<Skill> returnSkillsBasedOnId(List<Long> skillIds);
    99}
  • src/main/java/it/finki/tinki/service/WorkService.java

    r509cb95 ra8e8545  
    1616    List<Internship> getAllInternships();
    1717    List<Project> getAllProjects();
    18     Job insertJob(String title, String description, Long accId, int salary, List<Integer> skillsRequired, AccountType type);
    19     Internship insertInternship(String title, String description, Long adccId, int salary, List<Integer> skillsTrained, int openSpots, AccountType type);
    20     Project insertProject(String title, String description, Long adccId, int salary, List<Integer> skillsRequired, Date validUntil, AccountType type);
     18    Job insertJob(String title, String description, Long accId, int salary, List<Long> skillsRequired, AccountType type);
     19    Internship insertInternship(String title, String description, Long adccId, int salary, List<Long> skillsTrained, int openSpots, AccountType type);
     20    Project insertProject(String title, String description, Long adccId, int salary, List<Long> skillsRequired, Date validUntil, AccountType type);
    2121}
  • src/main/java/it/finki/tinki/service/impl/AccountServiceImpl.java

    r509cb95 ra8e8545  
    22
    33import it.finki.tinki.model.Address;
     4import it.finki.tinki.model.Jobs.Internship;
     5import it.finki.tinki.model.Jobs.Job;
     6import it.finki.tinki.model.Jobs.Project;
    47import it.finki.tinki.model.Skill;
    58import it.finki.tinki.model.Users.Account;
     
    1013import it.finki.tinki.model.exception.InvalidArgumentsException;
    1114import it.finki.tinki.model.exception.UserExistsException;
    12 import it.finki.tinki.repository.AddressRepository;
    13 import it.finki.tinki.repository.CompanyRepository;
    14 import it.finki.tinki.repository.TeamRepository;
    15 import it.finki.tinki.repository.UserRepository;
     15import it.finki.tinki.repository.*;
    1616import it.finki.tinki.service.AccountService;
     17import it.finki.tinki.service.MatchmakerService;
     18import it.finki.tinki.service.WorkService;
    1719import org.springframework.stereotype.Service;
    1820
     
    2830    TeamRepository teamRepository;
    2931    CompanyRepository companyRepository;
     32    JobRepository jobRepository;
     33    ProjectRepository projectRepository;
     34    InternshipRepository internshipRepository;
     35    MatchmakerService matchmakerService;
    3036
    31     public AccountServiceImpl(AddressRepository addressRepository, UserRepository userRepository, TeamRepository teamRepository, CompanyRepository companyRepository) {
     37    public AccountServiceImpl(AddressRepository addressRepository,
     38                              UserRepository userRepository,
     39                              TeamRepository teamRepository,
     40                              CompanyRepository companyRepository,
     41                              MatchmakerService matchmakerService,
     42                              JobRepository jobRepository,
     43                              ProjectRepository projectRepository,
     44                              InternshipRepository internshipRepository) {
    3245        this.addressRepository = addressRepository;
    3346        this.userRepository = userRepository;
    3447        this.teamRepository = teamRepository;
    3548        this.companyRepository = companyRepository;
     49        this.jobRepository = jobRepository;
     50        this.projectRepository = projectRepository;
     51        this.internshipRepository = internshipRepository;
     52        this.matchmakerService = matchmakerService;
    3653    }
    3754
     
    6582
    6683        User u = new User(email, password, name, AccountType.USER, surname, retainedSkills, skillsToLearn);
    67         return this.userRepository.save(u);
     84        User ru = this.userRepository.save(u);
     85
     86        List<Job> jobs = this.jobRepository.findAll();
     87        List<Project> projects = this.projectRepository.findAll();
     88        List<Internship> internships = this.internshipRepository.findAll();
     89
     90        if(jobs.size()!=0){
     91            for (Job job : jobs) {
     92                this.matchmakerService.setUpUserJobMatches(job, u);
     93            }
     94        }
     95
     96        if(projects.size()!=0){
     97            for (Project project : projects) {
     98                this.matchmakerService.setUpUserProjectMatches(project, u);
     99            }
     100        }
     101
     102        if(internships.size()!=0){
     103            for(Internship internship : internships){
     104                this.matchmakerService.setUpUserInternshipMatches(internship, u);
     105            }
     106        }
     107
     108        return ru;
    68109    }
    69110
  • src/main/java/it/finki/tinki/service/impl/MatchmakerServiceImpl.java

    r509cb95 ra8e8545  
    1111import it.finki.tinki.model.Users.User;
    1212import it.finki.tinki.model.enumerator.WorkType;
     13import it.finki.tinki.repository.InternshipRepository;
     14import it.finki.tinki.repository.JobRepository;
    1315import it.finki.tinki.repository.MatchRepository;
     16import it.finki.tinki.repository.ProjectRepository;
    1417import it.finki.tinki.service.MatchmakerService;
    1518import org.springframework.stereotype.Service;
     
    2326
    2427    MatchRepository matchRepository;
     28    JobRepository jobRepository;
     29    InternshipRepository internshipRepository;
     30    ProjectRepository projectRepository;
    2531
    26     public MatchmakerServiceImpl(MatchRepository matchRepository) {
     32    public MatchmakerServiceImpl(MatchRepository matchRepository,
     33                                 JobRepository jobRepository,
     34                                 InternshipRepository internshipRepository,
     35                                 ProjectRepository projectRepository) {
    2736        this.matchRepository = matchRepository;
     37        this.jobRepository = jobRepository;
     38        this.internshipRepository = internshipRepository;
     39        this.projectRepository = projectRepository;
    2840    }
    2941
    3042    @Override
    3143    public List<Internship> getMatchingInternshipsForUser(User user) {
    32         List<Match> matches = this.matchRepository.getAllByCombinedId_User_IdAndTypeOrderByCoefficientDesc(user.getId(), WorkType.INTERNSHIP);
     44        List<Match> matches = this.matchRepository.getAllByEmbeddedMatchIdUserAndTypeOrderByCoefficientDesc(user.getId(), WorkType.INTERNSHIP);
     45//        List<Match> matches = this.matchRepository.getAllByUserIdAndTypeOrderByCoefficientDesc(user.getId(), WorkType.INTERNSHIP);
    3346
    3447        List<Internship> internships = new ArrayList<>();
    3548        matches.forEach(match -> {
    36             internships.add((Internship) match.getCombinedId().getWork());
     49            internships.add((Internship) match.getEmbeddedMatchId().getWork());
     50//            internships.add(this.internshipRepository.findById(match.getWorkId()).get());
    3751        });
    3852
     
    4256    @Override
    4357    public List<Job> getMatchingJobsForUser(User user) {
    44         List<Match> matches = this.matchRepository.getAllByCombinedId_User_IdAndTypeOrderByCoefficientDesc(user.getId(), WorkType.JOB);
     58        List<Match> matches = this.matchRepository.getAllByEmbeddedMatchIdUserAndTypeOrderByCoefficientDesc(user.getId(), WorkType.INTERNSHIP);
     59//        List<Match> matches = this.matchRepository.getAllByUserIdAndTypeOrderByCoefficientDesc(user.getId(), WorkType.JOB);
    4560
    4661        List<Job> jobs = new ArrayList<>();
    4762        matches.forEach(match -> {
    48             jobs.add((Job) match.getCombinedId().getWork());
     63            jobs.add((Job) match.getEmbeddedMatchId().getWork());
     64//            jobs.add(this.jobRepository.findById(match.getWorkId()).get());
    4965        });
    5066
     
    5470    @Override
    5571    public List<Project> getMatchingProjectsForUser(User user) {
    56         List<Match> matches = this.matchRepository.getAllByCombinedId_User_IdAndTypeOrderByCoefficientDesc(user.getId(), WorkType.PROJECT);
     72        List<Match> matches = this.matchRepository.getAllByEmbeddedMatchIdUserAndTypeOrderByCoefficientDesc(user.getId(), WorkType.INTERNSHIP);
     73//        List<Match> matches = this.matchRepository.getAllByUserIdAndTypeOrderByCoefficientDesc(user.getId(), WorkType.PROJECT);
    5774
    5875        List<Project> projects = new ArrayList<>();
    5976        matches.forEach(match -> {
    60             projects.add((Project) match.getCombinedId().getWork());
     77            projects.add((Project) match.getEmbeddedMatchId().getWork());
     78//            projects.add(this.projectRepository.findById(match.getWorkId()).get());
    6179        });
    6280
     
    7290
    7391        if(coef!=0){
    74             EmbeddedMatchId matchId = new EmbeddedMatchId(job, user);
    75             Match m = new Match(matchId, coef, WorkType.JOB);
     92            EmbeddedMatchId embeddedMatchId = new EmbeddedMatchId(job, user);
     93            Match m = new Match(embeddedMatchId, coef, WorkType.JOB);
     94//            Match m = new Match(job.getId(), user.getId(), coef, WorkType.JOB);
    7695            this.matchRepository.save(m);
    7796        }
     
    86105
    87106        if(coef!=0){
    88             EmbeddedMatchId matchId = new EmbeddedMatchId(project, user);
    89             Match m = new Match(matchId, coef, WorkType.PROJECT);
     107            EmbeddedMatchId embeddedMatchId = new EmbeddedMatchId(project, user);
     108            Match m = new Match(embeddedMatchId, coef, WorkType.PROJECT);
     109//            Match m = new Match(project.getId(), user.getId(), coef, WorkType.JOB);
    90110            this.matchRepository.save(m);
    91111        }
     
    100120
    101121        if(coef!=0){
    102             EmbeddedMatchId matchId = new EmbeddedMatchId(internship, user);
    103             Match m = new Match(matchId, coef, WorkType.INTERNSHIP);
     122            EmbeddedMatchId embeddedMatchId = new EmbeddedMatchId(internship, user);
     123            Match m = new Match(embeddedMatchId, coef, WorkType.PROJECT);
     124//            Match m = new Match(internship.getId(), user.getId(), coef, WorkType.JOB);
    104125            this.matchRepository.save(m);
    105126        }
  • src/main/java/it/finki/tinki/service/impl/SkillServiceImpl.java

    r509cb95 ra8e8545  
    2020
    2121    @Override
    22     public List<Skill> returnSkillsBasedOnId(List<Integer> skillIds) {
     22    public List<Skill> returnSkillsBasedOnId(List<Long> skillIds) {
    2323
    2424        List<Skill> list = new ArrayList<>();
    2525
    2626        skillIds.forEach(skill -> {
    27             this.skillRepository.findById(Long.valueOf(skill)).ifPresent(list::add);
     27            this.skillRepository.findById(skill).ifPresent(list::add);
    2828        });
    2929
  • src/main/java/it/finki/tinki/service/impl/WorkServiceImpl.java

    r509cb95 ra8e8545  
    7777
    7878    @Override
    79     public Job insertJob(String title, String description, Long adccId, int salary, List<Integer> skillsRequired, AccountType type) {
     79    public Job insertJob(String title, String description, Long adccId, int salary, List<Long> skillsRequired, AccountType type) {
    8080        List<Skill> skills = this.skillService.returnSkillsBasedOnId(skillsRequired);
    8181        Account account = this.accountService.findByIdAndType(adccId, type);
     
    8585
    8686    @Override
    87     public Internship insertInternship(String title, String description, Long adccId, int salary, List<Integer> skillsTrained, int openSpots, AccountType type) {
     87    public Internship insertInternship(String title, String description, Long adccId, int salary, List<Long> skillsTrained, int openSpots, AccountType type) {
    8888        List<Skill> skills = this.skillService.returnSkillsBasedOnId(skillsTrained);
    8989        Account account = this.accountService.findByIdAndType(adccId, type);
     
    9393
    9494    @Override
    95     public Project insertProject(String title, String description, Long adccId, int salary, List<Integer> skillsRequired, Date validUntil, AccountType type) {
     95    public Project insertProject(String title, String description, Long adccId, int salary, List<Long> skillsRequired, Date validUntil, AccountType type) {
    9696        List<Skill> skills = this.skillService.returnSkillsBasedOnId(skillsRequired);
    9797        Account account = this.accountService.findByIdAndType(adccId, type);
  • src/main/java/it/finki/tinki/web/controller/RegisterController.java

    r509cb95 ra8e8545  
    4040                                             @RequestParam String name,
    4141                                             @RequestParam String surname,
    42                                              @RequestParam List<Integer> retainedSkills,
    43                                              @RequestParam List<Integer> skillsToLearn){
     42                                             @RequestParam List<Long> retainedSkills,
     43                                             @RequestParam List<Long> skillsToLearn){
    4444
    4545        List<Skill> retained = this.skillService.returnSkillsBasedOnId(retainedSkills);
     
    5353            response.put("error", "There was an error when trying to register user.");
    5454        }else{
    55             List<Job> jobs = this.workService.getAllJobs();
    56             List<Project> projects = this.workService.getAllProjects();
    57             List<Internship> internships = this.workService.getAllInternships();
    58 
    59             jobs.forEach(job -> {
    60                 this.matchmakerService.setUpUserJobMatches(job, (User) k);
    61             });
    62 
    63             projects.forEach(project -> {
    64                 this.matchmakerService.setUpUserProjectMatches(project, (User) k);
    65             });
    66 
    67             internships.forEach(internship -> {
    68                 this.matchmakerService.setUpUserInternshipMatches(internship, (User) k);
    69             });
    70 
    7155            response.put("success", "Registration completed successfully.");
    7256        }
     
    9579
    9680    @RequestMapping(path = "/company", method = RequestMethod.POST)
    97     private Map<String, String> registerTeam(@RequestParam String email,
    98                                              @RequestParam String password,
    99                                              @RequestParam String name,
    100                                              @RequestParam String country,
    101                                              @RequestParam String city,
    102                                              @RequestParam String street){
     81    private Map<String, String> registeCompany(@RequestParam String email,
     82                                               @RequestParam String password,
     83                                               @RequestParam String name,
     84                                               @RequestParam String country,
     85                                               @RequestParam String city,
     86                                               @RequestParam String street){
    10387
    10488        Account k = this.accountService.registerCompany(email, password, name, country, city, street);
Note: See TracChangeset for help on using the changeset viewer.