Example usage for org.apache.commons.beanutils PropertyUtils copyProperties

List of usage examples for org.apache.commons.beanutils PropertyUtils copyProperties

Introduction

In this page you can find the example usage for org.apache.commons.beanutils PropertyUtils copyProperties.

Prototype

public static void copyProperties(Object dest, Object orig)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException 

Source Link

Document

Copy property values from the "origin" bean to the "destination" bean for all cases where the property names are the same (even though the actual getter and setter methods might have been customized via BeanInfo classes).

For more details see PropertyUtilsBean.

Usage

From source file:us.mn.state.health.lims.label.action.LabelUpdateAction.java

protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    // The first job is to determine if we are coming to this action with an
    // ID parameter in the request. If there is no parameter, we are
    // creating a new Label.
    // If there is a parameter present, we should bring up an existing
    // Label to edit.

    String forward = FWD_SUCCESS;
    request.setAttribute(ALLOW_EDITS_KEY, "true");
    request.setAttribute(PREVIOUS_DISABLED, "false");
    request.setAttribute(NEXT_DISABLED, "false");

    String id = request.getParameter(ID);

    if (StringUtil.isNullorNill(id) || "0".equals(id)) {
        isNew = true;//w w w  . j  a  va2 s .  c  o  m
    } else {
        isNew = false;
    }

    BaseActionForm dynaForm = (BaseActionForm) form;

    // server-side validation (validation.xml)
    ActionMessages errors = dynaForm.validate(mapping, request);
    //AIS - bugzilla 1562 ( removed validateAll as scriptlet is now drop-down )
    if (errors != null && errors.size() > 0) {
        // System.out.println("Server side validation errors "
        // + errors.toString());
        saveErrors(request, errors);
        // since we forward to jsp - not Action we don't need to repopulate
        // the lists here
        return mapping.findForward(FWD_FAIL);
    }

    String start = (String) request.getParameter("startingRecNo");
    String direction = (String) request.getParameter("direction");

    // System.out.println("This is ID from request " + id);
    Label label = new Label();
    //get sysUserId from login module
    UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA);
    String sysUserId = String.valueOf(usd.getSystemUserId());
    label.setSysUserId(sysUserId);
    org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction();

    Scriptlet scriptlet = new Scriptlet();
    String scriptletName = (String) dynaForm.get("scriptletName");
    scriptlet.setScriptletName(scriptletName);

    ScriptletDAO scriptletDAO = new ScriptletDAOImpl();
    Scriptlet script = scriptletDAO.getScriptletByName(scriptlet);

    // populate valueholder from form
    PropertyUtils.copyProperties(label, dynaForm);

    label.setScriptlet(script);

    try {

        LabelDAO labelDAO = new LabelDAOImpl();

        if (!isNew) {
            // UPDATE

            labelDAO.updateData(label);

        } else {
            // INSERT

            labelDAO.insertData(label);
        }
        tx.commit();
    } catch (LIMSRuntimeException lre) {
        //bugzilla 2154
        LogEvent.logError("LabelUpdateAction", "performAction()", lre.toString());
        tx.rollback();
        errors = new ActionMessages();
        java.util.Locale locale = (java.util.Locale) request.getSession()
                .getAttribute("org.apache.struts.action.LOCALE");
        ActionError error = null;
        if (lre.getException() instanceof org.hibernate.StaleObjectStateException) {
            // how can I get popup instead of struts error at the top of
            // page?
            // ActionMessages errors = dynaForm.validate(mapping, request);
            error = new ActionError("errors.OptimisticLockException", null, null);

        } else {
            // bugzilla 1482
            if (lre.getException() instanceof LIMSDuplicateRecordException) {
                String messageKey = "label.labelName";
                String msg = ResourceLocator.getInstance().getMessageResources().getMessage(locale, messageKey);
                error = new ActionError("errors.DuplicateRecord", msg, null);

            } else {
                error = new ActionError("errors.UpdateException", null, null);
            }
        }

        errors.add(ActionMessages.GLOBAL_MESSAGE, error);
        saveErrors(request, errors);
        request.setAttribute(Globals.ERROR_KEY, errors);
        //bugzilla 1485: allow change and try updating again (enable save button)
        //request.setAttribute(IActionConstants.ALLOW_EDITS_KEY, "false");
        // disable previous and next
        request.setAttribute(PREVIOUS_DISABLED, "true");
        request.setAttribute(NEXT_DISABLED, "true");
        forward = FWD_FAIL;

    } finally {
        HibernateUtil.closeSession();
    }
    if (forward.equals(FWD_FAIL))
        return mapping.findForward(forward);

    // initialize the form
    dynaForm.initialize(mapping);
    // repopulate the form from valueholder
    PropertyUtils.copyProperties(dynaForm, label);

    if ("true".equalsIgnoreCase(request.getParameter("close"))) {
        forward = FWD_CLOSE;
    }

    if (label.getId() != null && !label.getId().equals("0")) {
        request.setAttribute(ID, label.getId());

    }

    //bugzilla 1400
    if (isNew)
        forward = FWD_SUCCESS_INSERT;
    //bugzilla 1467 added direction for redirect to NextPreviousAction
    return getForward(mapping.findForward(forward), id, start, direction);

}

