Search in sources :

Example 16 with Project

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

the class ApplicationServiceImpl method createApplication.

@Override
public ApplicationDTO createApplication(ApplicationDTO applicationDto) {
    validateApplication(applicationDto);
    User user = userDAO.findById(applicationDto.getUserId());
    Project project = projectDAO.findById(applicationDto.getProjectId());
    Application application = applicationDAO.findByUser_IdAndProject_Id(applicationDto.getUserId(), applicationDto.getProjectId());
    if (java.util.Objects.nonNull(application)) {
        isApplied(application, applicationDto.getStatus());
    }
    application = new Application();
    application.setUser(user);
    application.setProject(project);
    application.setStatus(applicationDto.getStatus());
    application.setComment(applicationDto.getComment());
    application.setResumeFlag(booleanToStringConverter.convert(applicationDto.getResumeFlag()));
    application.setAppliedTime(applicationDto.getAppliedTime());
    application.setCreatedTime(new Timestamp(Calendar.getInstance().getTime().getTime()));
    // application.setAppliedTime(new Timestamp(Calendar.getInstance().getTime().getTime()));
    applicationDAO.save(application);
    sendEmail(user, project, application);
    return applicationMapper.getApplicationDtoFromEntity(application);
}
Also used : Project(org.c4sg.entity.Project) User(org.c4sg.entity.User) Application(org.c4sg.entity.Application) Timestamp(java.sql.Timestamp)

Example 17 with Project

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

the class ApplicationServiceImpl method validateApplication.

private void validateApplication(ApplicationDTO application) {
    User user = userDAO.findById(application.getUserId());
    requireNonNull(user, "Invalid User Id");
    Project project = projectDAO.findById(application.getProjectId());
    requireNonNull(project, "Invalid Project Id");
    if (application.getStatus() == null || (!application.getStatus().equals("A") && !application.getStatus().equals("C") && !application.getStatus().equals("D"))) {
        throw new BadRequestException("Invalid Project Status");
    }
}
Also used : Project(org.c4sg.entity.Project) User(org.c4sg.entity.User) BadRequestException(org.c4sg.exception.BadRequestException)

Example 18 with Project

use of org.c4sg.entity.Project 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

Project (org.c4sg.entity.Project)18 User (org.c4sg.entity.User)9 UserProject (org.c4sg.entity.UserProject)8 HashMap (java.util.HashMap)4 Timestamp (java.sql.Timestamp)3 ArrayList (java.util.ArrayList)3 Application (org.c4sg.entity.Application)3 Organization (org.c4sg.entity.Organization)3 MimeMessage (javax.mail.internet.MimeMessage)2 Badge (org.c4sg.entity.Badge)2 BadRequestException (org.c4sg.exception.BadRequestException)2 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Map (java.util.Map)1 ProjectDTO (org.c4sg.dto.ProjectDTO)1 Bookmark (org.c4sg.entity.Bookmark)1 ProjectSkill (org.c4sg.entity.ProjectSkill)1 Skill (org.c4sg.entity.Skill)1 UserOrganization (org.c4sg.entity.UserOrganization)1 UserSkill (org.c4sg.entity.UserSkill)1