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:org.hoteia.qalingo.core.web.mvc.factory.ViewBeanFactory.java

/**
 * //from  w  w  w .  ja  v  a 2  s.  c  o  m
 */
public MarketAreaViewBean buildViewBeanMarketArea(final RequestData requestData, final MarketArea marketArea)
        throws Exception {
    final MarketAreaViewBean marketAreaViewBean = new MarketAreaViewBean();
    marketAreaViewBean.setCode(marketArea.getCode());
    marketAreaViewBean.setName(marketArea.getName());
    marketAreaViewBean.setDescription(marketArea.getDescription());

    marketAreaViewBean.setOpened(marketArea.isOpened());
    marketAreaViewBean.setEcommerce(marketArea.isEcommerce());
    marketAreaViewBean.setDefault(marketArea.isDefault());

    marketAreaViewBean.setLatitude(marketArea.getLatitude());
    marketAreaViewBean.setLongitude(marketArea.getLongitude());

    if (Hibernate.isInitialized(marketArea.getDefaultLocalization())
            && marketArea.getDefaultLocalization() != null) {
        marketAreaViewBean.setDefaultLocalization(
                buildViewBeanLocalization(requestData, marketArea.getDefaultLocalization()));
    }
    if (Hibernate.isInitialized(marketArea.getLocalizations()) && marketArea.getLocalizations() != null) {
        marketAreaViewBean.setLocalizations(buildListViewBeanLocalizations(requestData,
                new ArrayList<Localization>(marketArea.getLocalizations())));
    }

    if (Hibernate.isInitialized(marketArea.getDefaultCurrency()) && marketArea.getDefaultCurrency() != null) {
        marketAreaViewBean.setDefaultCurrency(
                buildViewBeanCurrencyReferential(requestData, marketArea.getDefaultCurrency()));
    }
    if (Hibernate.isInitialized(marketArea.getCurrencies()) && marketArea.getCurrencies() != null) {
        marketAreaViewBean.setCurrencies(buildListViewBeanCurrencyReferential(requestData,
                new ArrayList<CurrencyReferential>(marketArea.getCurrencies())));
    }

    if (Hibernate.isInitialized(marketArea.getMarket()) && marketArea.getMarket() != null) {
        RequestData requestDataChangecontext = new RequestData();
        BeanUtils.copyProperties(requestData, requestDataChangecontext);
        requestDataChangecontext.setMarket(marketArea.getMarket());
        requestDataChangecontext.setMarketArea(marketArea);
        marketAreaViewBean.setChangeContextUrl(urlService.buildChangeContextUrl(requestDataChangecontext));
        marketAreaViewBean.setHomeUrl(urlService.generateUrl(FoUrls.HOME, requestDataChangecontext));
    }

    return marketAreaViewBean;
}

From source file:org.hoteia.qalingo.core.web.mvc.factory.ViewBeanFactory.java

/**
 * //from w  w  w  .j a v a2  s  .c  om
 */
public LocalizationViewBean buildViewBeanLocalization(final RequestData requestData,
        final Localization localization, final Localization currentLocalization) throws Exception {
    final Locale locale = requestData.getLocale();

    final LocalizationViewBean localizationViewBean = new LocalizationViewBean();
    localizationViewBean.setCode(localization.getCode());
    localizationViewBean.setDescription(localization.getDescription());
    localizationViewBean.setCountry(localization.getCountry());
    localizationViewBean.setLanguage(localization.getLanguage());

    localizationViewBean.setLocaleCode(localization.getLocale().toString());
    localizationViewBean.setFallbackLocaleCode(localization.getFallbackLocaleCode());

    localizationViewBean.setName(localization.getName());

    String localizationCodeTranslation = currentLocalization.getCode();
    if (localizationCodeTranslation.contains("-")) {
        String[] split = localizationCodeTranslation.split("-");
        localizationCodeTranslation = split[0] + "-" + split[1].toUpperCase();
        String localizationTrad = getReferenceData(ScopeReferenceDataMessage.LANGUAGE,
                localizationCodeTranslation, locale);
        if (localizationTrad != null) {
            localizationViewBean.setName(localizationTrad);
        }
    } else {
        String localizationTrad = getReferenceData(ScopeReferenceDataMessage.LANGUAGE,
                localizationCodeTranslation.toLowerCase(), locale);
        if (localizationTrad != null) {
            localizationViewBean.setName(localizationTrad);
        }
    }

    if (localization.getLocale().equals(locale)) {
        localizationViewBean.setActive(true);
    }

    if (localization.getDateCreate() != null) {
        localizationViewBean.setDateCreate(buildCommonFormatDate(requestData, localization.getDateCreate()));
    }
    if (localization.getDateUpdate() != null) {
        localizationViewBean.setDateUpdate(buildCommonFormatDate(requestData, localization.getDateUpdate()));
    }

    RequestData requestDataChangecontext = new RequestData();
    BeanUtils.copyProperties(requestData, requestDataChangecontext);
    requestDataChangecontext.setMarketAreaLocalization(localization);
    localizationViewBean.setChangeContextUrl(urlService.buildChangeContextUrl(requestDataChangecontext));
    localizationViewBean.setChangeBackofficeLanguageUrl(
            urlService.buildChangeBackofficeLanguageUrl(requestDataChangecontext, localization));
    localizationViewBean.setHomeUrl(urlService.generateUrl(FoUrls.HOME, requestDataChangecontext));

    return localizationViewBean;
}