From source file:us.mn.state.health.lims.label.daoimpl.LabelDAOImpl.java

public void getData(Label label) throws LIMSRuntimeException {
    try {/*from  ww w.  j  av a  2s  .co  m*/
        Label labl = (Label) HibernateUtil.getSession().get(Label.class, label.getId());
        HibernateUtil.getSession().flush();
        HibernateUtil.getSession().clear();
        if (labl != null) {
            PropertyUtils.copyProperties(label, labl);
        } else {
            label.setId(null);
        }
    } catch (Exception e) {
        //bugzilla 2154
        LogEvent.logError("LabelDAOImpl", "getData()", e.toString());
        throw new LIMSRuntimeException("Error in Label getData()", e);
    }
}

From source file:us.mn.state.health.lims.login.action.LoginChangePasswordUpdateAction.java

protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    String forward = FWD_SUCCESS;
    BaseActionForm dynaForm = (BaseActionForm) form;

    // server-side validation (validation.xml) //regex does not match
    // instructions and can not be varied by installation
    // delete after merge
    ActionMessages errors = new ActionMessages();
    // dynaForm.validate(mapping, request);

    /*//from w w w. ja  v a  2 s  . c  o m
     * if (errors != null && errors.size() > 0) { saveErrors(request,
     * errors); return mapping.findForward(FWD_FAIL); }
     */

    String newPassword = dynaForm.getString("newPassword");
    String confirmPassword = dynaForm.getString("confirmPassword");

    if (GenericValidator.isBlankOrNull(newPassword) || !newPassword.equals(confirmPassword)) {
        ActionError error = new ActionError("login.error.password.notmatch", null, null);
        errors.add(ActionMessages.GLOBAL_MESSAGE, error);
    } else if (!PasswordValidationFactory.getPasswordValidator().passwordValid(newPassword)) {

        ActionError error = new ActionError("login.error.message", null, null);
        errors.add(ActionMessages.GLOBAL_MESSAGE, error);
    }

    if (errors.size() > 0) {
        saveErrors(request, errors);
        return mapping.findForward(FWD_FAIL);
    }

    Login login = new Login();
    org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction();
    // populate valueholder from form
    PropertyUtils.copyProperties(login, dynaForm);
    LoginDAO loginDAO = new LoginDAOImpl();
    boolean isSuccess = false;
    try {
        // get user infomation
        Login loginInfo = loginDAO.getValidateLogin(login);
        if (loginInfo == null) {
            tx.rollback();
            errors = new ActionMessages();
            ActionError error = new ActionError("login.error.message", null, null);
            errors.add(ActionMessages.GLOBAL_MESSAGE, error);
            saveErrors(request, errors);
            return mapping.findForward(FWD_FAIL);
        } else {

            // validate account disabled
            if (loginInfo.getAccountDisabled().equals(YES)) {
                errors = new ActionMessages();
                ActionError error = new ActionError("login.error.account.disable", null, null);
                errors.add(ActionMessages.GLOBAL_MESSAGE, error);
                saveErrors(request, errors);
                return mapping.findForward(IActionConstants.FWD_FAIL);
            }
            // validate account locked
            if (loginInfo.getAccountLocked().equals(YES)) {
                errors = new ActionMessages();
                ActionError error = new ActionError("login.error.account.lock", null, null);
                errors.add(ActionMessages.GLOBAL_MESSAGE, error);
                saveErrors(request, errors);
                return mapping.findForward(FWD_FAIL);
            }
            // validate password expired day
            // bugzilla 2286
            if (loginInfo.getPasswordExpiredDayNo() <= 0) {
                errors = new ActionMessages();
                ActionError error = new ActionError("login.error.password.expired", null, null);
                errors.add(ActionMessages.GLOBAL_MESSAGE, error);
                saveErrors(request, errors);
                return mapping.findForward(FWD_FAIL);
            }
            /*
             * if ( loginInfo.getPasswordExpiredDayNo() <=
             * Integer.parseInt(SystemConfiguration
             * .getInstance().getLoginUserChangePasswordAllowDay()) ) {
             * errors = new ActionMessages(); ActionError error = new
             * ActionError("login.error.password.day",
             * SystemConfiguration.getInstance
             * ().getLoginUserChangePasswordAllowDay(), null);
             * errors.add(ActionMessages.GLOBAL_MESSAGE, error);
             * saveErrors(request, errors); return
             * mapping.findForward(FWD_FAIL); }
             */
            // validate user id exists in system_user table
            if (loginInfo.getSystemUserId() == 0) {
                errors = new ActionMessages();
                ActionError error = new ActionError("login.error.system.user.id", loginInfo.getLoginName(),
                        null);
                errors.add(ActionMessages.GLOBAL_MESSAGE, error);
                saveErrors(request, errors);
                return mapping.findForward(FWD_FAIL);
            }

            // validate and update password
            loginInfo.setPassword(login.getNewPassword());

            java.util.Calendar rightNow = java.util.Calendar.getInstance();
            rightNow.add(java.util.Calendar.MONTH, Integer
                    .parseInt(SystemConfiguration.getInstance().getLoginUserChangePasswordExpiredMonth()));
            loginInfo.setPasswordExpiredDate(new java.sql.Date(rightNow.getTimeInMillis()));

            loginInfo.setSysUserId(String.valueOf(loginInfo.getSystemUserId())); //there is no loggedin user when you reset your password
            isSuccess = loginDAO.updatePassword(loginInfo);
            if (isSuccess) {
                tx.commit();
                // successfully changed password
                // force user to relogin with the new password
                errors = new ActionMessages();
                ActionError error = new ActionError("login.success.changePass.message", null, null);
                errors.add(ActionMessages.GLOBAL_MESSAGE, error);
                saveErrors(request, errors);
            } else {
                tx.rollback();
                errors = new ActionMessages();
                ActionError error = new ActionError("login.error.password.requirement", null, null);
                errors.add(ActionMessages.GLOBAL_MESSAGE, error);
                saveErrors(request, errors);
                forward = FWD_FAIL;
            }
        }

    } catch (LIMSRuntimeException lre) {
        // bugzilla 2154
        LogEvent.logError("LoginChangePasswordUpdateAction", "performAction()", lre.toString());
        tx.rollback();
        errors = new ActionMessages();
        ActionError error = new ActionError("login.error.message", null, null);
        errors.add(ActionMessages.GLOBAL_MESSAGE, error);
        saveErrors(request, errors);
        return mapping.findForward(FWD_FAIL);
    } finally {
        HibernateUtil.closeSession();
    }

    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.login.action.LoginUserAction.java

protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    String id = request.getParameter(ID);

    String forward = FWD_SUCCESS;
    request.setAttribute(ALLOW_EDITS_KEY, "true");
    request.setAttribute(PREVIOUS_DISABLED, "true");
    request.setAttribute(NEXT_DISABLED, "true");

    DynaActionForm dynaForm = (DynaActionForm) form;

    // initialize the form
    dynaForm.initialize(mapping);/*  w w w.  ja  v  a 2  s.  co  m*/

    //bugzilla 2314
    Date today = Calendar.getInstance().getTime();
    Locale locale = (Locale) request.getSession().getAttribute("org.apache.struts.action.LOCALE");
    String dateAsText = DateUtil.formatDateAsText(today, locale);
    PropertyUtils.setProperty(form, "currentDate", dateAsText);

    Login login = new Login();
    if ((id != null) && (!"0".equals(id))) {
        login.setId(id);
        LoginDAO loginDAO = new LoginDAOImpl();
        loginDAO.getData(login);

        isNew = false;

        List logins = loginDAO.getNextLoginUserRecord(login.getId());
        if (logins.size() > 0) {
            // enable next button
            request.setAttribute(NEXT_DISABLED, "false");
        }
        logins = loginDAO.getPreviousLoginUserRecord(login.getId());
        if (logins.size() > 0) {
            // enable next button
            request.setAttribute(PREVIOUS_DISABLED, "false");
        }
        // end of logic to enable next or previous button

    } else {
        //java.util.Date today = java.util.Calendar.getInstance().getTime();
        login.setPasswordExpiredDateForDisplay(dateAsText);
        isNew = true; // this is to set correct page title
    }

    if (login.getId() != null && !login.getId().equals("0")) {
        request.setAttribute(ID, login.getId());
    }

    // populate form from valueholder            
    PropertyUtils.copyProperties(form, login);

    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.login.action.LoginUserUpdateAction.java

protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    String forward = FWD_SUCCESS;
    request.setAttribute(IActionConstants.ALLOW_EDITS_KEY, "true");
    request.setAttribute(PREVIOUS_DISABLED, "false");
    request.setAttribute(NEXT_DISABLED, "false");

    String id = request.getParameter("ID");

    //get sysUserId from login module
    UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA);
    String sysUserId = String.valueOf(usd.getSystemUserId());

    if (StringUtil.isNullorNill(id) || "0".equals(id)) {
        isNew = true;//  w w  w .java  2  s .  co m
    } else {
        isNew = false;
    }

    BaseActionForm dynaForm = (BaseActionForm) form;

    // server-side validation (validation.xml)
    ActionMessages errors = dynaForm.validate(mapping, request);
    if (errors != null && errors.size() > 0) {
        saveErrors(request, errors);
        // since we forward to jsp - not Action we don't need to repopulate
        // the lists here
        return mapping.findForward(FWD_FAIL);
    }

    String start = (String) request.getParameter("startingRecNo");
    String direction = (String) request.getParameter("direction");

    Login login = new Login();
    login.setSysUserId(sysUserId);
    org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction();

    // populate valueholder from form
    PropertyUtils.copyProperties(login, dynaForm);

    try {
        LoginDAO loginDAO = new LoginDAOImpl();

        if (!isNew) {
            // UPDATE
            loginDAO.updateData(login);
        } else {
            // INSERT
            loginDAO.insertData(login);
        }
        tx.commit();
    } catch (LIMSRuntimeException lre) {
        //bugzilla 2154
        LogEvent.logError("LoginUserUpdateAction", "performAction()", lre.toString());
        tx.rollback();
        errors = new ActionMessages();
        java.util.Locale locale = (java.util.Locale) request.getSession()
                .getAttribute("org.apache.struts.action.LOCALE");
        ActionError error = null;
        if (lre.getException() instanceof org.hibernate.StaleObjectStateException) {
            error = new ActionError("errors.OptimisticLockException", null, null);
        } else {
            if (lre.getException() instanceof LIMSDuplicateRecordException) {
                String messageKey = "systemmodule.name";
                String msg = ResourceLocator.getInstance().getMessageResources().getMessage(locale, messageKey);
                error = new ActionError("errors.DuplicateRecord", msg, null);

            } else {
                error = new ActionError("errors.UpdateException", null, null);
            }
        }
        errors.add(ActionMessages.GLOBAL_MESSAGE, error);
        saveErrors(request, errors);
        request.setAttribute(Globals.ERROR_KEY, errors);
        request.setAttribute(PREVIOUS_DISABLED, "true");
        request.setAttribute(NEXT_DISABLED, "true");
        forward = FWD_FAIL;

    } finally {
        HibernateUtil.closeSession();
    }
    if (forward.equals(FWD_FAIL))
        return mapping.findForward(forward);

    // initialize the form
    dynaForm.initialize(mapping);
    // repopulate the form from valueholder
    PropertyUtils.copyProperties(dynaForm, login);

    if ("true".equalsIgnoreCase(request.getParameter("close"))) {
        forward = FWD_CLOSE;
    }

    if (login.getId() != null && !login.getId().equals("0")) {
        request.setAttribute("ID", login.getId());

    }

    if (isNew)
        forward = FWD_SUCCESS_INSERT;
    return getForward(mapping.findForward(forward), id, start, direction);

}

From source file:us.mn.state.health.lims.login.action.LoginValidateAction.java

protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    String forward = FWD_SUCCESS;
    BaseActionForm dynaForm = (BaseActionForm) form;

    // server-side validation (validation.xml)
    ActionMessages errors = dynaForm.validate(mapping, request);
    if (errors != null && errors.size() > 0) {
        saveErrors(request, errors);/*from   w  w  w  .  j a  va  2  s  . co m*/
        return mapping.findForward(FWD_FAIL);
    }

    Login login = new Login();
    PropertyUtils.copyProperties(login, dynaForm);
    login.setLoginName(login.getLoginName().trim());

    org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction();
    LoginDAO loginDAO = new LoginDAOImpl();
    Login userInfo = loginDAO.getUserProfile(login.getLoginName());
    Login loginInfo = loginDAO.getValidateLogin(login);
    HibernateUtil.closeSession();

    //if invalid loginName entered
    if (userInfo == null) {
        HibernateUtil.closeSession();
        errors = new ActionMessages();
        ActionError error = new ActionError("login.error.message", null, null);
        errors.add(ActionMessages.GLOBAL_MESSAGE, error);
        saveErrors(request, errors);
        return mapping.findForward(FWD_FAIL);
    } else {

        //if valid loginName entered then continue to check
        if (userInfo.getAccountDisabled().equalsIgnoreCase(YES)) {
            errors = new ActionMessages();
            ActionError error = new ActionError("login.error.account.disable", null, null);
            errors.add(ActionMessages.GLOBAL_MESSAGE, error);
            saveErrors(request, errors);
            return mapping.findForward(FWD_FAIL);
        }
        if (userInfo.getAccountLocked().equalsIgnoreCase(YES)) {
            errors = new ActionMessages();
            //ActionError error = new ActionError("login.error.account.lock", null, null);
            //errors.add(ActionMessages.GLOBAL_MESSAGE, error);
            //saveErrors(request, errors);
            //return mapping.findForward(FWD_FAIL);             
            if (request.getSession().getAttribute(ACCOUNT_LOCK_TIME) != null) {
                lockUnlockUserAccount(errors, request, userInfo);
            } else {
                ActionError error = new ActionError("login.error.account.lock", null, null);
                errors.add(ActionMessages.GLOBAL_MESSAGE, error);
                saveErrors(request, errors);
            }
            return mapping.findForward(FWD_FAIL);
        }
        if (userInfo.getPasswordExpiredDayNo() <= 0) {
            errors = new ActionMessages();
            ActionError error = new ActionError("login.error.password.expired", null, null);
            errors.add(ActionMessages.GLOBAL_MESSAGE, error);
            saveErrors(request, errors);
            return mapping.findForward(FWD_FAIL);
        }

        //verify loginName and password
        loginInfo = loginDAO.getValidateLogin(login);
        if (loginInfo == null) {
            int loginUserFailAttemptCount = 0;
            int loginUserFailAttemptCountDefault = Integer
                    .parseInt(SystemConfiguration.getInstance().getLoginUserFailAttemptCount());
            if (request.getSession().getAttribute(LOGIN_FAILED_CNT) != null) {
                loginUserFailAttemptCount = Integer
                        .parseInt((String) request.getSession().getAttribute(LOGIN_FAILED_CNT));
            }
            loginUserFailAttemptCount++;
            request.getSession().setAttribute(LOGIN_FAILED_CNT, String.valueOf(loginUserFailAttemptCount));

            //lock account after number of failed attempts
            if (loginUserFailAttemptCount == loginUserFailAttemptCountDefault) {
                tx = HibernateUtil.getSession().beginTransaction();
                login = loginDAO.getUserProfile(login.getLoginName());
                login.setAccountLocked(YES);
                loginDAO.lockAccount(login);
                tx.commit();
                HibernateUtil.closeSession();
                errors = new ActionMessages();

                ActionError error = new ActionError("login.error.account.lock", null);
                errors.add(ActionMessages.GLOBAL_MESSAGE, error);
                saveErrors(request, errors);

                lockUnlockUserAccount(errors, request, userInfo);
                request.getSession().removeAttribute(LOGIN_FAILED_CNT);
                return mapping.findForward(FWD_FAIL);
            }

            errors = new ActionMessages();
            ActionError error = new ActionError("login.error.attempt.message",
                    String.valueOf(loginUserFailAttemptCount), String.valueOf(loginUserFailAttemptCountDefault),
                    SystemConfiguration.getInstance().getLoginUserAccountUnlockMinute(), null);
            errors.add(ActionMessages.GLOBAL_MESSAGE, error);
            saveErrors(request, errors);
            return mapping.findForward(FWD_FAIL);
        } else {
            if ((loginInfo.getPasswordExpiredDayNo() <= Integer
                    .parseInt(SystemConfiguration.getInstance().getLoginUserPasswordExpiredReminderDay()))
                    && (loginInfo.getPasswordExpiredDayNo() > Integer.parseInt(
                            SystemConfiguration.getInstance().getLoginUserChangePasswordAllowDay()))) {
                errors = new ActionMessages();
                ActionError error = new ActionError("login.password.expired.reminder",
                        loginInfo.getPasswordExpiredDayNo(), null);
                errors.add(ActionMessages.GLOBAL_MESSAGE, error);
                saveErrors(request, errors);
            } else if ((loginInfo.getPasswordExpiredDayNo() <= Integer
                    .parseInt(SystemConfiguration.getInstance().getLoginUserChangePasswordAllowDay()))
                    && (loginInfo.getPasswordExpiredDayNo() > 0)) {
                errors = new ActionMessages();
                ActionError error = new ActionError("login.password.expired.force.notice",
                        loginInfo.getPasswordExpiredDayNo(), loginInfo.getPasswordExpiredDayNo(), null);
                errors.add(ActionMessages.GLOBAL_MESSAGE, error);
                saveErrors(request, errors);
                return mapping.findForward(FWD_CHANGE_PASS);
            }
            if (loginInfo.getSystemUserId() == 0) {
                errors = new ActionMessages();
                ActionError error = new ActionError("login.error.system.user.id", loginInfo.getLoginName(),
                        null);
                errors.add(ActionMessages.GLOBAL_MESSAGE, error);
                saveErrors(request, errors);
                return mapping.findForward(FWD_FAIL);
            } else {
                SystemUserDAO systemUserDAO = new SystemUserDAOImpl();
                SystemUser su = new SystemUser();
                su.setId(String.valueOf(loginInfo.getSystemUserId()));
                systemUserDAO.getData(su);

                //setup the user timeout in seconds
                int timeOut = Integer.parseInt((String) loginInfo.getUserTimeOut());
                request.getSession().setMaxInactiveInterval(timeOut * 60);

                UserSessionData usd = new UserSessionData();
                usd.setSytemUserId(loginInfo.getSystemUserId());
                usd.setLoginName(loginInfo.getLoginName());
                usd.setElisUserName(su.getNameForDisplay());
                usd.setUserTimeOut(timeOut * 60);
                request.getSession().setAttribute(USER_SESSION_DATA, usd);

                boolean showAdminMenu = loginInfo.getIsAdmin().equalsIgnoreCase(YES);

                if (SystemConfiguration.getInstance().getPermissionAgent().equals("ROLE")) {
                    HashSet<String> permittedPages = getPermittedForms(usd.getSystemUserId());
                    request.getSession().setAttribute(IActionConstants.PERMITTED_ACTIONS_MAP, permittedPages);
                    showAdminMenu |= permittedPages.contains("MasterList");
                }

            }

            //cleanup session
            if (request.getSession().getAttribute(LOGIN_FAILED_CNT) != null)
                request.getSession().removeAttribute(LOGIN_FAILED_CNT);
            if (request.getSession().getAttribute(ACCOUNT_LOCK_TIME) != null)
                request.getSession().removeAttribute(ACCOUNT_LOCK_TIME);

            if (loginInfo.getIsAdmin().equalsIgnoreCase(YES))
                //bugzilla 2154
                LogEvent.logInfo("LoginValidateAction", "performAction()", "======> USER TYPE: ADMIN");
            else {
                //bugzilla 2154
                LogEvent.logInfo("LoginValidateAction", "performAction()", "======> USER TYPE: NON-ADMIN");
                //bugzilla 2160
                UserModuleDAO userModuleDAO = new UserModuleDAOImpl();
                if (!userModuleDAO.isUserModuleFound(request)) {
                    errors = new ActionMessages();
                    ActionError error = new ActionError("login.error.no.module", null, null);
                    errors.add(ActionMessages.GLOBAL_MESSAGE, error);
                    saveErrors(request, errors);
                    return mapping.findForward(FWD_FAIL);
                }
            }
        }
    }
    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.login.daoimpl.LoginDAOImpl.java

