Search in sources :

Example 1 with Organization

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));
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Organization(org.c4sg.entity.Organization) UserOrganization(org.c4sg.entity.UserOrganization) Pageable(org.springframework.data.domain.Pageable)

Example 2 with Organization

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);
}
Also used : Organization(org.c4sg.entity.Organization) UserOrganization(org.c4sg.entity.UserOrganization)

Example 3 with 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);
}
Also used : User(org.c4sg.entity.User) Organization(org.c4sg.entity.Organization) UserOrganization(org.c4sg.entity.UserOrganization) UserOrganizationException(org.c4sg.exception.UserOrganizationException) UserOrganization(org.c4sg.entity.UserOrganization)

Example 4 with 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);
}
Also used : UserProject(org.c4sg.entity.UserProject) Project(org.c4sg.entity.Project) Organization(org.c4sg.entity.Organization) Timestamp(java.sql.Timestamp)

Example 5 with Organization

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
        }
    }
}
Also used : User(org.c4sg.entity.User) Organization(org.c4sg.entity.Organization) UserOrganization(org.c4sg.entity.UserOrganization) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) Async(org.springframework.scheduling.annotation.Async)

Aggregations

Organization (org.c4sg.entity.Organization)10 User (org.c4sg.entity.User)6 UserOrganization (org.c4sg.entity.UserOrganization)6 HashMap (java.util.HashMap)4 Project (org.c4sg.entity.Project)3 BigDecimal (java.math.BigDecimal)2 UserOrganizationException (org.c4sg.exception.UserOrganizationException)2 Timestamp (java.sql.Timestamp)1 Map (java.util.Map)1 MimeMessage (javax.mail.internet.MimeMessage)1 ProjectDTO (org.c4sg.dto.ProjectDTO)1 Badge (org.c4sg.entity.Badge)1 UserProject (org.c4sg.entity.UserProject)1 NotFoundException (org.c4sg.exception.NotFoundException)1 UserServiceException (org.c4sg.exception.UserServiceException)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 PageRequest (org.springframework.data.domain.PageRequest)1 Pageable (org.springframework.data.domain.Pageable)1 Async (org.springframework.scheduling.annotation.Async)1