@Override public String execute() throws Exception { SessionFactory factory = (SessionFactory) ServletActionContext.getServletContext().getAttribute("IDPPublic.hibernatefactory"); Session session = factory.openSession(); if (userReq == null) { userReq = (UserRequest) session.get(UserRequest.class, Long.parseLong(user_id)); } String userOrg; if (organizationDN.equals("newOrg")) { LDAPUtils.addOrganisation( (LDAPUser) ActionContext.getContext().getSession().get("ldapUser"), new Organization(orgname, null, userReq.getCountry(), orgdesc, NONE, orgref)); userOrg = LDAPUtils.getOrgDN(orgname, userReq.getCountry()); } else { userOrg = organizationDN; } if (LDAPUtils.registerUser( (LDAPUser) ActionContext.getContext().getSession().get("ldapUser"), userReq, userOrg, organizationUnitDN)) { session.beginTransaction(); Query query = session.createQuery("DELETE FROM UserRequest u WHERE u.id = :id"); query.setString("id", user_id); int r = query.executeUpdate(); session.getTransaction().commit(); session.close(); sendMail(userReq); return SUCCESS; } session.close(); return ERROR; }
@Override public void validate() { if (userReq == null) { SessionFactory factory = (SessionFactory) ServletActionContext.getServletContext().getAttribute("IDPPublic.hibernatefactory"); Session session = factory.openSession(); userReq = (UserRequest) session.get(UserRequest.class, Long.parseLong(user_id)); session.close(); } if (organizationDN.equals("newOrg")) { String orgDN = LDAPUtils.getOrgDN(orgname, userReq.getCountry()); if (orgDN != null && !orgDN.isEmpty()) { addFieldError("orgname", "An organisation with this name is already registered"); userReq.setOrganizationDN( LDAPUtils.getOrgDN(userReq.getOrganization(), userReq.getCountry())); orgs = new LinkedHashMap<String, String>(); for (Organization o : LDAPUtils.getOrgList(userReq.getCountry())) { orgs.put(o.getDn(), o.getKey() + " - " + o.getDescription()); } } } }