public Offer createOffer( String offerName, OfferType offerType, OfferDiscountType discountType, double value, String customerRule, String orderRule, boolean stackable, boolean combinable, int priority) { Offer offer = offerDao.create(); offer.setName(offerName); offer.setStartDate(SystemTime.asDate()); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, -1); offer.setStartDate(calendar.getTime()); calendar.add(Calendar.DATE, 2); offer.setEndDate(calendar.getTime()); offer.setType(offerType); offer.setDiscountType(discountType); offer.setValue(BigDecimal.valueOf(value)); offer.setDeliveryType(OfferDeliveryType.CODE); offer.setStackable(stackable); offer.setAppliesToOrderRules(orderRule); offer.setAppliesToCustomerRules(customerRule); offer.setCombinableWithOtherOffers(combinable); offer.setPriority(priority); offer = offerService.save(offer); offer.setMaxUses(50); return offer; }
private void setContentTime(HttpServletRequest request) { String sandboxDateTimeParam = request.getParameter(SANDBOX_DATE_TIME_VAR); if (sandBoxPreviewEnabled) { sandboxDateTimeParam = null; } Date overrideTime = null; try { if (request.getParameter(SANDBOX_DATE_TIME_RIBBON_OVERRIDE_PARAM) != null) { overrideTime = readDateFromRequest(request); } else if (sandboxDateTimeParam != null) { if (LOG.isDebugEnabled()) { LOG.debug("Setting date/time using " + sandboxDateTimeParam); } overrideTime = CONTENT_DATE_FORMATTER.parse(sandboxDateTimeParam); } } catch (ParseException e) { LOG.debug(e); } if (overrideTime == null) { HttpSession session = request.getSession(false); if (session != null) { overrideTime = (Date) session.getAttribute(SANDBOX_DATE_TIME_VAR); } } else { if (LOG.isDebugEnabled()) { LOG.debug( "Setting date-time for sandbox mode to " + overrideTime + " for sandboxDateTimeParam = " + sandboxDateTimeParam); } HttpSession session = request.getSession(); session.setAttribute(SANDBOX_DATE_TIME_VAR, overrideTime); } if (overrideTime != null) { FixedTimeSource ft = new FixedTimeSource(overrideTime.getTime()); SystemTime.setLocalTimeSource(ft); } else { SystemTime.resetLocalTimeSource(); } }
private Date readDateFromRequest(HttpServletRequest request) throws ParseException { String date = request.getParameter(SANDBOX_DISPLAY_DATE_TIME_DATE_PARAM); String minutes = request.getParameter(SANDBOX_DISPLAY_DATE_TIME_MINUTES_PARAM); String hours = request.getParameter(SANDBOX_DISPLAY_DATE_TIME_HOURS_PARAM); String ampm = request.getParameter(SANDBOX_DISPLAY_DATE_TIME_AMPM_PARAM); if (StringUtils.isEmpty(minutes)) { minutes = Integer.toString(SystemTime.asCalendar().get(Calendar.MINUTE)); } if (StringUtils.isEmpty(hours)) { hours = Integer.toString(SystemTime.asCalendar().get(Calendar.HOUR_OF_DAY)); } String dateString = date + " " + hours + ":" + minutes + " " + ampm; if (LOG.isDebugEnabled()) { LOG.debug("Setting date/time using " + dateString); } Date parsedDate = CONTENT_DATE_PARSE_FORMAT.parse(dateString); return parsedDate; }
private SandBox determineSandbox(HttpServletRequest request, Site site) { SandBox currentSandbox = null; if (!sandBoxPreviewEnabled) { if (LOG.isTraceEnabled()) { LOG.trace("Sandbox preview disabled. Setting sandbox to production"); } request.setAttribute(SANDBOX_VAR, currentSandbox); } else { Long sandboxId = null; if (request.getParameter("blSandboxDateTimeRibbonProduction") == null) { sandboxId = lookupSandboxId(request); } else { request.getSession().removeAttribute(SANDBOX_DATE_TIME_VAR); request.getSession().removeAttribute(SANDBOX_ID_VAR); } if (sandboxId != null) { currentSandbox = sandBoxService.retrieveSandboxById(sandboxId); request.setAttribute(SANDBOX_VAR, currentSandbox); if (currentSandbox != null && !SandBoxType.PRODUCTION.equals(currentSandbox.getSandBoxType())) { setContentTime(request); } } if (currentSandbox == null && site != null) { currentSandbox = site.getProductionSandbox(); } } if (LOG.isTraceEnabled()) { LOG.trace("Serving request using sandbox: " + currentSandbox); } Date currentSystemDateTime = SystemTime.asDate(true); Calendar sandboxDateTimeCalendar = Calendar.getInstance(); sandboxDateTimeCalendar.setTime(currentSystemDateTime); request.setAttribute( SANDBOX_DISPLAY_DATE_TIME_DATE_PARAM, CONTENT_DATE_DISPLAY_FORMATTER.format(currentSystemDateTime)); request.setAttribute( SANDBOX_DISPLAY_DATE_TIME_HOURS_PARAM, CONTENT_DATE_DISPLAY_HOURS_FORMATTER.format(currentSystemDateTime)); request.setAttribute( SANDBOX_DISPLAY_DATE_TIME_MINUTES_PARAM, CONTENT_DATE_DISPLAY_MINUTES_FORMATTER.format(currentSystemDateTime)); request.setAttribute( SANDBOX_DISPLAY_DATE_TIME_AMPM_PARAM, sandboxDateTimeCalendar.get(Calendar.AM_PM)); return currentSandbox; }
/** * (non-Javadoc) * * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, * javax.servlet.FilterChain) */ public void doFilterInternal( HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException, ServletException { if (!shouldProcessURL(request, request.getRequestURI())) { if (LOG.isTraceEnabled()) { LOG.trace("Process URL not processing URL " + request.getRequestURI()); } filterChain.doFilter(request, response); return; } final String requestURIWithoutContext; if (request.getContextPath() != null) { requestURIWithoutContext = request.getRequestURI().substring(request.getContextPath().length()); } else { requestURIWithoutContext = request.getRequestURI(); } if (LOG.isTraceEnabled()) { LOG.trace("Process URL Filter Begin " + requestURIWithoutContext); } if (request.getAttribute(REQUEST_DTO) == null) { request.setAttribute(REQUEST_DTO, new RequestDTOImpl(request)); } Site site = determineSite(request); SandBox currentSandbox = determineSandbox(request, site); BroadleafRequestContext brc = new BroadleafRequestContext(); brc.setLocale(determineLocale(request, site)); brc.setSandbox(currentSandbox); brc.setRequest(request); brc.setResponse(response); BroadleafRequestContext.setBroadleafRequestContext(brc); try { URLProcessor urlProcessor = null; if (isProduction(currentSandbox)) { try { urlProcessor = lookupProcessorFromCache(requestURIWithoutContext); } catch (ExecutionException e) { LOG.error(e); } } if (urlProcessor == null) { urlProcessor = determineURLProcessor(requestURIWithoutContext); } if (urlProcessor instanceof NullURLProcessor) { // Pass request down the filter chain if (LOG.isTraceEnabled()) { LOG.trace( "URL not being processed by a Broadleaf URLProcessor " + requestURIWithoutContext); } StatusExposingServletResponse sesResponse = new StatusExposingServletResponse(response); filterChain.doFilter(request, sesResponse); if (sesResponse.getStatus() == sesResponse.SC_NOT_FOUND) { if (LOG.isWarnEnabled()) { LOG.warn("Page not found. Unable to render " + requestURIWithoutContext); } urlCache.invalidate(requestURIWithoutContext); } } else { if (LOG.isTraceEnabled()) { LOG.trace( "URL about to be processed by a Broadleaf URLProcessor " + requestURIWithoutContext); } urlProcessor.processURL(requestURIWithoutContext); } } finally { // If the system-time was overridden, set it back to normal SystemTime.resetLocalTimeSource(); } }