Example usage for org.apache.commons.lang BooleanUtils toBoolean

List of usage examples for org.apache.commons.lang BooleanUtils toBoolean

Introduction

In this page you can find the example usage for org.apache.commons.lang BooleanUtils toBoolean.

Prototype

public static boolean toBoolean(String str) 

Source Link

Document

Converts a String to a boolean (optimised for performance).

'true', 'on' or 'yes' (case insensitive) will return true.

Usage

From source file:org.hoteia.qalingo.core.service.EngineSettingService.java

public boolean getEmailFileMirroringActivated(String context) {
    EngineSetting engineSetting = getSettingEmailFileMirroringActivated();
    boolean emailFileMirroringActivated = false;
    if (engineSetting != null) {
        emailFileMirroringActivated = BooleanUtils.toBoolean(engineSetting.getDefaultValue());
        EngineSettingValue engineSettingValue = engineSetting.getEngineSettingValue(context);
        if (engineSettingValue != null) {
            emailFileMirroringActivated = BooleanUtils.toBoolean(engineSettingValue.getValue());
        }/* w  ww.  j  a  v a2 s  .c o m*/
    }
    return emailFileMirroringActivated;
}

From source file:org.hoteia.qalingo.core.web.mvc.controller.security.LoginController.java

@RequestMapping(BoUrls.LOGIN_URL)
public ModelAndView login(final HttpServletRequest request, final Model model) throws Exception {
    ModelAndViewThemeDevice modelAndView = new ModelAndViewThemeDevice(getCurrentVelocityPath(request),
            BoUrls.LOGIN.getVelocityPage());
    final RequestData requestData = requestUtil.getRequestData(request);
    final Locale locale = requestData.getLocale();

    // SANITY CHECK: User logged
    if (securityUtil.isAuthenticated()) {
        final String url = backofficeUrlService.generateRedirectUrl(BoUrls.HOME,
                requestUtil.getRequestData(request));
        return new ModelAndView(new RedirectView(url));
    }/*from ww w .ja  v a  2  s.c o  m*/

    // SANITY CHECK : Param from spring-security
    String error = request.getParameter(RequestConstants.REQUEST_PARAMETER_AUTH_ERROR);
    if (BooleanUtils.toBoolean(error)) {
        model.addAttribute(ModelConstants.AUTH_HAS_FAIL, BooleanUtils.toBoolean(error));
        model.addAttribute(ModelConstants.AUTH_ERROR_MESSAGE,
                getCommonMessage(ScopeCommonMessage.AUTH, "login_or_password_are_wrong", locale));
    }

    return modelAndView;
}

