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:com.gp.cong.logisoft.struts.action.SedFilingAction.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    HttpSession session = request.getSession(true);
    SedFilingForm sedFilingForm = (SedFilingForm) form;
    SedSchedulebDetails sedSchedulebDetails = new SedSchedulebDetails();
    SedFilingsDAO sedFilingsDAO = new SedFilingsDAO();
    SedSchedulebDetailsDAO sedSchedulebDetailsDAO = new SedSchedulebDetailsDAO();
    EdiUtil ediUtil = new EdiUtil();
    SedFilings sedFilings = new SedFilings();
    String userName = "";
    String email = "";
    User user = new User();
    request.setAttribute("exportCodeList", new SedFilingBC().getFieldList(69, "Export Code"));
    request.setAttribute("licenseCodeList", new SedFilingBC().getFieldList(67, "License Code"));
    request.setAttribute("stateCodeList", new SedFilingBC().getFieldList(70, "Vehicle State"));
    request.setAttribute("status", sedFilingForm.getStatus());
    request.setAttribute("shpdr", sedFilingForm.getShpdr());
    request.setAttribute("schedId", sedFilingForm.getSchedId());
    if (sedFilingForm.getBkgnum() != null && !sedFilingForm.getBkgnum().trim().equals("")) {
        request.setAttribute("bkgNu", sedFilingForm.getBkgnum().toUpperCase());
    }//from w ww.  jav  a 2s  .com
    if (session.getAttribute("loginuser") != null) {
        user = (User) session.getAttribute("loginuser");
        userName = user.getLoginName();
        email = user.getEmail();
    }
    String buttonValue = sedFilingForm.getButtonValue();
    if (CommonUtils.isEmpty(buttonValue)) {
        buttonValue = request.getParameter("buttonValue");
    }
    request.setAttribute("buttonValue", buttonValue);
    if (CommonUtils.isNotEmpty(request.getParameter("mode"))) {
        request.setAttribute("mode", request.getParameter("mode"));
    }
    if (CommonUtils.isNotEmpty(buttonValue)) {
        if (buttonValue.trim().equals("submit") || buttonValue.trim().equals("update")) {
            if ("update".equals(buttonValue)) {
                sedSchedulebDetails = sedSchedulebDetailsDAO
                        .findById(Integer.parseInt(sedFilingForm.getSchedId()));
            }
            PropertyUtils.copyProperties(sedSchedulebDetails, sedFilingForm);
            sedSchedulebDetails.setScheduleBName(sedFilingForm.getScheduleB_Name());
            sedSchedulebDetails.setScheduleBNumber(sedFilingForm.getScheduleB_Number());
            sedSchedulebDetails.setShipment(sedFilingForm.getShpdr());
            sedSchedulebDetails.setEntnam(userName);
            sedSchedulebDetails.setEntrdt(new Date());
            sedSchedulebDetailsDAO.save(sedSchedulebDetails);
            editMethod(sedFilingForm.getTrnref(), request);
            return mapping.findForward("schedPage");
            //editMethod(sedFilingForm.getShpdr(), request);
        } else if (buttonValue.trim().equals("showSched")) {
            editMethod(sedFilingForm.getTrnref(), request);
        } else if (buttonValue.trim().equals("goToSedFiling")) {
            String bol = request.getParameter("bol");
            if (CommonUtils.isNotEmpty(bol)) {
                FclBl fclbl = new FclBlDAO().findById(null != bol ? Integer.parseInt(bol) : 0);
                SedFilingForm sedForm = new SedFilingForm(fclbl);
                int count = new SedFilingsDAO().getSedCount(fclbl.getFileNo());
                count = count + 1;
                String refNum = "04" + fclbl.getFileNo() + "-0" + count;
                sedForm.setTrnref(refNum);
                //                        sedForm.setBkgnum(refNum);
                sedForm.setEmail(email);
                sedForm.setStsusr(userName);
                sedForm.setStsDate(DateUtils.formatStringDateToAppFormatMMM(new Date()));
                request.setAttribute("sedFilingForm", sedForm);
                request.setAttribute("status", sedForm.getStatus());
            } else {
                request.setAttribute("sedFilingForm", new SedFilingForm());
            }
            return mapping.findForward("goToSedFiling");
        } else if ("editSedFiling".equalsIgnoreCase(buttonValue)) {
            String trnref = request.getParameter("trnref");
            sedFilings = new SedFilingsDAO().findByTrnref(trnref);
            SedFilingForm sedForm = new SedFilingForm();
            PropertyUtils.copyProperties(sedForm, sedFilings);
            sedForm.setDepDate(
                    null != sedFilings.getDepdat() ? DateUtils.parseDateToString(sedFilings.getDepdat())
                            : null);
            request.setAttribute("sedFilingForm", sedForm);
            request.setAttribute("action", "updateAes");
            request.setAttribute("bkgNu", sedForm.getBkgnum().toUpperCase());
            return mapping.findForward("goToSedFiling");
        } else if (buttonValue.trim().equals("edit")) {
            sedSchedulebDetails = sedSchedulebDetailsDAO.findById(Integer.parseInt(sedFilingForm.getSchedId()));
            request.setAttribute("schedB", sedSchedulebDetails);
            editMethod(sedFilingForm.getTrnref(), request);
        } else if (buttonValue.trim().equals("delete")) {
            sedSchedulebDetails = sedSchedulebDetailsDAO.findById(Integer.parseInt(sedFilingForm.getSchedId()));
            sedSchedulebDetailsDAO.delete(sedSchedulebDetails);
            editMethod(sedFilingForm.getTrnref(), request);
        } else if ("goToSchedB".equals(buttonValue)) {
            editMethod(sedFilingForm.getTrnref(), request);
        } else if ("saveAes".equalsIgnoreCase(buttonValue) || "updateAes".equalsIgnoreCase(buttonValue)) {
            if ("updateAes".equalsIgnoreCase(buttonValue)) {
                sedFilings = new SedFilingsDAO().findByTrnref(sedFilingForm.getTrnref());
            } else {
                sedFilings = new SedFilings();
            }
            PropertyUtils.copyProperties(sedFilings, sedFilingForm);
            if (null != sedFilingForm.getOrigin() && sedFilingForm.getOrigin().lastIndexOf("(") != -1
                    && sedFilingForm.getOrigin().lastIndexOf(")") != -1) {
                sedFilings.setExpctry(
                        sedFilingForm.getOrigin().substring(sedFilingForm.getOrigin().lastIndexOf("(") + 1,
                                sedFilingForm.getOrigin().lastIndexOf("(") + 3));
            }
            sedFilings.setEntrdt(new Date());
            sedFilings.setEntnam(userName);
            sedFilings.setDepdat(CommonUtils.isNotEmpty(sedFilingForm.getDepDate())
                    ? DateUtils.parseDate(sedFilingForm.getDepDate(), "MM/dd/yyyy")
                    : null);
            sedFilings.setStsdte(CommonUtils.isNotEmpty(sedFilingForm.getStsDate())
                    ? DateUtils.parseDate(sedFilingForm.getStsDate(), "dd-MMM-yyyy")
                    : null);
            if ("saveAes".equalsIgnoreCase(buttonValue)) {
                new SedFilingsDAO().save(sedFilings);
            }
            request.setAttribute("hideGbShow", "hideGbShow");
            request.setAttribute("sedFilingForm", new SedFilingForm());
            return mapping.findForward("goToSedFiling");
        } else if ("submitAes".equals(buttonValue)) {
            new SedFilingBC().createFlatFile(sedFilings);
        }
    }
    return mapping.findForward("schedPage");
}

