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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations