Search in sources :

Example 1 with UserServiceException

use of org.c4sg.exception.UserServiceException in project c4sg-services by Code4SocialGood.

the class UserServiceImpl method deleteUser.

public void deleteUser(Integer id) {
    User user = userDAO.findById(id);
    // Verify either admin or email matches from authenticated user
    if (!JwtUtil.isAdmin() && !JwtUtil.match(user.getEmail())) {
        throw new UserServiceException("Delete unauthorized");
    }
    user.setStatus(Constants.USER_STATUS_DELETED);
    user.setEmail(user.getEmail() + "-deleted");
    userDAO.save(user);
    // userDAO.deleteUserProjects(id);
    applicationDAO.deleteByUser_Id(id);
    bookmarkDAO.deleteByUser_Id(id);
    userDAO.deleteUserSkills(id);
    List<OrganizationDTO> organizations = organizationService.findByUser(id);
    for (OrganizationDTO org : organizations) {
        organizationService.deleteOrganization(org.getId());
    }
    // Sends notification to admin user. Delete user will be performed by admin user from Auth0 internally to reduce risk.
    Map<String, Object> context = new HashMap<String, Object>();
    context.put("user", user);
    asyncEmailService.sendWithContext(Constants.C4SG_ADDRESS, Constants.C4SG_ADDRESS, "", Constants.SUBJECT_DELETE_USER, Constants.TEMPLATE_DELETE_USER, context);
    System.out.println("Delete user email sent: User=" + id);
}
Also used : UserServiceException(org.c4sg.exception.UserServiceException) User(org.c4sg.entity.User) HashMap(java.util.HashMap) OrganizationDTO(org.c4sg.dto.OrganizationDTO)

Aggregations

HashMap (java.util.HashMap)1 OrganizationDTO (org.c4sg.dto.OrganizationDTO)1 User (org.c4sg.entity.User)1 UserServiceException (org.c4sg.exception.UserServiceException)1