Example usage for org.hibernate Session load

List of usage examples for org.hibernate Session load

Introduction

In this page you can find the example usage for org.hibernate Session load.

Prototype

void load(Object object, Serializable id);

Source Link

Document

Read the persistent state associated with the given identifier into the given transient instance.

Usage

From source file:com.krawler.esp.servlets.ExportServlet.java

License:Open Source License

public String currencyRender(String currency, Session session, HttpServletRequest request)
        throws SessionExpiredException {
    KWLCurrency cur = (KWLCurrency) session.load(KWLCurrency.class, AuthHandler.getCurrencyID(request));
    String symbol = cur.getHtmlcode();
    try {/*  w  ww .ja v a  2  s .  c om*/
        char temp = (char) Integer.parseInt(symbol, 16);
        symbol = Character.toString(temp);
    } catch (Exception e) {
    }

    float v = 0;
    DecimalFormat decimalFormat = new DecimalFormat("#,##0.00");
    if (currency.equals(""))
        return symbol;
    v = Float.parseFloat(currency);
    String fmt = decimalFormat.format(v);
    fmt = symbol + fmt;
    return fmt;
}

From source file:com.krawler.esp.servlets.remoteapi.java

License:Open Source License

public static String DeleteGoal(Session session, HttpServletRequest request) throws ServiceException {
    String result = "";
    try {// w  w w  . j a  v a 2 s  .  c o m
        String jsondata = request.getParameter("data");
        JSONArray jarr = new JSONArray("[" + jsondata + "]");
        for (int i = 0; i < jarr.length(); i++) {
            JSONObject jobj = jarr.getJSONObject(i);
            String id = jobj.getString("gid");
            Finalgoalmanagement fgmt = (Finalgoalmanagement) session.load(Finalgoalmanagement.class, id);
            if (fgmt != null) {
                fgmt.setDeleted(true);
                User usr = (User) session.load(User.class, jobj.getString("userid"));
                User empusr = (User) session.load(User.class, jobj.getString("empid"));
                if (usr != null && empusr != null) {
                    String Fullname = null, empFullname = null;
                    try {
                        Fullname = getFullName(usr);
                        empFullname = getFullName(empusr);
                    } catch (Exception ex) {
                        result = getMessage(2, 4); // user not exist
                        break;
                    }
                    String logtext = "User  " + Fullname + " has deleted " + empFullname + "'s goal "
                            + fgmt.getGoalname();
                    session.saveOrUpdate(fgmt);
                    insertAuditLog(session, AuditAction.GOAL_DELETED, logtext, request, usr);
                    result = getMessage(1, 13); // goal delete success
                } else {
                    result = getMessage(2, 4); // user not exist
                }
            } else {
                result = getMessage(2, 14); // Goal with id not exist
            }
        }
    } catch (Exception ex) {
        result = getMessage(2, 13);
    }
    return result;
}

From source file:com.krawler.esp.servlets.remoteapi.java

License:Open Source License