From source file:org.hoteia.qalingo.core.web.mvc.interceptor.PageModelDataHandlerInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    try {//from w w  w . j a  va 2s.co m
        final RequestData requestData = requestUtil.getRequestData(request);
        final GeolocData geolocData = requestData.getGeolocData();
        final MarketPlace currentMarketPlace = requestData.getMarketPlace();
        final MarketArea currentMarketArea = requestData.getMarketArea();
        final Localization currentLocalization = requestData.getMarketAreaLocalization();
        final Locale locale = requestData.getLocale();
        final Customer customer = requestData.getCustomer();
        final String currentUrl = requestUtil.getCurrentRequestUrl(request);

        if (modelAndView != null) {
            String requestParamMinifyAssets = request.getParameter("minifyAssets");
            if (StringUtils.isNotEmpty(requestParamMinifyAssets)) {
                request.getSession().setAttribute("minifyAssets", requestParamMinifyAssets);
            }
            String sessionMinifyAssets = (String) request.getSession().getAttribute("minifyAssets");
            if (StringUtils.isNotEmpty(sessionMinifyAssets)) {
                modelAndView.getModelMap().put("minifyAssets", BooleanUtils.toBoolean(sessionMinifyAssets));
            } else {
                modelAndView.getModelMap().put("minifyAssets", minifyAssets);
            }

            modelAndView.getModelMap().put("assetsVersion", assetsVersion);

            // SANITY CHECK : Controle MarketArea
            String referer = request.getHeader(Constants.REFERER);

            if (StringUtils.isEmpty(referer) || !referer.contains("coloroptical.com")) {
                // VISITOR COME FROM OTHER WEBSITE : check the target
                if (geolocData != null && geolocData.getCountry() != null && currentMarketArea != null
                        && StringUtils.isNotEmpty(geolocData.getCountry().getIsoCode()) && !geolocData
                                .getCountry().getIsoCode().equals(currentMarketArea.getGeolocCountryCode())) {
                    // TARGET IS NOT THE GEOLOCATED MARKET AREA
                    String targetUrl = request.getRequestURI().replace(request.getContextPath(), "");

                    //                     System.out.println("need redirect modal");
                    //                     System.out.println("targetUrl: " + targetUrl);

                    MarketArea marketAreaGeoloc = null;
                    List<MarketArea> marketAreas = marketService
                            .findMarketAreaOpenedByGeolocCountryCode(geolocData.getCountry().getIsoCode());
                    if (marketAreas != null) {
                        if (marketAreas.size() == 1) {
                            marketAreaGeoloc = marketAreas.get(0);
                        } else {
                            // WE HAVE MANY MARKET AREA FOR THE CURRENT COUNTRY CODE - WE SELECT THE DEFAULT MARKET PLACE ASSOCIATE
                            for (MarketArea marketAreaIt : marketAreas) {
                                if (marketAreaIt.getMarket().getMarketPlace().isDefault()) {
                                    marketAreaGeoloc = marketAreaIt;
                                }
                            }
                        }

                        String context = "/" + marketAreaGeoloc.getCode() + "/"
                                + marketAreaGeoloc.getDefaultLocalization().getCode() + "/";
                        String newSegmentl = urlService
                                .getSeoSegmentMain(marketAreaGeoloc.getDefaultLocalization().getLocale(), true);
                        String[] splits = request.getRequestURI().split("/");
                        String target = "";
                        int count = 0;
                        for (String split : splits) {
                            if (count == (splits.length - 1)) {
                                target = split;
                            }
                            count++;
                        }

                        String newUrl = context.toLowerCase() + newSegmentl + "/" + target;
                        String newAbsoluteUrl = urlService.buildAbsoluteUrl(requestData, newUrl);
                        logger.debug("Redirect to: " + newAbsoluteUrl);

                        try {
                            // TEST TARGET URL
                            URL obj = new URL(newAbsoluteUrl);
                            HttpURLConnection con = (HttpURLConnection) obj.openConnection();
                            con.setRequestMethod("GET");
                            con.setRequestProperty("User-Agent", request.getHeader("User-Agent"));
                            int responseCode = con.getResponseCode();
                            if (responseCode != 200) {
                                logger.debug("Url is not OK/200, url: " + newAbsoluteUrl);
                                MarketAreaViewBean marketAreaGeolocViewBean = frontofficeViewBeanFactory
                                        .buildViewBeanMarketArea(requestData, currentMarketArea);
                                newAbsoluteUrl = urlService.buildAbsoluteUrl(requestData,
                                        marketAreaGeolocViewBean.getChangeContextUrl());
                                logger.debug("Switch URL target, new url: " + newAbsoluteUrl);
                            }

                        } catch (Exception e) {
                            // TODO: handle exception
                        }

                        modelAndView.getModelMap().put("newAbsoluteUrl", newAbsoluteUrl);
                        modelAndView.getModelMap().put("redirectMarketArea", true);
                        modelAndView.getModelMap().put("redirectMarketAreaCountry", referentialDataService
                                .getCountryByLocale(geolocData.getCountry().getIsoCode(), locale));
                        modelAndView.getModelMap().put("targetMarketAreaCountry", referentialDataService
                                .getCountryByLocale(currentMarketArea.getGeolocCountryCode(), locale));

                    } else {
                        logger.debug("There is no MarketArea for this country:"
                                + geolocData.getCountry().getIsoCode());

                    }
                }
            }

            boolean displayHttpsNavBarMessage = false;
            if (currentUrl.contains("login")) {
                displayHttpsNavBarMessage = true;
            }
            Cookie[] cookies = request.getCookies();
            if (cookies != null) {
                Cookie navBarMessageCookie = null;
                boolean found = false;
                String navBarMessageName = cookiePrefix + "_NAV_BAR_MESSAGE";
                for (Cookie cookie : cookies) {
                    if (navBarMessageName.equals(cookie.getName())) {
                        navBarMessageCookie = cookie;
                        found = true;
                        break;
                    }
                }
                if (found && navBarMessageCookie.getValue().equals("hide")) {
                    displayHttpsNavBarMessage = false;
                }
            }
            modelAndView.getModelMap().put("displayHttpsNavBarMessage", displayHttpsNavBarMessage);

            if (geolocData != null && geolocData.getCity() != null
                    && StringUtils.isNotEmpty(geolocData.getCity().getName())) {
                modelAndView.getModelMap().addAttribute("cityName", geolocData.getCity().getName());
                modelAndView.getModelMap().addAttribute("isGeolocated", true);
            }

            modelAndView.getModelMap().put(ModelConstants.LEGAl_TERMS_VIEW_BEAN,
                    frontofficeViewBeanFactory.buildViewBeanLegalTerms(requestData));

            modelAndView.getModelMap().put(ModelConstants.HEADER_CART,
                    frontofficeViewBeanFactory.buildViewBeanHeaderCart(requestData));

            // MARKETS FOR THE CURRENT MARKETPLACE
            Set<Market> marketList = currentMarketPlace.getMarkets();
            List<MarketAreaViewBean> allMarketAreaViewBeans = new ArrayList<MarketAreaViewBean>();
            for (Market market : marketList) {
                Set<MarketArea> marketAreaList = market.getMarketAreas();
                for (MarketArea marketArea : marketAreaList) {
                    if (marketArea.isOpened()) {
                        MarketArea reloadedMarketArea = marketService.getMarketAreaById(marketArea.getId());
                        MarketAreaViewBean marketAreaViewBean = frontofficeViewBeanFactory
                                .buildViewBeanMarketArea(requestData, reloadedMarketArea);
                        if (currentMarketArea.getId().equals(reloadedMarketArea.getId())) {
                            marketAreaViewBean.setActive(true);
                        }
                        allMarketAreaViewBeans.add(marketAreaViewBean);
                    }
                }
            }

            // MARKET AREAS FOR THE CURRENT MARKET
            modelAndView.getModelMap().put(ModelConstants.MARKET_AREAS_VIEW_BEAN, allMarketAreaViewBeans);

            // CURRENT MARKET AREA
            modelAndView.getModelMap().put(ModelConstants.MARKET_AREA_VIEW_BEAN,
                    frontofficeViewBeanFactory.buildViewBeanMarketArea(requestData, currentMarketArea));

            // LOCALIZATIONS FOR THE CURRENT MARKET AREA
            modelAndView.getModelMap().put("marketAreaLocalization",
                    frontofficeViewBeanFactory.buildViewBeanLocalization(requestData, currentLocalization));
            modelAndView.getModelMap().put(ModelConstants.MARKET_AREA_LANGUAGES_VIEW_BEAN,
                    frontofficeViewBeanFactory.buildListViewBeanLocalizationByMarketArea(requestData,
                            currentLocalization));

            // RETAILERS FOR THE CURRENT MARKET AREA
            modelAndView.getModelMap().put(ModelConstants.MARKET_AREA_RETAILERS_VIEW_BEAN,
                    frontofficeViewBeanFactory.buildListViewBeanRetailerByMarketArea(requestData));

            // CURRENCIES FOR THE CURRENT MARKET AREA
            modelAndView.getModelMap().put(ModelConstants.MARKET_AREA_CURRENCIES_VIEW_BEAN,
                    frontofficeViewBeanFactory.buildListViewBeanCurrenciesByMarketArea(requestData));

            // HEADER
            modelAndView.getModelMap().put(ModelConstants.HEADER_NAVS_VIEW_BEAN,
                    frontofficeViewBeanFactory.buildListViewBeanHeaderNav(requestData));
            modelAndView.getModelMap().put(ModelConstants.HEADER_MENUS_VIEW_BEAN,
                    frontofficeViewBeanFactory.buildListViewBeanCmsMenus(requestData));

            // FOOTER
            modelAndView.getModelMap().put(ModelConstants.FOOTER_MENUS_VIEW_BEAN,
                    frontofficeViewBeanFactory.buildListViewBeanFooterMenu(requestData));
            modelAndView.getModelMap().put(ModelConstants.FOOTER_NAVS_VIEW_BEAN,
                    frontofficeViewBeanFactory.buildListViewBeanFooterNav(requestData));

            //TODO a remonter dans CommonViewBean
            modelAndView.getModelMap().put("checkoutShoppingCartUrl",
                    urlService.generateUrl(FoUrls.CART_DETAILS, requestData));

            final List<Long> lastCmsContentIds = cmsContentService.findLastActiveCmsContentIds(
                    CmsContent.APP_NAME_FRONTOFFICE_B2C, "ARTICLE", currentMarketArea.getId(),
                    currentLocalization.getId(), 20);
            final List<CmsContent> reloadedCmsContents = new ArrayList<CmsContent>();
            final Date now = new Date();
            for (Iterator<Long> iterator = lastCmsContentIds.iterator(); iterator.hasNext();) {
                Long cmsContentId = (Long) iterator.next();
                if (reloadedCmsContents.size() == 9) {
                    // WE HAVE LOAD 20 items WITHOUT PARAM PUBLISH DATE, WE FILTER AFTER 
                    // TODO : specific query to load 9 items already publish and active
                    break;
                }
                CmsContent reloadedCmsContent = cmsContentService.getCmsContentById(cmsContentId);
                if (reloadedCmsContent.getDatePublish().getTime() < now.getTime()) {
                    reloadedCmsContents.add(reloadedCmsContent);
                }
            }
            final List<CmsContentViewBean> cmsContentViewBeans = frontofficeViewBeanFactory
                    .buildListViewBeanCmsContent(requestData, reloadedCmsContents);
            if (cmsContentViewBeans != null && !cmsContentViewBeans.isEmpty()) {
                modelAndView.getModelMap().put("footerLastArticles", cmsContentViewBeans);
            }
            modelAndView.getModelMap().put("allArticleUrl",
                    urlService.generateUrl(FoUrls.ARTICLES, requestData));

            // GEOLOC
            //                if(requestData.getGeolocData() != null){
            //                    modelAndView.getModelMap().put(ModelConstants.GEOLOC_REMOTE_ADDRESS, requestData.getGeolocData().getRemoteAddress());
            //                    modelAndView.getModelMap().put(ModelConstants.GEOLOC_COUNTRY, requestData.getGeolocData().getCountry());
            //                    modelAndView.getModelMap().put(ModelConstants.GEOLOC_CITY, requestData.getGeolocData().getCity());
            //                }

            // APP NAME
            modelAndView.getModelMap().addAttribute(Constants.APP_NAME, requestUtil.getAppName(request));
            Object[] appNameParams = { StringUtils.capitalize(requestUtil.getApplicationName()) };
            modelAndView.getModelMap().addAttribute(Constants.APP_NAME_HTML, coreMessageSource.getCommonMessage(
                    ScopeCommonMessage.APP.getPropertyKey(), "name_html", appNameParams, locale));

            modelAndView.getModelMap().addAttribute(ModelConstants.LOCALE_LANGUAGE_CODE, locale.getLanguage());
            modelAndView.getModelMap().addAttribute(ModelConstants.CONTEXT_PATH, request.getContextPath());
            modelAndView.getModelMap().addAttribute(ModelConstants.THEME, requestUtil.getCurrentTheme(request));
            Object[] params = { StringUtils.capitalize(requestUtil.getEnvironmentName()) };
            modelAndView.getModelMap().addAttribute(ModelConstants.ENV_NAME,
                    coreMessageSource.getSpecificMessage(I18nKeyValueUniverse.FO.getPropertyKey(),
                            ScopeWebMessage.COMMON.getPropertyKey(), "header.env.name", params, locale));

            if (!modelAndView.getModelMap().containsAttribute(ModelConstants.SEO_DATA_VIEW_BEAN)) {
                SeoDataViewBean seoData = frontofficeViewBeanFactory.buildViewSeoData(requestData);
                if (modelAndView.getModelMap().containsAttribute(ModelConstants.PAGE_TITLE)) {
                    String pageTitle = (String) modelAndView.getModelMap().get(ModelConstants.PAGE_TITLE);
                    seoData.setMetaOgTitle(pageTitle);
                    seoData.setPageTitle(pageTitle);
                }
                modelAndView.getModelMap().put(ModelConstants.SEO_DATA_VIEW_BEAN, seoData);
            }

            modelAndView.getModelMap().put(ModelConstants.URL_SUBMIT_QUICK_SEARCH,
                    urlService.generateUrl(FoUrls.CATALOG_SEARCH, requestUtil.getRequestData(request)));

            String currentRequestUrl = requestUtil.getCurrentRequestUrl(request);
            if (modelAndView.getModelMap().get(ModelConstants.ALTERNATE_LINKS_VIEW_BEAN) == null) {
                System.out.println("!!!!! THIS URL NEED AN alternate: " + currentRequestUrl);
            }
            //              // Alternate Links
            //              if(modelAndView.getModelMap().get(ExtModelConstants.ALTERNATE_LINKS_VIEW_BEAN) == null){
            //                  String currentRequestUrl = requestUtil.getCurrentRequestUrl(request);
            //                  List<HeadLinkViewBean> alternateLinks = new ArrayList<HeadLinkViewBean>();
            //                  if(currentRequestUrl.contains("article")){
            //                     
            //                  } else {
            //                     // default
            //                      for (MarketAreaViewBean marketAreaViewBean : allMarketAreaViewBeans) {
            //                         for (LocalizationViewBean localizationViewBean : marketAreaViewBean.getLocalizations()) {
            //                             if(!marketAreaViewBean.getCode().equals(currentMarketArea.getCode())){
            //                                String splitUrl[] = currentRequestUrl.split("/");
            //                                String alternateUrl = "/" + marketAreaViewBean.getCode().toLowerCase() + "/" + localizationViewBean.getCode();
            //                                for (int i = 3; i < splitUrl.length; i++) {
            //                               alternateUrl = alternateUrl + "/" + splitUrl[i];
            //                            }
            //                                String hreflang = localizationViewBean.getLocaleCode().replace("_", "-");
            //                                if(marketAreaViewBean.getCode().equals("INT") && localizationViewBean.getCode().equals("en")){
            //                                   hreflang = "x-default";
            //                                }
            //                                 HeadLinkViewBean metaLink = new HeadLinkViewBean("alternate", hreflang, alternateUrl);
            //                                alternateLinks.add(metaLink);
            //                             }
            //                         }
            //                    }
            //                  }
            //                  if(!alternateLinks.isEmpty()){
            //                      modelAndView.getModelMap().addAttribute("alternateLinks", alternateLinks);
            //                  }
            //              }

        }

    } catch (Exception e) {
        logger.error("Inject common datas failed", e);
    }

}

