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.patientrelation.daoimpl.PatientRelationDAOImpl.java

public void getData(PatientRelation patientRelation) throws LIMSRuntimeException {
    try {//  w w w .  j  av a2 s. co  m
        PatientRelation pat = (PatientRelation) HibernateUtil.getSession().get(PatientRelation.class,
                patientRelation.getId());
        HibernateUtil.getSession().flush();
        HibernateUtil.getSession().clear();
        if (pat != null) {
            PropertyUtils.copyProperties(patientRelation, pat);
        } else {
            patientRelation.setId(null);
        }
    } catch (Exception e) {
        LogEvent.logError("PatientRelationDAOImpl", "getData()", e.toString());
        throw new LIMSRuntimeException("Error in PatientRelation getData()", e);
    }
}

From source file:us.mn.state.health.lims.person.action.PersonAction.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 Person.
    // If there is a parameter present, we should bring up an existing
    // Person to edit.

    String id = request.getParameter(ID);

    String forward = "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 w w  w.  j  av a2 s.co m*/

    Person person = new Person();

    String hPhoneForDisplay = "";
    String wPhoneForDisplay = "";
    String cPhoneForDisplay = "";
    String faxForDisplay = "";

    String wPhoneExtForDisplay = "";

    //System.out.println("I am in PersonAction and this is id " + id);
    if ((id != null) && (!"0".equals(id))) { // this is an existing
        // person

        person.setId(id);
        PersonDAO personDAO = new PersonDAOImpl();
        personDAO.getData(person);

        // format phone numbers for display
        String wPhone = person.getWorkPhone();
        wPhoneForDisplay = StringUtil.formatPhoneForDisplay(wPhone);
        wPhoneExtForDisplay = StringUtil.formatExtensionForDisplay(wPhone);

        String hPhone = person.getHomePhone();
        hPhoneForDisplay = StringUtil.formatPhoneForDisplay(hPhone);

        String cPhone = person.getCellPhone();
        cPhoneForDisplay = StringUtil.formatPhoneForDisplay(cPhone);

        String fax = person.getFax();
        faxForDisplay = StringUtil.formatPhoneForDisplay(fax);

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

        // do we need to enable next or previous?
        List persons = personDAO.getNextPersonRecord(person.getId());
        if (persons.size() > 0) {
            // enable next button
            request.setAttribute(NEXT_DISABLED, "false");
        }
        persons = personDAO.getPreviousPersonRecord(person.getId());
        if (persons.size() > 0) {
            // enable next button
            request.setAttribute(PREVIOUS_DISABLED, "false");
        }
        // end of logic to enable next or previous button
    } else { // this is a new person

        isNew = true; // this is to set correct page title
    }

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

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

    PropertyUtils.setProperty(dynaForm, "homePhone", hPhoneForDisplay);
    PropertyUtils.setProperty(dynaForm, "workPhone", wPhoneForDisplay);
    PropertyUtils.setProperty(dynaForm, "cellPhone", cPhoneForDisplay);
    PropertyUtils.setProperty(dynaForm, "fax", faxForDisplay);

    PropertyUtils.setProperty(dynaForm, "workPhoneExtension", wPhoneExtForDisplay);

    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.person.action.PersonUpdateAction.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 Person.
    // If there is a parameter present, we should bring up an existing
    // Person 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;/*from   w ww.j  a v a  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");

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

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

    // format workPhone and homePhone for storage
    String workPhone = (String) dynaForm.get("workPhone");
    String ext = (String) dynaForm.get("workPhoneExtension");
    String formattedPhone = StringUtil.formatPhone(workPhone, ext);
    // phone is stored as 999/999-9999.9999
    // area code/phone - number.extension
    person.setWorkPhone(formattedPhone);

    String homePhone = (String) dynaForm.get("homePhone");
    ext = "";
    formattedPhone = StringUtil.formatPhone(homePhone, ext);
    // phone is stored as 999/999-9999.9999
    // area code/phone - number.extension
    person.setHomePhone(formattedPhone);

    String cellPhone = (String) dynaForm.get("cellPhone");
    ext = "";
    formattedPhone = StringUtil.formatPhone(cellPhone, ext);
    // phone is stored as 999/999-9999.9999
    // area code/phone - number.extension
    person.setCellPhone(formattedPhone);

    String fax = (String) dynaForm.get("fax");
    ext = "";
    formattedPhone = StringUtil.formatPhone(fax, ext);
    // phone is stored as 999/999-9999.9999
    // area code/phone - number.extension
    person.setFax(formattedPhone);

    try {

        PersonDAO personDAO = new PersonDAOImpl();

        if (!isNew) {
            // UPDATE

            personDAO.updateData(person);
            if (FWD_NEXT.equals(direction)) {
                List persons = personDAO.getNextPersonRecord(person.getId());
                if (persons != null && persons.size() > 0) {
                    person = (Person) persons.get(0);
                    personDAO.getData(person);
                    if (persons.size() < 2) {
                        // disable next button
                        request.setAttribute(NEXT_DISABLED, "true");
                    }
                    id = person.getId();
                } else {
                    // disable next button
                    request.setAttribute(NEXT_DISABLED, "true");
                }
                forward = FWD_NEXT;
            }

            if (FWD_PREVIOUS.equals(direction)) {
                List persons = personDAO.getPreviousPersonRecord(person.getId());
                if (persons != null && persons.size() > 0) {
                    person = (Person) persons.get(0);
                    personDAO.getData(person);
                    if (persons.size() < 2) {
                        // disable previous button
                        request.setAttribute(PREVIOUS_DISABLED, "true");
                    }
                    id = person.getId();
                } else {
                    // disable previous button
                    request.setAttribute(PREVIOUS_DISABLED, "true");
                }
                forward = FWD_PREVIOUS;
            }
        } else {
            // INSERT

            personDAO.insertData(person);
        }
        tx.commit();
    } catch (LIMSRuntimeException lre) {
        //bugzilla 2154
        LogEvent.logError("PersonUpdateAction", "performAction()", lre.toString());
        tx.rollback();
        errors = new ActionMessages();
        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 {
            error = new ActionError("errors.UpdateException", null, null);
        }
        errors.add(ActionMessages.GLOBAL_MESSAGE, error);
        saveErrors(request, errors);
        request.setAttribute(Globals.ERROR_KEY, errors);
        request.setAttribute(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, person);

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

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

    }

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

}

