Example usage for org.springframework.beans BeanUtils copyProperties

List of usage examples for org.springframework.beans BeanUtils copyProperties

Introduction

In this page you can find the example usage for org.springframework.beans BeanUtils copyProperties.

Prototype

public static void copyProperties(Object source, Object target) throws BeansException 

Source Link

Document

Copy the property values of the given source bean into the target bean.

Usage

From source file:com.iselect.kernal.geo.service.GeographicServiceImpl.java

@Override
public void saveCountry(CountryDto country) {
    CountryModel countryModel = (CountryModel) CountryFactory.createCountry(EntityType.MODEL);
    BeanUtils.copyProperties(country, countryModel);
    List<StateDto> states = country.getStates();
    for (StateDto stateDto : states) {
        StateModel stateModel = (StateModel) StateFactory.createState(EntityType.MODEL);
        BeanUtils.copyProperties(stateDto, stateModel);
        countryModel.addState(stateModel);
    }//w  w  w .j  a v a2  s.co  m
    this.countryDao.insertCountry(countryModel);
}

From source file:com.dianping.lion.entity.User.java

@Override
public Object clone() {
    User cloned = new User();
    BeanUtils.copyProperties(this, cloned);
    return cloned;
}

From source file:org.bigtester.ate.model.casestep.RepeatStepExecutionLogger.java

/**
 * Step out processing./*from  w ww . j  a  va  2  s. c o  m*/
 *
 * @param event the event
 */
public void stepOutProcessing(RepeatStepInOutEvent event) {
    //recover the initial values of the currently finished repeatStep for future repeatStep nested case.
    final RepeatStepExecutionLoggerNode currentRepeatStepNode2 = currentRepeatStepNode;
    if (currentRepeatStepNode2 == null)
        throw GlobalUtils.createInternalError("repeat Internal error.");
    RepeatStep rStep = (RepeatStep) event.getSource();
    BeanUtils.copyProperties(currentRepeatStepNode2.getRepeatStepWithInitialValues(), rStep);

    final RepeatStepExecutionLoggerNode repeatStepExternalNode2 = repeatStepExternalNode;
    if (repeatStepExternalNode2 == null) {
        currentRepeatStepNode = null;// NOPMD
    } else {

        currentRepeatStepNode = repeatStepExternalNode2;
        repeatStepExternalNode = (RepeatStepExecutionLoggerNode) repeatStepExternalNode2.getParent();

    }

}

From source file:sample.web.account.AccountController.java

@RequestMapping(value = "/edit", method = RequestMethod.POST)
public String edit(@Validated EditAccountForm accountForm, BindingResult bindingResult, Model model,
        @AuthenticationPrincipal User user) {
    if (bindingResult.hasErrors()) {
        return modelAndViewForEdit(model, accountForm, user);
    }/*from  www.j  a va2 s. c om*/
    Account account = accountService.getAccount(user.getUsername());
    BeanUtils.copyProperties(accountForm, account);
    account.setUsername(user.getUsername());
    accountService.updateAccount(account);
    return "redirect:/";
}

From source file:technology.tikal.customers.model.CustomerOfy.java

@Override
public void update(Customer source) {
    BeanUtils.copyProperties(source, this);
    if (this.primaryContactRef != null && this.primaryContactRef.get() != null) {
        this.primaryContactRef.get().update(source.getPrimaryContact());
    } else {//from   w  ww .  ja  v  a 2  s  .  com
        this.transientInfo = new PrimaryContactOfy(this, source.getPrimaryContact());
    }
}

From source file:net.microwww.rurl.service.imp.HessianRightServiceImp.java

public Map<String, Object> save4url(String appname, String path) {
    Webapp app = Webapp.getByAppName(appname);
    List<Webappurl> urls = Webappurl.listByPath(path);
    Webappurl url = null;/*from   w w  w .j a  va 2  s.  c  o m*/
    if (urls != null && !urls.isEmpty()) {
        url = urls.get(0);
    } else {
        url = new Webappurl();
        url.setName(getName(path));
        url.setWebappPath(path);
        url.setWebapp(app);
        url.setDiscrption(" auto collection !" + path);
        url = webappService.saveWebappurl(app, url, null);
    }
    RightURL rt = new RightURL();
    BeanUtils.copyProperties(url, rt);
    return (JSONObject) JSONObject.toJSON(rt);
}

From source file:org.carewebframework.shell.plugins.PluginDefinition.java

/**
 * Copy constructor.
 * 
 * @param def Plugin definition to copy.
 */