From source file:org.hoteia.qalingo.core.web.mvc.interceptor.RequestPlatformDeviceHandlerInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    try {/*from ww w  .  j a  v a2  s.co m*/
        RequestData requestData = requestUtil.getRequestData(request);
        Device device = requestData.getDevice();
        String deviceFolder = "default";
        if (device != null) {
            boolean isSmartPhone = BooleanUtils.toBoolean(device.getVirtualCapability("is_smartphone"));
            boolean isIPhoneOs = BooleanUtils.toBoolean(device.getVirtualCapability("is_iphone_os"));
            boolean isAndroid = BooleanUtils.toBoolean(device.getVirtualCapability("is_android"));
            if (isSmartPhone || isIPhoneOs || isAndroid) {
                deviceFolder = "mobile";
            }
        }
        requestUtil.updateCurrentDevice(requestData, deviceFolder);

    } catch (Exception e) {
        logger.error("inject common datas failed", e);
    }
}

From source file:org.hoteia.qalingo.core.web.resolver.RequestData.java

public boolean isBot() throws Exception {
    try {// w w  w  .j a  v a 2s.  c  o  m
        if (device != null && device.getVirtualCapabilities() != null) {
            return BooleanUtils.toBoolean(device.getCapability("is_bot"));
        }
    } catch (Exception e) {
        // NOTHING
    }
    return false;
}

