use of org.c4sg.entity.UserSkill 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);
}
Aggregations