From source file:org.hoteia.qalingo.core.web.mvc.factory.ViewBeanFactory.java

/**
 *
 *//*from  w ww. j a  v a  2 s  .com*/
public CurrencyReferentialViewBean buildViewBeanCurrencyReferential(final RequestData requestData,
        final CurrencyReferential currencyReferential) throws Exception {
    final CurrencyReferentialViewBean currencyReferentialViewBean = new CurrencyReferentialViewBean();
    if (currencyReferential != null) {
        currencyReferentialViewBean.setName(currencyReferential.getName());
        currencyReferentialViewBean.setDescription(currencyReferential.getDescription());
        currencyReferentialViewBean.setCode(currencyReferential.getCode());
        currencyReferentialViewBean.setSign(currencyReferential.getSign());
        currencyReferentialViewBean.setAbbreviated(currencyReferential.getAbbreviated());

        DateFormat dateFormat = requestUtil.getCommonFormatDate(requestData, DateFormat.MEDIUM,
                DateFormat.MEDIUM);
        if (currencyReferential.getDateCreate() != null) {
            currencyReferentialViewBean.setDateCreate(dateFormat.format(currencyReferential.getDateCreate()));
        }
        if (currencyReferential.getDateUpdate() != null) {
            currencyReferentialViewBean.setDateUpdate(dateFormat.format(currencyReferential.getDateUpdate()));
        }

        // CLONE THE CURRENT REQUEST DATE TO BUILD THE CHANGE CONTEXT URL (MENU)
        RequestData requestDataChangecontext = new RequestData();
        BeanUtils.copyProperties(requestData, requestDataChangecontext);
        requestDataChangecontext.setMarketAreaCurrency(currencyReferential);

        currencyReferentialViewBean
                .setChangeContextUrl(urlService.buildChangeContextUrl(requestDataChangecontext));
        currencyReferentialViewBean.setHomeUrl(urlService.generateUrl(FoUrls.HOME, requestDataChangecontext));

    }
    return currencyReferentialViewBean;
}

From source file:org.hoteia.qalingo.core.web.mvc.factory.ViewBeanFactory.java

/**
 * //from   w  ww.  j a  v  a2  s  . com
 */
public RetailerViewBean buildViewBeanRetailerWithoutStore(final RequestData requestData,
        final Retailer retailer) throws Exception {
    final MarketArea marketArea = requestData.getMarketArea();
    final Localization localization = requestData.getMarketAreaLocalization();
    final String localizationCode = localization.getCode();
    final Locale locale = requestData.getLocale();

    final RetailerViewBean retailerViewBean = new RetailerViewBean();

    retailerViewBean.setCode(retailer.getCode());
    retailerViewBean.setName(retailer.getName());
    retailerViewBean.setDescription(retailer.getDescription());

    retailerViewBean.setI18nName(retailer.getI18nName(localizationCode));
    retailerViewBean.setI18nDescription(retailer.getI18nDescription(localizationCode));

    retailerViewBean.setOfficialRetailer(retailer.isOfficialRetailer());
    retailerViewBean.setBrand(retailer.isBrand());
    retailerViewBean.setEcommerce(retailer.isEcommerce());
    retailerViewBean.setCorner(retailer.isCorner());

    String logo = retailerService.buildRetailerLogoWebPath(retailer.getLogo());
    retailerViewBean.setImg(logo);

    if (Hibernate.isInitialized(retailer.getAddresses()) && retailer.getAddresses() != null) {
        RetailerAddress defaultAddress = retailer.getDefaultAddress();
        if (defaultAddress != null) {
            retailerViewBean.getDefaultAddress().setAddress1(defaultAddress.getAddress1());
            retailerViewBean.getDefaultAddress().setAddress2(defaultAddress.getAddress2());
            retailerViewBean.getDefaultAddress()
                    .setAddressAdditionalInformation(defaultAddress.getAddressAdditionalInformation());
            retailerViewBean.getDefaultAddress().setPostalCode(defaultAddress.getPostalCode());
            retailerViewBean.getDefaultAddress().setCity(defaultAddress.getCity());
            retailerViewBean.getDefaultAddress().setStateCode(defaultAddress.getStateCode());
            retailerViewBean.getDefaultAddress().setStateLabel(defaultAddress.getStateCode());
            retailerViewBean.getDefaultAddress().setAreaCode(defaultAddress.getAreaCode());
            retailerViewBean.getDefaultAddress().setAreaLabel(defaultAddress.getAreaCode());
            retailerViewBean.getDefaultAddress().setCountryCode(defaultAddress.getCountryCode());

            String countryLabel = referentialDataService.getCountryByLocale(defaultAddress.getCountryCode(),
                    locale);
            retailerViewBean.getDefaultAddress().setCountry(countryLabel);

            retailerViewBean.getDefaultAddress().setLongitude(defaultAddress.getLongitude());
            retailerViewBean.getDefaultAddress().setLatitude(defaultAddress.getLatitude());

            retailerViewBean.getDefaultAddress().setPhone(defaultAddress.getPhone());
            retailerViewBean.getDefaultAddress().setMobile(defaultAddress.getMobile());
            retailerViewBean.getDefaultAddress().setFax(defaultAddress.getFax());
            retailerViewBean.getDefaultAddress().setEmail(defaultAddress.getEmail());
            retailerViewBean.getDefaultAddress().setWebsite(defaultAddress.getWebsite());
        }
    }

    retailerViewBean.setQualityOfService(retailer.getQualityOfService());
    retailerViewBean.setPriceScore(retailer.getPriceScore());
    retailerViewBean.setRatioQualityPrice(retailer.getRatioQualityPrice());

    int reviewCount = retailerViewBean.getComments().size();
    retailerViewBean.setReviewCount(reviewCount);
    Object[] reviewCountLabelParams = { reviewCount };
    retailerViewBean.setReviewCountLabel(
            getSpecificMessage(ScopeWebMessage.SOCIAL, "review_count_label", reviewCountLabelParams, locale));

    Set<RetailerCustomerComment> customerComments = retailer.getCustomerComments();
    if (Hibernate.isInitialized(customerComments) && customerComments != null) {
        for (RetailerCustomerComment customerComment : customerComments) {
            RetailerCustomerCommentViewBean customerCommentViewBean = buildViewBeanRetailerCustomerComment(
                    requestData, retailer, customerComment);
            retailerViewBean.getComments().add(customerCommentViewBean);
        }
    }

    //        // TAGS
    //        Set<RetailerTag> tags = retailer.getTags();
    //        if (Hibernate.isInitialized(tags) &&
    //                tags != null) {
    //            for (Iterator<RetailerTag> iterator = tags.iterator(); iterator.hasNext();) {
    //                RetailerTag retailerTag = (RetailerTag) iterator.next();
    //                RetailerTagViewBean retailerTagViewBean = new RetailerTagViewBean();
    //                retailerTagViewBean.setCode(retailerTag.getCode());
    //                retailerTagViewBean.setName(retailerTag.getName());
    //                retailerTagViewBean.setDescription(retailerTag.getDescription());
    //                retailerViewBean.getTags().add(retailerTagViewBean);
    //            }
    //        }

    final String contextNameValue = requestUtil.getCurrentContextNameValue();
    List<String> shareOptions = marketArea.getShareOptions(contextNameValue);
    if (shareOptions != null) {
        for (String shareOption : shareOptions) {
            String relativeUrl = urlService.generateUrl(FoUrls.RETAILER_DETAILS, requestData, retailer);
            ShareOptionViewBean shareOptionViewBean = buildViewBeanShareOption(requestData, shareOption,
                    relativeUrl);
            retailerViewBean.getShareOptions().add(shareOptionViewBean);
        }
    }

    DateFormat dateFormat = requestUtil.getCommonFormatDate(requestData, DateFormat.MEDIUM, DateFormat.MEDIUM);
    if (retailer.getDateCreate() != null) {
        retailerViewBean.setDateCreate(dateFormat.format(retailer.getDateCreate()));
    }

    if (retailer.getDateUpdate() != null) {
        retailerViewBean.setDateUpdate(dateFormat.format(retailer.getDateUpdate()));
    }

    // CLONE THE CURRENT REQUEST DATE TO BUILD THE CHANGE CONTEXT URL (MENU)
    RequestData requestDataChangecontext = new RequestData();
    BeanUtils.copyProperties(requestData, requestDataChangecontext);
    requestDataChangecontext.setMarketAreaRetailer(retailer);

    retailerViewBean.setChangeContextUrl(urlService.buildChangeContextUrl(requestDataChangecontext));
    retailerViewBean.setHomeUrl(urlService.generateUrl(FoUrls.HOME, requestDataChangecontext));

    retailerViewBean.setDetailsUrl(urlService.generateUrl(FoUrls.RETAILER_DETAILS, requestData, retailer));

    return retailerViewBean;
}

