@SuppressWarnings("unchecked") @ResponseBody @RequestMapping(value = "/order/checkSpecialOffer.ajax", method = RequestMethod.POST) public ResponseEntity<byte[]> checkSpecialOfferAvailability( HttpServletRequest request, @RequestParam(value = "body") String body) throws Exception { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Checking if special offer is applicable for order"); } Map<String, Object> model = new HashMap<String, Object>(); try { // Extract request parameters Map<String, Object> params = (Map<String, Object>) jsonUtils.deserialize(body); String restaurantId = (String) params.get("restaurantId"); String orderId = (String) params.get("orderId"); String specialOfferId = (String) params.get("specialOfferId"); // Get the restaurant object Restaurant restaurant = restaurantRepository.findByRestaurantId(restaurantId); SpecialOffer specialOffer = restaurant.getSpecialOffer(specialOfferId); // Get the order object if (orderId != null) { Order order = orderRepository.findByOrderId(orderId); model.put("success", true); model.put("applicable", specialOffer.isApplicableTo(order)); } else { model.put("success", true); model.put("applicable", specialOffer.isAvailableAt(new DateTime())); } } catch (Exception ex) { LOGGER.error("", ex); model.put("success", false); model.put("message", ex.getMessage()); } return buildOrderResponse(model); }