From source file:jp.co.opentone.bsol.linkbinder.attachment.CopiedAttachmentInfo.java

@Override
public Attachment toAttachment() throws ServiceAbortException {
    Attachment a = new Attachment();
    try {//ww  w.  j a va  2s.  co m
        PropertyUtils.copyProperties(a, this.attachment);
    } catch (Exception e) {
        throw new ApplicationFatalRuntimeException(e);
    }
    a.setMode(UpdateMode.NEW);
    if (a.getContent() == null) {
        a.setContent(getContent());
        a.setSourcePath(getSourcePath());
    }

    return a;
}

From source file:com.floreantpos.bo.ui.explorer.QuickMaintenanceExplorer.java

private static void quickMaintainMenuItem(MenuItem menuItem) {
    try {//from w ww  . j a v a2  s  . c  o  m
        if (menuItem.getId() != null) {
            if (btnCopy.isSelected()) {
                MenuItem newMenuItem = new MenuItem();
                PropertyUtils.copyProperties(newMenuItem, menuItem);
                newMenuItem.setId(null);
                newMenuItem.setFractionalUnit(menuItem.isFractionalUnit());
                newMenuItem.setDisableWhenStockAmountIsZero(menuItem.isDisableWhenStockAmountIsZero());
                newMenuItem.setShowImageOnly(menuItem.isShowImageOnly());
                menuItem = newMenuItem;
            } else if (btnDelete.isSelected()) {
                if (POSMessageDialog.showYesNoQuestionDialog(POSUtil.getFocusedWindow(),
                        POSConstants.CONFIRM_DELETE, POSConstants.DELETE) != JOptionPane.YES_OPTION) {
                    return;
                }
                MenuItemDAO foodItemDAO = new MenuItemDAO();
                if (menuItem.getDiscounts() != null && menuItem.getDiscounts().size() > 0) {
                    foodItemDAO.releaseParentAndDelete(menuItem);
                } else {
                    try {
                        foodItemDAO.delete(menuItem.getId());
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
                OrderView.getInstance().getItemView().updateView(menuItem);
                return;
            }
        } else {
            menuItem.addToorderTypeList(OrderView.getInstance().getTicketView().getTicket().getOrderType());
        }
        MenuItemForm editor = new MenuItemForm(menuItem);
        BeanEditorDialog dialog = new BeanEditorDialog(Application.getPosWindow(), editor);
        dialog.open();
        if (dialog.isCanceled())
            return;
        OrderView.getInstance().getItemView().updateView(menuItem);
        return;
    } catch (Exception e) {
        return;
    }
}

From source file:com.bdx.rainbow.service.basic.impl.EnterpriseService.java

@Override
public Integer saveEnterpriseInfo(DubboEnterpriseInfo dubboEnterpriseInfo, String userLoginName,
        List<DubboLicense> licenses) throws Exception {
    TBasicEnterpriseInfo enterpriseInfo = new TBasicEnterpriseInfo();
    PropertyUtils.copyProperties(enterpriseInfo, dubboEnterpriseInfo);
    TBasicEnterpriseInfo enterpriseInfoOld = null;
    int enterpriseId = -1;
    if (enterpriseInfo != null) {
        if (enterpriseInfo.getEnterpriseId() == null) {// insert or update
            if (StringUtils.isNotEmpty(enterpriseInfo.getOrganizationCode())) {
                enterpriseInfoOld = getEnterpriseInfoByOrganizationCode(enterpriseInfo.getOrganizationCode());
                if (enterpriseInfoOld != null) {
                    enterpriseInfo.setEnterpriseId(enterpriseInfoOld.getEnterpriseId());
                }/*  w  w w  .j ava2s.  com*/
            }
        } else {
            enterpriseInfoOld = tBasicEnterpriseInfoMapper.selectByPrimaryKey(enterpriseInfo.getEnterpriseId());
        }

        Timestamp now = DateUtil.getCurrent();

        if (enterpriseInfoOld == null) {//insert
            enterpriseInfo.setCreateTime(now);
            enterpriseInfo.setCreater(userLoginName);
            tBasicEnterpriseInfoMapper.insertSelective(enterpriseInfo);
            enterpriseId = enterpriseInfo.getEnterpriseId();
        } else {//update
            enterpriseId = enterpriseInfoOld.getEnterpriseId();
            enterpriseInfo.setUpdater(userLoginName);
            enterpriseInfo.setUpdateTime(now);
            TBasicEnterpriseInfoHis his = new TBasicEnterpriseInfoHis();
            PropertyUtils.copyProperties(his, enterpriseInfoOld);
            tBasicEnterpriseInfoHisMapper.insertSelective(his);
            tBasicEnterpriseInfoMapper.updateByPrimaryKeySelective(enterpriseInfo);
        }
        //??
        if (licenses != null && licenses.size() != 0) {
            List<TBasicLicense> bLicenses = new ArrayList<TBasicLicense>();
            TBasicLicense destLicense = null;
            for (DubboLicense dubboLicense : licenses) {
                destLicense = new TBasicLicense();
                PropertyUtils.copyProperties(destLicense, dubboLicense);
                destLicense.setEnterpriseId(enterpriseId);
                bLicenses.add(destLicense);
            }
            saveLicense(bLicenses, userLoginName);
        }
    }
    return enterpriseId;
}

From source file:br.gov.jfrj.siga.cp.bl.CpBL.java

public void cancelarIdentidade(CpIdentidade ident, CpIdentidade identidadeCadastrante)
        throws AplicacaoException {
    try {// w  w  w .j a  v a  2  s  .c  o  m
        Date dt = dao().consultarDataEHoraDoServidor();
        CpIdentidade idNova = new CpIdentidade();
        try {
            PropertyUtils.copyProperties(idNova, ident);
        } catch (Exception e) {
            throw new AplicacaoException("Erro ao copiar as propriedades da identidade anterior.");
        }
        idNova.setIdIdentidade(null);
        idNova.setDtCancelamentoIdentidade(dt);
        idNova.setHisDtFim(dt);
        dao().iniciarTransacao();
        dao().gravarComHistorico(idNova, ident, dt, identidadeCadastrante);
        dao().commitTransacao();
    } catch (Exception e) {
        dao().rollbackTransacao();
        throw new AplicacaoException("No foi possvel cancelar a identidade.", 9, e);
    }
}

From source file:com.glweb.module.forum.ForumManager.java

public boolean updateCategory(Category newCategory) {
    Category _category = null;//from www .j av  a  2 s . com

    try {
        _category = getCategory(newCategory.getId());

        PropertyUtils.copyProperties(_category, newCategory);

        _category.setModifiedDate(new Date());

        getCategoryDAO().updateCategory(_category);
    } catch (GLWebPersistenceException e) {
        getLogger().error(e);
        return false;
    } catch (Exception e) {
        getLogger().error(e);
        return false;
    }

    return true;
}

From source file:com.jada.order.document.CreditEngine.java

static public CreditHeader clone(CreditHeader header)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    CreditHeader creditHeader = new CreditHeader();
    creditHeader.setCreditHeaderId(header.getCreditHeaderId());
    creditHeader.setCreditNum(header.getCreditNum());
    creditHeader.setUpdateInventory(header.getUpdateInventory());
    creditHeader.setShippingTotal(header.getShippingTotal());
    creditHeader.setCreditTotal(header.getCreditTotal());
    creditHeader.setCreditStatus(header.getCreditStatus());
    creditHeader.setCreditDate(header.getCreditDate());
    creditHeader.setRecUpdateBy(header.getRecUpdateBy());
    creditHeader.setRecUpdateDatetime(header.getRecUpdateDatetime());
    creditHeader.setRecCreateBy(header.getRecCreateBy());
    creditHeader.setRecCreateDatetime(header.getRecCreateDatetime());
    creditHeader.setOrderHeader(header.getOrderHeader());
    creditHeader.setInvoiceHeader(header.getInvoiceHeader());

    if (header.getPaymentTran() != null) {
        PaymentTran pt = header.getPaymentTran();
        PaymentTran paymentTran = new PaymentTran();
        PropertyUtils.copyProperties(paymentTran, pt);
        creditHeader.setPaymentTran(paymentTran);
    }//w w  w. jav a 2s  .c  om
    if (header.getVoidPaymentTran() != null) {
        PaymentTran pt = header.getVoidPaymentTran();
        PaymentTran paymentTran = new PaymentTran();
        PropertyUtils.copyProperties(paymentTran, pt);
        creditHeader.setVoidPaymentTran(paymentTran);
    }

    Iterator<?> iterator = header.getCreditDetails().iterator();
    while (iterator.hasNext()) {
        CreditDetail detail = (CreditDetail) iterator.next();
        CreditDetail creditDetail = new CreditDetail();
        creditDetail.setCreditHeader(creditHeader);
        creditHeader.getCreditDetails().add(creditDetail);
        creditDetail.setCreditDetailId(detail.getCreditDetailId());
        creditDetail.setSeqNum(detail.getSeqNum());
        creditDetail.setItemCreditQty(detail.getItemCreditQty());
        creditDetail.setItemCreditAmount(detail.getItemCreditAmount());
        creditDetail.setRecUpdateBy(header.getRecUpdateBy());
        creditDetail.setRecUpdateDatetime(header.getRecUpdateDatetime());
        creditDetail.setRecCreateBy(header.getRecCreateBy());
        creditDetail.setRecCreateDatetime(header.getRecCreateDatetime());
        creditDetail.setOrderItemDetail(detail.getOrderItemDetail());

        Iterator<?> taxIterator = detail.getCreditDetailTaxes().iterator();
        while (taxIterator.hasNext()) {
            CreditDetailTax detailTax = (CreditDetailTax) taxIterator.next();
            CreditDetailTax creditDetailTax = new CreditDetailTax();
            creditDetailTax.setCreditDetailTaxId(detailTax.getCreditDetailTaxId());
            creditDetailTax.setTaxName(detailTax.getTaxName());
            creditDetailTax.setTaxAmount(detailTax.getTaxAmount());
            creditDetailTax.setRecUpdateBy(detailTax.getRecUpdateBy());
            creditDetailTax.setRecUpdateDatetime(detailTax.getRecUpdateDatetime());
            creditDetailTax.setRecCreateBy(detailTax.getRecCreateBy());
            creditDetailTax.setRecCreateDatetime(detailTax.getRecCreateDatetime());
            creditDetailTax.setTax(detailTax.getTax());
            creditDetailTax.setCreditDetail(creditDetail);
            creditDetail.getCreditDetailTaxes().add(creditDetailTax);
            creditDetailTax.setCreditHeader(creditHeader);
            creditHeader.getCreditTaxes().add(creditDetailTax);
        }
    }

    Iterator<?> taxIterator = header.getCreditTaxes().iterator();
    while (taxIterator.hasNext()) {
        CreditDetailTax detailTax = (CreditDetailTax) taxIterator.next();
        if (detailTax.getCreditDetail() != null) {
            continue;
        }
        CreditDetailTax creditDetailTax = new CreditDetailTax();
        creditDetailTax.setCreditDetailTaxId(detailTax.getCreditDetailTaxId());
        creditDetailTax.setTaxName(detailTax.getTaxName());
        creditDetailTax.setTaxAmount(detailTax.getTaxAmount());
        creditDetailTax.setRecUpdateBy(detailTax.getRecUpdateBy());
        creditDetailTax.setRecUpdateDatetime(detailTax.getRecUpdateDatetime());
        creditDetailTax.setRecCreateBy(detailTax.getRecCreateBy());
        creditDetailTax.setRecCreateDatetime(detailTax.getRecCreateDatetime());
        creditDetailTax.setCreditHeader(creditHeader);
        creditHeader.getCreditTaxes().add(creditDetailTax);
    }

    return creditHeader;
}

From source file:jp.co.opentone.bsol.linkbinder.dao.BaseDao.java

/**
 * ??????./*www .ja  va2 s  .c o m*/
 *
 * ????
 *         (???????????)
 *
 * @param <C> ??
 * @param condition ?
 * @param fields ????
 * @return ?
 * @throws ReflectionRuntimeException ???
 */
@SuppressWarnings("unchecked")
protected <C> C getLikeSearchCondition(Object condition, List<String> fields)
        throws ReflectionRuntimeException {
    C clone = null;
    try {
        clone = (C) condition.getClass().getConstructor().newInstance();

        PropertyUtils.copyProperties(clone, condition);

        // 
        escape(clone, fields);
    } catch (NoSuchMethodException e) {
        throw new ReflectionRuntimeException(e);
    } catch (IllegalArgumentException e) {
        throw new ReflectionRuntimeException(e);
    } catch (SecurityException e) {
        throw new ReflectionRuntimeException(e);
    } catch (InstantiationException e) {
        throw new ReflectionRuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new ReflectionRuntimeException(e);
    } catch (InvocationTargetException e) {
        throw new ReflectionRuntimeException(e);
    }

    return clone;
}

From source file:com.bstek.dorado.data.model.TestDataHolder.java

public static void updateDomainTestData2(List<Employee> employees)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    for (Iterator<Employee> it = employees.iterator(); it.hasNext();) {
        Employee employee = it.next();/* w  ww .ja va2s  .c om*/
        EntityState state = EntityUtils.getState(employee);
        if (state == EntityState.DELETED) {
            demainTestData2.remove(employee.getId());
            it.remove();
        } else if (state == EntityState.MODIFIED) {
            Employee e = demainTestData2.get(employee.getId());
            employee.setSalary(employee.getSalary() + 1);
            if (e != null) {
                PropertyUtils.copyProperties(e, employee);
            }
            EntityUtils.setState(employee, EntityState.NONE);
        } else if (state == EntityState.NEW) {
            Employee e = new Employee();
            PropertyUtils.copyProperties(e, employee);
            demainTestData2.put(e.getId(), e);
            EntityUtils.setState(employee, EntityState.NONE);
        }
    }
}

From source file:com.jdon.model.ModelHandler.java

/**
 * for old version below 1.4/*from  w w w  . ja v  a  2 s .c  om*/
 */
public void modelCopyToForm(Model model, ModelForm form) throws Exception {
    try {
        PropertyUtils.copyProperties(form, model);
    } catch (Exception e) {
        String error = " Model:" + model.getClass().getName() + " copy To ModelForm:"
                + form.getClass().getName() + " error:" + e;
        Debug.logError(error, module);
        throw new Exception(error);
    }
}