public static String insertGoal(Session session, HttpServletRequest request) throws ServiceException {
    String result = "";
    try {//from  ww w  . j  ava  2s  . c  o  m
        Finalgoalmanagement fgmt = null;
        int logtext = 0;
        String jsondata = request.getParameter("data");
        JSONArray jarr = new JSONArray("[" + jsondata + "]");
        for (int i = 0; i < jarr.length(); i++) {
            JSONObject jobj = jarr.getJSONObject(i);
            String id = jobj.getString("gid");
            String companyid = jobj.getString("companyid");
            Date startdate = new Date(jobj.getString("gstartdate"));
            Date enddate = new Date(jobj.getString("genddate"));
            logtext = jobj.getInt("logtext");
            if (logtext == 0) {
                fgmt = new Finalgoalmanagement();
                fgmt.setId(id);
                fgmt.setCreatedon(new Date());
                fgmt.setInternal(false);
                fgmt.setArchivedflag(0);
                fgmt.setContext(getMasterDataField(session, companyid, 2));
                fgmt.setPriority(getMasterDataField(session, companyid, 3));
                fgmt.setGoalwth(Integer.parseInt(getMasterDataField(session, companyid, 4)));
                fgmt.setCompleted(false);
            } else {
                fgmt = (Finalgoalmanagement) session.load(Finalgoalmanagement.class, jobj.getString("gid"));
                fgmt.setUpdatedon(new Date());
            }
            User AppraisalUser = (User) session.get(User.class, jobj.getString("userid"));
            User usr = (User) session.get(User.class, jobj.getString("empid"));
            if (usr != null && AppraisalUser != null) {
                String Fullname = null;
                try {
                    Fullname = getFullName(AppraisalUser);
                } catch (Exception ex) {
                    result = getMessage(2, 4);
                    break;
                    //                            throw ServiceException.FAILURE("remoteapi.insertGoal", ex);
                }
                fgmt.setAssignedby(Fullname);
                fgmt.setManager(AppraisalUser);
                fgmt.setGoaldesc(jobj.getString("gdescription"));
                fgmt.setGoalname(jobj.getString("gname"));
                fgmt.setStartdate(startdate);
                fgmt.setEnddate(enddate);
                fgmt.setUserID(usr);
                session.save(fgmt);
                if (logtext == 0) {
                    insertAuditLog(
                            session, AuditAction.GOAL_ADDED, "User " + Fullname + " has assigned new goal "
                                    + fgmt.getGoalname() + " to " + getFullName(fgmt.getUserID()),
                            request, AppraisalUser);
                } else {
                    insertAuditLog(
                            session, AuditAction.GOAL_EDITED, "User " + Fullname + " has updated goal "
                                    + fgmt.getGoalname() + " for " + getFullName(fgmt.getUserID()),
                            request, AppraisalUser);
                }
                result = getMessage(1, 12);
            } else {
                result = getMessage(2, 4);
            }
        }
    } catch (Exception ex) {
        result = getMessage(2, 12);
        ex.printStackTrace();
        //            throw ServiceException.FAILURE("remoteapi.insertGoal", ex);
    }
    return result;
}

From source file:com.krawler.esp.servlets.remoteapi.java

License:Open Source License

private static String assignRole(Session session, HttpServletRequest request)
        throws SQLException, ServiceException {
    String result = "";
    try {/*from   w  ww  .  j a va 2  s. co  m*/
        JSONObject jobj = new JSONObject(request.getParameter("data"));
        String userid = jobj.isNull("userid") ? "" : jobj.getString("userid");
        String role = jobj.isNull("role") ? "" : jobj.getString("role");

        boolean flag = false;

        if (jobj.has("userid")) {
            userid = jobj.getString("userid");
        } else if (jobj.has("username")) {
            userid = jobj.getString("username");
            flag = true;
        } else {
            return getMessage(2, 1);
        }

        if (StringUtil.isNullOrEmpty(role) || StringUtil.isNullOrEmpty(userid)) {
            return getMessage(2, 1);
        }

        String query = "";
        String msgStr = "";

        if (flag) {
            String query1 = "from UserLogin where userName=?";
            List list1 = HibernateUtil.executeQuery(session, query1, userid);
            Iterator itr1 = list1.iterator();
            if (itr1.hasNext()) {
                UserLogin user = (UserLogin) itr1.next();
                userid = user.getUserID();
                if (StringUtil.isNullOrEmpty(userid)) {
                    return getMessage(2, 6);
                }
            }
        }
        query = "from User u where u.userID=?";
        List list = HibernateUtil.executeQuery(session, query, userid);
        int count = list.size();
        if (count > 0) {
            User userLogin = (User) session.load(User.class, userid);
            Useraccount ua = (Useraccount) session.get(Useraccount.class, userid);
            if (StringUtil.equal(role, "h1")) {
                role = "1";
            } else if (StringUtil.equal(role, "h2")) {
                role = "2";
            } else if (StringUtil.equal(role, "h3")) {
                role = "3";
            } else if (StringUtil.equal(role, "h4")) {
                role = "4";
            } else if (StringUtil.equal(role, "h0")) {
                replaceCompanyCreator(userLogin, userLogin.getCompany().getCompanyID(), session);
                role = "1";
            }
            //                String permission = "from Role where name=?";
            //                String roleStr = role.equals("h1")?"Administration":(role.equals("h2")?"Manager":"Employee");
            //                List perm=HibernateUtil.executeQuery(session, permission,roleStr);
            Role r = (Role) session.load(Role.class, role);
            ua.setRole(r);
            userLogin.setDeleteflag(0);
            session.update(userLogin);
            result = getMessage(1, 8);
        } else {
            result = getMessage(2, 6);
        }
    } catch (Exception e) {
        result = "{\"success\":false}";
        throw ServiceException.FAILURE("comapanyServlet.CompanyidExits:" + e.getMessage(), e);
    }
    return result;
}

