public void generateOrderConfirmation(final OrderCustomer order) { try { final MarketArea marketArea = marketService.getMarketAreaById(order.getMarketAreaId()); final Localization localization = localizationService.getLocalizationById(order.getLocalizationId()); final Locale locale = localization.getLocale(); // WE SET TO NULL USELESS DATA - BETTER WAY SHOULD BE TO USE A SPECIFIC DOZER RULE for (Iterator<OrderItem> iterator = order.getOrderItems().iterator(); iterator.hasNext(); ) { OrderItem orderItem = (OrderItem) iterator.next(); orderItem.getProductSku().setPrices(null); orderItem.getProductSku().setStocks(null); orderItem.getProductSku().setProductMarketing(null); orderItem.getProductSku().setRetailers(null); } final OrderCustomerPojo orderCustomerPojo = orderPojoService.handleOrderMapping(order); final String jrxml = getOrderConfirmationTemplateByMarketArea(marketArea); File fileJrxml = new File(jrxml); final String resourcePath = jrxml.replace(fileJrxml.getName(), ""); final JasperReport jasperReport = JasperCompileManager.compileReport(jrxml); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("RESOURCE_PATH", resourcePath); parameters.put("RECORD_DELIMITER", "\r\n"); parameters.put("order", orderCustomerPojo); Object[] orderInformationsParams = {orderCustomerPojo.getOrderNum()}; parameters.put( "orderInformations", coreMessageSource.getDocumentMessage( ScopeDocumentMessage.ORDER_CONFIRMATION, "header_order_informations", orderInformationsParams, locale)); parameters.put("date", orderCustomerPojo.getDateUpdate().toString()); parameters.put("billingAddress", orderCustomerPojo.getBillingAddress()); parameters.put("shippingAddress", orderCustomerPojo.getShippingAddress()); Map<String, String> wording = coreMessageSource.loadWording(I18nKeyValueUniverse.DOCUMENT.getPropertyKey(), locale); parameters.put("wording", wording); List<OrderItem> orderItems = new ArrayList<OrderItem>(); Set<OrderShipment> orderShipments = orderCustomerPojo.getOrderShipments(); for (Iterator<OrderShipment> iterator = orderShipments.iterator(); iterator.hasNext(); ) { OrderShipment orderShipment = (OrderShipment) iterator.next(); orderItems.addAll(orderShipment.getOrderItems()); } // TODO : denis : one page/table by OrderShipment JRDataSource datasource = new JRBeanCollectionDataSource(orderItems, true); final JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, datasource); String fullFilePath = getOrderConfirmationFilePath(order); JasperExportManager.exportReportToPdfFile(jasperPrint, fullFilePath); } catch (Exception e) { logger.error("", e); } }
@Override public void postHandle( HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { try { final RequestData requestData = requestUtil.getRequestData(request); final Locale locale = requestData.getLocale(); modelAndView .getModelMap() .put( ModelConstants.COMMON_VIEW_BEAN, backofficeViewBeanFactory.buildViewBeanCommon(requestData)); modelAndView .getModelMap() .put( ModelConstants.SECURITY_VIEW_BEAN, backofficeViewBeanFactory.buildViewBeanSecurity(requestUtil.getRequestData(request))); final MarketPlace currentMarketPlace = requestData.getMarketPlace(); final Market currentMarket = requestData.getMarket(); final MarketArea currentMarketArea = requestData.getMarketArea(); final Localization currentLocalization = requestData.getMarketAreaLocalization(); final User user = requestData.getUser(); final Company company = requestData.getCompany(); if (user != null) { modelAndView .getModelMap() .put( ModelConstants.AUTHENTICATED_USER_VIEW_BEAN, backofficeViewBeanFactory.buildViewBeanUser(requestData, user)); } modelAndView .getModelMap() .put( ModelConstants.LEGAl_TERMS_VIEW_BEAN, backofficeViewBeanFactory.buildViewBeanLegalTerms(requestData)); modelAndView .getModelMap() .put( ModelConstants.HEADER_CART, backofficeViewBeanFactory.buildViewBeanHeaderCart(requestData)); // ALL MARKETPLACES modelAndView .getModelMap() .put( ModelConstants.MARKET_PLACES_VIEW_BEAN, backofficeViewBeanFactory.buildListViewBeanMarketPlace(requestData)); // MARKETS FOR THE CURRENT MARKETPLACE Set<Market> marketList = currentMarketPlace.getMarkets(); modelAndView .getModelMap() .put( ModelConstants.MARKETS_VIEW_BEAN, backofficeViewBeanFactory.buildListViewBeanMarket( requestData, currentMarketPlace, new ArrayList<Market>(marketList))); // MARKET AREAS FOR THE CURRENT MARKET Set<MarketArea> marketAreaList = currentMarket.getMarketAreas(); modelAndView .getModelMap() .put( ModelConstants.MARKET_AREAS_VIEW_BEAN, backofficeViewBeanFactory.buildListViewBeanMarketArea( requestData, currentMarket, new ArrayList<MarketArea>(marketAreaList))); // LOCALIZATIONS FOR THE CURRENT MARKET AREA modelAndView .getModelMap() .put( ModelConstants.MARKET_AREA_LANGUAGES_VIEW_BEAN, backofficeViewBeanFactory.buildListViewBeanLocalizationByMarketArea( requestData, currentLocalization)); // RETAILERS FOR THE CURRENT MARKET AREA modelAndView .getModelMap() .put( ModelConstants.MARKET_AREA_RETAILERS_VIEW_BEAN, backofficeViewBeanFactory.buildListViewBeanRetailerByMarketArea(requestData)); // CURRENCIES FOR THE CURRENT MARKET AREA modelAndView .getModelMap() .put( ModelConstants.MARKET_AREA_CURRENCIES_VIEW_BEAN, backofficeViewBeanFactory.buildListViewBeanCurrenciesByMarketArea(requestData)); // CURRENT MARKET AREA modelAndView .getModelMap() .put( ModelConstants.MARKET_AREA_VIEW_BEAN, backofficeViewBeanFactory.buildViewBeanMarketArea(requestData, currentMarketArea)); // BACKOFFICE LOCALIZATIONS List<Localization> backofficeLocalizations = new ArrayList<Localization>(); if (company != null) { backofficeLocalizations = new ArrayList<Localization>(company.getLocalizations()); } else { backofficeLocalizations.add(localizationService.getLocalizationByCode("en")); backofficeLocalizations.add(localizationService.getLocalizationByCode("fr")); } modelAndView .getModelMap() .put( ModelConstants.BACKOFFICE_LOCALIZATION_VIEW_BEAN, backofficeViewBeanFactory.buildListViewBeanLocalization( requestData, backofficeLocalizations)); // HEADER modelAndView .getModelMap() .put( ModelConstants.HEADER_MENUS_VIEW_BEAN, backofficeViewBeanFactory.buildListViewBeanHeaderMenu(requestData)); modelAndView .getModelMap() .put( ModelConstants.MORE_PAGE_MENUS_VIEW_BEAN, backofficeViewBeanFactory.buildListViewBeanMorePageMenu(requestData)); // FOOTER modelAndView .getModelMap() .put( ModelConstants.FOOTER_MENUS_VIEW_BEAN, backofficeViewBeanFactory.buildListViewBeanFooterMenu(requestData)); String contextName = requestUtil.getContextName(); try { String contextValue = PropertiesUtil.getWebappContextKey(contextName); modelAndView .getModelMap() .addAttribute( ModelConstants.WORDING, coreMessageSource.loadWordingByContext(contextValue, locale)); } catch (Exception e) { logger.error( "Context name, " + contextName + " can't be resolve by EngineSettingWebAppContext class.", e); } } catch (Exception e) { logger.error("inject common datas failed", e); } }