public void updatePassword(Long userId) { String plainTextPassword = PasswordEncryption.generateRandomPassword(); VDCUser user = em.find(VDCUser.class, userId); user.setEncryptedPassword(encryptPassword(plainTextPassword)); mailService.sendPasswordUpdateNotification( user.getEmail(), user.getFirstName(), user.getUserName(), plainTextPassword); }
public void makeCreator(Long userId) { VDCUser user = em.find(VDCUser.class, userId); VDCNetwork vdcNetwork = vdcNetworkService.find(); // If the user already has a networkRole, then he is already a creator or networkAdmin, // so don't need to change the role. if (user.getNetworkRole() == null) { user.setNetworkRole(networkRoleService.getCreatorRole()); mailService.sendCreatorAccountNotification(vdcNetwork.getContactEmail(), user.getUserName()); } }
public void addVdcRole(Long userId, Long vdcId, String roleName) { Role role = roleService.findByName(roleName); VDCRole vdcRole = new VDCRole(); vdcRole.setVdcUser(em.find(VDCUser.class, userId)); vdcRole.setVdc(em.find(VDC.class, vdcId)); vdcRole.setRole(role); em.persist(vdcRole); // Added for EclipseLink - wasn't being saved otherwise VDCUser user = em.find(VDCUser.class, userId); user.getVdcRoles().add(vdcRole); VDC vdc = em.find(VDC.class, vdcId); vdc.getVdcRoles().add(vdcRole); }
public List findAll() { List userList = em.createQuery("select object(o) from VDCUser as o order by o.userName").getResultList(); // Loop thru VDCRoles to trigger load from the DB before detaching for (Iterator<VDCUser> it = userList.iterator(); it.hasNext(); ) { VDCUser elem = it.next(); Collection vdcRoles = elem.getVdcRoles(); for (Iterator<VDCRole> it2 = vdcRoles.iterator(); it2.hasNext(); ) { VDCRole vdcRole = it2.next(); Long id = vdcRole.getRole().getId(); id = vdcRole.getVdc().getId(); } } return userList; }
public VDCUser findByUserName(String userName, boolean activeOnly) { String query = "SELECT u from VDCUser u where u.userName = :userName "; if (activeOnly) { query += " and u.active=true "; } VDCUser user = null; try { user = (VDCUser) em.createQuery(query).setParameter("userName", userName).getSingleResult(); } catch (javax.persistence.NoResultException e) { // DO nothing, just return null. } // loop thru user vdc roles, so they are available if (user != null && user.getVdcRoles() != null) { for (Iterator it = user.getVdcRoles().iterator(); it.hasNext(); ) { VDCRole elem = (VDCRole) it.next(); Long id = elem.getRole().getId(); id = elem.getVdc().getId(); } } return user; }
public void remove(Long id) { VDCUser user = (VDCUser) em.find(VDCUser.class, id); if (user != null) { // Need to remove this user from other collections it may belong to. for (Iterator it = user.getUserGroups().iterator(); it.hasNext(); ) { UserGroup group = (UserGroup) it.next(); group.getUsers().remove(user); } for (Iterator it2 = user.getStudies().iterator(); it2.hasNext(); ) { Study study = (Study) it2.next(); study.getAllowedUsers().remove(user); } for (Iterator it2 = user.getStudyFiles().iterator(); it2.hasNext(); ) { StudyFile studyFile = (StudyFile) it2.next(); studyFile.getAllowedUsers().remove(user); } for (Iterator it = user.getAllowedFileVdcs().iterator(); it.hasNext(); ) { VDC elem = (VDC) it.next(); elem.getAllowedFileUsers().remove(user); } em.remove(user); } }
public void makeContributor(Long userId, Long vdcId) { VDCUser user = em.find(VDCUser.class, userId); VDC vdc = em.find(VDC.class, vdcId); // if the current role is priveleged viewer, remove it so we can promote // user to contributor. if (user.isPrivilegedViewer(vdc)) { VDCRole role = user.getVDCRole(vdc); user.getVdcRoles().remove(role); em.remove(role); } if (user.getVDCRole(vdc) == null) { addVdcRole(userId, vdcId, RoleServiceLocal.CONTRIBUTOR); mailService.sendContributorAccountNotification( vdc.getContactEmail(), user.getUserName(), vdc.getName()); } }
public void setAgreedTermsOfUse(Long userId, boolean agreed) { VDCUser user = em.find(VDCUser.class, userId); user.setAgreedTermsOfUse(agreed); }
public boolean validatePassword(Long userId, String password) { VDCUser user = em.find(VDCUser.class, userId); String encryptedPassword = PasswordEncryption.getInstance().encrypt(password); return encryptedPassword.equals(user.getEncryptedPassword()); }
public void setActiveStatus(Long userId, boolean active) { VDCUser user = em.find(VDCUser.class, userId); user.setActive(active); }