From source file:com.krawler.esp.servlets.remoteapi.java

License:Open Source License

private static String createUser(Session session, HttpServletRequest request)
        throws SQLException, ServiceException {
    String retStr = "";
    try {/*from  www  .  j  a v  a2  s  .c om*/
        JSONObject jobj = new JSONObject(request.getParameter("data"));
        String id = "";
        String pwdText = "";
        String companyid = jobj.isNull("companyid") ? "" : jobj.getString("companyid");
        String username = jobj.isNull("username") ? "" : jobj.getString("username");
        String pwd = jobj.isNull("password") ? "" : jobj.getString("password");
        String fname = jobj.isNull("fname") ? "" : jobj.getString("fname");
        String lname = jobj.isNull("lname") ? "" : jobj.getString("lname");
        String emailid = jobj.isNull("emailid") ? "" : jobj.getString("emailid");
        String userid = jobj.isNull("userid") ? "" : jobj.getString("userid");
        String subdomain = jobj.isNull("subdomain") ? "" : jobj.getString("subdomain");

        if (StringUtil.isNullOrEmpty(companyid) || StringUtil.isNullOrEmpty(username)
                || StringUtil.isNullOrEmpty(fname) || StringUtil.isNullOrEmpty(lname)
                || StringUtil.isNullOrEmpty(emailid) || StringUtil.isNullOrEmpty(userid)) {
            return getMessage(2, 1);
        }

        String hql = "from Company where companyID=?";
        List ls = HibernateUtil.executeQuery(session, hql, new Object[] { companyid });
        if (ls.size() == 0) {
            return getMessage(2, 8);
        }
        UserLogin userLogin;
        User user;
        Useraccount ua;
        Empprofile empProfile = new Empprofile();

        if (StringUtil.isNullOrEmpty(id) == false) {
            user = (User) session.load(User.class, id);
            ua = (Useraccount) session.load(Useraccount.class, id);
            userLogin = user.getUserLogin();
            String pass = jobj.getString("password");
            String oldpass = jobj.getString("oldpassword");
            if (StringUtil.isNullOrEmpty(oldpass) == false) {
                if (AuthHandler.getSHA1(oldpass).equals(userLogin.getPassword())) {
                    if (StringUtil.isNullOrEmpty(pass) == false)
                        userLogin.setPassword(AuthHandler.getSHA1(pass));
                } else
                    throw new Exception("Old Password does not match");
            }

        } else {
            hql = "from UserLogin u where u.userID=?";
            ls = null;
            ls = HibernateUtil.executeQuery(session, hql, new Object[] { userid });
            if (ls.size() > 0) {
                return getMessage(2, 7);
            } else {
                user = new User();
                ua = new Useraccount();
                userLogin = new UserLogin();

                userLogin.setUserID(userid);
                ua.setUserID(userid);
                //                user.setUserID(userid);
                user.setUserLogin(userLogin);
                //userLogin.setUser(user);
                String q = "from User where userLogin.userName=? and company.companyID=?";// and company.companyID=?";
                ls = null;
                ls = HibernateUtil.executeQuery(session, q, new Object[] { username, companyid });
                if (ls.size() > 0 && username.equals(userLogin.getUserName()) == false) {
                    return getMessage(2, 3);
                }
                userLogin.setUserName(username);
                if (jobj.isNull("password")) {
                    pwdText = AuthHandler.generateNewPassword();
                    pwd = AuthHandler.getSHA1(pwdText);
                }
                userLogin.setPassword(pwd);
                user.setCompany((Company) session.load(Company.class, companyid));

                empProfile = setEmployeeProfileDefault(userid, empProfile, userLogin);
            }

        }
        user.setDateFormat((KWLDateFormat) session.load(KWLDateFormat.class, "18"));
        user.setFirstName(fname);
        user.setLastName(lname);
        user.setEmailID(emailid);
        ua.setUser(user);
        ua.setSalary("0");
        String role = jobj.isNull("role") ? "h3" : jobj.getString("role");
        if (StringUtil.equal(role, "h1") || StringUtil.equal(role, "h0")) {
            role = "1";
        } else if (StringUtil.equal(role, "h2")) {
            role = "2";
        } else if (StringUtil.equal(role, "h3")) {
            role = "3";
        }
        ua.setRole((Role) session.load(Role.class, role));
        if (jobj.has("accno") && StringUtil.isNullOrEmpty(jobj.getString("accno")) == false) {
            if ((jobj.getString("accno")).length() > 0) {
                ua.setAccno(jobj.getString("accno"));
            } else {
                ua.setAccno("0");
            }
        }

        ua.setTemplateid("0");
        int empid = getMaxCountEmpid(session, companyid);
        ua.setEmployeeid(empid);
        if (jobj.has("formatid") && StringUtil.isNullOrEmpty(jobj.getString("formatid")) == false) {
            user.setDateFormat((KWLDateFormat) session.load(KWLDateFormat.class, jobj.getString("formatid")));
        }

        String diff = null;
        if (jobj.has("tzid") && StringUtil.isNullOrEmpty(jobj.getString("tzid")) == false) {
            KWLTimeZone timeZone = (KWLTimeZone) session.load(KWLTimeZone.class, jobj.getString("tzid"));
            diff = timeZone.getDifference();
            user.setTimeZone(timeZone);
        }

        if (jobj.has("aboutuser") && StringUtil.isNullOrEmpty(jobj.getString("aboutuser")) == false) {
            user.setAboutUser(jobj.getString("aboutuser"));
        }

        session.saveOrUpdate(userLogin);
        session.saveOrUpdate(user);
        session.save(ua);
        session.save(empProfile);

        updatePreferences(request, null, (jobj.has("formatid") ? jobj.getString("formatid") : null),
                (jobj.has("tzid") ? jobj.getString("tzid") : null), diff);
        retStr = getMessage(1, 5);
    } catch (Exception e) {
        e.printStackTrace();
        throw ServiceException.FAILURE(e.getMessage(), e);
    }
    return retStr;
}

