Search in sources :

Example 1 with Skill

use of org.c4sg.entity.Skill in project c4sg-services by Code4SocialGood.

the class SkillServiceImpl method saveSkillsForUser.

@Override
public void saveSkillsForUser(Integer id, List<String> skillsList) {
    User user = userDAO.findById(id);
    requireNonNull(user, "User with id: " + id + " doesn't exist. Please provide a valid user id.");
    List<UserSkill> userSkills = new ArrayList<UserSkill>();
    List<Skill> skills = new ArrayList<Skill>();
    requireNonNull(skillsList, "Please provide the skills in display order.");
    for (String skillName : skillsList) {
        UserSkill userSkill = new UserSkill();
        // user
        userSkill.setUser(user);
        Skill skill = skillDAO.findBySkillName(skillName);
        // user entered skills
        if (isNull(skill)) {
            skill = new Skill();
            skill.setSkillName(skillName);
            // new skill to add to Skill table
            skills.add(skill);
        }
        // skill
        userSkill.setSkill(skill);
        // displayOrder
        int displayOrder = skillsList.indexOf(skillName) + 1;
        userSkill.setDisplayOrder(displayOrder);
        userSkills.add(userSkill);
    }
    skillDAO.save(skills);
    userSkillDAO.deleteByUserId(id);
    userSkillDAO.save(userSkills);
}
Also used : Skill(org.c4sg.entity.Skill) ProjectSkill(org.c4sg.entity.ProjectSkill) UserSkill(org.c4sg.entity.UserSkill) User(org.c4sg.entity.User) UserSkill(org.c4sg.entity.UserSkill) ArrayList(java.util.ArrayList)

Example 2 with Skill

use of org.c4sg.entity.Skill in project c4sg-services by Code4SocialGood.

the class SkillServiceImpl method saveSkillsForProject.

@Override
public void saveSkillsForProject(Integer id, List<String> skillsList) {
    Project project = projectDAO.findById(id);
    requireNonNull(project, "Project with id: " + id + " doesn't exist. Please provide a valid project id.");
    List<ProjectSkill> projectSkills = new ArrayList<ProjectSkill>();
    List<Skill> skills = new ArrayList<Skill>();
    requireNonNull(skillsList, "Please provide the skills in display order.");
    for (String skillName : skillsList) {
        ProjectSkill projectSkill = new ProjectSkill();
        // project
        projectSkill.setProject(project);
        Skill skill = skillDAO.findBySkillName(skillName);
        // user entered skills
        if (isNull(skill)) {
            skill = new Skill();
            skill.setSkillName(skillName);
            // new skill to add to Skill table
            skills.add(skill);
        }
        // skill
        projectSkill.setSkill(skill);
        int displayOrder = skillsList.indexOf(skillName) + 1;
        // displayOrder
        projectSkill.setDisplayOrder(displayOrder);
        projectSkills.add(projectSkill);
    }
    skillDAO.save(skills);
    projectSkillDAO.deleteByProjectId(id);
    projectSkillDAO.save(projectSkills);
}
Also used : Project(org.c4sg.entity.Project) Skill(org.c4sg.entity.Skill) ProjectSkill(org.c4sg.entity.ProjectSkill) UserSkill(org.c4sg.entity.UserSkill) ProjectSkill(org.c4sg.entity.ProjectSkill) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)2 ProjectSkill (org.c4sg.entity.ProjectSkill)2 Skill (org.c4sg.entity.Skill)2 UserSkill (org.c4sg.entity.UserSkill)2 Project (org.c4sg.entity.Project)1 User (org.c4sg.entity.User)1