From source file:org.hoteia.qalingo.core.web.mvc.factory.ViewBeanFactory.java

public CmsContentBlockViewBean buildViewBeanCmsContentBlock(final RequestData requestData,
        final AbstractCmsEntity cmsEntity, final CmsContentBlock block) throws Exception {
    final MarketArea marketArea = requestData.getMarketArea();

    final CmsContentBlockViewBean blockViewBean = new CmsContentBlockViewBean();
    blockViewBean.setId(block.getId().toString());
    blockViewBean.setType(block.getType());
    blockViewBean.setOrdering(block.getOrdering());
    blockViewBean.setActive(block.isActive());

    if (Hibernate.isInitialized(block.getMarketArea()) && block.getMarketArea() != null) {
        blockViewBean.setMarketArea(buildViewBeanMarketArea(requestData, block.getMarketArea()));
    }/*  w  ww. j a v  a 2s . c  o m*/

    blockViewBean.setTitle(block.getTitle());
    blockViewBean.setText(block.getText());
    blockViewBean.setParams(block.getParams());

    // CMS CONTENT PARENT
    if (Hibernate.isInitialized(block.getCmsContent()) && block.getCmsContent() != null) {
        CmsContent clonedCmsContent = new CmsContent();
        BeanUtils.copyProperties(block.getCmsContent(), clonedCmsContent);
        clonedCmsContent.setBlocks(null);
        CmsContentViewBean parentViewBean = buildViewBeanCmsContent(requestData, clonedCmsContent);
        blockViewBean.setCmsContent(parentViewBean);
    }

    // LINK
    if (Hibernate.isInitialized(block.getLink()) && block.getLink() != null) {
        CmsContentLinkViewBean linkViewBean = buildViewBeanCmsContentLink(requestData, block.getLink());
        if (StringUtils.isEmpty(linkViewBean.getName())) {
            linkViewBean.setName(block.getTitle());
        }
        blockViewBean.setLink(linkViewBean);
    }

    // ASSETS
    if (block.getAssets() != null && Hibernate.isInitialized(block.getAssets())
            && block.getAssets().size() > 0) {
        for (Iterator<CmsContentAsset> iteratorCmsContentAsset = block.getSortedAssets()
                .iterator(); iteratorCmsContentAsset.hasNext();) {
            CmsContentAsset asset = (CmsContentAsset) iteratorCmsContentAsset.next();
            AssetViewBean assetViewBean = buildViewBeanCmsContentAsset(requestData, asset);
            final String path = engineSettingService.getCmsContentImageWebPath(cmsEntity, block, asset);
            assetViewBean.setRelativeWebPath(path);
            assetViewBean.setAbsoluteWebPath(urlService.buildAbsoluteUrl(requestData, path));
            blockViewBean.getAssets().add(assetViewBean);
        }
    }

    // BLOCK
    if (Hibernate.isInitialized(block.getCmsContentBlock()) && block.getCmsContentBlock() != null) {
        CmsContentBlock clonedCmsContentBlock = new CmsContentBlock();
        BeanUtils.copyProperties(block.getCmsContentBlock(), clonedCmsContentBlock);
        clonedCmsContentBlock.setBlocks(null);
        CmsContentBlockViewBean parentBlockViewBean = buildViewBeanCmsContentBlock(requestData, cmsEntity,
                clonedCmsContentBlock);
        blockViewBean.setCmsContentBlock(parentBlockViewBean);
    }
    if (Hibernate.isInitialized(block.getBlocks()) && block.getBlocks() != null) {
        for (Iterator<CmsContentBlock> iterator = block.getSortedCmsContentBlocks().iterator(); iterator
                .hasNext();) {
            CmsContentBlock subBlock = (CmsContentBlock) iterator.next();
            CmsContentBlockViewBean subBlockViewBean = buildViewBeanCmsContentBlock(requestData, cmsEntity,
                    subBlock);
            blockViewBean.getBlocks().add(subBlockViewBean);
        }
    }
    if (StringUtils.isNotEmpty(block.getType())) {
        if (block.getType().contains("PRODUCT_SELECTION_SMALL")
                || block.getType().contains("PRODUCT_SELECTION_MEDIUM")) {
            String[] productCodes = block.getParams().split(";");
            List<SpecificFetchMode> fetchplansProductMarketing = new ArrayList<SpecificFetchMode>();
            fetchplansProductMarketing
                    .add(new SpecificFetchMode(ProductMarketing_.productMarketingType.getName()));
            fetchplansProductMarketing.add(new SpecificFetchMode(ProductMarketing_.productBrand.getName()));
            fetchplansProductMarketing.add(new SpecificFetchMode(ProductMarketing_.attributes.getName()));
            fetchplansProductMarketing.add(new SpecificFetchMode(ProductMarketing_.assets.getName()));
            fetchplansProductMarketing.add(new SpecificFetchMode(ProductMarketing_.productSkus.getName()));
            fetchplansProductMarketing.add(new SpecificFetchMode(
                    ProductMarketing_.productSkus.getName() + "." + ProductSku_.assets.getName()));
            fetchplansProductMarketing.add(new SpecificFetchMode(ProductMarketing_.productSkus.getName() + "."
                    + ProductSku_.catalogCategoryVirtualProductSkuRels.getName()));
            fetchplansProductMarketing.add(new SpecificFetchMode(ProductMarketing_.productSkus.getName() + "."
                    + ProductSku_.catalogCategoryVirtualProductSkuRels.getName() + "."
                    + CatalogCategoryVirtualProductSkuRel_.pk.getName()));
            fetchplansProductMarketing.add(new SpecificFetchMode(ProductMarketing_.productSkus.getName() + "."
                    + ProductSku_.catalogCategoryVirtualProductSkuRels.getName() + "."
                    + CatalogCategoryVirtualProductSkuRel_.pk.getName() + "."
                    + CatalogCategoryVirtualProductSkuPk_.catalogCategoryVirtual.getName()));

            List<SpecificFetchMode> fetchplansProductSku = new ArrayList<SpecificFetchMode>();
            fetchplansProductSku.add(new SpecificFetchMode(ProductSku_.productMarketing.getName()));
            fetchplansProductSku.add(new SpecificFetchMode(
                    ProductSku_.productMarketing.getName() + "." + ProductMarketing_.productBrand.getName()));
            fetchplansProductSku.add(new SpecificFetchMode(ProductSku_.attributes.getName()));
            fetchplansProductSku.add(new SpecificFetchMode(ProductSku_.assets.getName()));
            fetchplansProductSku
                    .add(new SpecificFetchMode(ProductSku_.catalogCategoryVirtualProductSkuRels.getName()));
            fetchplansProductSku
                    .add(new SpecificFetchMode(ProductSku_.catalogCategoryVirtualProductSkuRels.getName() + "."
                            + CatalogCategoryVirtualProductSkuRel_.pk.getName()));
            fetchplansProductSku
                    .add(new SpecificFetchMode(ProductSku_.catalogCategoryVirtualProductSkuRels.getName() + "."
                            + CatalogCategoryVirtualProductSkuRel_.pk.getName() + "."
                            + CatalogCategoryVirtualProductSkuPk_.catalogCategoryVirtual.getName()));

            for (int i = 0; i < productCodes.length; i++) {
                String productMarketingCode = productCodes[i];
                ProductSku productSku = productService.getProductSkuByCode(productMarketingCode,
                        new FetchPlan(fetchplansProductSku));
                ProductMarketing productMarketing = null;
                ProductMarketingViewBean productMarketingViewBean = null;
                if (productSku != null) {
                    productMarketing = productService.getProductMarketingByCode(
                            productSku.getProductMarketing().getCode(),
                            new FetchPlan(fetchplansProductMarketing));
                    CatalogCategoryVirtual catalogCategoryVirtual = productSku
                            .getDefaultCatalogCategoryVirtual(marketArea.getCatalog());
                    ProductSkuViewBean productSkuViewBean = buildViewBeanProductSku(requestData, productSku);
                    productMarketingViewBean = buildViewBeanProductMarketing(requestData,
                            catalogCategoryVirtual, productMarketing, productSku);
                    // HACK : USE SKU AS DEFAULT ASSET
                    productMarketingViewBean.getDefaultAsset()
                            .setAbsoluteWebPath(productSkuViewBean.getDefaultAsset().getAbsoluteWebPath());
                } else {
                    productMarketing = productService.getProductMarketingByCode(productMarketingCode,
                            new FetchPlan(fetchplansProductMarketing));
                    productMarketingViewBean = buildViewBeanProductMarketing(requestData, productMarketing);
                }

                if (productMarketing != null) {
                    if (block.getType().contains("PRODUCT_SELECTION_SMALL")) {
                        if (productMarketingViewBean != null
                                && StringUtils.isNotEmpty(productMarketingViewBean.getDetailsUrl())) {
                            blockViewBean.getProductMarketings().add(productMarketingViewBean);
                        } else {
                            // HACK : CAT EMPTY
                            productSku = productMarketing.getDefaultProductSku();
                            if (productSku != null) {
                                CatalogCategoryVirtual catalogCategory = catalogCategoryService
                                        .getVirtualCatalogCategoryByCode("GLASSES",
                                                marketArea.getCatalog().getCode());
                                if (catalogCategory != null) {
                                    productMarketingViewBean.setDetailsUrl(
                                            urlService.generateUrl(FoUrls.PRODUCT_DETAILS, requestData,
                                                    catalogCategory, productMarketing, productSku));
                                }
                                if (productMarketingViewBean != null
                                        && StringUtils.isNotEmpty(productMarketingViewBean.getDetailsUrl())) {
                                    blockViewBean.getProductMarketings().add(productMarketingViewBean);
                                }
                            }
                        }
                    }
                    if (block.getType().contains("PRODUCT_SELECTION_MEDIUM")) {
                        if (productMarketingViewBean != null
                                && StringUtils.isNotEmpty(productMarketingViewBean.getDetailsUrl())) {
                            blockViewBean.getProductMarketings().add(productMarketingViewBean);
                        } else {
                            // HACK : CAT EMPTY
                            productSku = productMarketing.getDefaultProductSku();
                            if (productSku != null) {
                                CatalogCategoryVirtual catalogCategory = catalogCategoryService
                                        .getVirtualCatalogCategoryByCode("GLASSES",
                                                marketArea.getCatalog().getCode());
                                if (catalogCategory != null) {
                                    productMarketingViewBean.setDetailsUrl(
                                            urlService.generateUrl(FoUrls.PRODUCT_DETAILS, requestData,
                                                    catalogCategory, productMarketing, productSku));
                                }
                                if (productMarketingViewBean != null
                                        && StringUtils.isNotEmpty(productMarketingViewBean.getDetailsUrl())) {
                                    blockViewBean.getProductMarketings().add(productMarketingViewBean);
                                }
                            }
                        }
                    }
                }
            }

            if (block.getType().contains("STORE_SELECTION_MEDIUM")
                    || block.getType().contains("STORE_SELECTION_SMALL")) {
                GeolocData geolocData = requestData.getGeolocData();

                List<SpecificFetchMode> storeFetchPlans = new ArrayList<SpecificFetchMode>();
                storeFetchPlans.add(new SpecificFetchMode(Store_.attributes.getName()));
                storeFetchPlans.add(new SpecificFetchMode(Store_.assets.getName()));

                int maxStoreList = 5;
                List<GeolocatedStore> storeRandom = null;
                if (geolocData != null) {
                    storeRandom = new ArrayList<GeolocatedStore>();
                    int distance = 20;
                    storeRandom = retailerService.findRandomB2CStores(marketArea, geolocData, maxStoreList,
                            distance);
                    int escape = 10;
                    int retray = 0;
                    while (storeRandom == null || (storeRandom != null && storeRandom.size() < maxStoreList)) {
                        if (retray > escape) {
                            break;
                        }
                        storeRandom = retailerService.findRandomB2CStores(marketArea, geolocData, maxStoreList,
                                distance);
                        distance = distance + 15;
                        retray++;
                    }
                }

                List<Store> stores = new ArrayList<Store>();
                if (storeRandom != null) {
                    for (Iterator<GeolocatedStore> iterator = storeRandom.iterator(); iterator.hasNext();) {
                        GeolocatedStore geolocatedStore = (GeolocatedStore) iterator.next();
                        Store store = retailerService.getStoreById(geolocatedStore.getId(),
                                new FetchPlan(storeFetchPlans));
                        stores.add(store);
                    }
                } else {
                    // DEFAULT LIST : LIKE BOT WITHOUT GEOLOC
                    List<String> types = new ArrayList<String>();
                    types.add("OPTICIAN");
                    stores = retailerService.findB2CStoresByType(types, maxStoreList,
                            new FetchPlan(storeFetchPlans));
                }

                for (Store store : stores) {
                    Store reloadedStore = retailerService.getStoreByCode(store.getCode(),
                            new FetchPlan(storeFetchPlans));
                    if (store != null) {
                        if (block.getType().contains("STORE_SELECTION_MEDIUM")
                                && blockViewBean.getStores().size() < 5) {
                            StoreViewBean storeViewBean = buildViewBeanStore(requestData, reloadedStore);
                            if (storeViewBean != null
                                    && StringUtils.isNotEmpty(storeViewBean.getDetailsUrl())) {
                                blockViewBean.getStores().add(storeViewBean);
                            }
                        }
                        if (block.getType().contains("STORE_SELECTION_SMALL")
                                && blockViewBean.getStores().size() < 10) {
                            StoreViewBean storeViewBean = buildViewBeanStore(requestData, reloadedStore);
                            if (storeViewBean != null
                                    && StringUtils.isNotEmpty(storeViewBean.getDetailsUrl())) {
                                blockViewBean.getStores().add(storeViewBean);
                            }
                        }
                    }
                }
            }
        }

        DateFormat dateFormat = requestUtil.getCommonFormatDate(requestData, DateFormat.MEDIUM, null);
        if (block.getDateCreate() != null) {
            blockViewBean.setDateCreate(dateFormat.format(block.getDateCreate()));
        }
        if (block.getDateUpdate() != null) {
            blockViewBean.setDateUpdate(dateFormat.format(block.getDateUpdate()));
        }
    }

    return blockViewBean;
}