From source file:com.krawler.esp.servlets.remoteapi.java

License:Open Source License

private static void replaceCompanyCreator(User user, String companyid, Session session)
        throws ServiceException {

    try {// w  w w.j  av  a  2 s.  co m
        Company company = (Company) session.load(Company.class, companyid);
        company.setCreator(user);
        session.save(company);

    } catch (Exception e) {
        Logger.getLogger(remoteapi.class.getName()).log(Level.SEVERE,
                "replaceCompanyCreator : Exception while replaceing company creator", e);
    }

}

From source file:com.krawler.esp.servlets.remoteapi.java

License:Open Source License

/**
 * Create company with passed company name and company created user
 * @param session A current transaction session
 * @param request A HttpServletRequest/*from  w  w w  .java2  s.  c om*/
 * @param id Unique username
 * @param password User password
 * @param emailid User emailid
 * @param fname User's name
 * @return JSON with success/failure response.
 * @throws ServiceException
 */
private static String signupCompany(Session session, HttpServletRequest request, String id, String password,
        String emailid, String companyname, String fname, JSONObject jobj, String companyid, String creatorid,
        String subdomain, String lname) throws ServiceException {
    String result = "failure";
    int modules = 0;
    try {
        Company company = null;
        String query1 = "from Company c where c.subDomain= ?";
        List list1 = HibernateUtil.executeQuery(session, query1, subdomain);
        Iterator itr1 = list1.iterator();
        if (itr1.hasNext()) {
            // rename company's invalid subdomain
            Company oldcompany = (Company) itr1.next();
            oldcompany.setSubDomain("old_" + oldcompany.getSubDomain());
            session.saveOrUpdate(oldcompany);

            //                return getMessage(2, 8);//result="e11";
        } else {
            query1 = "from UserLogin u where u.userID=?";
            list1 = HibernateUtil.executeQuery(session, query1, creatorid);
            itr1 = list1.iterator();
            if (itr1.hasNext()) {
                return getMessage(2, 7);
            }
            query1 = "from Company c where c.companyID= ?";
            list1 = HibernateUtil.executeQuery(session, query1, companyid);
            itr1 = list1.iterator();
            if (itr1.hasNext()) {
                return getMessage(2, 8);//result="e11";
            }
            company = new Company();
            company.setCompanyID(companyid);
            company.setSubDomain(subdomain);
            company.setAddress("");
            company.setCompanyName(companyname);
            company.setCountry((Country) session.get(Country.class, "244"));
            company.setTimeZone((KWLTimeZone) session.get(KWLTimeZone.class, "23"));
            company.setEmailID(emailid);
            company.setCurrency((KWLCurrency) session.get(KWLCurrency.class, "1"));
            company.setDeleted(0);
            company.setCreatedOn(new Date());
            company.setModifiedOn(new Date());
            session.save(company);

            UserLogin userLogin = new UserLogin();
            User user = new User();
            Useraccount ua = new Useraccount();
            Empprofile empProfile = new Empprofile();

            ua.setUserID(creatorid);
            userLogin.setUserID(creatorid);
            user.setUserLogin(userLogin);
            user.setDateFormat((KWLDateFormat) session.load(KWLDateFormat.class, "18"));
            userLogin.setUserName(id);
            userLogin.setPassword(password);
            user.setFirstName(fname);
            user.setLastName(lname);
            user.setEmailID(emailid);
            ua.setUser(user);
            ua.setEmployeeid(0001);
            user.setCompany(company);
            ua.setRole((Role) session.load(Role.class, Role.COMPANY_ADMIN));
            ua.setSalary("10000");
            ua.setAccno("");
            user.setDesignation("admin");
            ua.setTemplateid("0");

            empProfile = setEmployeeProfileDefault(creatorid, empProfile, userLogin);

            session.save(userLogin);
            session.save(user);
            session.save(ua);
            session.save(empProfile);

            company.setCreator(user);
            session.save(company);
            CompanyPreferences cmpPref = new CompanyPreferences();
            cmpPref.setCompany(company);
            cmpPref.setAnnmanager(true);
            cmpPref.setTimesheetjob(true);
            modules = getmodules(session);
            cmpPref.setSubscriptionCode(modules);
            cmpPref.setSelfappraisal(true);
            cmpPref.setCompetency(true);
            cmpPref.setGoal(true);
            cmpPref.setApproveappraisal(true);
            cmpPref.setReviewappraisal(true);
            cmpPref.setFullupdates(true);
            cmpPref.setWeightage(true);
            session.save(cmpPref);
            createRecruitmentFormFields(session, request, company);
            createPayrollFields(session, company);

            result = "success";
        }
    } catch (Exception e) {
        throw ServiceException.FAILURE("CompanyHandler.Signup Company", e);
    }
    return result;
}

