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;
}
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);
}
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()));
}
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);
}
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);
}
Aggregations