Example usage for org.springframework.http MediaType APPLICATION_XML_VALUE

List of usage examples for org.springframework.http MediaType APPLICATION_XML_VALUE

Introduction

In this page you can find the example usage for org.springframework.http MediaType APPLICATION_XML_VALUE.

Prototype

String APPLICATION_XML_VALUE

To view the source code for org.springframework.http MediaType APPLICATION_XML_VALUE.

Click Source Link

Document

A String equivalent of MediaType#APPLICATION_XML .

Usage

From source file:org.yes.cart.web.service.rest.CartController.java

/**
 * Interface: PUT /order/preview//  w  w w  .  ja  v  a  2  s. c  o m
 * <p>
 * <p>
 * Create order preview (temporary order that is ready to be paid).
 * <p>
 * <p>
 * <h3>Headers for operation</h3><p>
 * <table border="1">
 *     <tr><td>Content-Type</td><td>application/json or application/json</td></tr>
 *     <tr><td>Accept</td><td>application/json or application/xml</td></tr>
 *     <tr><td>yc</td><td>token uuid</td></tr>
 * </table>
 * <p>
 * <p>
 * <h3>Parameters for operation</h3><p>
 * <table border="1">
 *     <tr><td>JSON example</td><td>
 * <pre><code>
 * {
 *     "forceSingleDelivery": true
 * }
 * </code></pre>
 *     </td></tr>
 *     <tr><td>XML example</td><td>
 * <pre><code>
 *    &lt;order-delivery-option&gt;
 *        &lt;force-single-delivery&gt;true&lt;/force-single-delivery&gt;
 *    &lt;/order-delivery-option&gt;
 * </code></pre>
 *     </td></tr>
 * </table>
 * <p>
 * <p>
 * <h3>Output</h3><p>
 * <table border="1">
 *     <tr><td>JSON object OrderPreviewRO</td><td>
 * <pre><code>
 * {
 *     "success": true,
 *     "problems": null,
 *     "pgName": "courierPaymentGateway",
 *     "pgOnline": false,
 *     "pgExternalForm": false,
 *     "pgFormUrl": "/order/payment",
 *     "pgFormHtml": "&lt;form method=\"POST\" action=\"/order/payment\"&gt;\n\n&lt;input type=\"submit\" value=\"submit\"&gt;&lt;/form&gt;",
 *     "order": {
 *         "customerorderId": 1,
 *         "ordernum": "150407103424-1",
 *         "pgLabel": "courierPaymentGatewayLabel",
 *         "billingAddress": "In the middle of  0001 Nowhere GB GB-GB Bob Doe 123123123",
 *         "shippingAddress": "In the middle of  0001 Nowhere GB GB-GB Bob Doe 123123123",
 *         "cartGuid": "a06cd0b1-b153-47ec-9cc1-12e30320a9c1",
 *         "currency": "EUR",
 *         "orderMessage": "My Message",
 *         "orderStatus": "os.none",
 *         "multipleShipmentOption": false,
 *         "orderTimestamp": 1428399264811,
 *         "email": "bob.doe@yc-checkout-json.com",
 *         "firstname": "Bob",
 *         "lastname": "Doe",
 *         "middlename": null,
 *         "customerId": 1,
 *         "shopId": 10,
 *         "code": "SHOIP1",
 *         "total": {
 *             "listSubTotal": 99.99,
 *             "saleSubTotal": 99.99,
 *             "nonSaleSubTotal": 99.99,
 *             "priceSubTotal": 99.99,
 *             "orderPromoApplied": false,
 *             "appliedOrderPromo": null,
 *             "subTotal": 99.99,
 *             "subTotalTax": 16.67,
 *             "subTotalAmount": 99.99,
 *             "deliveryListCost": 10.00,
 *             "deliveryCost": 10.00,
 *             "deliveryPromoApplied": false,
 *             "appliedDeliveryPromo": null,
 *             "deliveryTax": 1.67,
 *             "deliveryCostAmount": 10.00,
 *             "total": 109.99,
 *             "totalTax": 18.34,
 *             "listTotalAmount": 109.99,
 *             "totalAmount": 109.99
 *         },
 *         "deliveries": [{
 *             "customerOrderDeliveryId": 1,
 *             "deliveryNum": "150407103424-1-0",
 *             "refNo": null,
 *             "carrierSlaId": 4,
 *             "carrierSlaName": "14",
 *             "carrierSlaDisplayNames": null,
 *             "carrierId": 1,
 *             "carrierName": "Test carrier 1",
 *             "carrierDisplayNames": null,
 *             "deliveryStatus": "ds.fullfillment",
 *             "deliveryGroup": "D1",
 *             "total": {
 *                 "listSubTotal": 99.99,
 *                 "saleSubTotal": 99.99,
 *                 "nonSaleSubTotal": 99.99,
 *                 "priceSubTotal": 99.99,
 *                 "orderPromoApplied": false,
 *                 "appliedOrderPromo": null,
 *                 "subTotal": 99.99,
 *                 "subTotalTax": 16.67,
 *                 "subTotalAmount": 99.99,
 *                 "deliveryListCost": 10.00,
 *                 "deliveryCost": 10.00,
 *                 "deliveryPromoApplied": false,
 *                 "appliedDeliveryPromo": null,
 *                 "deliveryTax": 1.67,
 *                 "deliveryCostAmount": 10.00,
 *                 "total": 109.99,
 *                 "totalTax": 18.34,
 *                 "listTotalAmount": 109.99,
 *                 "totalAmount": 109.99
 *             },
 *             "deliveryItems": [{
 *                 "productSkuCode": "BENDER-ua",
 *                 "quantity": 1,
 *                 "price": 99.99,
 *                 "salePrice": 99.99,
 *                 "listPrice": 99.99,
 *                 "netPrice": 83.32,
 *                 "grossPrice": 99.99,
 *                 "taxRate": 20.00,
 *                 "taxCode": "VAT",
 *                 "taxExclusiveOfPrice": false,
 *                 "gift": false,
 *                 "promoApplied": false,
 *                 "appliedPromo": null,
 *                 "customerOrderDeliveryDetId": 0
 *             }]
 *         }],
 *         "orderItems": [{
 *             "productSkuCode": "BENDER-ua",
 *             "quantity": 1,
 *             "price": 99.99,
 *             "salePrice": 99.99,
 *             "listPrice": 99.99,
 *             "netPrice": 83.32,
 *             "grossPrice": 99.99,
 *             "taxRate": 20.00,
 *             "taxCode": "VAT",
 *             "taxExclusiveOfPrice": false,
 *             "gift": false,
 *             "promoApplied": false,
 *             "appliedPromo": null,
 *             "customerOrderDetId": 0
 *         }]
 *     }
 * }
 * </code></pre>
 *     </td></tr>
 *     <tr><td>XML object OrderPreviewRO</td><td>
 * <pre><code>
 * &lt;order-review success="true"&gt;
 *    &lt;order cart-guid="e4d72c92-2f5f-4a4b-a5ca-97383c54152b" shop-code="SHOIP1" currency="EUR"
 *              customer-id="2" customer-order-id="2" multiple-shipment-option="false" order-status="os.none"
 *              order-timestamp="2015-04-07T10:34:27.809+01:00" ordernum="150407103427-2"
 *              pg-label="courierPaymentGatewayLabel" shop-id="10"&gt;
 *       &lt;billing-address&gt;In the middle of  0001 Nowhere GB GB-GB Bob Doe 123123123&lt;/billing-address&gt;
 *       &lt;deliveries&gt;
 *          &lt;delivery carrier-id="1" carriersla-id="4" customer-order-delivery-id="2" delivery-group="D1"
 *                       delivery-num="150407103427-2-0" delivery-status="ds.fullfillment"&gt;
 *             &lt;carrier-name&gt;Test carrier 1&lt;/carrier-name&gt;
 *             &lt;carriersla-name&gt;14&lt;/carriersla-name&gt;
 *             &lt;delivery-items&gt;
 *                &lt;delivery-item customer-order-delivery-det-id="0" gift="false" gross-price="99.99"
 *                                    list-price="99.99" net-price="83.32" price="99.99" product-sku-code="BENDER-ua"
 *                                    promo-applied="false" quantity="1" sale-price="99.99" tax-code="VAT"
 *                                    tax-exclusive-of-price="false" tax-rate="20.00"/&gt;
 *             &lt;/delivery-items&gt;
 *             &lt;total delivery-cost="10.00" delivery-cost-amount="10.00" delivery-list-cost="10.00"
 *                       delivery-promo-applied="false" delivery-tax="1.67" list-sub-total="99.99" list-total-amount="109.99"
 *                       non-sale-sub-total="99.99" promo-applied="false" price-sub-total="99.99" sale-sub-total="99.99"
 *                       sub-total="99.99" sub-total-amount="99.99" sub-total-tax="16.67" total="109.99" total-amount="109.99"
 *                       total-tax="18.34"/&gt;
 *          &lt;/delivery&gt;
 *       &lt;/deliveries&gt;
 *       &lt;email&gt;bob.doe@-checkout-xml.com&lt;/email&gt;
 *       &lt;firstname&gt;Bob&lt;/firstname&gt;
 *       &lt;lastname&gt;Doe&lt;/lastname&gt;
 *       &lt;order-items&gt;
 *          &lt;order-item customer-order-det-id="0" gift="false" gross-price="99.99" list-price="99.99" net-price="83.32"
 *                          price="99.99" product-sku-code="BENDER-ua" promo-applied="false" quantity="1" sale-price="99.99"
 *                          tax-code="VAT" tax-exclusive-of-price="false" tax-rate="20.00"/&gt;
 *       &lt;/order-items&gt;
 *       &lt;order-message&gt;My Message&lt;/order-message&gt;
 *       &lt;shipping-address&gt;In the middle of  0001 Nowhere GB GB-GB Bob Doe 123123123&lt;/shipping-address&gt;
 *       &lt;total delivery-cost="10.00" delivery-cost-amount="10.00" delivery-list-cost="10.00" delivery-promo-applied="false"
 *                 delivery-tax="1.67" list-sub-total="99.99" list-total-amount="109.99" non-sale-sub-total="99.99"
 *                 promo-applied="false" price-sub-total="99.99" sale-sub-total="99.99" sub-total="99.99" sub-total-amount="99.99"
 *                 sub-total-tax="16.67" total="109.99" total-amount="109.99" total-tax="18.34"/&gt;
 *    &lt;/order&gt;
 *    &lt;pg-external-form&gt;false&lt;/pg-external-form&gt;
 *    &lt;pg-form-html&gt;&lt;!-- escaped form --&gt;&lt;form method="POST" action="/order/payment"&gt;
 *
 * &lt;input type="submit" value="submit"&gt;&lt;/form&gt;&lt;/pg-form-html&gt;
 *    &lt;pg-form-url&gt;/order/payment&lt;/pg-form-url&gt;
 *    &lt;pg-name&gt;courierPaymentGateway&lt;/pg-name&gt;
 *    &lt;pg-online&gt;false&lt;/pg-online&gt;
 * &lt;/order-review&gt;
 * </code></pre>
 *     </td></tr>
 * </table>
 *
 * <p>
 * <h3>Error codes</h3><p>
 * <table border="1">
 *     <tr><td>CART_ITEMS</td><td>MISSING if no items present in the cart</td></tr>
 *     <tr><td>BILLING_ADDRESS</td><td>MISSING if billing address is required and it is missing</td></tr>
 *     <tr><td>DELIVERY_ADDRESS</td><td>MISSING if delivery address is required and it is missing</td></tr>
 *     <tr><td>SHIPPING_METHOD</td><td>MISSING if carrier SLA is not set</td></tr>
 *     <tr><td>PAYMENT_METHOD</td><td>MISSING if payment gateway is not set</td></tr>
 *     <tr><td>ERROR_COUPON</td><td>coupon code, if coupon is not valid</td></tr>
 *     <tr><td>ERROR_SKU</td><td>sku code, if sku is unavailable</td></tr>
 *     <tr><td>CART_ITEMS</td><td>error message, if order cannot be created from cart items</td></tr>
 * </table>
 * <p>
 *
 * @param request request
 * @param response response
 *
 * @return order preview object
 */
