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