/**
*
*/
public RetailerViewBean buildViewBeanRetailer(final RequestData requestData, final Retailer retailer) throws Exception {
final HttpServletRequest request = requestData.getRequest();
final MarketArea marketArea = requestData.getMarketArea();
final Localization localization = requestData.getMarketAreaLocalization();
final String localizationCodeNavigation = localization.getCode();
final Locale locale = requestData.getLocale();
final RetailerViewBean retailerViewBean = new RetailerViewBean();
retailerViewBean.setCode(retailer.getCode());
retailerViewBean.setName(retailer.getName());
retailerViewBean.setI18nName(retailer.getI18nName(localizationCodeNavigation));
retailerViewBean.setDescription(retailer.getDescription());
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().setCountryLabel(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());
String websiteUrl = defaultAddress.getWebsite();
if (StringUtils.isNotEmpty(websiteUrl) && !websiteUrl.contains("http")) {
websiteUrl = "http://" + websiteUrl;
}
retailerViewBean.getDefaultAddress().setWebsite(websiteUrl);
}
}
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 (Iterator<RetailerCustomerComment> iterator = customerComments.iterator(); iterator.hasNext();) {
RetailerCustomerComment retailerCustomerComment = (RetailerCustomerComment) iterator.next();
RetailerCustomerCommentViewBean retailerCustomerCommentViewBean = new RetailerCustomerCommentViewBean();
retailerCustomerCommentViewBean.setCustomerDisplayName(retailerCustomerComment.getCustomer().getScreenName());
retailerCustomerCommentViewBean.setCustomerUrl(urlService.buildCustomerDetailsUrl(requestData, retailerCustomerComment.getCustomer().getPermalink()));
retailerCustomerCommentViewBean.setCustomerAvatarImg(requestUtil.getCustomerAvatar(requestData.getRequest(), retailerCustomerComment.getCustomer()));
DateFormat dateFormat = requestUtil.getFormatDate(requestData, DateFormat.MEDIUM, DateFormat.MEDIUM);
if (retailerCustomerComment.getDateCreate() != null) {
retailerCustomerCommentViewBean.setDateCreate(dateFormat.format(retailerCustomerComment.getDateCreate()));
}
retailerCustomerCommentViewBean.setComment(retailerCustomerComment.getComment());
ReviewDataVocabularyPojo reviewDataVocabulary = new ReviewDataVocabularyPojo();
reviewDataVocabulary.setItemreviewed(retailer.getName());
reviewDataVocabulary.setReviewer(retailerCustomerComment.getCustomer().getScreenName());
DateFormat dateFormatDataVocabulary = requestUtil.getDataVocabularyFormatDate(requestData);
reviewDataVocabulary.setDtreviewed(dateFormat.format(retailerCustomerComment.getDateCreate()));
// reviewDataVocabulary.setSummary(summary);
reviewDataVocabulary.setDescription(retailerCustomerComment.getComment());
// reviewDataVocabulary.setRating(rating);
retailerCustomerCommentViewBean.setReviewDataVocabulary(reviewDataVocabulary);
retailerViewBean.getComments().add(retailerCustomerCommentViewBean);
}
}
Set<RetailerTag> tags = retailer.getRetailerTags();
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);
}
}
Set<Store> stores = retailer.getStores();
if (Hibernate.isInitialized(stores) &&
stores != null) {
for (Iterator<Store> iterator = stores.iterator(); iterator.hasNext();) {
Store store = (Store) iterator.next();
StoreViewBean storeViewBean = buildViewBeanStore(requestData, store);
retailerViewBean.getStores().add(storeViewBean);
}
}
final String contextNameValue = requestUtil.getCurrentContextNameValue(request);
List<String> shareOptions = marketArea.getShareOptions(contextNameValue);
if (shareOptions != null) {
for (Iterator<String> iterator = shareOptions.iterator(); iterator.hasNext();) {
String shareOption = (String) iterator.next();
String relativeUrl = urlService.generateUrl(FoUrls.RETAILER_DETAILS, requestData, retailer);
ShareOptionViewBean shareOptionViewBean = buildViewBeanShareOption(requestData, shareOption, relativeUrl);