public Company getCompanyById(final Long companyId, Object... params) { Criteria criteria = createDefaultCriteria(Company.class); FetchPlan fetchPlan = handleCompanySpecificFetchMode(criteria, params); criteria.add(Restrictions.eq("id", companyId)); Company company = (Company) criteria.uniqueResult(); if (company != null) { company.setFetchPlan(fetchPlan); } return company; }
public Company saveOrUpdateCompany(Company company) { if (company.getDateCreate() == null) { company.setDateCreate(new Date()); } company.setDateUpdate(new Date()); if (company.getId() != null) { if (em.contains(company)) { em.refresh(company); } Company mergedCompany = em.merge(company); em.flush(); return mergedCompany; } else { em.persist(company); return company; } }
@Override public void postHandle( HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { try { final RequestData requestData = requestUtil.getRequestData(request); // THEME User user = requestData.getUser(); if (user != null) { final Company company = user.getCompany(); if (company != null && StringUtils.isNotEmpty(company.getTheme())) { String themeFolder = company.getTheme(); requestUtil.updateCurrentTheme(request, themeFolder); } } } catch (Exception e) { logger.error("inject common datas failed", 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); } }