From source file:com.krawler.esp.servlets.remoteapi.java

License:Open Source License

private static String CompanyDelete(Session session, HttpServletRequest request, JSONObject jobj)
        throws SQLException, ServiceException {
    String result = "{\"success\":false}";
    try {//from w  w w  .  ja v  a  2s . c  o m
        String companyid = "";
        if (!jobj.isNull("companyid")) {
            companyid = jobj.getString("companyid");
        } else {
            return getMessage(2, 1);
        }
        String query = "from Company c where c.companyID= ? and deleted = ?";
        List list = HibernateUtil.executeQuery(session, query, new Object[] { companyid, false });
        int count = list.size();
        if (count > 0) {
            Company c = (Company) session.load(Company.class, companyid);
            c.setDeleted(1);
            result = "{\"success\":true, 'msg': 'Company deleted successfully.'}";
        } else {
            result = getMessage(2, 4);
        }
    } catch (Exception e) {
        result = "{\"success\":false, 'errormsg': 'Following error occured while deleting company : '"
                + e.getMessage() + "}";
        throw ServiceException.FAILURE("comapanyServlet.CompanyDelete:" + e.getMessage(), e);
    }
    return result;
}

From source file:com.krawler.esp.servlets.remoteapi.java

License:Open Source License

private static String updateCompany(Session session, HttpServletRequest request)
        throws ServiceException, JSONException, SessionExpiredException {
    String result = "";
    JSONObject jobj = new JSONObject(request.getParameter("data"));
    String address = jobj.isNull("address") ? "" : jobj.getString("address");
    String city = jobj.isNull("city") ? "" : jobj.getString("city");
    String state = jobj.isNull("state") ? "" : jobj.getString("state");
    String companyname = jobj.isNull("companyname") ? "" : jobj.getString("companyname");
    String companyid = jobj.isNull("companyid") ? "" : jobj.getString("companyid");
    String phone = jobj.isNull("phone") ? "" : jobj.getString("phone");
    String subdomain = jobj.isNull("subdomain") ? "" : jobj.getString("subdomain");
    String fax = jobj.isNull("fax") ? "" : jobj.getString("fax");
    String zip = jobj.isNull("zip") ? "" : jobj.getString("zip");
    String website = jobj.isNull("website") ? "" : jobj.getString("website");
    String emailid = jobj.isNull("emailid") ? "" : jobj.getString("emailid");
    String currency = jobj.isNull("currency") ? "" : jobj.getString("currency");
    String country = jobj.isNull("country") ? "" : jobj.getString("country");
    String timezone = jobj.isNull("timezone") ? "" : jobj.getString("timezone");
    String imgPath = jobj.isNull("image") ? "" : jobj.getString("image");
    if (StringUtil.isNullOrEmpty(companyid) || StringUtil.isNullOrEmpty(subdomain)
            || StringUtil.isNullOrEmpty(companyname) || StringUtil.isNullOrEmpty(currency)
            || StringUtil.isNullOrEmpty(country) || StringUtil.isNullOrEmpty(timezone)) {
        return getMessage(2, 1);
    }/*from   w w  w.j  a v a2 s .  c o  m*/
    try {
        Company company = null;
        String query1 = "from Company c where c.companyID= ?";
        List list1 = HibernateUtil.executeQuery(session, query1, companyid);
        Iterator itr1 = list1.iterator();
        if (!(itr1.hasNext())) {
            return getMessage(2, 4);
        } else {
            query1 = "from Company c where c.subDomain= ? and c.companyID <> ?";
            list1 = HibernateUtil.executeQuery(session, query1, new Object[] { subdomain, companyid });
            itr1 = list1.iterator();
            if (itr1.hasNext()) {
                return getMessage(2, 10);
            }
            company = (Company) session.load(Company.class, companyid);
            company.setSubDomain(subdomain);
            company.setCompanyName(companyname);
            company.setAddress(address);
            company.setCity(city);
            company.setState(state);
            company.setPhoneNumber(phone);
            company.setFaxNumber(fax);
            company.setZipCode(zip);
            company.setWebsite(website);
            company.setEmailID(emailid);
            company.setCompanyLogo(imgPath);
            company.setCountry((Country) session.load(Country.class, country));
            company.setCurrency((KWLCurrency) session.load(KWLCurrency.class, currency));
            KWLTimeZone timeZone = (KWLTimeZone) session.load(KWLTimeZone.class, timezone);
            company.setTimeZone(timeZone);
            company.setModifiedOn(new Date());
            session.saveOrUpdate(company);
            result = getMessage(1, 11);
        }
    } catch (NullPointerException e) {
        throw ServiceException.FAILURE("CompanyHandler.updateCompany", e);
    }
    return result;
}

