/modules/apps/commerce/headless/headless-commerce/headless-commerce-admin-shipment-client/src/main/java/com/liferay/headless/commerce/admin/shipment/client/resource/v1_0/ShipmentItemResource.java

https://github.com/danielreuther/liferay-portal · Java · 1144 lines · 859 code · 268 blank · 17 comment · 86 complexity · 74c3a49ba2d643011828b3d2efab045c MD5 · raw file

  1. /**
  2. * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or modify it under
  5. * the terms of the GNU Lesser General Public License as published by the Free
  6. * Software Foundation; either version 2.1 of the License, or (at your option)
  7. * any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  12. * details.
  13. */
  14. package com.liferay.headless.commerce.admin.shipment.client.resource.v1_0;
  15. import com.liferay.headless.commerce.admin.shipment.client.dto.v1_0.ShipmentItem;
  16. import com.liferay.headless.commerce.admin.shipment.client.http.HttpInvoker;
  17. import com.liferay.headless.commerce.admin.shipment.client.pagination.Page;
  18. import com.liferay.headless.commerce.admin.shipment.client.pagination.Pagination;
  19. import com.liferay.headless.commerce.admin.shipment.client.problem.Problem;
  20. import com.liferay.headless.commerce.admin.shipment.client.serdes.v1_0.ShipmentItemSerDes;
  21. import java.util.LinkedHashMap;
  22. import java.util.Locale;
  23. import java.util.Map;
  24. import java.util.logging.Level;
  25. import java.util.logging.Logger;
  26. import javax.annotation.Generated;
  27. /**
  28. * @author Andrea Sbarra
  29. * @generated
  30. */
  31. @Generated("")
  32. public interface ShipmentItemResource {
  33. public static Builder builder() {
  34. return new Builder();
  35. }
  36. public void deleteShipmentItemByExternalReferenceCode(
  37. String externalReferenceCode)
  38. throws Exception;
  39. public HttpInvoker.HttpResponse
  40. deleteShipmentItemByExternalReferenceCodeHttpResponse(
  41. String externalReferenceCode)
  42. throws Exception;
  43. public ShipmentItem getShipmentByExternalReferenceCodeItem(
  44. String externalReferenceCode)
  45. throws Exception;
  46. public HttpInvoker.HttpResponse
  47. getShipmentByExternalReferenceCodeItemHttpResponse(
  48. String externalReferenceCode)
  49. throws Exception;
  50. public ShipmentItem patchShipmentItemByExternalReferenceCode(
  51. String externalReferenceCode, ShipmentItem shipmentItem)
  52. throws Exception;
  53. public HttpInvoker.HttpResponse
  54. patchShipmentItemByExternalReferenceCodeHttpResponse(
  55. String externalReferenceCode, ShipmentItem shipmentItem)
  56. throws Exception;
  57. public void deleteShipmentItem(Long shipmentItemId) throws Exception;
  58. public HttpInvoker.HttpResponse deleteShipmentItemHttpResponse(
  59. Long shipmentItemId)
  60. throws Exception;
  61. public void deleteShipmentItemBatch(String callbackURL, Object object)
  62. throws Exception;
  63. public HttpInvoker.HttpResponse deleteShipmentItemBatchHttpResponse(
  64. String callbackURL, Object object)
  65. throws Exception;
  66. public ShipmentItem getShipmentItem(Long shipmentItemId) throws Exception;
  67. public HttpInvoker.HttpResponse getShipmentItemHttpResponse(
  68. Long shipmentItemId)
  69. throws Exception;
  70. public ShipmentItem patchShipmentItem(
  71. Long shipmentItemId, ShipmentItem shipmentItem)
  72. throws Exception;
  73. public HttpInvoker.HttpResponse patchShipmentItemHttpResponse(
  74. Long shipmentItemId, ShipmentItem shipmentItem)
  75. throws Exception;
  76. public Page<ShipmentItem> getShipmentByExternalReferenceCodeItemsPage(
  77. String externalReferenceCode, Pagination pagination)
  78. throws Exception;
  79. public HttpInvoker.HttpResponse
  80. getShipmentByExternalReferenceCodeItemsPageHttpResponse(
  81. String externalReferenceCode, Pagination pagination)
  82. throws Exception;
  83. public ShipmentItem putShipmentByExternalReferenceCodeItem(
  84. String externalReferenceCode, ShipmentItem shipmentItem)
  85. throws Exception;
  86. public HttpInvoker.HttpResponse
  87. putShipmentByExternalReferenceCodeItemHttpResponse(
  88. String externalReferenceCode, ShipmentItem shipmentItem)
  89. throws Exception;
  90. public Page<ShipmentItem> getShipmentItemsPage(
  91. Long shipmentId, Pagination pagination)
  92. throws Exception;
  93. public HttpInvoker.HttpResponse getShipmentItemsPageHttpResponse(
  94. Long shipmentId, Pagination pagination)
  95. throws Exception;
  96. public ShipmentItem postShipmentItem(
  97. Long shipmentId, ShipmentItem shipmentItem)
  98. throws Exception;
  99. public HttpInvoker.HttpResponse postShipmentItemHttpResponse(
  100. Long shipmentId, ShipmentItem shipmentItem)
  101. throws Exception;
  102. public static class Builder {
  103. public Builder authentication(String login, String password) {
  104. _login = login;
  105. _password = password;
  106. return this;
  107. }
  108. public ShipmentItemResource build() {
  109. return new ShipmentItemResourceImpl(this);
  110. }
  111. public Builder contextPath(String contextPath) {
  112. _contextPath = contextPath;
  113. return this;
  114. }
  115. public Builder endpoint(String host, int port, String scheme) {
  116. _host = host;
  117. _port = port;
  118. _scheme = scheme;
  119. return this;
  120. }
  121. public Builder header(String key, String value) {
  122. _headers.put(key, value);
  123. return this;
  124. }
  125. public Builder locale(Locale locale) {
  126. _locale = locale;
  127. return this;
  128. }
  129. public Builder parameter(String key, String value) {
  130. _parameters.put(key, value);
  131. return this;
  132. }
  133. public Builder parameters(String... parameters) {
  134. if ((parameters.length % 2) != 0) {
  135. throw new IllegalArgumentException(
  136. "Parameters length is not an even number");
  137. }
  138. for (int i = 0; i < parameters.length; i += 2) {
  139. String parameterName = String.valueOf(parameters[i]);
  140. String parameterValue = String.valueOf(parameters[i + 1]);
  141. _parameters.put(parameterName, parameterValue);
  142. }
  143. return this;
  144. }
  145. private Builder() {
  146. }
  147. private String _contextPath = "";
  148. private Map<String, String> _headers = new LinkedHashMap<>();
  149. private String _host = "localhost";
  150. private Locale _locale;
  151. private String _login = "";
  152. private String _password = "";
  153. private Map<String, String> _parameters = new LinkedHashMap<>();
  154. private int _port = 8080;
  155. private String _scheme = "http";
  156. }
  157. public static class ShipmentItemResourceImpl
  158. implements ShipmentItemResource {
  159. public void deleteShipmentItemByExternalReferenceCode(
  160. String externalReferenceCode)
  161. throws Exception {
  162. HttpInvoker.HttpResponse httpResponse =
  163. deleteShipmentItemByExternalReferenceCodeHttpResponse(
  164. externalReferenceCode);
  165. String content = httpResponse.getContent();
  166. if ((httpResponse.getStatusCode() / 100) != 2) {
  167. _logger.log(
  168. Level.WARNING,
  169. "Unable to process HTTP response content: " + content);
  170. _logger.log(
  171. Level.WARNING,
  172. "HTTP response message: " + httpResponse.getMessage());
  173. _logger.log(
  174. Level.WARNING,
  175. "HTTP response status code: " +
  176. httpResponse.getStatusCode());
  177. throw new Problem.ProblemException(Problem.toDTO(content));
  178. }
  179. else {
  180. _logger.fine("HTTP response content: " + content);
  181. _logger.fine(
  182. "HTTP response message: " + httpResponse.getMessage());
  183. _logger.fine(
  184. "HTTP response status code: " +
  185. httpResponse.getStatusCode());
  186. }
  187. try {
  188. return;
  189. }
  190. catch (Exception e) {
  191. _logger.log(
  192. Level.WARNING,
  193. "Unable to process HTTP response: " + content, e);
  194. throw new Problem.ProblemException(Problem.toDTO(content));
  195. }
  196. }
  197. public HttpInvoker.HttpResponse
  198. deleteShipmentItemByExternalReferenceCodeHttpResponse(
  199. String externalReferenceCode)
  200. throws Exception {
  201. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  202. if (_builder._locale != null) {
  203. httpInvoker.header(
  204. "Accept-Language", _builder._locale.toLanguageTag());
  205. }
  206. for (Map.Entry<String, String> entry :
  207. _builder._headers.entrySet()) {
  208. httpInvoker.header(entry.getKey(), entry.getValue());
  209. }
  210. for (Map.Entry<String, String> entry :
  211. _builder._parameters.entrySet()) {
  212. httpInvoker.parameter(entry.getKey(), entry.getValue());
  213. }
  214. httpInvoker.httpMethod(HttpInvoker.HttpMethod.DELETE);
  215. httpInvoker.path(
  216. _builder._scheme + "://" + _builder._host + ":" +
  217. _builder._port + _builder._contextPath +
  218. "/o/headless-commerce-admin-shipment/v1.0/shipment-items/by-externalReferenceCode/{externalReferenceCode}");
  219. httpInvoker.path("externalReferenceCode", externalReferenceCode);
  220. httpInvoker.userNameAndPassword(
  221. _builder._login + ":" + _builder._password);
  222. return httpInvoker.invoke();
  223. }
  224. public ShipmentItem getShipmentByExternalReferenceCodeItem(
  225. String externalReferenceCode)
  226. throws Exception {
  227. HttpInvoker.HttpResponse httpResponse =
  228. getShipmentByExternalReferenceCodeItemHttpResponse(
  229. externalReferenceCode);
  230. String content = httpResponse.getContent();
  231. if ((httpResponse.getStatusCode() / 100) != 2) {
  232. _logger.log(
  233. Level.WARNING,
  234. "Unable to process HTTP response content: " + content);
  235. _logger.log(
  236. Level.WARNING,
  237. "HTTP response message: " + httpResponse.getMessage());
  238. _logger.log(
  239. Level.WARNING,
  240. "HTTP response status code: " +
  241. httpResponse.getStatusCode());
  242. throw new Problem.ProblemException(Problem.toDTO(content));
  243. }
  244. else {
  245. _logger.fine("HTTP response content: " + content);
  246. _logger.fine(
  247. "HTTP response message: " + httpResponse.getMessage());
  248. _logger.fine(
  249. "HTTP response status code: " +
  250. httpResponse.getStatusCode());
  251. }
  252. try {
  253. return ShipmentItemSerDes.toDTO(content);
  254. }
  255. catch (Exception e) {
  256. _logger.log(
  257. Level.WARNING,
  258. "Unable to process HTTP response: " + content, e);
  259. throw new Problem.ProblemException(Problem.toDTO(content));
  260. }
  261. }
  262. public HttpInvoker.HttpResponse
  263. getShipmentByExternalReferenceCodeItemHttpResponse(
  264. String externalReferenceCode)
  265. throws Exception {
  266. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  267. if (_builder._locale != null) {
  268. httpInvoker.header(
  269. "Accept-Language", _builder._locale.toLanguageTag());
  270. }
  271. for (Map.Entry<String, String> entry :
  272. _builder._headers.entrySet()) {
  273. httpInvoker.header(entry.getKey(), entry.getValue());
  274. }
  275. for (Map.Entry<String, String> entry :
  276. _builder._parameters.entrySet()) {
  277. httpInvoker.parameter(entry.getKey(), entry.getValue());
  278. }
  279. httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
  280. httpInvoker.path(
  281. _builder._scheme + "://" + _builder._host + ":" +
  282. _builder._port + _builder._contextPath +
  283. "/o/headless-commerce-admin-shipment/v1.0/shipment-items/by-externalReferenceCode/{externalReferenceCode}");
  284. httpInvoker.path("externalReferenceCode", externalReferenceCode);
  285. httpInvoker.userNameAndPassword(
  286. _builder._login + ":" + _builder._password);
  287. return httpInvoker.invoke();
  288. }
  289. public ShipmentItem patchShipmentItemByExternalReferenceCode(
  290. String externalReferenceCode, ShipmentItem shipmentItem)
  291. throws Exception {
  292. HttpInvoker.HttpResponse httpResponse =
  293. patchShipmentItemByExternalReferenceCodeHttpResponse(
  294. externalReferenceCode, shipmentItem);
  295. String content = httpResponse.getContent();
  296. if ((httpResponse.getStatusCode() / 100) != 2) {
  297. _logger.log(
  298. Level.WARNING,
  299. "Unable to process HTTP response content: " + content);
  300. _logger.log(
  301. Level.WARNING,
  302. "HTTP response message: " + httpResponse.getMessage());
  303. _logger.log(
  304. Level.WARNING,
  305. "HTTP response status code: " +
  306. httpResponse.getStatusCode());
  307. throw new Problem.ProblemException(Problem.toDTO(content));
  308. }
  309. else {
  310. _logger.fine("HTTP response content: " + content);
  311. _logger.fine(
  312. "HTTP response message: " + httpResponse.getMessage());
  313. _logger.fine(
  314. "HTTP response status code: " +
  315. httpResponse.getStatusCode());
  316. }
  317. try {
  318. return ShipmentItemSerDes.toDTO(content);
  319. }
  320. catch (Exception e) {
  321. _logger.log(
  322. Level.WARNING,
  323. "Unable to process HTTP response: " + content, e);
  324. throw new Problem.ProblemException(Problem.toDTO(content));
  325. }
  326. }
  327. public HttpInvoker.HttpResponse
  328. patchShipmentItemByExternalReferenceCodeHttpResponse(
  329. String externalReferenceCode, ShipmentItem shipmentItem)
  330. throws Exception {
  331. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  332. httpInvoker.body(shipmentItem.toString(), "application/json");
  333. if (_builder._locale != null) {
  334. httpInvoker.header(
  335. "Accept-Language", _builder._locale.toLanguageTag());
  336. }
  337. for (Map.Entry<String, String> entry :
  338. _builder._headers.entrySet()) {
  339. httpInvoker.header(entry.getKey(), entry.getValue());
  340. }
  341. for (Map.Entry<String, String> entry :
  342. _builder._parameters.entrySet()) {
  343. httpInvoker.parameter(entry.getKey(), entry.getValue());
  344. }
  345. httpInvoker.httpMethod(HttpInvoker.HttpMethod.PATCH);
  346. httpInvoker.path(
  347. _builder._scheme + "://" + _builder._host + ":" +
  348. _builder._port + _builder._contextPath +
  349. "/o/headless-commerce-admin-shipment/v1.0/shipment-items/by-externalReferenceCode/{externalReferenceCode}");
  350. httpInvoker.path("externalReferenceCode", externalReferenceCode);
  351. httpInvoker.userNameAndPassword(
  352. _builder._login + ":" + _builder._password);
  353. return httpInvoker.invoke();
  354. }
  355. public void deleteShipmentItem(Long shipmentItemId) throws Exception {
  356. HttpInvoker.HttpResponse httpResponse =
  357. deleteShipmentItemHttpResponse(shipmentItemId);
  358. String content = httpResponse.getContent();
  359. if ((httpResponse.getStatusCode() / 100) != 2) {
  360. _logger.log(
  361. Level.WARNING,
  362. "Unable to process HTTP response content: " + content);
  363. _logger.log(
  364. Level.WARNING,
  365. "HTTP response message: " + httpResponse.getMessage());
  366. _logger.log(
  367. Level.WARNING,
  368. "HTTP response status code: " +
  369. httpResponse.getStatusCode());
  370. throw new Problem.ProblemException(Problem.toDTO(content));
  371. }
  372. else {
  373. _logger.fine("HTTP response content: " + content);
  374. _logger.fine(
  375. "HTTP response message: " + httpResponse.getMessage());
  376. _logger.fine(
  377. "HTTP response status code: " +
  378. httpResponse.getStatusCode());
  379. }
  380. try {
  381. return;
  382. }
  383. catch (Exception e) {
  384. _logger.log(
  385. Level.WARNING,
  386. "Unable to process HTTP response: " + content, e);
  387. throw new Problem.ProblemException(Problem.toDTO(content));
  388. }
  389. }
  390. public HttpInvoker.HttpResponse deleteShipmentItemHttpResponse(
  391. Long shipmentItemId)
  392. throws Exception {
  393. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  394. if (_builder._locale != null) {
  395. httpInvoker.header(
  396. "Accept-Language", _builder._locale.toLanguageTag());
  397. }
  398. for (Map.Entry<String, String> entry :
  399. _builder._headers.entrySet()) {
  400. httpInvoker.header(entry.getKey(), entry.getValue());
  401. }
  402. for (Map.Entry<String, String> entry :
  403. _builder._parameters.entrySet()) {
  404. httpInvoker.parameter(entry.getKey(), entry.getValue());
  405. }
  406. httpInvoker.httpMethod(HttpInvoker.HttpMethod.DELETE);
  407. httpInvoker.path(
  408. _builder._scheme + "://" + _builder._host + ":" +
  409. _builder._port + _builder._contextPath +
  410. "/o/headless-commerce-admin-shipment/v1.0/shipment-items/{shipmentItemId}");
  411. httpInvoker.path("shipmentItemId", shipmentItemId);
  412. httpInvoker.userNameAndPassword(
  413. _builder._login + ":" + _builder._password);
  414. return httpInvoker.invoke();
  415. }
  416. public void deleteShipmentItemBatch(String callbackURL, Object object)
  417. throws Exception {
  418. HttpInvoker.HttpResponse httpResponse =
  419. deleteShipmentItemBatchHttpResponse(callbackURL, object);
  420. String content = httpResponse.getContent();
  421. if ((httpResponse.getStatusCode() / 100) != 2) {
  422. _logger.log(
  423. Level.WARNING,
  424. "Unable to process HTTP response content: " + content);
  425. _logger.log(
  426. Level.WARNING,
  427. "HTTP response message: " + httpResponse.getMessage());
  428. _logger.log(
  429. Level.WARNING,
  430. "HTTP response status code: " +
  431. httpResponse.getStatusCode());
  432. throw new Problem.ProblemException(Problem.toDTO(content));
  433. }
  434. else {
  435. _logger.fine("HTTP response content: " + content);
  436. _logger.fine(
  437. "HTTP response message: " + httpResponse.getMessage());
  438. _logger.fine(
  439. "HTTP response status code: " +
  440. httpResponse.getStatusCode());
  441. }
  442. }
  443. public HttpInvoker.HttpResponse deleteShipmentItemBatchHttpResponse(
  444. String callbackURL, Object object)
  445. throws Exception {
  446. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  447. httpInvoker.body(object.toString(), "application/json");
  448. if (_builder._locale != null) {
  449. httpInvoker.header(
  450. "Accept-Language", _builder._locale.toLanguageTag());
  451. }
  452. for (Map.Entry<String, String> entry :
  453. _builder._headers.entrySet()) {
  454. httpInvoker.header(entry.getKey(), entry.getValue());
  455. }
  456. for (Map.Entry<String, String> entry :
  457. _builder._parameters.entrySet()) {
  458. httpInvoker.parameter(entry.getKey(), entry.getValue());
  459. }
  460. httpInvoker.httpMethod(HttpInvoker.HttpMethod.DELETE);
  461. if (callbackURL != null) {
  462. httpInvoker.parameter(
  463. "callbackURL", String.valueOf(callbackURL));
  464. }
  465. httpInvoker.path(
  466. _builder._scheme + "://" + _builder._host + ":" +
  467. _builder._port + _builder._contextPath +
  468. "/o/headless-commerce-admin-shipment/v1.0/shipment-items/batch");
  469. httpInvoker.userNameAndPassword(
  470. _builder._login + ":" + _builder._password);
  471. return httpInvoker.invoke();
  472. }
  473. public ShipmentItem getShipmentItem(Long shipmentItemId)
  474. throws Exception {
  475. HttpInvoker.HttpResponse httpResponse = getShipmentItemHttpResponse(
  476. shipmentItemId);
  477. String content = httpResponse.getContent();
  478. if ((httpResponse.getStatusCode() / 100) != 2) {
  479. _logger.log(
  480. Level.WARNING,
  481. "Unable to process HTTP response content: " + content);
  482. _logger.log(
  483. Level.WARNING,
  484. "HTTP response message: " + httpResponse.getMessage());
  485. _logger.log(
  486. Level.WARNING,
  487. "HTTP response status code: " +
  488. httpResponse.getStatusCode());
  489. throw new Problem.ProblemException(Problem.toDTO(content));
  490. }
  491. else {
  492. _logger.fine("HTTP response content: " + content);
  493. _logger.fine(
  494. "HTTP response message: " + httpResponse.getMessage());
  495. _logger.fine(
  496. "HTTP response status code: " +
  497. httpResponse.getStatusCode());
  498. }
  499. try {
  500. return ShipmentItemSerDes.toDTO(content);
  501. }
  502. catch (Exception e) {
  503. _logger.log(
  504. Level.WARNING,
  505. "Unable to process HTTP response: " + content, e);
  506. throw new Problem.ProblemException(Problem.toDTO(content));
  507. }
  508. }
  509. public HttpInvoker.HttpResponse getShipmentItemHttpResponse(
  510. Long shipmentItemId)
  511. throws Exception {
  512. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  513. if (_builder._locale != null) {
  514. httpInvoker.header(
  515. "Accept-Language", _builder._locale.toLanguageTag());
  516. }
  517. for (Map.Entry<String, String> entry :
  518. _builder._headers.entrySet()) {
  519. httpInvoker.header(entry.getKey(), entry.getValue());
  520. }
  521. for (Map.Entry<String, String> entry :
  522. _builder._parameters.entrySet()) {
  523. httpInvoker.parameter(entry.getKey(), entry.getValue());
  524. }
  525. httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
  526. httpInvoker.path(
  527. _builder._scheme + "://" + _builder._host + ":" +
  528. _builder._port + _builder._contextPath +
  529. "/o/headless-commerce-admin-shipment/v1.0/shipment-items/{shipmentItemId}");
  530. httpInvoker.path("shipmentItemId", shipmentItemId);
  531. httpInvoker.userNameAndPassword(
  532. _builder._login + ":" + _builder._password);
  533. return httpInvoker.invoke();
  534. }
  535. public ShipmentItem patchShipmentItem(
  536. Long shipmentItemId, ShipmentItem shipmentItem)
  537. throws Exception {
  538. HttpInvoker.HttpResponse httpResponse =
  539. patchShipmentItemHttpResponse(shipmentItemId, shipmentItem);
  540. String content = httpResponse.getContent();
  541. if ((httpResponse.getStatusCode() / 100) != 2) {
  542. _logger.log(
  543. Level.WARNING,
  544. "Unable to process HTTP response content: " + content);
  545. _logger.log(
  546. Level.WARNING,
  547. "HTTP response message: " + httpResponse.getMessage());
  548. _logger.log(
  549. Level.WARNING,
  550. "HTTP response status code: " +
  551. httpResponse.getStatusCode());
  552. throw new Problem.ProblemException(Problem.toDTO(content));
  553. }
  554. else {
  555. _logger.fine("HTTP response content: " + content);
  556. _logger.fine(
  557. "HTTP response message: " + httpResponse.getMessage());
  558. _logger.fine(
  559. "HTTP response status code: " +
  560. httpResponse.getStatusCode());
  561. }
  562. try {
  563. return ShipmentItemSerDes.toDTO(content);
  564. }
  565. catch (Exception e) {
  566. _logger.log(
  567. Level.WARNING,
  568. "Unable to process HTTP response: " + content, e);
  569. throw new Problem.ProblemException(Problem.toDTO(content));
  570. }
  571. }
  572. public HttpInvoker.HttpResponse patchShipmentItemHttpResponse(
  573. Long shipmentItemId, ShipmentItem shipmentItem)
  574. throws Exception {
  575. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  576. httpInvoker.body(shipmentItem.toString(), "application/json");
  577. if (_builder._locale != null) {
  578. httpInvoker.header(
  579. "Accept-Language", _builder._locale.toLanguageTag());
  580. }
  581. for (Map.Entry<String, String> entry :
  582. _builder._headers.entrySet()) {
  583. httpInvoker.header(entry.getKey(), entry.getValue());
  584. }
  585. for (Map.Entry<String, String> entry :
  586. _builder._parameters.entrySet()) {
  587. httpInvoker.parameter(entry.getKey(), entry.getValue());
  588. }
  589. httpInvoker.httpMethod(HttpInvoker.HttpMethod.PATCH);
  590. httpInvoker.path(
  591. _builder._scheme + "://" + _builder._host + ":" +
  592. _builder._port + _builder._contextPath +
  593. "/o/headless-commerce-admin-shipment/v1.0/shipment-items/{shipmentItemId}");
  594. httpInvoker.path("shipmentItemId", shipmentItemId);
  595. httpInvoker.userNameAndPassword(
  596. _builder._login + ":" + _builder._password);
  597. return httpInvoker.invoke();
  598. }
  599. public Page<ShipmentItem> getShipmentByExternalReferenceCodeItemsPage(
  600. String externalReferenceCode, Pagination pagination)
  601. throws Exception {
  602. HttpInvoker.HttpResponse httpResponse =
  603. getShipmentByExternalReferenceCodeItemsPageHttpResponse(
  604. externalReferenceCode, pagination);
  605. String content = httpResponse.getContent();
  606. if ((httpResponse.getStatusCode() / 100) != 2) {
  607. _logger.log(
  608. Level.WARNING,
  609. "Unable to process HTTP response content: " + content);
  610. _logger.log(
  611. Level.WARNING,
  612. "HTTP response message: " + httpResponse.getMessage());
  613. _logger.log(
  614. Level.WARNING,
  615. "HTTP response status code: " +
  616. httpResponse.getStatusCode());
  617. throw new Problem.ProblemException(Problem.toDTO(content));
  618. }
  619. else {
  620. _logger.fine("HTTP response content: " + content);
  621. _logger.fine(
  622. "HTTP response message: " + httpResponse.getMessage());
  623. _logger.fine(
  624. "HTTP response status code: " +
  625. httpResponse.getStatusCode());
  626. }
  627. try {
  628. return Page.of(content, ShipmentItemSerDes::toDTO);
  629. }
  630. catch (Exception e) {
  631. _logger.log(
  632. Level.WARNING,
  633. "Unable to process HTTP response: " + content, e);
  634. throw new Problem.ProblemException(Problem.toDTO(content));
  635. }
  636. }
  637. public HttpInvoker.HttpResponse
  638. getShipmentByExternalReferenceCodeItemsPageHttpResponse(
  639. String externalReferenceCode, Pagination pagination)
  640. throws Exception {
  641. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  642. if (_builder._locale != null) {
  643. httpInvoker.header(
  644. "Accept-Language", _builder._locale.toLanguageTag());
  645. }
  646. for (Map.Entry<String, String> entry :
  647. _builder._headers.entrySet()) {
  648. httpInvoker.header(entry.getKey(), entry.getValue());
  649. }
  650. for (Map.Entry<String, String> entry :
  651. _builder._parameters.entrySet()) {
  652. httpInvoker.parameter(entry.getKey(), entry.getValue());
  653. }
  654. httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
  655. if (pagination != null) {
  656. httpInvoker.parameter(
  657. "page", String.valueOf(pagination.getPage()));
  658. httpInvoker.parameter(
  659. "pageSize", String.valueOf(pagination.getPageSize()));
  660. }
  661. httpInvoker.path(
  662. _builder._scheme + "://" + _builder._host + ":" +
  663. _builder._port + _builder._contextPath +
  664. "/o/headless-commerce-admin-shipment/v1.0/shipments/by-externalReferenceCode/{externalReferenceCode}/items");
  665. httpInvoker.path("externalReferenceCode", externalReferenceCode);
  666. httpInvoker.userNameAndPassword(
  667. _builder._login + ":" + _builder._password);
  668. return httpInvoker.invoke();
  669. }
  670. public ShipmentItem putShipmentByExternalReferenceCodeItem(
  671. String externalReferenceCode, ShipmentItem shipmentItem)
  672. throws Exception {
  673. HttpInvoker.HttpResponse httpResponse =
  674. putShipmentByExternalReferenceCodeItemHttpResponse(
  675. externalReferenceCode, shipmentItem);
  676. String content = httpResponse.getContent();
  677. if ((httpResponse.getStatusCode() / 100) != 2) {
  678. _logger.log(
  679. Level.WARNING,
  680. "Unable to process HTTP response content: " + content);
  681. _logger.log(
  682. Level.WARNING,
  683. "HTTP response message: " + httpResponse.getMessage());
  684. _logger.log(
  685. Level.WARNING,
  686. "HTTP response status code: " +
  687. httpResponse.getStatusCode());
  688. throw new Problem.ProblemException(Problem.toDTO(content));
  689. }
  690. else {
  691. _logger.fine("HTTP response content: " + content);
  692. _logger.fine(
  693. "HTTP response message: " + httpResponse.getMessage());
  694. _logger.fine(
  695. "HTTP response status code: " +
  696. httpResponse.getStatusCode());
  697. }
  698. try {
  699. return ShipmentItemSerDes.toDTO(content);
  700. }
  701. catch (Exception e) {
  702. _logger.log(
  703. Level.WARNING,
  704. "Unable to process HTTP response: " + content, e);
  705. throw new Problem.ProblemException(Problem.toDTO(content));
  706. }
  707. }
  708. public HttpInvoker.HttpResponse
  709. putShipmentByExternalReferenceCodeItemHttpResponse(
  710. String externalReferenceCode, ShipmentItem shipmentItem)
  711. throws Exception {
  712. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  713. httpInvoker.body(shipmentItem.toString(), "application/json");
  714. if (_builder._locale != null) {
  715. httpInvoker.header(
  716. "Accept-Language", _builder._locale.toLanguageTag());
  717. }
  718. for (Map.Entry<String, String> entry :
  719. _builder._headers.entrySet()) {
  720. httpInvoker.header(entry.getKey(), entry.getValue());
  721. }
  722. for (Map.Entry<String, String> entry :
  723. _builder._parameters.entrySet()) {
  724. httpInvoker.parameter(entry.getKey(), entry.getValue());
  725. }
  726. httpInvoker.httpMethod(HttpInvoker.HttpMethod.PUT);
  727. httpInvoker.path(
  728. _builder._scheme + "://" + _builder._host + ":" +
  729. _builder._port + _builder._contextPath +
  730. "/o/headless-commerce-admin-shipment/v1.0/shipments/by-externalReferenceCode/{externalReferenceCode}/items");
  731. httpInvoker.path("externalReferenceCode", externalReferenceCode);
  732. httpInvoker.userNameAndPassword(
  733. _builder._login + ":" + _builder._password);
  734. return httpInvoker.invoke();
  735. }
  736. public Page<ShipmentItem> getShipmentItemsPage(
  737. Long shipmentId, Pagination pagination)
  738. throws Exception {
  739. HttpInvoker.HttpResponse httpResponse =
  740. getShipmentItemsPageHttpResponse(shipmentId, pagination);
  741. String content = httpResponse.getContent();
  742. if ((httpResponse.getStatusCode() / 100) != 2) {
  743. _logger.log(
  744. Level.WARNING,
  745. "Unable to process HTTP response content: " + content);
  746. _logger.log(
  747. Level.WARNING,
  748. "HTTP response message: " + httpResponse.getMessage());
  749. _logger.log(
  750. Level.WARNING,
  751. "HTTP response status code: " +
  752. httpResponse.getStatusCode());
  753. throw new Problem.ProblemException(Problem.toDTO(content));
  754. }
  755. else {
  756. _logger.fine("HTTP response content: " + content);
  757. _logger.fine(
  758. "HTTP response message: " + httpResponse.getMessage());
  759. _logger.fine(
  760. "HTTP response status code: " +
  761. httpResponse.getStatusCode());
  762. }
  763. try {
  764. return Page.of(content, ShipmentItemSerDes::toDTO);
  765. }
  766. catch (Exception e) {
  767. _logger.log(
  768. Level.WARNING,
  769. "Unable to process HTTP response: " + content, e);
  770. throw new Problem.ProblemException(Problem.toDTO(content));
  771. }
  772. }
  773. public HttpInvoker.HttpResponse getShipmentItemsPageHttpResponse(
  774. Long shipmentId, Pagination pagination)
  775. throws Exception {
  776. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  777. if (_builder._locale != null) {
  778. httpInvoker.header(
  779. "Accept-Language", _builder._locale.toLanguageTag());
  780. }
  781. for (Map.Entry<String, String> entry :
  782. _builder._headers.entrySet()) {
  783. httpInvoker.header(entry.getKey(), entry.getValue());
  784. }
  785. for (Map.Entry<String, String> entry :
  786. _builder._parameters.entrySet()) {
  787. httpInvoker.parameter(entry.getKey(), entry.getValue());
  788. }
  789. httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
  790. if (pagination != null) {
  791. httpInvoker.parameter(
  792. "page", String.valueOf(pagination.getPage()));
  793. httpInvoker.parameter(
  794. "pageSize", String.valueOf(pagination.getPageSize()));
  795. }
  796. httpInvoker.path(
  797. _builder._scheme + "://" + _builder._host + ":" +
  798. _builder._port + _builder._contextPath +
  799. "/o/headless-commerce-admin-shipment/v1.0/shipments/{shipmentId}/items");
  800. httpInvoker.path("shipmentId", shipmentId);
  801. httpInvoker.userNameAndPassword(
  802. _builder._login + ":" + _builder._password);
  803. return httpInvoker.invoke();
  804. }
  805. public ShipmentItem postShipmentItem(
  806. Long shipmentId, ShipmentItem shipmentItem)
  807. throws Exception {
  808. HttpInvoker.HttpResponse httpResponse =
  809. postShipmentItemHttpResponse(shipmentId, shipmentItem);
  810. String content = httpResponse.getContent();
  811. if ((httpResponse.getStatusCode() / 100) != 2) {
  812. _logger.log(
  813. Level.WARNING,
  814. "Unable to process HTTP response content: " + content);
  815. _logger.log(
  816. Level.WARNING,
  817. "HTTP response message: " + httpResponse.getMessage());
  818. _logger.log(
  819. Level.WARNING,
  820. "HTTP response status code: " +
  821. httpResponse.getStatusCode());
  822. throw new Problem.ProblemException(Problem.toDTO(content));
  823. }
  824. else {
  825. _logger.fine("HTTP response content: " + content);
  826. _logger.fine(
  827. "HTTP response message: " + httpResponse.getMessage());
  828. _logger.fine(
  829. "HTTP response status code: " +
  830. httpResponse.getStatusCode());
  831. }
  832. try {
  833. return ShipmentItemSerDes.toDTO(content);
  834. }
  835. catch (Exception e) {
  836. _logger.log(
  837. Level.WARNING,
  838. "Unable to process HTTP response: " + content, e);
  839. throw new Problem.ProblemException(Problem.toDTO(content));
  840. }
  841. }
  842. public HttpInvoker.HttpResponse postShipmentItemHttpResponse(
  843. Long shipmentId, ShipmentItem shipmentItem)
  844. throws Exception {
  845. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  846. httpInvoker.body(shipmentItem.toString(), "application/json");
  847. if (_builder._locale != null) {
  848. httpInvoker.header(
  849. "Accept-Language", _builder._locale.toLanguageTag());
  850. }
  851. for (Map.Entry<String, String> entry :
  852. _builder._headers.entrySet()) {
  853. httpInvoker.header(entry.getKey(), entry.getValue());
  854. }
  855. for (Map.Entry<String, String> entry :
  856. _builder._parameters.entrySet()) {
  857. httpInvoker.parameter(entry.getKey(), entry.getValue());
  858. }
  859. httpInvoker.httpMethod(HttpInvoker.HttpMethod.POST);
  860. httpInvoker.path(
  861. _builder._scheme + "://" + _builder._host + ":" +
  862. _builder._port + _builder._contextPath +
  863. "/o/headless-commerce-admin-shipment/v1.0/shipments/{shipmentId}/items");
  864. httpInvoker.path("shipmentId", shipmentId);
  865. httpInvoker.userNameAndPassword(
  866. _builder._login + ":" + _builder._password);
  867. return httpInvoker.invoke();
  868. }
  869. private ShipmentItemResourceImpl(Builder builder) {
  870. _builder = builder;
  871. }
  872. private static final Logger _logger = Logger.getLogger(
  873. ShipmentItemResource.class.getName());
  874. private Builder _builder;
  875. }
  876. }