use of org.c4sg.entity.Organization 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.Organization 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.Organization in project c4sg-services by Code4SocialGood.
the class UserServiceImpl method createUser.
@Override
public UserDTO createUser(CreateUserDTO createUserDTO) {
User user = userMapper.getUserEntityFromCreateUserDto(createUserDTO);
if ((user != null) && !StringUtils.isEmpty(user.getCountry())) {
try {
Map<String, BigDecimal> geoCode = geocodeService.getGeoCode(user.getState(), user.getCountry());
user.setLatitude(geoCode.get("lat"));
user.setLongitude(geoCode.get("lng"));
} catch (Exception e) {
// Don't throw exception, geocoding error won't present user from being created.
System.out.println("Error getting geocode: " + e.toString());
}
}
// Set user status to "N" for new user
user.setStatus("N");
User userEntity = userDAO.save(user);
// If the user is organization user:
// 1. Creates an empty organization.
// 2. Create a relationship between user and organization. The relationship is one to one.
String role = createUserDTO.getRole();
if ((role != null) && role.equals("O")) {
Organization organization = new Organization();
organization.setStatus("N");
Organization organizationEntity = organizationDAO.save(organization);
organizationService.saveUserOrganization(userEntity.getId(), organizationEntity.getId());
}
return userMapper.getUserDtoFromEntity(userEntity);
}
use of org.c4sg.entity.Organization in project c4sg-services by Code4SocialGood.
the class OrganizationServiceImpl method updateOrganization.
public OrganizationDTO updateOrganization(int id, OrganizationDTO organizationDTO) {
Organization organization = organizationDAO.findOne(id);
if (organization == null) {
System.out.println("Organization does not exist.");
} else {
organization = organizationMapper.getOrganizationEntityFromDto(organizationDTO);
try {
Map<String, BigDecimal> geoCode = geocodeService.getGeoCode(organization.getState(), organization.getCountry());
organization.setLatitude(geoCode.get("lat"));
organization.setLongitude(geoCode.get("lng"));
} catch (Exception e) {
// throw new NotFoundException("Error getting geocode");
System.out.println("Error getting geocode: " + e.toString());
}
organizationDAO.save(organization);
String newStatus = organization.getStatus();
// Notify admin users of new organization, or update for a declined organization
if (newStatus.equals(Constants.ORGANIZATION_STATUS_PENDIONG_REVIEW) || newStatus.equals(Constants.ORGANIZATION_STATUS_DECLINED)) {
String toAddress = null;
List<User> users = userDAO.findByKeyword(null, "A", "A", null);
if (users != null && !users.isEmpty()) {
User adminUser = users.get(0);
toAddress = adminUser.getEmail();
}
Map<String, Object> context = new HashMap<String, Object>();
context.put("organization", organization);
asyncEmailService.sendWithContext(Constants.C4SG_ADDRESS, toAddress, "", Constants.SUBJECT_NEW_ORGANIZATION_REVIEW, Constants.TEMPLATE_NEW_ORGANIZATION_REVIEW, context);
System.out.println("New organization email sent: Organization=" + organization.getId() + " ; Email=" + toAddress);
}
}
return organizationMapper.getOrganizationDtoFromEntity(organization);
}
use of org.c4sg.entity.Organization in project c4sg-services by Code4SocialGood.
the class OrganizationServiceImpl method deleteOrganization.
public void deleteOrganization(int id) {
Organization organization = organizationDAO.findOne(id);
if (organization != null) {
organization.setStatus(Constants.ORGANIZATION_STATUS_DELETED);
// TODO Delete logo from S3 by frontend
organizationDAO.save(organization);
List<ProjectDTO> projects = projectService.findByOrganization(id, null);
for (ProjectDTO project : projects) {
projectService.deleteProject(project.getId());
}
organizationDAO.deleteUserOrganizations(id);
// TODO: Local or Timezone?
// TODO: Format date
// organization.setDeleteTime(LocalDateTime.now().toString());
// organization.setDeleteBy(user.getUsername());
}
}
Aggregations