Example usage for org.hibernate Session saveOrUpdate

List of usage examples for org.hibernate Session saveOrUpdate

Introduction

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

Prototype

void saveOrUpdate(Object object);

Source Link

Document

Either #save(Object) or #update(Object) the given instance, depending upon resolution of the unsaved-value checks (see the manual for discussion of unsaved-value checking).

Usage

From source file:com.krawler.esp.handlers.PermissionHandler.java

License:Open Source License

public static void saveActivity(Session session, HttpServletRequest request) throws ServiceException {
    try {//  w w w. ja  va2 s .  c  o m
        String id = request.getParameter("activityid");
        ProjectActivity activity;

        if (StringUtil.isNullOrEmpty(id) == false) {
            activity = (ProjectActivity) session.load(ProjectActivity.class, id);
        } else {
            activity = new ProjectActivity();
            ProjectFeature feature = (ProjectFeature) session.load(ProjectFeature.class,
                    request.getParameter("featureid"));
            activity.setFeature(feature);
        }
        activity.setActivityName(request.getParameter("activityname"));
        activity.setDisplayActivityName(request.getParameter("displayactivityname"));
        session.saveOrUpdate(activity);
        if (StringUtil.isNullOrEmpty(id) == false) {
            updatePermissionsForActivity(session, activity, activity.getFeature(), true);
        }
    } catch (Exception e) {
        throw ServiceException.FAILURE("PermissionHandler.saveActivity", e);
    }
}

From source file:com.krawler.esp.handlers.PermissionHandler.java

License:Open Source License

public static void saveFeature(Session session, HttpServletRequest request) throws ServiceException {
    try {/*  w  ww . j  a  v a2  s .  c  o  m*/
        String id = request.getParameter("featureid");
        ProjectFeature feature;
        if (StringUtil.isNullOrEmpty(id) == false) {
            feature = (ProjectFeature) session.load(ProjectFeature.class, id);
        } else {
            feature = new ProjectFeature();
        }
        feature.setFeatureName(request.getParameter("featurename"));
        feature.setDisplayFeatureName(request.getParameter("displayfeaturename"));
        session.saveOrUpdate(feature);
    } catch (Exception e) {
        throw ServiceException.FAILURE("PermissionHandler.saveFeature", e);
    }
}

From source file:com.krawler.esp.handlers.PermissionHandler.java

License:Open Source License

public static void saveRole(Session session, HttpServletRequest request) throws ServiceException {
    try {//from w  ww.  j  a v  a 2s.c  o m
        String id = request.getParameter("roleid");
        Role role;
        if (StringUtil.isNullOrEmpty(id)) {
            role = new Role();
        } else {
            role = (Role) session.load(Role.class, id);
        }
        role.setCompany((Company) session.load(Company.class, AuthHandler.getCompanyid(request)));
        role.setName(request.getParameter("rolename"));
        session.saveOrUpdate(role);
    } catch (Exception e) {
        throw ServiceException.FAILURE(e.getMessage(), e);
    }
}

From source file:com.krawler.esp.handlers.PermissionHandlercrm.java

License:Open Source License

public static void saveActivity(Session session, HttpServletRequest request) throws ServiceException {
    try {/*from  w  ww.j  ava2  s.  co m*/
        String id = request.getParameter("activityid");
        ProjectActivity activity;
        ProjectFeature feature = null;
        if (id != null && id.length() > 0) {
            activity = (ProjectActivity) session.load(ProjectActivity.class, id);
        } else {
            activity = new ProjectActivity();
            feature = (ProjectFeature) session.load(ProjectFeature.class, request.getParameter("featureid"));
            activity.setFeature(feature);
        }
        activity.setActivityName(request.getParameter("activityname"));
        activity.setDisplayActivityName(request.getParameter("displayactivityname"));
        session.saveOrUpdate(activity);
        if (id != null && id.length() > 0) {
            updatePermissionsForActivity(session, activity, feature, true);
        }
    } catch (Exception e) {
        throw ServiceException.FAILURE("PermissionHandler.saveActivity", e);
    }
}