public PluginDefinition(PluginDefinition def) {
    BeanUtils.copyProperties(def, this);
}

From source file:com.iselect.kernal.account.service.AccountServiceImpl.java

@Override
@Transactional(readOnly = true)// w  ww.  ja va 2  s  .  c om
public UserDto loadUserByUsername(String string) throws UsernameNotFoundException {
    UserModel<UserProfileModel, AuthorityModel> userModel = this.userDaoExt.getByUserName(string);
    if (userModel == null) {
        return null;
    }

    UserDto userDto = dtoFactory.createUser();
    BeanUtils.copyProperties(userModel, userDto);

    UserProfileModel profileModel = userModel.getProfile();
    if (profileModel != null) {
        UserProfileDto profileDto = dtoFactory.createUserProfile();
        BeanUtils.copyProperties(profileModel, profileDto);
    }

    Collection<AuthorityModel> authorities = userModel.getAuthorities();
    for (AuthorityModel auth : authorities) {
        AuthorityDto authorityDto = dtoFactory.createAuthority();
        BeanUtils.copyProperties(auth, authorityDto);
        userDto.addAuthority(authorityDto);
    }

    return userDto;
}

From source file:org.simbasecurity.core.service.manager.ConditionManagerService.java

private Condition findOrCreate(@RequestBody ConditionDTO condition) {
    final Condition attachedCondition;

    if (condition.getId() == 0L) {
        attachedCondition = conditionRepository.persist(assemble(condition));
    } else {//w  w w.  jav a  2 s . co  m
        attachedCondition = conditionRepository.refreshWithOptimisticLocking(condition);
        BeanUtils.copyProperties(condition, attachedCondition);
    }

    return attachedCondition;
}

From source file:com.wcna.calms.jpos.services.quote.JPOSQuickQuoteAssetLoadService.java