From source file:org.hoteia.qalingo.core.web.servlet.DispatcherServlet.java

private void initPlatformDevice(HttpServletRequest request) {
    final ServletContext context = getServletContext();
    final ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
    final RequestUtil requestUtil = (RequestUtil) ctx.getBean("requestUtil");

    // DEVICE/*from ww w.  j  a  v a2 s. c  o  m*/
    try {
        final RequestData requestData = requestUtil.getRequestData(request);

        final WURFLHolder wurfl = (WURFLHolder) ctx.getBean("wurflHolder");
        final WURFLManager manager = wurfl.getWURFLManager();
        Device device = manager.getDeviceForRequest(request);
        String deviceFolder = "default";
        if (device != null) {
            boolean isSmartPhone = BooleanUtils.toBoolean(device.getVirtualCapability("is_smartphone"));
            boolean isIPhoneOs = BooleanUtils.toBoolean(device.getVirtualCapability("is_iphone_os"));
            boolean isAndroid = BooleanUtils.toBoolean(device.getVirtualCapability("is_android"));
            if (isSmartPhone || isIPhoneOs || isAndroid) {
                deviceFolder = "mobile";
            }
        }
        requestUtil.updateCurrentDevice(requestData, deviceFolder);

    } catch (Exception e) {
        logger.error("", e);
    }
}