From source file:com.krawler.esp.handlers.PermissionHandlercrm.java

License:Open Source License

public static void saveFeature(Session session, HttpServletRequest request) throws ServiceException {
    try {/*  ww  w  .j  av  a  2s  .c om*/
        String id = request.getParameter("featureid");
        ProjectFeature feature;
        if (id != null && id.length() > 0) {
            feature = (ProjectFeature) session.load(ProjectFeature.class, id);
        } else {
            feature = new ProjectFeature();
        }
        feature.setFeatureName(request.getParameter("featurename"));
        feature.setDisplayFeatureName(request.getParameter("displayfeaturename"));
        session.saveOrUpdate(feature);
    } catch (Exception e) {
        throw ServiceException.FAILURE("PermissionHandler.saveFeature", e);
    }
}

From source file:com.krawler.esp.handlers.PermissionHandlercrm.java

License:Open Source License

public static void saveRole(Session session, HttpServletRequest request) throws ServiceException {
    try {//from w  w  w.  ja v  a  2 s.  c om
        String id = request.getParameter("roleid");
        Rolelist role;
        if (id != null && id.length() > 0) {
            role = (Rolelist) session.load(Rolelist.class, id);
        } else {
            role = new Rolelist();
        }
        role.setRolename(request.getParameter("rolename"));
        role.setDisplayrolename(request.getParameter("displayrolename"));
        session.saveOrUpdate(role);
    } catch (Exception e) {
        throw ServiceException.FAILURE("PermissionHandler.saveRole", e);
    }
}

From source file:com.krawler.esp.handlers.ProfileHandler.java

License:Open Source License

public static void deleteUser(Session session, HttpServletRequest request) throws ServiceException {
    try {//from  w ww.  ja v  a2 s .  co  m
        JSONObject jobj = new JSONObject();
        JSONArray jArr = new JSONArray();

        String[] ids = request.getParameterValues("userids");
        for (int i = 0; i < ids.length; i++) {
            User u = (User) session.load(User.class, ids[i]);
            if (u.getRoleID() == 1) {
                throw new Exception("Cannot delete Administrator");
            }
            //UserLogin userLogin = (UserLogin) session.load(UserLogin.class, ids[i]);
            u.setDeleteflag(1);
            session.saveOrUpdate(u);
            //session.delete(userLogin);
        }
    } catch (Exception e) {
        throw ServiceException.FAILURE(e.getMessage(), e);
    }
}

From source file:com.krawler.esp.handlers.ProfileHandler.java

License:Open Source License