public void getData(Login login) throws LIMSRuntimeException {
    try {//w  w w .  j a  v a2  s  .co m
        Login l = (Login) HibernateUtil.getSession().get(Login.class, login.getId());
        HibernateUtil.getSession().flush();
        HibernateUtil.getSession().clear();
        if (l != null) {
            Crypto crypto = new Crypto();
            l.setPassword(crypto.getDecrypt(l.getPassword()));
            PropertyUtils.copyProperties(login, l);
        } else {
            login.setId(null);
        }
    } catch (Exception e) {
        // bugzilla 2154
        LogEvent.logError("LoginDAOImpl", "getData()", e.toString());
        throw new LIMSRuntimeException("Error in Login getData()", e);
    }
}

From source file:us.mn.state.health.lims.messageorganization.action.MessageOrganizationAction.java

protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    // The first job is to determine if we are coming to this action with an
    // ID parameter in the request. If there is no parameter, we are
    // creating a new MessageOrganization.
    // If there is a parameter present, we should bring up an existing
    // MessageOrganization to edit.
    String id = request.getParameter(ID);

    String forward = FWD_SUCCESS;
    request.setAttribute(ALLOW_EDITS_KEY, "true");
    request.setAttribute(PREVIOUS_DISABLED, "true");
    request.setAttribute(NEXT_DISABLED, "true");

    DynaActionForm dynaForm = (DynaActionForm) form;

    // initialize the form
    dynaForm.initialize(mapping);/*from   ww w .ja v  a 2s  . c o m*/

    MessageOrganization messageOrganization = new MessageOrganization();

    if ((id != null) && (!"0".equals(id))) { // this is an existing
        // messageOrganization

        messageOrganization.setId(id);
        MessageOrganizationDAO messageOrganizationDAO = new MessageOrganizationDAOImpl();
        messageOrganizationDAO.getData(messageOrganization);
        // initialize selectedPanelItemId
        if (messageOrganization.getOrganization() != null) {
            messageOrganization.setSelectedOrganizationId(messageOrganization.getOrganization().getId());
        }

        isNew = false; // this is to set correct page title

        // do we need to enable next or previous?
        // bugzilla 1427 pass in name not id
        List messageOrganizations = messageOrganizationDAO
                .getNextMessageOrganizationRecord(messageOrganization.getId());
        if (messageOrganizations.size() > 0) {
            // enable next button
            request.setAttribute(NEXT_DISABLED, "false");
        }
        // bugzilla 1427 pass in name not id
        messageOrganizations = messageOrganizationDAO
                .getPreviousMessageOrganizationRecord(messageOrganization.getId());
        if (messageOrganizations.size() > 0) {
            // enable next button
            request.setAttribute(PREVIOUS_DISABLED, "false");
        }
        // end of logic to enable next or previous button
    } else { // this is a new messageOrganization
        // default started date to today's date
        Date today = Calendar.getInstance().getTime();
        Locale locale = (Locale) request.getSession().getAttribute("org.apache.struts.action.LOCALE");

        String dateAsText = DateUtil.formatDateAsText(today, locale);
        messageOrganization.setActiveBeginDateForDisplay(dateAsText);

        // default isActive to 'Y'
        messageOrganization.setIsActive(YES);
        isNew = true; // this is to set correct page title
    }

    if (messageOrganization.getId() != null && !messageOrganization.getId().equals("0")) {
        request.setAttribute(ID, messageOrganization.getId());
    }

    // populate form from valueholder
    PropertyUtils.copyProperties(form, messageOrganization);

    OrganizationDAO organizationDAO = new OrganizationDAOImpl();
    // org.setId(messageOrganization.getSelectedOrganizationId());
    // organizationDAO.getData(org);
    String organizationName = null;
    if (!StringUtil.isNullorNill(messageOrganization.getSelectedOrganizationId())) {
        Organization organization = new Organization();
        organization.setId(messageOrganization.getSelectedOrganizationId());
        organizationDAO.getData(organization);
        organizationName = organization.getOrganizationName();
    }

    PropertyUtils.setProperty(form, "organizationName", organizationName);

    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.messageorganization.action.MessageOrganizationUpdateAction.java

protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    // The first job is to determine if we are coming to this action with an
    // ID parameter in the request. If there is no parameter, we are
    // creating a new MessageOrganization.
    // If there is a parameter present, we should bring up an existing
    // MessageOrganization to edit.

    String forward = FWD_SUCCESS;
    request.setAttribute(ALLOW_EDITS_KEY, "true");
    request.setAttribute(PREVIOUS_DISABLED, "false");
    request.setAttribute(NEXT_DISABLED, "false");

    String id = request.getParameter(ID);

    if (StringUtil.isNullorNill(id) || "0".equals(id)) {
        isNew = true;/*www .ja v a  2  s.com*/
    } else {
        isNew = false;
    }

    BaseActionForm dynaForm = (BaseActionForm) form;

    // server-side validation (validation.xml)
    ActionMessages errors = dynaForm.validate(mapping, request);

    //bugzilla 1923 validateAll was not being executed
    if (errors == null || errors.size() == 0) {
        try {
            errors = validateAll(request, errors, dynaForm);
        } catch (Exception e) {
            //bugzilla 2154
            LogEvent.logError("MessageOrganizationUpdateAction", "performAction()", e.toString());
            ActionError error = new ActionError("errors.ValidationException", null, null);
            errors.add(ActionMessages.GLOBAL_MESSAGE, error);
        }
    }

    if (errors != null && errors.size() > 0) {
        // System.out.println("Server side validation errors "
        // + errors.toString());
        saveErrors(request, errors);
        // since we forward to jsp - not Action we don't need to repopulate
        // the lists here
        return mapping.findForward(FWD_FAIL);
    }

    String start = (String) request.getParameter("startingRecNo");
    String direction = (String) request.getParameter("direction");

    // System.out.println("This is ID from request " + id);
    MessageOrganization messageOrganization = new MessageOrganization();
    // get sysUserId from login module
    UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA);
    String sysUserId = String.valueOf(usd.getSystemUserId());
    messageOrganization.setSysUserId(sysUserId);
    org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction();

    // populate valueholder from form
    PropertyUtils.copyProperties(messageOrganization, dynaForm);

    // get org valueholder to be set in messageOrganization
    OrganizationDAO organizationDAO = new OrganizationDAOImpl();
    Organization organization = new Organization();
    organization.setOrganizationName(messageOrganization.getOrganizationName());
    organization = organizationDAO.getOrganizationByName(organization, true);
    organizationDAO.getData(organization);
    messageOrganization.setOrganization(organization);

    try {

        MessageOrganizationDAO messageOrganizationDAO = new MessageOrganizationDAOImpl();

        if (!isNew) {
            // UPDATE

            messageOrganizationDAO.updateData(messageOrganization);

        } else {
            // INSERT

            messageOrganizationDAO.insertData(messageOrganization);
        }
        tx.commit();
    } catch (LIMSRuntimeException lre) {
        //bugzilla 2154
        LogEvent.logError("MessageOrganizationUpdateAction", "performAction()", lre.toString());
        tx.rollback();
        errors = new ActionMessages();
        java.util.Locale locale = (java.util.Locale) request.getSession()
                .getAttribute("org.apache.struts.action.LOCALE");
        ActionError error = null;
        if (lre.getException() instanceof org.hibernate.StaleObjectStateException) {
            // how can I get popup instead of struts error at the top of
            // page?
            // ActionMessages errors = dynaForm.validate(mapping, request);
            error = new ActionError("errors.OptimisticLockException", null, null);

        } else {
            // bugzilla 1482
            if (lre.getException() instanceof LIMSDuplicateRecordException) {
                String messageKey = "messageorganization.organization";
                String msg = ResourceLocator.getInstance().getMessageResources().getMessage(locale, messageKey);
                error = new ActionError("errors.DuplicateRecord", msg, null);

            } else {
                error = new ActionError("errors.UpdateException", null, null);
            }
        }

        errors.add(ActionMessages.GLOBAL_MESSAGE, error);
        saveErrors(request, errors);
        request.setAttribute(Globals.ERROR_KEY, errors);
        // bugzilla 1485: allow change and try updating again (enable save
        // button)
        // request.setAttribute(IActionConstants.ALLOW_EDITS_KEY, "false");
        // disable previous and next
        request.setAttribute(PREVIOUS_DISABLED, "true");
        request.setAttribute(NEXT_DISABLED, "true");
        forward = FWD_FAIL;

    } finally {
        HibernateUtil.closeSession();
    }
    if (forward.equals(FWD_FAIL))
        return mapping.findForward(forward);

    // initialize the form
    dynaForm.initialize(mapping);
    // repopulate the form from valueholder
    PropertyUtils.copyProperties(dynaForm, messageOrganization);

    if ("true".equalsIgnoreCase(request.getParameter("close"))) {
        forward = FWD_CLOSE;
    }

    if (messageOrganization.getId() != null && !messageOrganization.getId().equals("0")) {
        request.setAttribute(ID, messageOrganization.getId());

    }

    // bugzilla 1400
    if (isNew)
        forward = FWD_SUCCESS_INSERT;
    // bugzilla 1467 added direction for redirect to NextPreviousAction
    return getForward(mapping.findForward(forward), id, start, direction);

}

From source file:us.mn.state.health.lims.messageorganization.daoimpl.MessageOrganizationDAOImpl.java

public void getData(MessageOrganization messageOrganization) throws LIMSRuntimeException {
    try {/*www . ja  va  2 s . c om*/
        MessageOrganization pan = (MessageOrganization) HibernateUtil.getSession()
                .get(MessageOrganization.class, messageOrganization.getId());
        HibernateUtil.getSession().flush();
        HibernateUtil.getSession().clear();
        if (pan != null) {
            PropertyUtils.copyProperties(messageOrganization, pan);
        } else {
            messageOrganization.setId(null);
        }
    } catch (Exception e) {
        //bugzilla 2154
        LogEvent.logError("MessageOrganizationDAOImpl", "getData()", e.toString());
        throw new LIMSRuntimeException("Error in MessageOrganization getData()", e);
    }

}