/modules/apps/commerce/headless/headless-commerce/headless-commerce-delivery-cart-client/src/main/java/com/liferay/headless/commerce/delivery/cart/client/resource/v1_0/CartResource.java
https://github.com/danielreuther/liferay-portal · Java · 1079 lines · 801 code · 261 blank · 17 comment · 88 complexity · df5a3ba0f50e8100235398a213502c08 MD5 · raw file
- /**
- * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License as published by the Free
- * Software Foundation; either version 2.1 of the License, or (at your option)
- * any later version.
- *
- * This library is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
- * details.
- */
- package com.liferay.headless.commerce.delivery.cart.client.resource.v1_0;
- import com.liferay.headless.commerce.delivery.cart.client.dto.v1_0.Cart;
- import com.liferay.headless.commerce.delivery.cart.client.dto.v1_0.CouponCode;
- import com.liferay.headless.commerce.delivery.cart.client.http.HttpInvoker;
- import com.liferay.headless.commerce.delivery.cart.client.pagination.Page;
- import com.liferay.headless.commerce.delivery.cart.client.pagination.Pagination;
- import com.liferay.headless.commerce.delivery.cart.client.problem.Problem;
- import com.liferay.headless.commerce.delivery.cart.client.serdes.v1_0.CartSerDes;
- import java.util.LinkedHashMap;
- import java.util.Locale;
- import java.util.Map;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.annotation.Generated;
- /**
- * @author Andrea Sbarra
- * @generated
- */
- @Generated("")
- public interface CartResource {
- public static Builder builder() {
- return new Builder();
- }
- public void deleteCart(Long cartId) throws Exception;
- public HttpInvoker.HttpResponse deleteCartHttpResponse(Long cartId)
- throws Exception;
- public void deleteCartBatch(String callbackURL, Object object)
- throws Exception;
- public HttpInvoker.HttpResponse deleteCartBatchHttpResponse(
- String callbackURL, Object object)
- throws Exception;
- public Cart getCart(Long cartId) throws Exception;
- public HttpInvoker.HttpResponse getCartHttpResponse(Long cartId)
- throws Exception;
- public Cart patchCart(Long cartId, Cart cart) throws Exception;
- public HttpInvoker.HttpResponse patchCartHttpResponse(
- Long cartId, Cart cart)
- throws Exception;
- public Cart putCart(Long cartId, Cart cart) throws Exception;
- public HttpInvoker.HttpResponse putCartHttpResponse(Long cartId, Cart cart)
- throws Exception;
- public void putCartBatch(String callbackURL, Object object)
- throws Exception;
- public HttpInvoker.HttpResponse putCartBatchHttpResponse(
- String callbackURL, Object object)
- throws Exception;
- public Cart postCartCheckout(Long cartId) throws Exception;
- public HttpInvoker.HttpResponse postCartCheckoutHttpResponse(Long cartId)
- throws Exception;
- public Cart postCartCouponCode(Long cartId, CouponCode couponCode)
- throws Exception;
- public HttpInvoker.HttpResponse postCartCouponCodeHttpResponse(
- Long cartId, CouponCode couponCode)
- throws Exception;
- public String getCartPaymentURL(Long cartId, String callbackURL)
- throws Exception;
- public HttpInvoker.HttpResponse getCartPaymentURLHttpResponse(
- Long cartId, String callbackURL)
- throws Exception;
- public Page<Cart> getChannelCartsPage(
- Long accountId, Long channelId, Pagination pagination)
- throws Exception;
- public HttpInvoker.HttpResponse getChannelCartsPageHttpResponse(
- Long accountId, Long channelId, Pagination pagination)
- throws Exception;
- public Cart postChannelCart(Long channelId, Cart cart) throws Exception;
- public HttpInvoker.HttpResponse postChannelCartHttpResponse(
- Long channelId, Cart cart)
- throws Exception;
- public static class Builder {
- public Builder authentication(String login, String password) {
- _login = login;
- _password = password;
- return this;
- }
- public CartResource build() {
- return new CartResourceImpl(this);
- }
- public Builder contextPath(String contextPath) {
- _contextPath = contextPath;
- return this;
- }
- public Builder endpoint(String host, int port, String scheme) {
- _host = host;
- _port = port;
- _scheme = scheme;
- return this;
- }
- public Builder header(String key, String value) {
- _headers.put(key, value);
- return this;
- }
- public Builder locale(Locale locale) {
- _locale = locale;
- return this;
- }
- public Builder parameter(String key, String value) {
- _parameters.put(key, value);
- return this;
- }
- public Builder parameters(String... parameters) {
- if ((parameters.length % 2) != 0) {
- throw new IllegalArgumentException(
- "Parameters length is not an even number");
- }
- for (int i = 0; i < parameters.length; i += 2) {
- String parameterName = String.valueOf(parameters[i]);
- String parameterValue = String.valueOf(parameters[i + 1]);
- _parameters.put(parameterName, parameterValue);
- }
- return this;
- }
- private Builder() {
- }
- private String _contextPath = "";
- private Map<String, String> _headers = new LinkedHashMap<>();
- private String _host = "localhost";
- private Locale _locale;
- private String _login = "";
- private String _password = "";
- private Map<String, String> _parameters = new LinkedHashMap<>();
- private int _port = 8080;
- private String _scheme = "http";
- }
- public static class CartResourceImpl implements CartResource {
- public void deleteCart(Long cartId) throws Exception {
- HttpInvoker.HttpResponse httpResponse = deleteCartHttpResponse(
- cartId);
- String content = httpResponse.getContent();
- if ((httpResponse.getStatusCode() / 100) != 2) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response content: " + content);
- _logger.log(
- Level.WARNING,
- "HTTP response message: " + httpResponse.getMessage());
- _logger.log(
- Level.WARNING,
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- else {
- _logger.fine("HTTP response content: " + content);
- _logger.fine(
- "HTTP response message: " + httpResponse.getMessage());
- _logger.fine(
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- }
- }
- public HttpInvoker.HttpResponse deleteCartHttpResponse(Long cartId)
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- if (_builder._locale != null) {
- httpInvoker.header(
- "Accept-Language", _builder._locale.toLanguageTag());
- }
- for (Map.Entry<String, String> entry :
- _builder._headers.entrySet()) {
- httpInvoker.header(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry :
- _builder._parameters.entrySet()) {
- httpInvoker.parameter(entry.getKey(), entry.getValue());
- }
- httpInvoker.httpMethod(HttpInvoker.HttpMethod.DELETE);
- httpInvoker.path(
- _builder._scheme + "://" + _builder._host + ":" +
- _builder._port + _builder._contextPath +
- "/o/headless-commerce-delivery-cart/v1.0/carts/{cartId}");
- httpInvoker.path("cartId", cartId);
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public void deleteCartBatch(String callbackURL, Object object)
- throws Exception {
- HttpInvoker.HttpResponse httpResponse = deleteCartBatchHttpResponse(
- callbackURL, object);
- String content = httpResponse.getContent();
- if ((httpResponse.getStatusCode() / 100) != 2) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response content: " + content);
- _logger.log(
- Level.WARNING,
- "HTTP response message: " + httpResponse.getMessage());
- _logger.log(
- Level.WARNING,
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- else {
- _logger.fine("HTTP response content: " + content);
- _logger.fine(
- "HTTP response message: " + httpResponse.getMessage());
- _logger.fine(
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- }
- }
- public HttpInvoker.HttpResponse deleteCartBatchHttpResponse(
- String callbackURL, Object object)
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- httpInvoker.body(object.toString(), "application/json");
- if (_builder._locale != null) {
- httpInvoker.header(
- "Accept-Language", _builder._locale.toLanguageTag());
- }
- for (Map.Entry<String, String> entry :
- _builder._headers.entrySet()) {
- httpInvoker.header(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry :
- _builder._parameters.entrySet()) {
- httpInvoker.parameter(entry.getKey(), entry.getValue());
- }
- httpInvoker.httpMethod(HttpInvoker.HttpMethod.DELETE);
- if (callbackURL != null) {
- httpInvoker.parameter(
- "callbackURL", String.valueOf(callbackURL));
- }
- httpInvoker.path(
- _builder._scheme + "://" + _builder._host + ":" +
- _builder._port + _builder._contextPath +
- "/o/headless-commerce-delivery-cart/v1.0/carts/batch");
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public Cart getCart(Long cartId) throws Exception {
- HttpInvoker.HttpResponse httpResponse = getCartHttpResponse(cartId);
- String content = httpResponse.getContent();
- if ((httpResponse.getStatusCode() / 100) != 2) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response content: " + content);
- _logger.log(
- Level.WARNING,
- "HTTP response message: " + httpResponse.getMessage());
- _logger.log(
- Level.WARNING,
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- else {
- _logger.fine("HTTP response content: " + content);
- _logger.fine(
- "HTTP response message: " + httpResponse.getMessage());
- _logger.fine(
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- }
- try {
- return CartSerDes.toDTO(content);
- }
- catch (Exception e) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response: " + content, e);
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- }
- public HttpInvoker.HttpResponse getCartHttpResponse(Long cartId)
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- if (_builder._locale != null) {
- httpInvoker.header(
- "Accept-Language", _builder._locale.toLanguageTag());
- }
- for (Map.Entry<String, String> entry :
- _builder._headers.entrySet()) {
- httpInvoker.header(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry :
- _builder._parameters.entrySet()) {
- httpInvoker.parameter(entry.getKey(), entry.getValue());
- }
- httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
- httpInvoker.path(
- _builder._scheme + "://" + _builder._host + ":" +
- _builder._port + _builder._contextPath +
- "/o/headless-commerce-delivery-cart/v1.0/carts/{cartId}");
- httpInvoker.path("cartId", cartId);
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public Cart patchCart(Long cartId, Cart cart) throws Exception {
- HttpInvoker.HttpResponse httpResponse = patchCartHttpResponse(
- cartId, cart);
- String content = httpResponse.getContent();
- if ((httpResponse.getStatusCode() / 100) != 2) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response content: " + content);
- _logger.log(
- Level.WARNING,
- "HTTP response message: " + httpResponse.getMessage());
- _logger.log(
- Level.WARNING,
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- else {
- _logger.fine("HTTP response content: " + content);
- _logger.fine(
- "HTTP response message: " + httpResponse.getMessage());
- _logger.fine(
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- }
- try {
- return CartSerDes.toDTO(content);
- }
- catch (Exception e) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response: " + content, e);
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- }
- public HttpInvoker.HttpResponse patchCartHttpResponse(
- Long cartId, Cart cart)
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- httpInvoker.body(cart.toString(), "application/json");
- if (_builder._locale != null) {
- httpInvoker.header(
- "Accept-Language", _builder._locale.toLanguageTag());
- }
- for (Map.Entry<String, String> entry :
- _builder._headers.entrySet()) {
- httpInvoker.header(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry :
- _builder._parameters.entrySet()) {
- httpInvoker.parameter(entry.getKey(), entry.getValue());
- }
- httpInvoker.httpMethod(HttpInvoker.HttpMethod.PATCH);
- httpInvoker.path(
- _builder._scheme + "://" + _builder._host + ":" +
- _builder._port + _builder._contextPath +
- "/o/headless-commerce-delivery-cart/v1.0/carts/{cartId}");
- httpInvoker.path("cartId", cartId);
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public Cart putCart(Long cartId, Cart cart) throws Exception {
- HttpInvoker.HttpResponse httpResponse = putCartHttpResponse(
- cartId, cart);
- String content = httpResponse.getContent();
- if ((httpResponse.getStatusCode() / 100) != 2) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response content: " + content);
- _logger.log(
- Level.WARNING,
- "HTTP response message: " + httpResponse.getMessage());
- _logger.log(
- Level.WARNING,
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- else {
- _logger.fine("HTTP response content: " + content);
- _logger.fine(
- "HTTP response message: " + httpResponse.getMessage());
- _logger.fine(
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- }
- try {
- return CartSerDes.toDTO(content);
- }
- catch (Exception e) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response: " + content, e);
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- }
- public HttpInvoker.HttpResponse putCartHttpResponse(
- Long cartId, Cart cart)
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- httpInvoker.body(cart.toString(), "application/json");
- if (_builder._locale != null) {
- httpInvoker.header(
- "Accept-Language", _builder._locale.toLanguageTag());
- }
- for (Map.Entry<String, String> entry :
- _builder._headers.entrySet()) {
- httpInvoker.header(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry :
- _builder._parameters.entrySet()) {
- httpInvoker.parameter(entry.getKey(), entry.getValue());
- }
- httpInvoker.httpMethod(HttpInvoker.HttpMethod.PUT);
- httpInvoker.path(
- _builder._scheme + "://" + _builder._host + ":" +
- _builder._port + _builder._contextPath +
- "/o/headless-commerce-delivery-cart/v1.0/carts/{cartId}");
- httpInvoker.path("cartId", cartId);
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public void putCartBatch(String callbackURL, Object object)
- throws Exception {
- HttpInvoker.HttpResponse httpResponse = putCartBatchHttpResponse(
- callbackURL, object);
- String content = httpResponse.getContent();
- if ((httpResponse.getStatusCode() / 100) != 2) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response content: " + content);
- _logger.log(
- Level.WARNING,
- "HTTP response message: " + httpResponse.getMessage());
- _logger.log(
- Level.WARNING,
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- else {
- _logger.fine("HTTP response content: " + content);
- _logger.fine(
- "HTTP response message: " + httpResponse.getMessage());
- _logger.fine(
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- }
- }
- public HttpInvoker.HttpResponse putCartBatchHttpResponse(
- String callbackURL, Object object)
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- httpInvoker.body(object.toString(), "application/json");
- if (_builder._locale != null) {
- httpInvoker.header(
- "Accept-Language", _builder._locale.toLanguageTag());
- }
- for (Map.Entry<String, String> entry :
- _builder._headers.entrySet()) {
- httpInvoker.header(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry :
- _builder._parameters.entrySet()) {
- httpInvoker.parameter(entry.getKey(), entry.getValue());
- }
- httpInvoker.httpMethod(HttpInvoker.HttpMethod.PUT);
- if (callbackURL != null) {
- httpInvoker.parameter(
- "callbackURL", String.valueOf(callbackURL));
- }
- httpInvoker.path(
- _builder._scheme + "://" + _builder._host + ":" +
- _builder._port + _builder._contextPath +
- "/o/headless-commerce-delivery-cart/v1.0/carts/batch");
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public Cart postCartCheckout(Long cartId) throws Exception {
- HttpInvoker.HttpResponse httpResponse =
- postCartCheckoutHttpResponse(cartId);
- String content = httpResponse.getContent();
- if ((httpResponse.getStatusCode() / 100) != 2) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response content: " + content);
- _logger.log(
- Level.WARNING,
- "HTTP response message: " + httpResponse.getMessage());
- _logger.log(
- Level.WARNING,
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- else {
- _logger.fine("HTTP response content: " + content);
- _logger.fine(
- "HTTP response message: " + httpResponse.getMessage());
- _logger.fine(
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- }
- try {
- return CartSerDes.toDTO(content);
- }
- catch (Exception e) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response: " + content, e);
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- }
- public HttpInvoker.HttpResponse postCartCheckoutHttpResponse(
- Long cartId)
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- if (_builder._locale != null) {
- httpInvoker.header(
- "Accept-Language", _builder._locale.toLanguageTag());
- }
- for (Map.Entry<String, String> entry :
- _builder._headers.entrySet()) {
- httpInvoker.header(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry :
- _builder._parameters.entrySet()) {
- httpInvoker.parameter(entry.getKey(), entry.getValue());
- }
- httpInvoker.httpMethod(HttpInvoker.HttpMethod.POST);
- httpInvoker.path(
- _builder._scheme + "://" + _builder._host + ":" +
- _builder._port + _builder._contextPath +
- "/o/headless-commerce-delivery-cart/v1.0/carts/{cartId}/checkout");
- httpInvoker.path("cartId", cartId);
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public Cart postCartCouponCode(Long cartId, CouponCode couponCode)
- throws Exception {
- HttpInvoker.HttpResponse httpResponse =
- postCartCouponCodeHttpResponse(cartId, couponCode);
- String content = httpResponse.getContent();
- if ((httpResponse.getStatusCode() / 100) != 2) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response content: " + content);
- _logger.log(
- Level.WARNING,
- "HTTP response message: " + httpResponse.getMessage());
- _logger.log(
- Level.WARNING,
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- else {
- _logger.fine("HTTP response content: " + content);
- _logger.fine(
- "HTTP response message: " + httpResponse.getMessage());
- _logger.fine(
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- }
- try {
- return CartSerDes.toDTO(content);
- }
- catch (Exception e) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response: " + content, e);
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- }
- public HttpInvoker.HttpResponse postCartCouponCodeHttpResponse(
- Long cartId, CouponCode couponCode)
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- httpInvoker.body(couponCode.toString(), "application/json");
- if (_builder._locale != null) {
- httpInvoker.header(
- "Accept-Language", _builder._locale.toLanguageTag());
- }
- for (Map.Entry<String, String> entry :
- _builder._headers.entrySet()) {
- httpInvoker.header(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry :
- _builder._parameters.entrySet()) {
- httpInvoker.parameter(entry.getKey(), entry.getValue());
- }
- httpInvoker.httpMethod(HttpInvoker.HttpMethod.POST);
- httpInvoker.path(
- _builder._scheme + "://" + _builder._host + ":" +
- _builder._port + _builder._contextPath +
- "/o/headless-commerce-delivery-cart/v1.0/carts/{cartId}/coupon-code");
- httpInvoker.path("cartId", cartId);
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public String getCartPaymentURL(Long cartId, String callbackURL)
- throws Exception {
- HttpInvoker.HttpResponse httpResponse =
- getCartPaymentURLHttpResponse(cartId, callbackURL);
- String content = httpResponse.getContent();
- if ((httpResponse.getStatusCode() / 100) != 2) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response content: " + content);
- _logger.log(
- Level.WARNING,
- "HTTP response message: " + httpResponse.getMessage());
- _logger.log(
- Level.WARNING,
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- else {
- _logger.fine("HTTP response content: " + content);
- _logger.fine(
- "HTTP response message: " + httpResponse.getMessage());
- _logger.fine(
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- }
- try {
- return content;
- }
- catch (Exception e) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response: " + content, e);
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- }
- public HttpInvoker.HttpResponse getCartPaymentURLHttpResponse(
- Long cartId, String callbackURL)
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- if (_builder._locale != null) {
- httpInvoker.header(
- "Accept-Language", _builder._locale.toLanguageTag());
- }
- for (Map.Entry<String, String> entry :
- _builder._headers.entrySet()) {
- httpInvoker.header(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry :
- _builder._parameters.entrySet()) {
- httpInvoker.parameter(entry.getKey(), entry.getValue());
- }
- httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
- if (callbackURL != null) {
- httpInvoker.parameter(
- "callbackURL", String.valueOf(callbackURL));
- }
- httpInvoker.path(
- _builder._scheme + "://" + _builder._host + ":" +
- _builder._port + _builder._contextPath +
- "/o/headless-commerce-delivery-cart/v1.0/carts/{cartId}/payment-url");
- httpInvoker.path("cartId", cartId);
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public Page<Cart> getChannelCartsPage(
- Long accountId, Long channelId, Pagination pagination)
- throws Exception {
- HttpInvoker.HttpResponse httpResponse =
- getChannelCartsPageHttpResponse(
- accountId, channelId, pagination);
- String content = httpResponse.getContent();
- if ((httpResponse.getStatusCode() / 100) != 2) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response content: " + content);
- _logger.log(
- Level.WARNING,
- "HTTP response message: " + httpResponse.getMessage());
- _logger.log(
- Level.WARNING,
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- else {
- _logger.fine("HTTP response content: " + content);
- _logger.fine(
- "HTTP response message: " + httpResponse.getMessage());
- _logger.fine(
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- }
- try {
- return Page.of(content, CartSerDes::toDTO);
- }
- catch (Exception e) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response: " + content, e);
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- }
- public HttpInvoker.HttpResponse getChannelCartsPageHttpResponse(
- Long accountId, Long channelId, Pagination pagination)
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- if (_builder._locale != null) {
- httpInvoker.header(
- "Accept-Language", _builder._locale.toLanguageTag());
- }
- for (Map.Entry<String, String> entry :
- _builder._headers.entrySet()) {
- httpInvoker.header(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry :
- _builder._parameters.entrySet()) {
- httpInvoker.parameter(entry.getKey(), entry.getValue());
- }
- httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
- if (pagination != null) {
- httpInvoker.parameter(
- "page", String.valueOf(pagination.getPage()));
- httpInvoker.parameter(
- "pageSize", String.valueOf(pagination.getPageSize()));
- }
- httpInvoker.path(
- _builder._scheme + "://" + _builder._host + ":" +
- _builder._port + _builder._contextPath +
- "/o/headless-commerce-delivery-cart/v1.0/channels/{channelId}/account/{accountId}/carts");
- httpInvoker.path("accountId", accountId);
- httpInvoker.path("channelId", channelId);
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public Cart postChannelCart(Long channelId, Cart cart)
- throws Exception {
- HttpInvoker.HttpResponse httpResponse = postChannelCartHttpResponse(
- channelId, cart);
- String content = httpResponse.getContent();
- if ((httpResponse.getStatusCode() / 100) != 2) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response content: " + content);
- _logger.log(
- Level.WARNING,
- "HTTP response message: " + httpResponse.getMessage());
- _logger.log(
- Level.WARNING,
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- else {
- _logger.fine("HTTP response content: " + content);
- _logger.fine(
- "HTTP response message: " + httpResponse.getMessage());
- _logger.fine(
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- }
- try {
- return CartSerDes.toDTO(content);
- }
- catch (Exception e) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response: " + content, e);
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- }
- public HttpInvoker.HttpResponse postChannelCartHttpResponse(
- Long channelId, Cart cart)
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- httpInvoker.body(cart.toString(), "application/json");
- if (_builder._locale != null) {
- httpInvoker.header(
- "Accept-Language", _builder._locale.toLanguageTag());
- }
- for (Map.Entry<String, String> entry :
- _builder._headers.entrySet()) {
- httpInvoker.header(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry :
- _builder._parameters.entrySet()) {
- httpInvoker.parameter(entry.getKey(), entry.getValue());
- }
- httpInvoker.httpMethod(HttpInvoker.HttpMethod.POST);
- httpInvoker.path(
- _builder._scheme + "://" + _builder._host + ":" +
- _builder._port + _builder._contextPath +
- "/o/headless-commerce-delivery-cart/v1.0/channels/{channelId}/carts");
- httpInvoker.path("channelId", channelId);
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- private CartResourceImpl(Builder builder) {
- _builder = builder;
- }
- private static final Logger _logger = Logger.getLogger(
- CartResource.class.getName());
- private Builder _builder;
- }
- }