From source file:org.kuali.kfs.module.tem.document.service.impl.TravelDocumentServiceImpl.java

/**
 *
 * @see org.kuali.kfs.module.tem.document.service.TravelDocumentService#copyGroupTravelers(java.util.List, java.lang.String)
 *//*  w  w  w  .j a  v  a2  s .  c  om*/
@Override
public List<GroupTraveler> copyGroupTravelers(List<GroupTraveler> groupTravelers, String documentNumber) {
    List<GroupTraveler> newGroupTravelers = new ArrayList<GroupTraveler>();
    if (groupTravelers != null) {
        for (GroupTraveler groupTraveler : groupTravelers) {
            GroupTraveler newGroupTraveler = new GroupTraveler();
            BeanUtils.copyProperties(groupTraveler, newGroupTraveler);
            newGroupTraveler.setDocumentNumber(documentNumber);
            newGroupTraveler.setVersionNumber(new Long(1));
            newGroupTraveler.setObjectId(null);
            newGroupTraveler.setId(null);
            newGroupTravelers.add(newGroupTraveler);
        }
    }
    return newGroupTravelers;
}

From source file:org.kuali.kfs.module.tem.document.service.impl.TravelDocumentServiceImpl.java

/**
 *
 * @see org.kuali.kfs.module.tem.document.service.TravelDocumentService#copyActualExpenses(java.util.List, java.lang.String)
 *//*from   ww  w  .  j av  a2 s.c  o  m*/
