public String execute() throws Exception { try { OrganisationUnit unit = organisationUnitService.getOrganisationUnit(id); if (unit == null) { throw new RuntimeException("OrganisationUnit with id " + id + " doesn't exist"); } selectedUnits = selectionManager.getSelectedOrganisationUnits(); selectedUnits.remove(unit); selectionManager.setSelectedOrganisationUnits(selectedUnits); } catch (Exception e) { LOG.error(e.getMessage(), e); throw e; } return SUCCESS; }
public String execute() throws Exception { UserCredentials currentUserCredentials = currentUserService.getCurrentUser() != null ? currentUserService.getCurrentUser().getUserCredentials() : null; // --------------------------------------------------------------------- // Prepare values // --------------------------------------------------------------------- if (email != null && email.trim().length() == 0) { email = null; } if (rawPassword != null && rawPassword.trim().length() == 0) { rawPassword = null; } // --------------------------------------------------------------------- // Update userCredentials and user // --------------------------------------------------------------------- Collection<OrganisationUnit> units = selectionTreeManager.getReloadedSelectedOrganisationUnits(); User user = userService.getUser(id); user.setSurname(surname); user.setFirstName(firstName); user.setEmail(email); user.setPhoneNumber(phoneNumber); user.updateOrganisationUnits(new HashSet<OrganisationUnit>(units)); UserCredentials userCredentials = userService.getUserCredentials(user); Set<UserAuthorityGroup> userAuthorityGroups = new HashSet<UserAuthorityGroup>(); for (String id : selectedList) { UserAuthorityGroup group = userService.getUserAuthorityGroup(Integer.parseInt(id)); if (currentUserCredentials != null && currentUserCredentials.canIssue(group)) { userAuthorityGroups.add(group); } } userCredentials.setUserAuthorityGroups(userAuthorityGroups); if (rawPassword != null) { userCredentials.setPassword( passwordManager.encodePassword(userCredentials.getUsername(), rawPassword)); } if (jsonAttributeValues != null) { AttributeUtils.updateAttributeValuesFromJson( user.getAttributeValues(), jsonAttributeValues, attributeService); } userService.updateUserCredentials(userCredentials); userService.updateUser(user); if (currentUserService.getCurrentUser() == user) { selectionManager.setRootOrganisationUnits(units); selectionManager.setSelectedOrganisationUnits(units); selectionTreeManager.setRootOrganisationUnits(units); selectionTreeManager.setSelectedOrganisationUnits(units); } if (units.size() > 0) { selectionManager.setSelectedOrganisationUnits(units); } return SUCCESS; }