Search in sources :

Example 1 with TimeDTO

use of org.broadleafcommerce.common.TimeDTO in project BroadleafCommerce by BroadleafCommerce.

the class PageHandlerMapping method buildMvelParameters.

/**
 * MVEL is used to process the content targeting rules.
 *
 * @param request
 * @return
 */
private Map<String, Object> buildMvelParameters(HttpServletRequest request) {
    TimeDTO timeDto = new TimeDTO(SystemTime.asCalendar());
    RequestDTO requestDto = (RequestDTO) request.getAttribute(REQUEST_DTO);
    Map<String, Object> mvelParameters = new HashMap<String, Object>();
    mvelParameters.put("time", timeDto);
    mvelParameters.put("request", requestDto);
    Map<String, Object> blcRuleMap = (Map<String, Object>) request.getAttribute(BLC_RULE_MAP_PARAM);
    if (blcRuleMap != null) {
        for (String mapKey : blcRuleMap.keySet()) {
            mvelParameters.put(mapKey, blcRuleMap.get(mapKey));
        }
    }
    return mvelParameters;
}
Also used : TimeDTO(org.broadleafcommerce.common.TimeDTO) HashMap(java.util.HashMap) RequestDTO(org.broadleafcommerce.common.RequestDTO) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with TimeDTO

use of org.broadleafcommerce.common.TimeDTO in project BroadleafCommerce by BroadleafCommerce.

the class AbstractBaseProcessor method couldOfferApplyToTimePeriod.

protected boolean couldOfferApplyToTimePeriod(Offer offer) {
    boolean appliesToTimePeriod = false;
    String rule = null;
    OfferOfferRuleXref ruleXref = offer.getOfferMatchRulesXref().get(OfferRuleType.TIME.getType());
    if (ruleXref != null && ruleXref.getOfferRule() != null) {
        rule = ruleXref.getOfferRule().getMatchRule();
    }
    if (rule != null) {
        TimeZone timeZone = getOfferTimeZoneProcessor().getTimeZone(offer);
        TimeDTO timeDto = new TimeDTO(SystemTime.asCalendar(timeZone));
        HashMap<String, Object> vars = new HashMap<String, Object>();
        vars.put("time", timeDto);
        Boolean expressionOutcome = executeExpression(rule, vars);
        if (expressionOutcome != null && expressionOutcome) {
            appliesToTimePeriod = true;
        }
    } else {
        appliesToTimePeriod = true;
    }
    return appliesToTimePeriod;
}
Also used : TimeZone(java.util.TimeZone) TimeDTO(org.broadleafcommerce.common.TimeDTO) HashMap(java.util.HashMap) OfferOfferRuleXref(org.broadleafcommerce.core.offer.domain.OfferOfferRuleXref)

Example 3 with TimeDTO

use of org.broadleafcommerce.common.TimeDTO in project BroadleafCommerce by BroadleafCommerce.

the class MvelHelper method buildMvelParameters.

/**
 * Builds parameters using time, request, customer, and cart.
 *
 * Should be called from within a valid web request.
 *
 * @param request
 * @return
 */
public static Map<String, Object> buildMvelParameters() {
    Map<String, Object> mvelParameters = new HashMap<String, Object>();
    BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
    if (brc != null && brc.getRequest() != null) {
        TimeDTO timeDto = new TimeDTO(SystemTime.asCalendar());
        HttpServletRequest request = brc.getRequest();
        RequestDTO requestDto = brc.getRequestDTO();
        mvelParameters.put("time", timeDto);
        mvelParameters.put("request", requestDto);
        Map<String, Object> blcRuleMap = (Map<String, Object>) request.getAttribute(BLC_RULE_MAP_PARAM);
        if (blcRuleMap != null) {
            for (String mapKey : blcRuleMap.keySet()) {
                mvelParameters.put(mapKey, blcRuleMap.get(mapKey));
            }
        }
    }
    return mvelParameters;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HashMap(java.util.HashMap) TimeDTO(org.broadleafcommerce.common.TimeDTO) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) RequestDTO(org.broadleafcommerce.common.RequestDTO) HashMap(java.util.HashMap) EfficientLRUMap(org.broadleafcommerce.common.util.EfficientLRUMap) Map(java.util.Map)