public static void setPassword(Session session, HttpServletRequest request) throws ServiceException {
    try {//from  ww w .j  a v a 2  s  .  com
        String password = request.getParameter("password");
        if (password == null || password.length() <= 0) {
            password = AuthHandler.generateNewPassword();
        }
        String newpass = AuthHandler.getSHA1(password);
        User user = (User) session.load(User.class, request.getParameter("userid"));
        UserLogin userLogin = user.getUserLogin();
        userLogin.setPassword(newpass);
        session.saveOrUpdate(userLogin);
        String uri = URLUtil.getPageURL(request, Links.loginpageFull);
        String fname = user.getFirstName();
        if (StringUtil.isNullOrEmpty(fname)) {
            fname = user.getUserLogin().getUserName();
        }
        String pmsg = String.format(KWLErrorMsgs.msgTempPassword, fname, password, uri);
        String htmlmsg = String.format(KWLErrorMsgs.msgMailPassword, fname, password, uri, uri);
        try {
            String adminEmailId = request.getSession().getAttribute("sysemailid").toString();
            SendMailHandler.postMail(new String[] { user.getEmailID() }, KWLErrorMsgs.msgMailSubjectPassword,
                    htmlmsg, pmsg, adminEmailId);
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    } catch (Exception e) {
        throw ServiceException.FAILURE("ProfileHandler.setPassword", e);
    }
}

From source file:com.krawler.esp.handlers.ProfileHandler.java

License:Open Source License

public static void deletecompany(Session session, HttpServletRequest request) throws ServiceException {
    try {/*  w  ww .  j a va2 s . c o m*/
        String[] ids = request.getParameterValues("cmpid");
        for (int i = 0; i < ids.length; i++) {
            Company c = (Company) session.load(Company.class, ids[i]);
            c.setDeleted(1);
            session.saveOrUpdate(c);
        }
    } catch (Exception e) {
        throw ServiceException.FAILURE("ProfileHandler.deletecompanies", e);
    }
}

From source file:com.krawler.esp.handlers.ProfileHandler.java

License:Open Source License

public static JSONObject changePassword(String platformURL, Session session, HttpServletRequest request)
        throws ServiceException {
    JSONObject jobj = new JSONObject();
    String msg = "";
    try {//  w ww.  j a  va2 s.  c  om
        String password = request.getParameter("currentpassword");
        String pwd = request.getParameter("changepassword").toString();
        String uid = AuthHandler.getUserid(request);
        String companyid = AuthHandler.getCompanyid(request);

        if (password == null || password.length() <= 0) {
            msg = MessageSourceProxy.getMessage("hrms.common.InvalidPassword", null, "Invalid Password.",
                    RequestContextUtils.getLocale(request));
        } else {
            //String newpass=AuthHandler.getSHA1(password);
            if (StringUtil.isStandAlone()) {
                platformURL = "";
            }
            if (!StringUtil.isNullOrEmpty(platformURL)) {
                JSONObject userData = new JSONObject();
                userData.put("pwd", pwd);
                userData.put("oldpwd", password);
                userData.put("userid", uid);
                userData.put("remoteapikey", StorageHandler.GetRemoteAPIKey());
                String action = "3";
                JSONObject resObj = APICallHandler.callApp(platformURL, userData, companyid, action);
                if (!resObj.isNull("success") && resObj.getBoolean("success")) {
                    User user = (User) session.load(User.class, uid);
                    UserLogin userLogin = user.getUserLogin();
                    userLogin.setPassword(pwd);
                    session.saveOrUpdate(userLogin);
                    msg = MessageSourceProxy.getMessage("hrms.common.PasswordChangedsuccessfully", null,
                            "Invalid Password.", RequestContextUtils.getLocale(request));

                } else {
                    if (!resObj.isNull("errorcode") && resObj.getString("errorcode").equals("e10")) {
                        msg = MessageSourceProxy.getMessage("hrms.common.OldpasswordisincorrectPleasetryagain",
                                null, "Invalid Password.", RequestContextUtils.getLocale(request));
                    } else {
                        msg = MessageSourceProxy.getMessage("hrms.common.ErrorinchangingPassword", null,
                                "Invalid Password.", RequestContextUtils.getLocale(request));
                    }
                }
            } else {
                User user = (User) session.load(User.class, uid);
                UserLogin userLogin = user.getUserLogin();
                String currentpass = userLogin.getPassword();
                if (StringUtil.equal(password, currentpass)) {
                    userLogin.setPassword(pwd);
                    session.saveOrUpdate(userLogin);
                    msg = MessageSourceProxy.getMessage("hrms.common.PasswordChangedsuccessfully", null,
                            "Invalid Password.", RequestContextUtils.getLocale(request));
                } else {
                    msg = MessageSourceProxy.getMessage("hrms.common.OldpasswordisincorrectPleasetryagain",
                            null, "Invalid Password.", RequestContextUtils.getLocale(request));
                }
            }
        }
        jobj.put("msg", msg);
    } catch (Exception e) {
        throw ServiceException.FAILURE("ProfileHandler.setPassword", e);
    }
    return jobj;
}