Search in sources :

Example 11 with Project

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

the class BadgeServiceImpl method saveBadge.

@Override
public Badge saveBadge(Integer userId, Integer projectId) {
    /* Volunteer Recognition  - Give badge to the volunteer(accepted applicant)
		 * Send out email to the volunteer
		 * Save it to the database
		*/
    System.out.println("save Badge called...");
    User user = userDAO.findById(userId);
    requireNonNull(user, "Invalid User Id");
    Project project = projectDAO.findById(projectId);
    requireNonNull(project, "Invalid Project Id");
    Integer orgId = project.getOrganization().getId();
    Organization org = organizationDAO.findOne(orgId);
    List<User> users = userDAO.findByOrgId(orgId);
    User orgUser = users.get(0);
    isBadgeGiven(userId, projectId);
    Badge heroBadge = new Badge();
    heroBadge.setUser(user);
    heroBadge.setProject(project);
    heroBadge = badgeDAO.save(heroBadge);
    System.out.println("Hero Badge Given to" + userId + "," + projectId);
    // send email to the volunteer
    Map<String, Object> contextVolunteer = new HashMap<String, Object>();
    contextVolunteer.put("heroesLink", urlService.getHeroUrl());
    contextVolunteer.put("org", org);
    contextVolunteer.put("orgUser", orgUser);
    contextVolunteer.put("project", project);
    contextVolunteer.put("projectLink", urlService.getProjectUrl(project.getId()));
    asyncEmailService.sendWithContext(Constants.C4SG_ADDRESS, user.getEmail(), orgUser.getEmail(), Constants.SUBJECT_HERO_USER, Constants.TEMPLATE_HERO_USER, contextVolunteer);
    System.out.println("Hero Badge email sent: Project=" + project.getId() + " ; ApplicantEmail=" + user.getEmail());
    return heroBadge;
}
Also used : Project(org.c4sg.entity.Project) User(org.c4sg.entity.User) Organization(org.c4sg.entity.Organization) HashMap(java.util.HashMap) Badge(org.c4sg.entity.Badge)

Example 12 with Project

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

the class ProjectServiceImpl method saveUserProject.

@Override
public ProjectDTO saveUserProject(Integer userId, Integer projectId, String userProjectStatus) {
    User user = userDAO.findById(userId);
    requireNonNull(user, "Invalid User Id");
    Project project = projectDAO.findById(projectId);
    requireNonNull(project, "Invalid Project Id");
    if (userProjectStatus == null || (!userProjectStatus.trim().equalsIgnoreCase("A") && !userProjectStatus.trim().equalsIgnoreCase("B"))) {
        throw new BadRequestException("Invalid Project Status");
    } else if (userProjectStatus.trim().equalsIgnoreCase("A")) {
        isUserAppliedPresent(userId, projectId);
        UserProject userProject = new UserProject();
        userProject.setUser(user);
        userProject.setProject(project);
        userProject.setStatus("A");
        apply(user, project);
        userProjectDAO.save(userProject);
    } else if (userProjectStatus.trim().equalsIgnoreCase("B")) {
        isBookmarkPresent(userId, projectId);
        UserProject userProject = new UserProject();
        userProject.setUser(user);
        userProject.setProject(project);
        userProject.setStatus("B");
        userProjectDAO.save(userProject);
    }
    return projectMapper.getProjectDtoFromEntity(project);
}
Also used : UserProject(org.c4sg.entity.UserProject) Project(org.c4sg.entity.Project) User(org.c4sg.entity.User) UserProject(org.c4sg.entity.UserProject) BadRequestException(org.c4sg.exception.BadRequestException)

Example 13 with Project

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

the class EmailServiceTest method testSendVolunteerApplicantEmail.

@Test
public void testSendVolunteerApplicantEmail() throws MessagingException {
    Organization org = new Organization();
    org.setName("Test Organization");
    org.setContactEmail("test@c4sg.org");
    org.setContactName("John Sloan");
    org.setContactPhone("9898989899");
    User user = new User();
    user.setEmail("test@c4sg.org");
    user.setFirstName("John");
    user.setLastName("Sloan");
    user.setChatUsername("jsloan");
    Project project = new Project();
    project.setId(110);
    project.setName("Test Project");
    Map<String, Object> mailContext = new HashMap<String, Object>();
    mailContext.put("org", org);
    mailContext.put("user", user);
    mailContext.put("projectLink", "http://codeforsocialgood.org");
    mailContext.put("project", project);
    mailService.sendWithContext(from, user.getEmail(), "", "Test Email", "applicant-application", mailContext);
    // received message
    MimeMessage[] receivedMessages = mailer.getReceivedMessages();
    assertEquals(1, receivedMessages.length);
    MimeMessage msg = receivedMessages[0];
    assertThat(from, is(msg.getFrom()[0].toString()));
    assertThat("Test Email", is(msg.getSubject()));
}
Also used : Project(org.c4sg.entity.Project) Organization(org.c4sg.entity.Organization) User(org.c4sg.entity.User) HashMap(java.util.HashMap) MimeMessage(javax.mail.internet.MimeMessage) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with Project

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

the class ApplicationServiceImpl method updateApplication.

@Override
public ApplicationDTO updateApplication(ApplicationDTO applicationDto) {
    validateApplication(applicationDto);
    Application application = applicationDAO.findByUser_IdAndProject_Id(applicationDto.getUserId(), applicationDto.getProjectId());
    isApplied(application, applicationDto.getStatus());
    application.setStatus(applicationDto.getStatus());
    application.setComment(applicationDto.getComment());
    application.setResumeFlag(booleanToStringConverter.convert(applicationDto.getResumeFlag()));
    if (applicationDto.getStatus().equals("C")) {
        application.setAcceptedTime(new Timestamp(Calendar.getInstance().getTime().getTime()));
    } else if (applicationDto.getStatus().equals("D")) {
        application.setDeclinedTime(new Timestamp(Calendar.getInstance().getTime().getTime()));
    }
    application.setUpdatedTime(new Timestamp(Calendar.getInstance().getTime().getTime()));
    applicationDAO.save(application);
    User user = userDAO.findById(applicationDto.getUserId());
    Project project = projectDAO.findById(applicationDto.getProjectId());
    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 15 with Project

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

the class ApplicationServiceImpl method getApplicationsByOrgAndByApplicant.

@Override
public List<ApplicationProjectDTO> getApplicationsByOrgAndByApplicant(Integer userId, Integer nonProfitUserId, String status) {
    // get org id from nonProfitUserId;
    List<UserOrganization> userOrganizations = userOrganizationDAO.findByUserId(nonProfitUserId);
    // get projects for the org
    List<Project> projects = new ArrayList<Project>();
    for (UserOrganization userOrganization : userOrganizations) {
        // list gets overwritten here becasue there should be only one organization for one nonprofit user
        projects = projectDAO.getProjectsByOrganization(userOrganization.getOrganization().getId(), "A");
    }
    // get applications by project and userId
    List<Application> applications = new ArrayList<Application>();
    Application application;
    for (Project project : projects) {
        application = new Application();
        application = applicationDAO.findByUser_IdAndProject_IdAndStatus(userId, project.getId(), status);
        if (java.util.Objects.nonNull(application)) {
            applications.add(application);
        }
    }
    return applicationMapper.getApplicationProjectDtosFromEntities(applications);
}
Also used : Project(org.c4sg.entity.Project) UserOrganization(org.c4sg.entity.UserOrganization) ArrayList(java.util.ArrayList) Application(org.c4sg.entity.Application)

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