@RequestMapping(value = "/order/preview", method = RequestMethod.PUT, produces = {
        MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
public @ResponseBody OrderPreviewRO orderPreview(@RequestBody final OrderDeliveryOptionRO option,
        final HttpServletRequest request, final HttpServletResponse response) {

    cartMixin.throwSecurityExceptionIfNotLoggedIn();

    final ShoppingCart cart = cartMixin.getCurrentCart();
    shoppingCartCommandFactory.execute(ShoppingCartCommand.CMD_MULTIPLEDELIVERY, cart,
            (Map) Collections.singletonMap(ShoppingCartCommand.CMD_MULTIPLEDELIVERY,
                    String.valueOf(option.isForceSingleDelivery())));
    cartMixin.persistShoppingCart(request, response);

    if (cart.getCartItemsCount() == 0) {

        final OrderPreviewRO review = new OrderPreviewRO();
        review.setSuccess(false);
        final Map<String, String> problems = new HashMap<String, String>();
        problems.put("CART_ITEMS", "MISSING");
        review.setProblems(problems);
        return review;

    }

    if ((!cart.isBillingAddressNotRequired() || !cart.isDeliveryAddressNotRequired())
            && !addressBookFacade.customerHasAtLeastOneAddress(cart.getCustomerEmail())) {
        // Must have an address if it is required
        final OrderPreviewRO review = new OrderPreviewRO();
        review.setSuccess(false);
        final Map<String, String> problems = new HashMap<String, String>();
        if (!cart.isBillingAddressNotRequired()) {
            problems.put("BILLING_ADDRESS", "MISSING");
        }
        if (!cart.isDeliveryAddressNotRequired()) {
            problems.put("DELIVERY_ADDRESS", "MISSING");
        }
        review.setProblems(problems);
        return review;
    }

    if (cart.getCarrierSlaId() == null) {
        // Must select a carrier
        final OrderPreviewRO review = new OrderPreviewRO();
        review.setSuccess(false);
        final Map<String, String> problems = new HashMap<String, String>();
        problems.put("SHIPPING_METHOD", "MISSING");
        review.setProblems(problems);
        return review;
    }

    if (StringUtils.isBlank(cart.getOrderInfo().getPaymentGatewayLabel())) {
        // Must select a PG
        final OrderPreviewRO review = new OrderPreviewRO();
        review.setSuccess(false);
        final Map<String, String> problems = new HashMap<String, String>();
        problems.put("PAYMENT_METHOD", "MISSING");
        review.setProblems(problems);
        return review;
    }

    try {
        final CustomerOrder order = checkoutServiceFacade.createFromCart(cart);
        order.setPgLabel(cart.getOrderInfo().getPaymentGatewayLabel());
        checkoutServiceFacade.update(order);

        final Total total = checkoutServiceFacade.getOrderTotal(order);
        final OrderRO ro = mappingMixin.map(order, OrderRO.class, CustomerOrder.class);
        ro.setTotal(mappingMixin.map(total, CartTotalRO.class, Total.class));

        for (final CustomerOrderDelivery delivery : order.getDelivery()) {
            final DeliveryRO dro = mappingMixin.map(delivery, DeliveryRO.class, CustomerOrderDelivery.class);
            final Total dtotal = checkoutServiceFacade.getOrderDeliveryTotal(order, delivery);
            dro.setTotal(mappingMixin.map(dtotal, CartTotalRO.class, Total.class));
            ro.getDeliveries().add(dro);
        }

        final PaymentGateway gateway = checkoutServiceFacade.getOrderPaymentGateway(order);
        final Payment payment = checkoutServiceFacade.createPaymentToAuthorize(order);

        boolean isExternalFormPg = false;

        String submitBtnValue = null;
        if (gateway instanceof PaymentGatewayExternalForm) {
            submitBtnValue = ((PaymentGatewayExternalForm) gateway).getSubmitButton();
        }
        if (StringUtils.isBlank(submitBtnValue)) {
            submitBtnValue = "<input type=\"submit\" value=\"submit\">";
        }

        String postActionUrl = null;
        if (gateway instanceof PaymentGatewayExternalForm) {
            // some pgs will point to local mounted page (e.g. paypal express points to paymentpaypalexpress)
            // that triggers internal payment information processing via filter
            postActionUrl = ((PaymentGatewayExternalForm) gateway).getPostActionUrl();
        }
        if (StringUtils.isBlank(postActionUrl)) {
            // Default behaviour for internal payment processing
            postActionUrl = request.getRequestURI().replace("/order/preview", "/order/place");
        } else if (!postActionUrl.startsWith("http")) {
            // special behaviour handled by specific PG filters
            postActionUrl = request.getRequestURI().replace("/order/preview", "/order/place/")
                    .concat(postActionUrl);
        } else {
            // else this is an external url
            isExternalFormPg = true;
        }

        String fullName = StringUtils.EMPTY;

        if (order.getCustomer() != null) {

            fullName = (order.getCustomer().getFirstname() + " " + order.getCustomer().getLastname())
                    .toUpperCase();

        }

        final BigDecimal grandTotal = total.getTotalAmount();

        final String htmlFragment = gateway.getHtmlForm(fullName, cart.getCurrentLocale(), grandTotal,
                cart.getCurrencyCode(), cart.getGuid(), payment);

        final String fullFormHtml = MessageFormat.format(
                "<form method=\"POST\" action=\"{0}\">\n{1}\n{2}</form>", postActionUrl, htmlFragment,
                submitBtnValue);

        final OrderPreviewRO review = new OrderPreviewRO();
        review.setSuccess(true);

        review.setPgName(gateway.getName(cart.getCurrentLocale()));
        review.setPgOnline(gateway.getPaymentGatewayFeatures().isOnlineGateway());
        review.setPgExternalForm(isExternalFormPg);
        review.setPgFormUrl(postActionUrl);
        review.setPgFormHtml(fullFormHtml);

        review.setOrder(ro);

        return review;

    } catch (CouponCodeInvalidException invalidCoupon) {

        ShopCodeContext.getLog(this).error(invalidCoupon.getMessage(), invalidCoupon);

        final OrderPreviewRO review = new OrderPreviewRO();
        review.setSuccess(false);
        final Map<String, String> problems = new HashMap<String, String>();
        problems.put("ERROR_COUPON", invalidCoupon.getCoupon());
        review.setProblems(problems);
        return review;

    } catch (SkuUnavailableException skuUnavailable) {

        ShopCodeContext.getLog(this).error(skuUnavailable.getMessage(), skuUnavailable);

        final OrderPreviewRO review = new OrderPreviewRO();
        review.setSuccess(false);
        final Map<String, String> problems = new HashMap<String, String>();
        problems.put("ERROR_SKU", skuUnavailable.getSkuCode());
        review.setProblems(problems);
        return review;

    } catch (OrderAssemblyException assembly) {

        ShopCodeContext.getLog(this).error(assembly.getMessage(), assembly);

        final OrderPreviewRO review = new OrderPreviewRO();
        review.setSuccess(false);
        final Map<String, String> problems = new HashMap<String, String>();
        problems.put("CART_ITEMS", assembly.getMessage());
        review.setProblems(problems);
        return review;

    }

}

From source file:org.yes.cart.web.service.rest.CartController.java

/**
 * Interface: POST /order/place/*  ww  w.ja v  a2  s.c o  m*/
 * <p>
 * <p>
 * Submit payment for internal payment processor and place order.
 * <p>
 * <p>
 * <h3>Headers for operation</h3><p>
 * <table border="1">
 *     <tr><td>Accept</td><td>application/json or application/xml</td></tr>
 *     <tr><td>yc</td><td>token uuid</td></tr>
 * </table>
 * <p>
 * <p>
 * <h3>Parameters for operation</h3><p>
 * Parameters posted from card form from PUT /order/preview
 * <p>
 * <p>
 * <h3>Output</h3><p>
 * <table border="1">
 *     <tr><td>JSON object OrderPlacedRO</td><td>
 * <pre><code>
 * {
 *     "success": true,
 *     "problems": null,
 *     "order": {
 *         "customerorderId": 1,
 *         "ordernum": "150407155547-1",
 *         "pgLabel": "courierPaymentGatewayLabel",
 *         "billingAddress": "In the middle of  0001 Nowhere GB GB-GB Bob Doe 123123123",
 *         "shippingAddress": "In the middle of  0001 Nowhere GB GB-GB Bob Doe 123123123",
 *         "cartGuid": "94bde080-612f-41b9-b566-d2bd1269559e",
 *         "currency": "EUR",
 *         "orderMessage": "My Message",
 *         "orderStatus": "os.waiting",
 *         "multipleShipmentOption": false,
 *         "orderTimestamp": 1428418547773,
 *         "email": "bob.doe@yc-checkout-json.com",
 *         "firstname": "Bob",
 *         "lastname": "Doe",
 *         "middlename": null,
 *         "customerId": 1,
 *         "shopId": 10,
 *         "code": "SHOIP1",
 *         "total": {
 *             "listSubTotal": 99.99,
 *             "saleSubTotal": 99.99,
 *             "nonSaleSubTotal": 99.99,
 *             "priceSubTotal": 99.99,
 *             "orderPromoApplied": false,
 *             "appliedOrderPromo": null,
 *             "subTotal": 99.99,
 *             "subTotalTax": 16.67,
 *             "subTotalAmount": 99.99,
 *             "deliveryListCost": 10.00,
 *             "deliveryCost": 10.00,
 *             "deliveryPromoApplied": false,
 *             "appliedDeliveryPromo": null,
 *             "deliveryTax": 1.67,
 *             "deliveryCostAmount": 10.00,
 *             "total": 109.99,
 *             "totalTax": 18.34,
 *             "listTotalAmount": 109.99,
 *             "totalAmount": 109.99
 *         },
 *         "deliveries": [{
 *             "customerOrderDeliveryId": 1,
 *             "deliveryNum": "150407155547-1-0",
 *             "refNo": null,
 *             "carrierSlaId": 4,
 *             "carrierSlaName": "14",
 *             "carrierSlaDisplayNames": null,
 *             "carrierId": 1,
 *             "carrierName": "Test carrier 1",
 *             "carrierDisplayNames": null,
 *             "deliveryStatus": "ds.inventory.reserved",
 *             "deliveryGroup": "D1",
 *             "total": {
 *                 "listSubTotal": 99.99,
 *                 "saleSubTotal": 99.99,
 *                 "nonSaleSubTotal": 99.99,
 *                 "priceSubTotal": 99.99,
 *                 "orderPromoApplied": false,
 *                 "appliedOrderPromo": null,
 *                 "subTotal": 99.99,
 *                 "subTotalTax": 16.67,
 *                 "subTotalAmount": 99.99,
 *                 "deliveryListCost": 10.00,
 *                 "deliveryCost": 10.00,
 *                 "deliveryPromoApplied": false,
 *                 "appliedDeliveryPromo": null,
 *                 "deliveryTax": 1.67,
 *                 "deliveryCostAmount": 10.00,
 *                 "total": 109.99,
 *                 "totalTax": 18.34,
 *                 "listTotalAmount": 109.99,
 *                 "totalAmount": 109.99
 *             },
 *             "deliveryItems": [{
 *                 "productSkuCode": "BENDER-ua",
 *                 "quantity": 1.00,
 *                 "price": 99.99,
 *                 "salePrice": 99.99,
 *                 "listPrice": 99.99,
 *                 "netPrice": 83.32,
 *                 "grossPrice": 99.99,
 *                 "taxRate": 20.00,
 *                 "taxCode": "VAT",
 *                 "taxExclusiveOfPrice": false,
 *                 "gift": false,
 *                 "promoApplied": false,
 *                 "appliedPromo": null,
 *                 "customerOrderDeliveryDetId": 0
 *             }]
 *         }],
 *         "orderItems": [{
 *             "productSkuCode": "BENDER-ua",
 *             "quantity": 1.00,
 *             "price": 99.99,
 *             "salePrice": 99.99,
 *             "listPrice": 99.99,
 *             "netPrice": 83.32,
 *             "grossPrice": 99.99,
 *             "taxRate": 20.00,
 *             "taxCode": "VAT",
 *             "taxExclusiveOfPrice": false,
 *             "gift": false,
 *             "promoApplied": false,
 *             "appliedPromo": null,
 *             "customerOrderDetId": 0
 *         }]
 *     }
 * }
 * </code></pre>
 *     </td></tr>
 *     <tr><td>XML object OrderPlacedRO</td><td>
 * <pre><code>
 * &lt;order-placed success="true"&gt;
 *    &lt;order cart-guid="54880429-628f-45fb-bc9b-6fb04667cded" shop-code="SHOIP1" currency="EUR" customer-id="2"
 *              customer-order-id="2" multiple-shipment-option="false" order-status="os.waiting" order-timestamp="2015-04-07T15:55:50.540+01:00"
 *              ordernum="150407155550-2" pg-label="courierPaymentGatewayLabel" shop-id="10"&gt;
 *       &lt;billing-address&gt;In the middle of  0001 Nowhere GB GB-GB Bob Doe 123123123&lt;/billing-address&gt;
 *       &lt;deliveries&gt;
 *          &lt;delivery carrier-id="1" carriersla-id="4" customer-order-delivery-id="2" delivery-group="D1"
 *                         delivery-num="150407155550-2-0" delivery-status="ds.inventory.reserved"&gt;
 *             &lt;carrier-name&gt;Test carrier 1&lt;/carrier-name&gt;
 *             &lt;carriersla-name&gt;14&lt;/carriersla-name&gt;
 *             &lt;delivery-items&gt;
 *                &lt;delivery-item customer-order-delivery-det-id="0" gift="false" gross-price="99.99" list-price="99.99"
 *                                   net-price="83.32" price="99.99" product-sku-code="BENDER-ua" promo-applied="false"
 *                                   quantity="1.00" sale-price="99.99" tax-code="VAT" tax-exclusive-of-price="false"
 *                                   tax-rate="20.00"/&gt;
 *             &lt;/delivery-items&gt;
 *             &lt;total delivery-cost="10.00" delivery-cost-amount="10.00" delivery-list-cost="10.00"
 *                       delivery-promo-applied="false" delivery-tax="1.67" list-sub-total="99.99" list-total-amount="109.99"
 *                       non-sale-sub-total="99.99" promo-applied="false" price-sub-total="99.99" sale-sub-total="99.99"
 *                       sub-total="99.99" sub-total-amount="99.99" sub-total-tax="16.67" total="109.99" total-amount="109.99"
 *                       total-tax="18.34"/&gt;
 *          &lt;/delivery&gt;
 *       &lt;/deliveries&gt;
 *       &lt;email&gt;bob.doe@-checkout-xml.com&lt;/email&gt;
 *       &lt;firstname&gt;Bob&lt;/firstname&gt;
 *       &lt;lastname&gt;Doe&lt;/lastname&gt;
 *       &lt;order-items&gt;
 *          &lt;order-item customer-order-det-id="0" gift="false" gross-price="99.99" list-price="99.99" net-price="83.32"
 *                         price="99.99" product-sku-code="BENDER-ua" promo-applied="false" quantity="1.00" sale-price="99.99"
 *                         tax-code="VAT" tax-exclusive-of-price="false" tax-rate="20.00"/&gt;
 *       &lt;/order-items&gt;
 *       &lt;order-message&gt;My Message&lt;/order-message&gt;
 *       &lt;shipping-address&gt;In the middle of  0001 Nowhere GB GB-GB Bob Doe 123123123&lt;/shipping-address&gt;
 *       &lt;total delivery-cost="10.00" delivery-cost-amount="10.00" delivery-list-cost="10.00" delivery-promo-applied="false"
 *                  delivery-tax="1.67" list-sub-total="99.99" list-total-amount="109.99" non-sale-sub-total="99.99"
 *                  promo-applied="false" price-sub-total="99.99" sale-sub-total="99.99" sub-total="99.99"
 *                  sub-total-amount="99.99" sub-total-tax="16.67" total="109.99" total-amount="109.99" total-tax="18.34"/&gt;
 *    &lt;/order&gt;
 * &lt;/order-placed&gt;
 * </code></pre>
 *     </td></tr>
 * </table>
 * <p>
 * <h3>Error codes</h3><p>
 * <table border="1">
 *     <tr><td>CART_ITEMS</td><td>MISSING if no items present in the cart</td></tr>
 *     <tr><td>ORDER</td><td>MISSING if order has not been previewed</td></tr>
 *     <tr><td>PAYMENT_METHOD</td><td>PAYMENT_FAILED if payment failed</td></tr>
 *     <tr><td>CART_ITEM_OUT_OF_STOCK</td><td>sku code, if SKU is out of stock</td></tr>
 *     <tr><td>ORDER</td><td>error message, for any other reason</td></tr>
 * </table>
 * <p>
 *
 * @param request request
 * @param response response
 *
 * @return order placed object
 */
@RequestMapping(value = "/order/place", method = RequestMethod.POST, produces = {
        MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
public @ResponseBody OrderPlacedRO orderPlace(final HttpServletRequest request,
        final HttpServletResponse response) {

    cartMixin.throwSecurityExceptionIfNotLoggedIn();

    final Map param = request.getParameterMap();
    final Map mparam = new HashMap();
    mparam.putAll(param);
    mparam.put(PaymentMiscParam.CLIENT_IP, ApplicationDirector.getShopperIPAddress());

    final ShoppingCart cart = cartMixin.getCurrentCart();
    final String guid = cart.getGuid();
    final OrderPlacedRO placed = new OrderPlacedRO();

    try {

        if (cart.getCartItemsCount() > 0) {

            final CustomerOrder order = checkoutServiceFacade.findByGuid(guid);

            if (order == null) {

                placed.setSuccess(false);
                final Map<String, String> problems = new HashMap<String, String>();
                problems.put("ORDER", "MISSING");
                placed.setProblems(problems);

            } else {

                boolean result = paymentProcessFacade.pay(cart, mparam);
                if (result) {

                    final Total total = checkoutServiceFacade.getOrderTotal(order);
                    final OrderRO ro = mappingMixin.map(order, OrderRO.class, CustomerOrder.class);
                    ro.setTotal(mappingMixin.map(total, CartTotalRO.class, Total.class));

                    for (final CustomerOrderDelivery delivery : order.getDelivery()) {
                        final DeliveryRO dro = mappingMixin.map(delivery, DeliveryRO.class,
                                CustomerOrderDelivery.class);
                        final Total dtotal = checkoutServiceFacade.getOrderDeliveryTotal(order, delivery);
                        dro.setTotal(mappingMixin.map(dtotal, CartTotalRO.class, Total.class));
                        ro.getDeliveries().add(dro);
                    }

                    shoppingCartCommandFactory.execute(ShoppingCartCommand.CMD_CLEAN,
                            ApplicationDirector.getShoppingCart(),
                            Collections.singletonMap(ShoppingCartCommand.CMD_CLEAN, null));

                    placed.setOrder(ro);
                    placed.setSuccess(true);

                } else {

                    placed.setSuccess(false);
                    final Map<String, String> problems = new HashMap<String, String>();
                    problems.put("PAYMENT_METHOD", "PAYMENT_FAILED");
                    placed.setProblems(problems);

                }
            }
        } else {

            placed.setSuccess(false);
            final Map<String, String> problems = new HashMap<String, String>();
            problems.put("CART_ITEMS", "MISSING");
            placed.setProblems(problems);

        }

    } catch (OrderItemAllocationException e) {

        placed.setSuccess(false);
        final Map<String, String> problems = new HashMap<String, String>();
        problems.put("CART_ITEM_OUT_OF_STOCK", e.getProductSkuCode());
        placed.setProblems(problems);

    } catch (OrderException e) {

        placed.setSuccess(false);
        final Map<String, String> problems = new HashMap<String, String>();
        problems.put("ORDER", e.getMessage());
        placed.setProblems(problems);

    }

    cartMixin.persistShoppingCart(request, response);
    return placed;
}

From source file:org.yes.cart.web.service.rest.CategoryController.java

@RequestMapping(value = "/top", method = RequestMethod.GET, produces = MediaType.APPLICATION_XML_VALUE)
public @ResponseBody CategoryListRO listRootXML(final HttpServletRequest request,
        final HttpServletResponse response) {

    persistShoppingCart(request, response);

    return new CategoryListRO(listRootInternal());

}

From source file:org.yes.cart.web.service.rest.CategoryController.java

@RequestMapping(value = "/view/{id}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE,
        MediaType.APPLICATION_XML_VALUE })
public @ResponseBody CategoryRO viewCategory(@PathVariable(value = "id") final String category,
        final HttpServletRequest request, final HttpServletResponse response) {

    persistShoppingCart(request, response);

    final long categoryId = resolveId(category);

    if (categoryIsVisibleInShop(categoryId)) {

        final CategoryRO cat = map(categoryService.getById(categoryId), CategoryRO.class, Category.class);
        cat.setBreadcrumbs(generateBreadcrumbs(cat.getCategoryId()));
        return cat;

    }//from www.j av  a  2 s . c o  m

    return null;

}

From source file:org.yes.cart.web.service.rest.CategoryController.java

@RequestMapping(value = "/list/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_XML_VALUE)
public @ResponseBody CategoryListRO listCategoryXML(@PathVariable(value = "id") final String category,
        final HttpServletRequest request, final HttpServletResponse response) {

    persistShoppingCart(request, response);

    return new CategoryListRO(listCategoryInternal(category));

}

From source file:org.yes.cart.web.service.rest.ContentController.java

@RequestMapping(value = "/view/{id}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE,
        MediaType.APPLICATION_XML_VALUE })
public @ResponseBody ContentRO viewContent(@PathVariable(value = "id") final String content,
        final HttpServletRequest request, final HttpServletResponse response) {

    persistShoppingCart(request, response);

    return viewContentInternal(content, null);
}

From source file:org.yes.cart.web.service.rest.ContentController.java

@RequestMapping(value = "/view/{id}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_XML_VALUE, consumes = MediaType.APPLICATION_XML_VALUE)
public @ResponseBody ContentRO viewContentXML(@PathVariable(value = "id") final String content,
        @RequestBody final XMLParamsRO params, final HttpServletRequest request,
        final HttpServletResponse response) {

    persistShoppingCart(request, response);

    return viewContentInternal(content, (Map) params.getParameters());
}

From source file:org.yes.cart.web.service.rest.ContentController.java

@RequestMapping(value = "/list/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_XML_VALUE)
public @ResponseBody ContentListRO listContentXML(@PathVariable(value = "id") final String category,
        final HttpServletRequest request, final HttpServletResponse response) {

    persistShoppingCart(request, response);

    return new ContentListRO(listContentInternal(category, null));

}

From source file:org.yes.cart.web.service.rest.ContentController.java

@RequestMapping(value = "/list/{id}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_XML_VALUE, consumes = MediaType.APPLICATION_XML_VALUE)
public @ResponseBody ContentListRO listContentXML(@PathVariable(value = "id") final String category,
        final XMLParamsRO contentParams, final HttpServletRequest request, final HttpServletResponse response) {

    persistShoppingCart(request, response);

    return new ContentListRO(listContentInternal(category, (Map) contentParams.getParameters()));

}

From source file:org.yes.cart.web.service.rest.CustomerController.java

/**
 * Interface: GET /yes-api/rest/customer/summary
 * <p>/*from   ww w .j a v a 2  s  .co  m*/
 * <p>
 * Display customer profile information.
 * <p>
 * <p>
 * <h3>Headers for operation</h3><p>
 * <table border="1">
 *     <tr><td>Accept</td><td>application/json or application/xml</td></tr>
 *     <tr><td>yc</td><td>token uuid</td></tr>
 * </table>
 * <p>
 * <p>
 * <h3>Parameters for operation</h3><p>
 * NONE
 * <p>
 * <p>
 * <h3>Output</h3><p>
 * <table border="1">
 *     <tr><td>JSON object CustomerRO</td><td>
 * <pre><code>
 * {
 *     "customerId": 1,
 *     "email": "bob.doe@yc-json.com",
 *     "firstname": "Bob",
 *     "lastname": "Doe",
 *     "middlename": null,
 *     "tag": null,
 *     "attributes": [{
 *         "attrvalueId": 1,
 *         "val": "123123123",
 *         "displayVals": null,
 *         "attributeId": 1030,
 *         "attributeName": "Customer phone",
 *         "attributeDisplayNames": null,
 *         "customerId": 1
 *     }]
 * }
 * </code></pre>
 *     </td></tr>
 *     <tr><td>XML object CustomerRO</td><td>
 * <pre><code>
 * &lt;customer&gt;
 *    &lt;attribute-values&gt;
 *       &lt;attribute-value attribute-id="1030" attrvalue-id="2" customer-id="2"&gt;
 *          &lt;attribute-name&gt;Customer phone&lt;/attribute-name&gt;
 *          &lt;val&gt;123123123&lt;/val&gt;
 *       &lt;/attribute-value&gt;
 *    &lt;/attribute-values&gt;
 *    &lt;customerId&gt;2&lt;/customerId&gt;
 *    &lt;email&gt;bob.doe@yc-xml.com&lt;/email&gt;
 *    &lt;firstname&gt;Bob&lt;/firstname&gt;
 *    &lt;lastname&gt;Doe&lt;/lastname&gt;
 * &lt;/customer&gt;
 * </code></pre>
 *     </td></tr>
 * </table>
 *
 * @param request request
 * @param response response
 *
 * @return customer object
 */
@RequestMapping(value = "/summary", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE,
        MediaType.APPLICATION_XML_VALUE })
public @ResponseBody CustomerRO viewSummary(final HttpServletRequest request,
        final HttpServletResponse response) {

    cartMixin.throwSecurityExceptionIfNotLoggedIn();
    cartMixin.persistShoppingCart(request, response);

    final Shop shop = cartMixin.getCurrentShop();
    final ShoppingCart cart = cartMixin.getCurrentCart();

    final Customer customer = customerServiceFacade.getCustomerByEmail(cart.getCustomerEmail());

    final CustomerRO ro = mappingMixin.map(customer, CustomerRO.class, Customer.class);

    // Only map allowed attributes
    final List<AttrValueCustomerRO> profileAttrs = new ArrayList<AttrValueCustomerRO>();
    for (final Pair<AttrValueCustomer, Boolean> av : customerServiceFacade.getCustomerProfileAttributes(shop,
            customer)) {
        profileAttrs.add(mappingMixin.map(av.getFirst(), AttrValueCustomerRO.class, AttrValueCustomer.class));
    }
    ro.setAttributes(profileAttrs);

    return ro;

}