Search in sources :

Example 1 with UserOrganization

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

the class OrganizationServiceImpl method findByUser.

@Override
public List<OrganizationDTO> findByUser(Integer userId) {
    User user = userDAO.findById(userId);
    requireNonNull(user, "Invalid User Id");
    List<UserOrganization> userOrganizations = userOrganizationDAO.findByUserId(userId);
    List<OrganizationDTO> organizationDtos = new ArrayList<OrganizationDTO>();
    for (UserOrganization userOrganization : userOrganizations) {
        organizationDtos.add(organizationMapper.getOrganizationDtoFromEntity(userOrganization));
    }
    return organizationDtos;
}
Also used : User(org.c4sg.entity.User) UserOrganization(org.c4sg.entity.UserOrganization) ArrayList(java.util.ArrayList) CreateOrganizationDTO(org.c4sg.dto.CreateOrganizationDTO) OrganizationDTO(org.c4sg.dto.OrganizationDTO)

Example 2 with UserOrganization

use of org.c4sg.entity.UserOrganization 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 3 with UserOrganization

use of org.c4sg.entity.UserOrganization 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

UserOrganization (org.c4sg.entity.UserOrganization)3 ArrayList (java.util.ArrayList)2 User (org.c4sg.entity.User)2 CreateOrganizationDTO (org.c4sg.dto.CreateOrganizationDTO)1 OrganizationDTO (org.c4sg.dto.OrganizationDTO)1 Application (org.c4sg.entity.Application)1 Organization (org.c4sg.entity.Organization)1 Project (org.c4sg.entity.Project)1 UserOrganizationException (org.c4sg.exception.UserOrganizationException)1