@Override
public List<? extends TemExpense> copyActualExpenses(List<? extends TemExpense> actualExpenses,
        String documentNumber) {
    List<ActualExpense> newActualExpenses = new ArrayList<ActualExpense>();

    if (actualExpenses != null) {
        for (TemExpense expense : actualExpenses) {
            ActualExpense actualExpense = (ActualExpense) expense;
            ActualExpense newActualExpense = new ActualExpense();
            boolean nullCheck = false;
            if (actualExpense.getExpenseDate() == null) {
                nullCheck = true;
                actualExpense.setExpenseDate(new Date(0));
            }
            BeanUtils.copyProperties(actualExpense, newActualExpense);
            if (nullCheck) {
                actualExpense.setExpenseDate(null);
                newActualExpense.setExpenseDate(null);
            }

            List<TemExpense> newDetails = (List<TemExpense>) this
                    .copyActualExpenses(actualExpense.getExpenseDetails(), documentNumber);
            newActualExpense.setExpenseDetails(newDetails);
            newActualExpense.setDocumentNumber(documentNumber);
            newActualExpense.setVersionNumber(new Long(1));
            newActualExpense.setId(null);
            newActualExpense.setObjectId(null);
            newActualExpenses.add(newActualExpense);
        }
    }
    return newActualExpenses;
}