From source file:com.krawler.esp.servlets.remoteapi.java

License:Open Source License

public static String editUser(Session session, HttpServletRequest request) throws ServiceException {
    String r = getMessage(1, 11);//"{\"success\": true, \"infocode\": \"m07\"}";
    try {/*from   w ww  .j a  v  a2  s. c om*/
        String userid = "";
        JSONObject jobj = new JSONObject(request.getParameter("data"));
        boolean flag = false;
        if (jobj.has("userid")) {
            userid = StringUtil.serverHTMLStripper(jobj.get("userid").toString());
        } else {
            flag = true;
            r = getMessage(2, 1);//"{\"success\": false, \"errorcode\": \"e01\"}";
        }
        if (!flag) {
            String emailid = jobj.has("emailid") ? jobj.getString("emailid").trim().replace(" ", "+") : "";
            String fname = jobj.has("fname") ? StringUtil.serverHTMLStripper(jobj.get("fname").toString()) : "";
            String lname = jobj.has("lname") ? StringUtil.serverHTMLStripper(jobj.get("lname").toString()) : "";
            emailid = StringUtil.serverHTMLStripper(emailid);
            String contactno = jobj.has("contactno")
                    ? StringUtil.serverHTMLStripper(jobj.get("contactno").toString())
                    : "";
            String address = jobj.has("address") ? StringUtil.serverHTMLStripper(jobj.get("address").toString())
                    : "";
            String tzId = jobj.has("timezone") ? StringUtil.serverHTMLStripper(jobj.get("timezone").toString())
                    : "";

            User usr = (User) session.get(User.class, userid);
            if (usr != null) {
                usr.setFirstName(fname);
                usr.setLastName(lname);
                usr.setEmailID(emailid);
                usr.setAddress(address);
                usr.setContactNumber(contactno);
                usr.setTimeZone(StringUtil.isNullOrEmpty(tzId) ? null
                        : (KWLTimeZone) session.load(KWLTimeZone.class, tzId));
                session.save(usr);
            } else {
                r = getMessage(2, 6);
            }
        }
    } catch (JSONException e) {
        // Error Connecting to Server
        r = getMessage(2, 2);//"{\"success\": false, \"errorcode\": \"e02\"}";
        Logger.getLogger(remoteapi.class.getName()).log(Level.SEVERE, "JSON Exception While Editing User", e);
        throw ServiceException.FAILURE(r, e);

    } catch (Exception e) {
        // Error Connecting to Server
        r = getMessage(2, 2);//"{\"success\": false, \"errorcode\": \"e02\"}";
        Logger.getLogger(remoteapi.class.getName()).log(Level.SEVERE, "Exception While Editing User", e);
        throw ServiceException.FAILURE(r, e);
    }
    return r;
}