From source file:us.mn.state.health.lims.person.daoimpl.PersonDAOImpl.java

public void getData(Person person) throws LIMSRuntimeException {
    try {//from   w w  w . j  a  va 2 s .co m
        Person pers = (Person) HibernateUtil.getSession().get(Person.class, person.getId());
        HibernateUtil.getSession().flush();
        HibernateUtil.getSession().clear();
        if (pers != null) {
            PropertyUtils.copyProperties(person, pers);
        } else {
            person.setId(null);
        }

    } catch (Exception e) {
        //bugzilla 2154
        LogEvent.logError("PersonDAOImpl", "getData()", e.toString());
        throw new LIMSRuntimeException("Error in Person getData()", e);
    }
}

From source file:us.mn.state.health.lims.program.action.ProgramAction.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 Program.
    // If there is a parameter present, we should bring up an existing
    // Program 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 www. java 2s  .  com*/

    Program program = new Program();

    //System.out.println("I am in ProgramAction and this is id " + id);
    if ((id != null) && (!"0".equals(id))) { // this is an existing
        // program

        program.setId(id);
        ProgramDAO programDAO = new ProgramDAOImpl();
        programDAO.getData(program);
        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 programs = programDAO.getNextProgramRecord(program.getProgramName());
        if (programs.size() > 0) {
            // enable next button
            request.setAttribute(NEXT_DISABLED, "false");
        }
        //bugzilla 1427 pass in name not id
        programs = programDAO.getPreviousProgramRecord(program.getProgramName());
        if (programs.size() > 0) {
            // enable next button
            request.setAttribute(PREVIOUS_DISABLED, "false");
        }
        // end of logic to enable next or previous button
    } else { // this is a new program
        isNew = true; // this is to set correct page title
    }

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

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

    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.program.action.ProgramUpdateAction.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 Program.
    // If there is a parameter present, we should bring up an existing
    // Program 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;//from  w w  w . ja v  a  2 s  .c om
    } 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");

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

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

    try {

        ProgramDAO programDAO = new ProgramDAOImpl();

        if (!isNew) {
            // UPDATE

            programDAO.updateData(program);
        } else {
            // INSERT

            programDAO.insertData(program);
        }
        tx.commit();
    } catch (LIMSRuntimeException lre) {
        //bugzilla 2154
        LogEvent.logError("ProgramUpdateAction", "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 = "program.program";
                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, program);

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

    if (program.getId() != null && !program.getId().equals("0")) {
        request.setAttribute(ID, program.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.program.daoimpl.ProgramDAOImpl.java

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

From source file:us.mn.state.health.lims.project.action.ProjectAction.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 Project.
    // If there is a parameter present, we should bring up an existing
    // Project 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);/* w  w  w  .  j  a  va  2 s .  c  o  m*/

    Project project = new Project();
    //System.out.println("I am in ProjectAction and this is id " + id);
    if ((id != null) && (!"0".equals(id))) { // this is an existing
        // project

        project.setId(id);
        ProjectDAO projectDAO = new ProjectDAOImpl();
        projectDAO.getData(project);

        // initialize sysUserId
        if (project.getSystemUser() != null) {
            project.setSysUserId(project.getSystemUser().getId());
        }
        // initialize scriptlet
        if (project.getScriptlet() != null) {
            project.setScriptletName(project.getScriptlet().getScriptletName());
        }

        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 projects = projectDAO.getNextProjectRecord(project.getProjectName());
        if (projects.size() > 0) {
            // enable next button
            request.setAttribute(NEXT_DISABLED, "false");
        }
        //bugzilla 1427 pass in name not id
        projects = projectDAO.getPreviousProjectRecord(project.getProjectName());
        if (projects.size() > 0) {
            // enable next button
            request.setAttribute(PREVIOUS_DISABLED, "false");
        }
        // end of logic to enable next or previous button

    } else { // this is a new project
        // 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);

        project.setStartedDateForDisplay(dateAsText);

        // default isActive to 'Y'
        project.setIsActive("Y");

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

    }

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

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

    ProgramDAO programDAO = new ProgramDAOImpl();
    SystemUserDAO sysUserDAO = new SystemUserDAOImpl();

    List programs = programDAO.getAllPrograms();
    List sysUsers = sysUserDAO.getAllSystemUsers();

    PropertyUtils.setProperty(form, "programs", programs);
    PropertyUtils.setProperty(form, "sysUsers", sysUsers);

    //System.out.println("I am in ProjectAction this is forward " + forward);
    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.project.action.ProjectUpdateAction.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 Project.
    // If there is a parameter present, we should bring up an existing
    // Project 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;/*from  w w  w. java 2s.com*/
    } else {
        isNew = false;
    }

    BaseActionForm dynaForm = (BaseActionForm) form;

    // server-side validation (validation.xml)
    ActionMessages errors = dynaForm.validate(mapping, request);
    try {
        errors = validateAll(request, errors, dynaForm);
    } catch (Exception e) {
        //bugzilla 2154
        LogEvent.logError("ProjectUpdateAction", "performAction()", e.toString());
        ActionError error = new ActionError("errors.ValidationException", null, null);
        errors.add(ActionMessages.GLOBAL_MESSAGE, error);
    }

    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);
    }

    List sysUsers = new ArrayList();
    List programs = new ArrayList();
    org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction();

    if (dynaForm.get("sysUsers") != null) {
        sysUsers = (List) dynaForm.get("sysUsers");
    } else {
        SystemUserDAO sysUserDAO = new SystemUserDAOImpl();
        sysUsers = sysUserDAO.getAllSystemUsers();
    }
    if (dynaForm.get("programs") != null) {
        programs = (List) dynaForm.get("programs");
    } else {
        ProgramDAO programDAO = new ProgramDAOImpl();
        programs = programDAO.getAllPrograms();
    }

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

    String sysUserId = (String) dynaForm.get("sysUserId");

    SystemUser sysUser = null;

    for (int i = 0; i < sysUsers.size(); i++) {
        SystemUser su = (SystemUser) sysUsers.get(i);
        if (su.getId().equals(sysUserId)) {
            sysUser = su;
            break;
        }
    }

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

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

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

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

    project.setSystemUser(sysUser);
    project.setScriptlet(scr);
    // there is no specification for sticker req flag, but it can't be null
    // so default to N
    if (project.getStickerReqFlag() == null) {
        project.setStickerReqFlag(NO);
    }

    try {

        ProjectDAO projectDAO = new ProjectDAOImpl();

        if (!isNew) {
            // UPDATE
            projectDAO.updateData(project);
        } else {
            // INSERT
            projectDAO.insertData(project);
        }
        tx.commit();
    } catch (LIMSRuntimeException lre) {
        //bugzilla 2154
        LogEvent.logError("ProjectUpdateAction", "performAction()", lre.toString());
        tx.rollback();
        errors = new ActionMessages();
        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) {
                java.util.Locale locale = (java.util.Locale) request.getSession()
                        .getAttribute("org.apache.struts.action.LOCALE");
                //bugzilla 2438
                String messageKey = "project.projectNameOrLocalAbbrev";
                String msg = ResourceLocator.getInstance().getMessageResources().getMessage(locale, messageKey);
                error = new ActionError("errors.DuplicateRecord.activate", 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);
        // in case of database exception don't allow another save without
        // cancel first
        //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, project);

    PropertyUtils.setProperty(dynaForm, "programs", programs);
    PropertyUtils.setProperty(dynaForm, "sysUsers", sysUsers);

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

    if (project.getId() != null && !project.getId().equals("0")) {
        request.setAttribute(ID, project.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.project.daoimpl.ProjectDAOImpl.java

public void getData(Project project) throws LIMSRuntimeException {
    try {//from  www.  j  a  va 2  s .  com
        Project proj = (Project) HibernateUtil.getSession().get(Project.class, project.getId());
        HibernateUtil.getSession().flush();
        HibernateUtil.getSession().clear();

        if (proj != null) {
            // set the display dates for STARTED_DATE, COMPLETED_DATE
            String locale = SystemConfiguration.getInstance().getDefaultLocale().toString();
            if (proj.getStartedDate() != null) {

                proj.setStartedDateForDisplay(
                        DateUtil.convertSqlDateToStringDate(proj.getStartedDate(), locale));
            }
            if (proj.getCompletedDate() != null) {
                proj.setCompletedDateForDisplay(
                        DateUtil.convertSqlDateToStringDate(proj.getCompletedDate(), locale));
            }
            PropertyUtils.copyProperties(project, proj);
        } else {
            project.setId(null);
        }
    } catch (Exception e) {
        //bugzilla 2154
        LogEvent.logError("ProjectDAOImpl", "getData()", e.toString());
        throw new LIMSRuntimeException("Error in Project getData()", e);
    }
}