From source file:org.kuali.kfs.module.tem.document.service.impl.TravelDocumentServiceImpl.java

/**
 *
 * @see org.kuali.kfs.module.tem.document.service.TravelDocumentService#copyPerDiemExpenses(java.util.List, java.lang.String)
 *//*  ww  w  .j av a 2s  .  c o  m*/
@Override
public List<PerDiemExpense> copyPerDiemExpenses(List<PerDiemExpense> perDiemExpenses, String documentNumber) {
    List<PerDiemExpense> newPerDiemExpenses = new ArrayList<PerDiemExpense>();
    if (perDiemExpenses != null) {
        for (PerDiemExpense expense : perDiemExpenses) {
            PerDiemExpense newExpense = new PerDiemExpense();
            BeanUtils.copyProperties(expense, newExpense);
            newExpense.setBreakfastValue(expense.getBreakfastValue());
            newExpense.setLunchValue(expense.getLunchValue());
            newExpense.setDinnerValue(expense.getDinnerValue());
            newExpense.setIncidentalsValue(expense.getIncidentalsValue());
            newExpense.setDocumentNumber(documentNumber);
            newExpense.setVersionNumber(new Long(1));
            newExpense.setObjectId(null);
            newExpense.setId(null);
            newPerDiemExpenses.add(newExpense);
        }
    }
    return newPerDiemExpenses;
}