From source file:org.hoteia.qalingo.core.web.util.impl.RequestUtilImpl.java

/**
* 
*///from ww w. ja v  a 2  s .co m
protected EngineEcoSession initEcoSession(final HttpServletRequest request) throws Exception {
    EngineEcoSession engineEcoSession = new EngineEcoSession();
    EngineSetting engineSettingEnvironmentStagingModeEnabled = engineSettingService
            .getEnvironmentStagingModeEnabled();
    if (engineSettingEnvironmentStagingModeEnabled != null) {
        engineEcoSession.setEnvironmentStagingModeEnabled(
                BooleanUtils.toBoolean(engineSettingEnvironmentStagingModeEnabled.getDefaultValue()));
    } else {
        engineEcoSession.setEnvironmentStagingModeEnabled(false);
        logger.warn("Environment Type is not define in your database. Check the "
                + EngineSettingService.ENGINE_SETTING_ENVIRONMENT_STAGING_MODE_ENABLED
                + " value in settings table.");
    }
    EngineSetting engineSettingEnvironmentType = engineSettingService.getEnvironmentType();
    if (engineSettingEnvironmentType != null) {
        String environmentType = engineSettingEnvironmentType.getDefaultValue();
        try {
            engineEcoSession.setEnvironmentType(EnvironmentType.valueOf(environmentType));
        } catch (Exception e) {
            logger.error("Environment Type has wrong value define in your database. Check the "
                    + EngineSettingService.ENGINE_SETTING_ENVIRONMENT_TYPE + " value in settings table.");
        }
    } else {
        engineEcoSession.setEnvironmentType(EnvironmentType.REEL);
        logger.warn("Environment Type is not define in your database. Check the "
                + EngineSettingService.ENGINE_SETTING_ENVIRONMENT_TYPE + " value in settings table.");
    }

    // INIT STAGING OR REEL ENVIRONMENT

    setCurrentEcoSession(request, engineEcoSession);
    String jSessionId = request.getSession().getId();
    engineEcoSession.setjSessionId(jSessionId);
    engineEcoSession = initDefaultEcoMarketPlace(request);
    engineEcoSession = initCart(request);

    engineEcoSession = updateCurrentEcoSession(request, engineEcoSession);

    engineEcoSession = engineSessionService.saveOrUpdateEngineEcoSession(engineEcoSession);

    return engineEcoSession;
}

