use of org.c4sg.entity.Organization in project c4sg-services by Code4SocialGood.
the class OrganizationServiceImpl method findByCriteria.
public Page<OrganizationDTO> findByCriteria(String keyWord, List<String> countries, Boolean open, String status, List<String> categories, Integer page, Integer size) {
Page<Organization> organizationPages;
List<Organization> organizations = null;
if (page == null)
page = 0;
if (size == null) {
if (countries == null || countries.isEmpty()) {
if (open == null) {
if (categories != null) {
organizations = organizationDAO.findByCriteria(keyWord, open, status, categories);
} else {
organizations = organizationDAO.findByCriteriaNoCategoriesFilter(keyWord, open, status);
}
} else {
if (categories == null) {
organizations = organizationDAO.findByCriteriaAndOpenNoCategoriesFilter(keyWord, open, status);
} else {
organizations = organizationDAO.findByCriteriaAndOpen(keyWord, open, status, categories);
}
}
} else {
if (open == null) {
if (categories != null) {
organizations = organizationDAO.findByCriteriaAndCountries(keyWord, countries, open, status, categories);
}
} else {
organizations = organizationDAO.findByCriteriaAndCountriesAndOpen(keyWord, countries, open, status, categories);
}
}
organizationPages = new PageImpl<>(organizations);
return organizationPages.map(o -> organizationMapper.getOrganizationDtoFromEntity(o));
}
Pageable pageable = new PageRequest(page, size);
if (countries == null || countries.isEmpty()) {
if (open == null) {
if (categories == null) {
organizationPages = organizationDAO.findByCriteriaNoCategoriesFilter(keyWord, open, status, pageable);
} else {
organizationPages = organizationDAO.findByCriteria(keyWord, open, status, categories, pageable);
}
} else {
if (categories == null) {
organizationPages = organizationDAO.findByCriteriaAndOpenNoCategoriesFilter(keyWord, open, status, pageable);
} else {
organizationPages = organizationDAO.findByCriteriaAndOpen(keyWord, open, status, categories, pageable);
}
}
} else if (open == null) {
organizationPages = organizationDAO.findByCriteriaAndCountries(keyWord, countries, open, status, categories, pageable);
} else {
organizationPages = organizationDAO.findByCriteriaAndCountriesAndOpen(keyWord, countries, open, status, categories, pageable);
}
return organizationPages.map(o -> organizationMapper.getOrganizationDtoFromEntity(o));
}
use of org.c4sg.entity.Organization in project c4sg-services by Code4SocialGood.
the class OrganizationServiceImpl method save.
public void save(OrganizationDTO organizationDTO) {
Organization organization = organizationMapper.getOrganizationEntityFromDto(organizationDTO);
organizationDAO.save(organization);
}
use of org.c4sg.entity.Organization in project c4sg-services by Code4SocialGood.
the class OrganizationServiceImpl method saveUserOrganization.
@Override
public OrganizationDTO saveUserOrganization(Integer userId, Integer organizationId) throws UserOrganizationException {
User user = userDAO.findById(userId);
requireNonNull(user, "Invalid User Id");
Organization organization = organizationDAO.findOne(organizationId);
requireNonNull(organization, "Invalid organization Id");
UserOrganization userOrganization = userOrganizationDAO.findByUser_IdAndOrganization_Id(userId, organizationId);
if (nonNull(userOrganization)) {
throw new UserOrganizationException("The user organization relationship already exists.");
} else {
userOrganization = new UserOrganization();
userOrganization.setUser(user);
userOrganization.setOrganization(organization);
userOrganizationDAO.save(userOrganization);
}
return organizationMapper.getOrganizationDtoFromEntity(organization);
}
use of org.c4sg.entity.Organization in project c4sg-services by Code4SocialGood.
the class ProjectServiceImpl method createProject.
public ProjectDTO createProject(CreateProjectDTO createProjectDTO) {
Project project = projectDAO.findByNameAndOrganizationId(createProjectDTO.getName(), createProjectDTO.getOrganizationId());
if (project != null) {
System.out.println("Project already exist.");
} else {
project = projectDAO.save(projectMapper.getProjectEntityFromCreateProjectDto(createProjectDTO));
// Updates projectUpdateTime for the organization
Organization localOrgan = project.getOrganization();
localOrgan.setProjectUpdatedTime(new Timestamp(Calendar.getInstance().getTime().getTime()));
organizationDAO.save(localOrgan);
}
return projectMapper.getProjectDtoFromEntity(project);
}
use of org.c4sg.entity.Organization in project c4sg-services by Code4SocialGood.
the class ApplicationServiceImpl method sendEmail.
@Async
private void sendEmail(User user, Project project, Application application) {
Integer orgId = project.getOrganization().getId();
List<User> users = userDAO.findByOrgId(orgId);
if (users != null && !users.isEmpty()) {
List<String> userSkills = skillService.findSkillsForUser(user.getId());
User orgUser = users.get(0);
Organization org = organizationDAO.findOne(project.getOrganization().getId());
if (application.getStatus().equals("A")) {
// send email to organization
Map<String, Object> contextOrg = new HashMap<String, Object>();
contextOrg.put("user", user);
contextOrg.put("skills", userSkills);
contextOrg.put("project", project);
contextOrg.put("projectLink", urlService.getProjectUrl(project.getId()));
contextOrg.put("userLink", urlService.getUserUrl(user.getId()));
contextOrg.put("application", application);
asyncEmailService.sendWithContext(Constants.C4SG_ADDRESS, orgUser.getEmail(), user.getEmail(), Constants.SUBJECT_APPLICATION_ORGANIZATION, Constants.TEMPLATE_APPLICAITON_ORGANIZATION, contextOrg);
// send email to volunteer
Map<String, Object> contextVolunteer = new HashMap<String, Object>();
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_APPLICATION_VOLUNTEER, Constants.TEMPLATE_APPLICAITON_VOLUNTEER, contextVolunteer);
System.out.println("Application email sent: Project=" + project.getId() + " ; ApplicantEmail=" + user.getEmail() + " ; OrgEmail=" + orgUser.getEmail());
} else if (application.getStatus().equals("C")) {
// send email to organization
Map<String, Object> contextOrg = new HashMap<String, Object>();
contextOrg.put("user", user);
contextOrg.put("skills", userSkills);
contextOrg.put("project", project);
contextOrg.put("projectLink", urlService.getProjectUrl(project.getId()));
contextOrg.put("userLink", urlService.getUserUrl(user.getId()));
contextOrg.put("application", application);
asyncEmailService.sendWithContext(Constants.C4SG_ADDRESS, orgUser.getEmail(), user.getEmail(), Constants.SUBJECT_APPLICATION_ACCEPT_ORGANIZATION, Constants.TEMPLATE_APPLICAITON_ACCEPT_ORGANIZATION, contextOrg);
System.out.println("Application email sent to org user: Project=" + project.getId() + " ; OrgUserEmail=" + orgUser.getEmail());
// send email to volunteer
Map<String, Object> contextVolunteer = new HashMap<String, Object>();
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_APPLICATION_ACCEPT, Constants.TEMPLATE_APPLICAITON_ACCEPT, contextVolunteer);
System.out.println("Application email sent to volunteer: Project=" + project.getId() + " ; ApplicantEmail=" + user.getEmail());
} else if (application.getStatus().equals("D")) {
// send email to volunteer
Map<String, Object> contextVolunteer = new HashMap<String, Object>();
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_APPLICATION_DECLINE, Constants.TEMPLATE_APPLICAITON_DECLINE, contextVolunteer);
System.out.println("Application email sent: Project=" + project.getId() + " ; ApplicantEmail=" + user.getEmail());
} else if (application.getStatus().equals("B")) {
// do nothing
}
}
}
Aggregations