Example 4 with TimeDTO

use of org.broadleafcommerce.common.TimeDTO in project BroadleafCommerce by BroadleafCommerce.

the class BroadleafRobotsController method buildMvelParameters.

/**
 * @param request
 * @return
 */
private Map<String, Object> buildMvelParameters(HttpServletRequest request) {
    TimeDTO timeDto = new TimeDTO(SystemTime.asCalendar());
    RequestDTO requestDto = (RequestDTO) request.getAttribute(REQUEST_DTO);
    Map<String, Object> mvelParameters = new HashMap<String, Object>();
    mvelParameters.put("time", timeDto);
    mvelParameters.put("request", requestDto);
    Map<String, Object> blcRuleMap = (Map<String, Object>) request.getAttribute(BLC_RULE_MAP_PARAM);
    if (blcRuleMap != null) {
        for (String mapKey : blcRuleMap.keySet()) {
            mvelParameters.put(mapKey, blcRuleMap.get(mapKey));
        }
    }
    return mvelParameters;
}
Also used : TimeDTO(org.broadleafcommerce.common.TimeDTO) HashMap(java.util.HashMap) RequestDTO(org.broadleafcommerce.common.RequestDTO) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with TimeDTO

use of org.broadleafcommerce.common.TimeDTO in project BroadleafCommerce by BroadleafCommerce.

the class ContentProcessor method buildMvelParameters.

/**
 * MVEL is used to process the content targeting rules.
 *
 * @param request
 * @return
 */
protected Map<String, Object> buildMvelParameters(HttpServletRequest request, Map<String, String> tagAttributes, BroadleafTemplateContext context) {
    TimeZone timeZone = BroadleafRequestContext.getBroadleafRequestContext().getTimeZone();
    final TimeDTO timeDto;
    if (timeZone != null) {
        timeDto = new TimeDTO(SystemTime.asCalendar(timeZone));
    } else {
        timeDto = new TimeDTO();
    }
    RequestDTO requestDto = (RequestDTO) request.getAttribute(REQUEST_DTO);
    Map<String, Object> mvelParameters = new HashMap<>();
    mvelParameters.put("time", timeDto);
    mvelParameters.put("request", requestDto);
    String productString = tagAttributes.get("product");
    if (productString != null) {
        Object product = context.parseExpression(productString);
        if (product != null) {
            mvelParameters.put("product", product);
        }
    }
    String categoryString = tagAttributes.get("category");
    if (categoryString != null) {
        Object category = context.parseExpression(categoryString);
        if (category != null) {
            mvelParameters.put("category", category);
        }
    }
    @SuppressWarnings("unchecked") Map<String, Object> blcRuleMap = (Map<String, Object>) request.getAttribute(BLC_RULE_MAP_PARAM);
    if (blcRuleMap != null) {
        for (String mapKey : blcRuleMap.keySet()) {
            mvelParameters.put(mapKey, blcRuleMap.get(mapKey));
        }
    }
    return mvelParameters;
}
Also used : TimeZone(java.util.TimeZone) TimeDTO(org.broadleafcommerce.common.TimeDTO) HashMap(java.util.HashMap) RequestDTO(org.broadleafcommerce.common.RequestDTO) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HashMap (java.util.HashMap)5 TimeDTO (org.broadleafcommerce.common.TimeDTO)5 Map (java.util.Map)4 RequestDTO (org.broadleafcommerce.common.RequestDTO)4 TimeZone (java.util.TimeZone)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 EfficientLRUMap (org.broadleafcommerce.common.util.EfficientLRUMap)1 BroadleafRequestContext (org.broadleafcommerce.common.web.BroadleafRequestContext)1 OfferOfferRuleXref (org.broadleafcommerce.core.offer.domain.OfferOfferRuleXref)1