From source file:org.hoteia.qalingo.core.web.util.impl.RequestUtilImpl.java

/**
* 
*//*from   w w  w. j av  a  2  s . c o  m*/
protected EngineBoSession initBoSession(final HttpServletRequest request) throws Exception {
    final EngineBoSession engineBoSession = new EngineBoSession();
    EngineSetting engineSettingEnvironmentStagingModeEnabled = engineSettingService
            .getEnvironmentStagingModeEnabled();
    if (engineSettingEnvironmentStagingModeEnabled != null) {
        engineBoSession.setEnvironmentStagingModeEnabled(
                BooleanUtils.toBoolean(engineSettingEnvironmentStagingModeEnabled.getDefaultValue()));
    } else {
        engineBoSession.setEnvironmentStagingModeEnabled(false);
        logger.warn("Environment Type is not define in your database. Check the "
                + EngineSettingService.ENGINE_SETTING_ENVIRONMENT_STAGING_MODE_ENABLED
                + " value in settings table.");
    }
    EngineSetting engineSetting = engineSettingService.getEnvironmentType();
    if (engineSetting != null) {
        String environmentType = engineSetting.getDefaultValue();
        try {
            engineBoSession.setEnvironmentType(EnvironmentType.valueOf(environmentType));
        } catch (Exception e) {
            logger.error("Environment Type has wrong value define in your database. Check the "
                    + EngineSettingService.ENGINE_SETTING_ENVIRONMENT_TYPE + " value in settings table.");
        }
    } else {
        engineBoSession.setEnvironmentType(EnvironmentType.REEL);
        logger.warn("Environment Type is not define in your database. Check the "
                + EngineSettingService.ENGINE_SETTING_ENVIRONMENT_TYPE + " value in settings table.");
    }

    setCurrentBoSession(request, engineBoSession);
    String jSessionId = request.getSession().getId();
    engineBoSession.setjSessionId(jSessionId);
    initDefaultBoMarketPlace(request);

    // Default Localization
    Company company = getCurrentCompany(request);
    if (company != null) {
        // USER IS LOGGED
        engineBoSession.setCurrentBackofficeLocalization(company.getDefaultLocalization());
    } else {
        Localization defaultLocalization = localizationService.getLocalizationByCode("en");
        engineBoSession.setCurrentBackofficeLocalization(defaultLocalization);
    }

    updateCurrentBoSession(request, engineBoSession);
    return engineBoSession;
}