public Object invoke(Object arg0) {
    HashMap assetMap = new HashMap();

    int quoteIdx = this.jposQuoteUtil.getQuoteIdx((Map) arg0);

    Map<String, Object> inputMap = (Map<String, Object>) arg0;
    String invokedByPricesScr = "0";
    Locale locale = getUserContainer().getLocale();
    try {/* www .ja v a2s. com*/
        if (inputMap.get("invokedByPricesScr") != null) {
            invokedByPricesScr = (String) inputMap.get("invokedByPricesScr");
        }
    } catch (Exception e) {
        Logger.error(e.getMessage(), e);
    }
    ////////////--load for prices-start/////////
    if (invokedByPricesScr.equals("1")) {
        String appId = this.getAppContainer() == null ? ""
                : this.getAppContainer().getAppID() <= 0 ? "" : this.getAppContainer().getAppID() + "";
        IJPOSApplicationAssetDataVO assetDataVo = null;
        quickQuoteService.initializeQuoteContainer();
        //IJPOSQuoteDataVO quoteVo = quickQuoteService.loadQuote(Long.valueOf(appId), locale);
        Map<String, Object> loadMap = new HashMap<String, Object>();
        assetDataVo = loadAssetSubProcess(assetDataVo, appId, loadMap);
    }

    //////////---load for prices - end /////////////

    String screenCode = this.getScreenCode(arg0);
    //      System.err.println("=========>JPOSQuickQuoteAssetLoadService.invoke ((1.1)) screenCode=" + screenCode);
    JPOSQuickQuoteAssetVO assetVO = new JPOSQuickQuoteAssetVO();

    Logger.debug("getting asset info for quoteIdx = " + quoteIdx);

    IJPOSQuickQuoteAssetInputForm existingAssetVO = this.quickQuoteAssetService.getAssetForm(quoteIdx);
    Set<String> noAccessFields = this.entityAccessService.getNoAccessFields(screenCode);

    if (existingAssetVO == null) {
        Logger.debug("got an existing asset VO which is NULL");

    } else {
        Logger.debug("got an existing asset VO with contents: " + "; DiscountVatAmt: "
                + existingAssetVO.getDiscountVatAmt() + "; DiscountVatRate: "
                + existingAssetVO.getDiscountVatRate() + "; MakeId: " + existingAssetVO.getMakeId()
                + "; ModelId: " + existingAssetVO.getModelId());
    }

    //Copy all properties
    BeanUtils.copyProperties(existingAssetVO, assetVO);

    //Copy all properties from assetVO to form
    IJPOSQuickQuoteAssetForm form = createBean(IJPOSQuickQuoteAssetForm.class);
    BeanUtils.copyProperties(assetVO, form);

    //Copy only properties that only system can access to VO for display
    assetVO = new JPOSQuickQuoteAssetVO();
    BeanUtils.copyProperties(existingAssetVO, assetVO,
            noAccessFields.toArray(new String[noAccessFields.size()]));

    quickQuoteAssetService.loadVehicleInfo(form);

    ArrayList makeList = new ArrayList();
    String[] makeKeys = form.getManufacturerKeys();
    String[] makeValues = form.getManufacturerValues();
    if (makeKeys != null) {
        for (int i = 0; i < makeKeys.length; i++) {
            OptionLabelValue make = new OptionLabelValue(makeValues[i], makeKeys[i]);
            makeList.add(make);
        }
    }
    ArrayList modelList = new ArrayList();
    String[] modelKeys = form.getModelKeys();
    String[] modelValues = form.getModelValues();
    if (modelKeys != null) {
        for (int i = 0; i < modelKeys.length; i++) {
            OptionLabelValue model = new OptionLabelValue(modelValues[i], modelKeys[i]);
            modelList.add(model);
        }
    }
    ArrayList variantList = new ArrayList();
    String[] variKeys = form.getVariantKeys();
    String[] variValues = form.getVariantValues();
    if (variKeys != null) {
        for (int i = 0; i < variKeys.length; i++) {
            OptionLabelValue variant = new OptionLabelValue(variValues[i], variKeys[i]);
            variantList.add(variant);
        }
    }

    //      JPOSQuickQuoteAssetVO quoteAssetData = new JPOSQuickQuoteAssetVO();
    //      BeanUtils.copyProperties(form, quoteAssetData,
    //            new String[]{"manufacturerKeys", "manufacturerValues", "modelKeys", "modelValues", "variantKeys", "variantValues", "registrationOptions"});

    //      assetMap.put("assetDetails", quoteAssetData);
    assetMap.put("assetTypes", form.getAssetTypes());
    //      assetMap.put("vatRateTypes", form.getVatRateTypes());
    assetMap.put("makeList", makeList);
    assetMap.put("modelList", modelList);
    assetMap.put("variantList", variantList);
    //      assetMap.put("options", form.getOptionAccessories());
    assetMap.put("registrationOptions", form.getRegistrationOptions());
    if (!"on".equals(assetVO.getFreeFormatFlag()) && !StringUtils.isBlank(assetVO.getModelVariantId())) {
        assetMap.put("originalPriceAmt",
                this.quickQuoteAssetService.getPriceAmtForVariant(Long.valueOf(assetVO.getModelVariantId())));
    }
    IUserContainer userContainer = this.getUserContainer();
    boolean isRentACarAllowed = this.quickQuoteAssetService
            .isRentACarAllowed(Long.valueOf(getUserContainer().getRoleID()));
    assetMap.put("isRentACarAvailable", isRentACarAllowed ? IConstants.FLAG_YES : IConstants.FLAG_NO);

    try {

        String taxIncludingFlag = "";
        //It is important to use deriveTaxIncludingFlag() , because when the taxincludingflag is hidden, it does get removed from the assetVO.

        if (assetVO.getTotalGross() != null
                && formatService.parseDouble(assetVO.getTotalGross(), locale, false, 0d) > 0) {//Quote/Asset Exist, Assume to TotalGross will never be zero.
            taxIncludingFlag = quickQuoteAssetService.deriveTaxIncludingFlag("quickQuoteAsset", false,
                    assetVO.getTaxIncludingFlag(), assetVO.getNewUsed());
        } else {//new Quote/Asset
            taxIncludingFlag = quickQuoteAssetService.deriveTaxIncludingFlag("quickQuoteAsset", true,
                    assetVO.getTaxIncludingFlag(), assetVO.getNewUsed());
        }

        Date taxPointDate = formatService.parseDate(assetVO.getTaxPointDate(),
                this.getUserContainer().getLocale(), false, new Date());

        quickQuoteAssetService.populateAssetScreenVatDropDowns(assetVO, assetMap, taxIncludingFlag);

        if (assetVO == null) {
            Logger.debug("got an assetVO which is NULL");

        } else {
            Logger.debug("got an assetVO with contents " + "; TaxCode: " + assetVO.getTaxCode() + "; TaxAmt: "
                    + assetVO.getTaxAmt() + "; TaxRateValue: " + assetVO.getTaxRateValue() + "; SalePrice: "
                    + assetVO.getSalePrice());
        }

        // this should not be null
        Logger.debug("About to call jposQuoteVatService.getTaxRateDataById ");
        ITaxRateDataVO savedTaxRateVO = this.jposQuoteVatService
                .getTaxRateDataById(Long.valueOf(assetVO.getTaxCode()));
        double currentTaxRate = this.jposQuoteVatService.getTaxRate(savedTaxRateVO.getTaxTypeCode(),
                taxPointDate, userContainer.getCountryCode());
        double savedTaxRate = formatService.parseDouble(assetVO.getTaxRateValue(), userContainer.getLocale(),
                false, 0d);
        // compare the saved tax rate against the current rate for the tax code
        if (currentTaxRate != savedTaxRate) {
            List<ITaxRateDataVO> currentList = this.jposQuoteVatService.getTaxRateDataVOList(false,
                    !IConstants.FLAG_YES.equals(taxIncludingFlag), taxPointDate,
                    userContainer.getCountryCode());
            // should not be null
            if (currentList != null) {
                ITaxRateDataVO target = null;
                for (ITaxRateDataVO v : currentList) {
                    if (v.getTaxTypeCode().equals(savedTaxRateVO.getTaxTypeCode())) {
                        target = v;
                        break;
                    }
                }
                // in the case that this particular tax is not valid at this point in time,
                // we will default to the first one in the list
                if (target == null) {
                    target = currentList.get(0);
                }
                assetVO.setTaxCode(target.getId());
                assetVO.setExtraTaxCode(assetVO.getTaxCode());
                assetVO.setTaxableDFOptionsVatRate(assetVO.getTaxCode());
                assetVO.setDiscountVatRate(assetVO.getTaxCode());
                assetVO.setTaxRateValue(
                        formatService.formatDouble(target.getRate(), userContainer.getLocale()));
                //locale = userContainer.getLocale();

                String net = assetVO.getSalePrice();
                String vatAmt = quickQuoteAssetService.getVatAmountFromNet(net, assetVO.getTaxRateValue(),
                        locale);
                String grossAmt = quickQuoteAssetService.getGrossAmount(net, vatAmt, locale);
                assetVO.setTaxAmt(vatAmt);
                assetVO.setGrossCost(grossAmt);
                form.setTaxAmt(assetVO.getTaxAmt());
                form.setGrossCost(assetVO.getGrossCost());

                net = assetVO.getExtraAmt();
                vatAmt = quickQuoteAssetService.getVatAmountFromNet(net, assetVO.getTaxRateValue(), locale);
                grossAmt = quickQuoteAssetService.getGrossAmount(net, vatAmt, locale);
                assetVO.setExtraTaxAmt(vatAmt);
                assetVO.setExtraTotalCost(grossAmt);
                form.setExtraTaxAmt(assetVO.getExtraTaxAmt());
                form.setExtraTotalCost(assetVO.getExtraTotalCost());

                net = assetVO.getTaxableDFOptionsNet();
                vatAmt = quickQuoteAssetService.getVatAmountFromNet(net, assetVO.getTaxRateValue(), locale);
                grossAmt = quickQuoteAssetService.getGrossAmount(net, vatAmt, locale);
                assetVO.setTaxableDFOptionsVatAmt(vatAmt);
                assetVO.setTaxableDFOptionsGross(grossAmt);
                form.setTaxableDFOptionsVatAmt(assetVO.getTaxableDFOptionsVatAmt());
                form.setTaxableDFOptionsGross(assetVO.getTaxableDFOptionsGross());

                quickQuoteAssetService.calcAndSetTotals(form, locale);

                assetVO.setDiscountNet(form.getDiscountNet());
                assetVO.setDiscountVatAmt(form.getDiscountVatAmt());
                assetVO.setDiscountGross(form.getDiscountGross());

                assetVO.setTotalNet(form.getTotalNet());
                assetVO.setTotalVatAmt(form.getTotalVatAmt());
                assetVO.setTotalGross(form.getTotalGross());

                assetMap.put("taxRateChange", "Y");
            }

        }
        assetMap.put("screenData", assetVO);
        assetMap.put("ffoList", this.quickQuoteAssetService.getFFOList(quoteIdx));
        List<IRentACarBean> rentACarList = this.quickQuoteAssetService.getRentACarList(quoteIdx);
        if (rentACarList != null && !rentACarList.isEmpty()) {
            assetMap.put("rentACarList", rentACarList);
        }
    } catch (ParseException e) {
        throw new SystemException(e);
    }

    return assetMap;
}