From source file:org.kuali.kfs.module.tem.document.service.impl.TravelDocumentServiceImpl.java

/**
 *
 * @see org.kuali.kfs.module.tem.document.service.TravelDocumentService#copySpecialCircumstances(java.util.List, java.lang.String)
 *//*from  w  w  w . j  av a  2s .  co  m*/
@Override
public List<SpecialCircumstances> copySpecialCircumstances(List<SpecialCircumstances> specialCircumstancesList,
        String documentNumber) {
    List<SpecialCircumstances> newSpecialCircumstancesList = new ArrayList<SpecialCircumstances>();
    if (specialCircumstancesList != null) {
        for (SpecialCircumstances specialCircumstances : specialCircumstancesList) {
            SpecialCircumstances newSpecialCircumstances = new SpecialCircumstances();
            BeanUtils.copyProperties(specialCircumstances, newSpecialCircumstances);
            newSpecialCircumstances.setDocumentNumber(documentNumber);
            newSpecialCircumstances.setVersionNumber(new Long(1));
            newSpecialCircumstances.setObjectId(null);
            newSpecialCircumstances.setId(null);
            newSpecialCircumstancesList.add(newSpecialCircumstances);
        }
    }
    return newSpecialCircumstancesList;
}

From source file:org.kuali.kfs.module.tem.document.service.impl.TravelDocumentServiceImpl.java

/**
 * @see org.kuali.kfs.module.tem.document.service.TravelDocumentService#copyTransportationModeDetails(java.util.List, java.lang.String)
 *///from  w ww  .  ja  v  a2 s .  c  o  m
@Override
public List<TransportationModeDetail> copyTransportationModeDetails(
        List<TransportationModeDetail> transportationModeDetails, String documentNumber) {
    List<TransportationModeDetail> newTransportationModeDetails = new ArrayList<TransportationModeDetail>();
    if (transportationModeDetails != null) {
        for (TransportationModeDetail detail : transportationModeDetails) {
            TransportationModeDetail newDetail = new TransportationModeDetail();
            BeanUtils.copyProperties(detail, newDetail);
            newDetail.setDocumentNumber(documentNumber);
            newDetail.setVersionNumber(new Long(1));
            newDetail.setObjectId(null);
            newTransportationModeDetails.add(newDetail);
        }
    }
    return newTransportationModeDetails;
}