From source file:org.hoteia.qalingo.core.web.util.RequestUtil.java

protected EngineEcoSession initEcoSession(final HttpServletRequest request) throws Exception {
    EngineEcoSession engineEcoSession = new EngineEcoSession();
    EngineSetting engineSettingEnvironmentStagingModeEnabled = engineSettingService
            .getSettingEnvironmentStagingModeEnabled();
    if (engineSettingEnvironmentStagingModeEnabled != null) {
        engineEcoSession.setEnvironmentStagingModeEnabled(
                BooleanUtils.toBoolean(engineSettingEnvironmentStagingModeEnabled.getDefaultValue()));
    } else {/*from  w ww  .j a  v a  2 s . c  o  m*/
        engineEcoSession.setEnvironmentStagingModeEnabled(false);
        logger.warn("Environment Type is not define in your database. Check the "
                + EngineSettingService.ENGINE_SETTING_ENVIRONMENT_STAGING_MODE_ENABLED
                + " value in settings table.");
    }
    EngineSetting engineSettingEnvironmentType = engineSettingService.getSettingEnvironmentType();
    if (engineSettingEnvironmentType != null) {
        String environmentType = engineSettingEnvironmentType.getDefaultValue();
        try {
            engineEcoSession.setEnvironmentType(EnvironmentType.valueOf(environmentType));
        } catch (Exception e) {
            logger.error("Environment Type has wrong value define in your database. Check the "
                    + EngineSettingService.ENGINE_SETTING_ENVIRONMENT_TYPE + " value in settings table.");
        }
    } else {
        engineEcoSession.setEnvironmentType(EnvironmentType.REEL);
        logger.warn("Environment Type is not define in your database. Check the "
                + EngineSettingService.ENGINE_SETTING_ENVIRONMENT_TYPE + " value in settings table.");
    }

    // INIT STAGING OR REEL ENVIRONMENT

    setCurrentEcoSession(request, engineEcoSession);
    String jSessionId = request.getSession().getId();
    engineEcoSession.setjSessionId(jSessionId);

    // STEP 2 - TRY TO GEOLOC THE CUSTOMER AND SET THE RIGHT MARKET AREA
    checkGeolocData(request, engineEcoSession);
    initEcoMarketPlace(request);
    //        engineEcoSession = initCart(request);

    engineEcoSession = updateCurrentEcoSession(request, engineEcoSession);

    if (wurflHolder != null) {
        try {
            final WURFLManager manager = wurflHolder.getWURFLManager();
            final Device device = manager.getDeviceForRequest(request);
            if (device != null && device.getVirtualCapabilities() != null) {
                boolean isBot = BooleanUtils.toBoolean(device.getCapability("is_bot"));
                if (!isBot) {
                    engineEcoSession = engineSessionService.saveOrUpdateEngineEcoSession(engineEcoSession);
                }
            }
        } catch (Exception e) {
            // NOTHING
        }
    }

    return engineEcoSession;
}

From source file:org.hoteia.qalingo.core.web.util.RequestUtil.java

protected EngineBoSession initBoSession(final HttpServletRequest request) throws Exception {
    final EngineBoSession engineBoSession = new EngineBoSession();
    EngineSetting engineSettingEnvironmentStagingModeEnabled = engineSettingService
            .getSettingEnvironmentStagingModeEnabled();
    if (engineSettingEnvironmentStagingModeEnabled != null) {
        engineBoSession.setEnvironmentStagingModeEnabled(
                BooleanUtils.toBoolean(engineSettingEnvironmentStagingModeEnabled.getDefaultValue()));
    } else {/*  ww w  .  j  a  va  2 s .  c om*/
        engineBoSession.setEnvironmentStagingModeEnabled(false);
        logger.warn("Environment Type is not define in your database. Check the "
                + EngineSettingService.ENGINE_SETTING_ENVIRONMENT_STAGING_MODE_ENABLED
                + " value in settings table.");
    }
    EngineSetting engineSetting = engineSettingService.getSettingEnvironmentType();
    if (engineSetting != null) {
        String environmentType = engineSetting.getDefaultValue();
        try {
            engineBoSession.setEnvironmentType(EnvironmentType.valueOf(environmentType));
        } catch (Exception e) {
            logger.error("Environment Type has wrong value define in your database. Check the "
                    + EngineSettingService.ENGINE_SETTING_ENVIRONMENT_TYPE + " value in settings table.");
        }
    } else {
        engineBoSession.setEnvironmentType(EnvironmentType.REEL);
        logger.warn("Environment Type is not define in your database. Check the "
                + EngineSettingService.ENGINE_SETTING_ENVIRONMENT_TYPE + " value in settings table.");
    }

    setCurrentBoSession(request, engineBoSession);
    String jSessionId = request.getSession().getId();
    engineBoSession.setjSessionId(jSessionId);
    initDefaultBoMarketPlace(request);

    // Default Localization
    Company company = getCurrentCompany(request);
    if (company != null) {
        // USER IS LOGGED
        engineBoSession.setCurrentBackofficeLocalization(company.getDefaultLocalization());
    } else {
        String requestLocale = request.getLocale().toString();
        if (StringUtils.isNotEmpty(requestLocale)) {
            if (requestLocale.length() > 2) {
                String localeLanguage = request.getLocale().getLanguage();
                engineBoSession.setCurrentBackofficeLocalization(
                        localizationService.getLocalizationByCode(localeLanguage));
            } else if (requestLocale.length() == 2) {
                engineBoSession.setCurrentBackofficeLocalization(
                        localizationService.getLocalizationByCode(requestLocale));
            }
        } else {
            Localization defaultLocalization = localizationService.getLocalizationByCode("en");
            engineBoSession.setCurrentBackofficeLocalization(defaultLocalization);
        }
    }

    updateCurrentBoSession(request, engineBoSession);
    return engineBoSession;
}