/modules/apps/headless/headless-delivery/headless-delivery-client/src/main/java/com/liferay/headless/delivery/client/resource/v1_0/StructuredContentResource.java

https://github.com/danielreuther/liferay-portal · Java · 1699 lines · 1306 code · 376 blank · 17 comment · 131 complexity · 9673ad0fbf30e83b0da1f50f0f7dc515 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.delivery.client.resource.v1_0;
  15. import com.liferay.headless.delivery.client.dto.v1_0.Rating;
  16. import com.liferay.headless.delivery.client.dto.v1_0.StructuredContent;
  17. import com.liferay.headless.delivery.client.http.HttpInvoker;
  18. import com.liferay.headless.delivery.client.pagination.Page;
  19. import com.liferay.headless.delivery.client.pagination.Pagination;
  20. import com.liferay.headless.delivery.client.permission.Permission;
  21. import com.liferay.headless.delivery.client.problem.Problem;
  22. import com.liferay.headless.delivery.client.serdes.v1_0.RatingSerDes;
  23. import com.liferay.headless.delivery.client.serdes.v1_0.StructuredContentSerDes;
  24. import java.util.LinkedHashMap;
  25. import java.util.List;
  26. import java.util.Locale;
  27. import java.util.Map;
  28. import java.util.logging.Level;
  29. import java.util.logging.Logger;
  30. import java.util.stream.Collectors;
  31. import java.util.stream.Stream;
  32. import javax.annotation.Generated;
  33. /**
  34. * @author Javier Gamarra
  35. * @generated
  36. */
  37. @Generated("")
  38. public interface StructuredContentResource {
  39. public static Builder builder() {
  40. return new Builder();
  41. }
  42. public Page<StructuredContent> getAssetLibraryStructuredContentsPage(
  43. Long assetLibraryId, Boolean flatten, String search,
  44. List<String> aggregations, String filterString,
  45. Pagination pagination, String sortString)
  46. throws Exception;
  47. public HttpInvoker.HttpResponse
  48. getAssetLibraryStructuredContentsPageHttpResponse(
  49. Long assetLibraryId, Boolean flatten, String search,
  50. List<String> aggregations, String filterString,
  51. Pagination pagination, String sortString)
  52. throws Exception;
  53. public StructuredContent postAssetLibraryStructuredContent(
  54. Long assetLibraryId, StructuredContent structuredContent)
  55. throws Exception;
  56. public HttpInvoker.HttpResponse
  57. postAssetLibraryStructuredContentHttpResponse(
  58. Long assetLibraryId, StructuredContent structuredContent)
  59. throws Exception;
  60. public void postAssetLibraryStructuredContentBatch(
  61. Long assetLibraryId, String callbackURL, Object object)
  62. throws Exception;
  63. public HttpInvoker.HttpResponse
  64. postAssetLibraryStructuredContentBatchHttpResponse(
  65. Long assetLibraryId, String callbackURL, Object object)
  66. throws Exception;
  67. public void deleteAssetLibraryStructuredContentByExternalReferenceCode(
  68. Long assetLibraryId, String externalReferenceCode)
  69. throws Exception;
  70. public HttpInvoker.HttpResponse
  71. deleteAssetLibraryStructuredContentByExternalReferenceCodeHttpResponse(
  72. Long assetLibraryId, String externalReferenceCode)
  73. throws Exception;
  74. public StructuredContent
  75. getAssetLibraryStructuredContentByExternalReferenceCode(
  76. Long assetLibraryId, String externalReferenceCode)
  77. throws Exception;
  78. public HttpInvoker.HttpResponse
  79. getAssetLibraryStructuredContentByExternalReferenceCodeHttpResponse(
  80. Long assetLibraryId, String externalReferenceCode)
  81. throws Exception;
  82. public StructuredContent
  83. putAssetLibraryStructuredContentByExternalReferenceCode(
  84. Long assetLibraryId, String externalReferenceCode,
  85. StructuredContent structuredContent)
  86. throws Exception;
  87. public HttpInvoker.HttpResponse
  88. putAssetLibraryStructuredContentByExternalReferenceCodeHttpResponse(
  89. Long assetLibraryId, String externalReferenceCode,
  90. StructuredContent structuredContent)
  91. throws Exception;
  92. public Page<Permission> getAssetLibraryStructuredContentPermissionsPage(
  93. Long assetLibraryId, String roleNames)
  94. throws Exception;
  95. public HttpInvoker.HttpResponse
  96. getAssetLibraryStructuredContentPermissionsPageHttpResponse(
  97. Long assetLibraryId, String roleNames)
  98. throws Exception;
  99. public Page<Permission> putAssetLibraryStructuredContentPermissionsPage(
  100. Long assetLibraryId, Permission[] permissions)
  101. throws Exception;
  102. public HttpInvoker.HttpResponse
  103. putAssetLibraryStructuredContentPermissionsPageHttpResponse(
  104. Long assetLibraryId, Permission[] permissions)
  105. throws Exception;
  106. public Page<StructuredContent> getContentStructureStructuredContentsPage(
  107. Long contentStructureId, String search, List<String> aggregations,
  108. String filterString, Pagination pagination, String sortString)
  109. throws Exception;
  110. public HttpInvoker.HttpResponse
  111. getContentStructureStructuredContentsPageHttpResponse(
  112. Long contentStructureId, String search,
  113. List<String> aggregations, String filterString,
  114. Pagination pagination, String sortString)
  115. throws Exception;
  116. public Page<StructuredContent> getSiteStructuredContentsPage(
  117. Long siteId, Boolean flatten, String search,
  118. List<String> aggregations, String filterString,
  119. Pagination pagination, String sortString)
  120. throws Exception;
  121. public HttpInvoker.HttpResponse getSiteStructuredContentsPageHttpResponse(
  122. Long siteId, Boolean flatten, String search,
  123. List<String> aggregations, String filterString,
  124. Pagination pagination, String sortString)
  125. throws Exception;
  126. public StructuredContent postSiteStructuredContent(
  127. Long siteId, StructuredContent structuredContent)
  128. throws Exception;
  129. public HttpInvoker.HttpResponse postSiteStructuredContentHttpResponse(
  130. Long siteId, StructuredContent structuredContent)
  131. throws Exception;
  132. public void postSiteStructuredContentBatch(
  133. Long siteId, String callbackURL, Object object)
  134. throws Exception;
  135. public HttpInvoker.HttpResponse postSiteStructuredContentBatchHttpResponse(
  136. Long siteId, String callbackURL, Object object)
  137. throws Exception;
  138. public void deleteSiteStructuredContentByExternalReferenceCode(
  139. Long siteId, String externalReferenceCode)
  140. throws Exception;
  141. public HttpInvoker.HttpResponse
  142. deleteSiteStructuredContentByExternalReferenceCodeHttpResponse(
  143. Long siteId, String externalReferenceCode)
  144. throws Exception;
  145. public StructuredContent getSiteStructuredContentByExternalReferenceCode(
  146. Long siteId, String externalReferenceCode)
  147. throws Exception;
  148. public HttpInvoker.HttpResponse
  149. getSiteStructuredContentByExternalReferenceCodeHttpResponse(
  150. Long siteId, String externalReferenceCode)
  151. throws Exception;
  152. public StructuredContent putSiteStructuredContentByExternalReferenceCode(
  153. Long siteId, String externalReferenceCode,
  154. StructuredContent structuredContent)
  155. throws Exception;
  156. public HttpInvoker.HttpResponse
  157. putSiteStructuredContentByExternalReferenceCodeHttpResponse(
  158. Long siteId, String externalReferenceCode,
  159. StructuredContent structuredContent)
  160. throws Exception;
  161. public StructuredContent getSiteStructuredContentByKey(
  162. Long siteId, String key)
  163. throws Exception;
  164. public HttpInvoker.HttpResponse getSiteStructuredContentByKeyHttpResponse(
  165. Long siteId, String key)
  166. throws Exception;
  167. public StructuredContent getSiteStructuredContentByUuid(
  168. Long siteId, String uuid)
  169. throws Exception;
  170. public HttpInvoker.HttpResponse getSiteStructuredContentByUuidHttpResponse(
  171. Long siteId, String uuid)
  172. throws Exception;
  173. public Page<Permission> getSiteStructuredContentPermissionsPage(
  174. Long siteId, String roleNames)
  175. throws Exception;
  176. public HttpInvoker.HttpResponse
  177. getSiteStructuredContentPermissionsPageHttpResponse(
  178. Long siteId, String roleNames)
  179. throws Exception;
  180. public Page<Permission> putSiteStructuredContentPermissionsPage(
  181. Long siteId, Permission[] permissions)
  182. throws Exception;
  183. public HttpInvoker.HttpResponse
  184. putSiteStructuredContentPermissionsPageHttpResponse(
  185. Long siteId, Permission[] permissions)
  186. throws Exception;
  187. public Page<StructuredContent>
  188. getStructuredContentFolderStructuredContentsPage(
  189. Long structuredContentFolderId, Boolean flatten, String search,
  190. List<String> aggregations, String filterString,
  191. Pagination pagination, String sortString)
  192. throws Exception;
  193. public HttpInvoker.HttpResponse
  194. getStructuredContentFolderStructuredContentsPageHttpResponse(
  195. Long structuredContentFolderId, Boolean flatten, String search,
  196. List<String> aggregations, String filterString,
  197. Pagination pagination, String sortString)
  198. throws Exception;
  199. public StructuredContent postStructuredContentFolderStructuredContent(
  200. Long structuredContentFolderId, StructuredContent structuredContent)
  201. throws Exception;
  202. public HttpInvoker.HttpResponse
  203. postStructuredContentFolderStructuredContentHttpResponse(
  204. Long structuredContentFolderId,
  205. StructuredContent structuredContent)
  206. throws Exception;
  207. public void postStructuredContentFolderStructuredContentBatch(
  208. Long structuredContentFolderId, String callbackURL, Object object)
  209. throws Exception;
  210. public HttpInvoker.HttpResponse
  211. postStructuredContentFolderStructuredContentBatchHttpResponse(
  212. Long structuredContentFolderId, String callbackURL,
  213. Object object)
  214. throws Exception;
  215. public void deleteStructuredContent(Long structuredContentId)
  216. throws Exception;
  217. public HttpInvoker.HttpResponse deleteStructuredContentHttpResponse(
  218. Long structuredContentId)
  219. throws Exception;
  220. public void deleteStructuredContentBatch(String callbackURL, Object object)
  221. throws Exception;
  222. public HttpInvoker.HttpResponse deleteStructuredContentBatchHttpResponse(
  223. String callbackURL, Object object)
  224. throws Exception;
  225. public StructuredContent getStructuredContent(Long structuredContentId)
  226. throws Exception;
  227. public HttpInvoker.HttpResponse getStructuredContentHttpResponse(
  228. Long structuredContentId)
  229. throws Exception;
  230. public StructuredContent patchStructuredContent(
  231. Long structuredContentId, StructuredContent structuredContent)
  232. throws Exception;
  233. public HttpInvoker.HttpResponse patchStructuredContentHttpResponse(
  234. Long structuredContentId, StructuredContent structuredContent)
  235. throws Exception;
  236. public StructuredContent putStructuredContent(
  237. Long structuredContentId, StructuredContent structuredContent)
  238. throws Exception;
  239. public HttpInvoker.HttpResponse putStructuredContentHttpResponse(
  240. Long structuredContentId, StructuredContent structuredContent)
  241. throws Exception;
  242. public void putStructuredContentBatch(String callbackURL, Object object)
  243. throws Exception;
  244. public HttpInvoker.HttpResponse putStructuredContentBatchHttpResponse(
  245. String callbackURL, Object object)
  246. throws Exception;
  247. public void deleteStructuredContentMyRating(Long structuredContentId)
  248. throws Exception;
  249. public HttpInvoker.HttpResponse deleteStructuredContentMyRatingHttpResponse(
  250. Long structuredContentId)
  251. throws Exception;
  252. public Rating getStructuredContentMyRating(Long structuredContentId)
  253. throws Exception;
  254. public HttpInvoker.HttpResponse getStructuredContentMyRatingHttpResponse(
  255. Long structuredContentId)
  256. throws Exception;
  257. public Rating postStructuredContentMyRating(
  258. Long structuredContentId, Rating rating)
  259. throws Exception;
  260. public HttpInvoker.HttpResponse postStructuredContentMyRatingHttpResponse(
  261. Long structuredContentId, Rating rating)
  262. throws Exception;
  263. public Rating putStructuredContentMyRating(
  264. Long structuredContentId, Rating rating)
  265. throws Exception;
  266. public HttpInvoker.HttpResponse putStructuredContentMyRatingHttpResponse(
  267. Long structuredContentId, Rating rating)
  268. throws Exception;
  269. public Page<Permission> getStructuredContentPermissionsPage(
  270. Long structuredContentId, String roleNames)
  271. throws Exception;
  272. public HttpInvoker.HttpResponse
  273. getStructuredContentPermissionsPageHttpResponse(
  274. Long structuredContentId, String roleNames)
  275. throws Exception;
  276. public Page<Permission> putStructuredContentPermissionsPage(
  277. Long structuredContentId, Permission[] permissions)
  278. throws Exception;
  279. public HttpInvoker.HttpResponse
  280. putStructuredContentPermissionsPageHttpResponse(
  281. Long structuredContentId, Permission[] permissions)
  282. throws Exception;
  283. public String
  284. getStructuredContentRenderedContentByDisplayPageDisplayPageKey(
  285. Long structuredContentId, String displayPageKey)
  286. throws Exception;
  287. public HttpInvoker.HttpResponse
  288. getStructuredContentRenderedContentByDisplayPageDisplayPageKeyHttpResponse(
  289. Long structuredContentId, String displayPageKey)
  290. throws Exception;
  291. public String getStructuredContentRenderedContentContentTemplate(
  292. Long structuredContentId, String contentTemplateId)
  293. throws Exception;
  294. public HttpInvoker.HttpResponse
  295. getStructuredContentRenderedContentContentTemplateHttpResponse(
  296. Long structuredContentId, String contentTemplateId)
  297. throws Exception;
  298. public void putStructuredContentSubscribe(Long structuredContentId)
  299. throws Exception;
  300. public HttpInvoker.HttpResponse putStructuredContentSubscribeHttpResponse(
  301. Long structuredContentId)
  302. throws Exception;
  303. public void putStructuredContentUnsubscribe(Long structuredContentId)
  304. throws Exception;
  305. public HttpInvoker.HttpResponse putStructuredContentUnsubscribeHttpResponse(
  306. Long structuredContentId)
  307. throws Exception;
  308. public static class Builder {
  309. public Builder authentication(String login, String password) {
  310. _login = login;
  311. _password = password;
  312. return this;
  313. }
  314. public StructuredContentResource build() {
  315. return new StructuredContentResourceImpl(this);
  316. }
  317. public Builder contextPath(String contextPath) {
  318. _contextPath = contextPath;
  319. return this;
  320. }
  321. public Builder endpoint(String host, int port, String scheme) {
  322. _host = host;
  323. _port = port;
  324. _scheme = scheme;
  325. return this;
  326. }
  327. public Builder header(String key, String value) {
  328. _headers.put(key, value);
  329. return this;
  330. }
  331. public Builder locale(Locale locale) {
  332. _locale = locale;
  333. return this;
  334. }
  335. public Builder parameter(String key, String value) {
  336. _parameters.put(key, value);
  337. return this;
  338. }
  339. public Builder parameters(String... parameters) {
  340. if ((parameters.length % 2) != 0) {
  341. throw new IllegalArgumentException(
  342. "Parameters length is not an even number");
  343. }
  344. for (int i = 0; i < parameters.length; i += 2) {
  345. String parameterName = String.valueOf(parameters[i]);
  346. String parameterValue = String.valueOf(parameters[i + 1]);
  347. _parameters.put(parameterName, parameterValue);
  348. }
  349. return this;
  350. }
  351. private Builder() {
  352. }
  353. private String _contextPath = "";
  354. private Map<String, String> _headers = new LinkedHashMap<>();
  355. private String _host = "localhost";
  356. private Locale _locale;
  357. private String _login = "";
  358. private String _password = "";
  359. private Map<String, String> _parameters = new LinkedHashMap<>();
  360. private int _port = 8080;
  361. private String _scheme = "http";
  362. }
  363. public static class StructuredContentResourceImpl
  364. implements StructuredContentResource {
  365. public Page<StructuredContent> getAssetLibraryStructuredContentsPage(
  366. Long assetLibraryId, Boolean flatten, String search,
  367. List<String> aggregations, String filterString,
  368. Pagination pagination, String sortString)
  369. throws Exception {
  370. HttpInvoker.HttpResponse httpResponse =
  371. getAssetLibraryStructuredContentsPageHttpResponse(
  372. assetLibraryId, flatten, search, aggregations, filterString,
  373. pagination, sortString);
  374. String content = httpResponse.getContent();
  375. if ((httpResponse.getStatusCode() / 100) != 2) {
  376. _logger.log(
  377. Level.WARNING,
  378. "Unable to process HTTP response content: " + content);
  379. _logger.log(
  380. Level.WARNING,
  381. "HTTP response message: " + httpResponse.getMessage());
  382. _logger.log(
  383. Level.WARNING,
  384. "HTTP response status code: " +
  385. httpResponse.getStatusCode());
  386. throw new Problem.ProblemException(Problem.toDTO(content));
  387. }
  388. else {
  389. _logger.fine("HTTP response content: " + content);
  390. _logger.fine(
  391. "HTTP response message: " + httpResponse.getMessage());
  392. _logger.fine(
  393. "HTTP response status code: " +
  394. httpResponse.getStatusCode());
  395. }
  396. try {
  397. return Page.of(content, StructuredContentSerDes::toDTO);
  398. }
  399. catch (Exception e) {
  400. _logger.log(
  401. Level.WARNING,
  402. "Unable to process HTTP response: " + content, e);
  403. throw new Problem.ProblemException(Problem.toDTO(content));
  404. }
  405. }
  406. public HttpInvoker.HttpResponse
  407. getAssetLibraryStructuredContentsPageHttpResponse(
  408. Long assetLibraryId, Boolean flatten, String search,
  409. List<String> aggregations, String filterString,
  410. Pagination pagination, String sortString)
  411. throws Exception {
  412. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  413. if (_builder._locale != null) {
  414. httpInvoker.header(
  415. "Accept-Language", _builder._locale.toLanguageTag());
  416. }
  417. for (Map.Entry<String, String> entry :
  418. _builder._headers.entrySet()) {
  419. httpInvoker.header(entry.getKey(), entry.getValue());
  420. }
  421. for (Map.Entry<String, String> entry :
  422. _builder._parameters.entrySet()) {
  423. httpInvoker.parameter(entry.getKey(), entry.getValue());
  424. }
  425. httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
  426. if (flatten != null) {
  427. httpInvoker.parameter("flatten", String.valueOf(flatten));
  428. }
  429. if (search != null) {
  430. httpInvoker.parameter("search", String.valueOf(search));
  431. }
  432. if (filterString != null) {
  433. httpInvoker.parameter("filter", filterString);
  434. }
  435. if (pagination != null) {
  436. httpInvoker.parameter(
  437. "page", String.valueOf(pagination.getPage()));
  438. httpInvoker.parameter(
  439. "pageSize", String.valueOf(pagination.getPageSize()));
  440. }
  441. if (sortString != null) {
  442. httpInvoker.parameter("sort", sortString);
  443. }
  444. httpInvoker.path(
  445. _builder._scheme + "://" + _builder._host + ":" +
  446. _builder._port + _builder._contextPath +
  447. "/o/headless-delivery/v1.0/asset-libraries/{assetLibraryId}/structured-contents");
  448. httpInvoker.path("assetLibraryId", assetLibraryId);
  449. httpInvoker.userNameAndPassword(
  450. _builder._login + ":" + _builder._password);
  451. return httpInvoker.invoke();
  452. }
  453. public StructuredContent postAssetLibraryStructuredContent(
  454. Long assetLibraryId, StructuredContent structuredContent)
  455. throws Exception {
  456. HttpInvoker.HttpResponse httpResponse =
  457. postAssetLibraryStructuredContentHttpResponse(
  458. assetLibraryId, structuredContent);
  459. String content = httpResponse.getContent();
  460. if ((httpResponse.getStatusCode() / 100) != 2) {
  461. _logger.log(
  462. Level.WARNING,
  463. "Unable to process HTTP response content: " + content);
  464. _logger.log(
  465. Level.WARNING,
  466. "HTTP response message: " + httpResponse.getMessage());
  467. _logger.log(
  468. Level.WARNING,
  469. "HTTP response status code: " +
  470. httpResponse.getStatusCode());
  471. throw new Problem.ProblemException(Problem.toDTO(content));
  472. }
  473. else {
  474. _logger.fine("HTTP response content: " + content);
  475. _logger.fine(
  476. "HTTP response message: " + httpResponse.getMessage());
  477. _logger.fine(
  478. "HTTP response status code: " +
  479. httpResponse.getStatusCode());
  480. }
  481. try {
  482. return StructuredContentSerDes.toDTO(content);
  483. }
  484. catch (Exception e) {
  485. _logger.log(
  486. Level.WARNING,
  487. "Unable to process HTTP response: " + content, e);
  488. throw new Problem.ProblemException(Problem.toDTO(content));
  489. }
  490. }
  491. public HttpInvoker.HttpResponse
  492. postAssetLibraryStructuredContentHttpResponse(
  493. Long assetLibraryId, StructuredContent structuredContent)
  494. throws Exception {
  495. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  496. httpInvoker.body(structuredContent.toString(), "application/json");
  497. if (_builder._locale != null) {
  498. httpInvoker.header(
  499. "Accept-Language", _builder._locale.toLanguageTag());
  500. }
  501. for (Map.Entry<String, String> entry :
  502. _builder._headers.entrySet()) {
  503. httpInvoker.header(entry.getKey(), entry.getValue());
  504. }
  505. for (Map.Entry<String, String> entry :
  506. _builder._parameters.entrySet()) {
  507. httpInvoker.parameter(entry.getKey(), entry.getValue());
  508. }
  509. httpInvoker.httpMethod(HttpInvoker.HttpMethod.POST);
  510. httpInvoker.path(
  511. _builder._scheme + "://" + _builder._host + ":" +
  512. _builder._port + _builder._contextPath +
  513. "/o/headless-delivery/v1.0/asset-libraries/{assetLibraryId}/structured-contents");
  514. httpInvoker.path("assetLibraryId", assetLibraryId);
  515. httpInvoker.userNameAndPassword(
  516. _builder._login + ":" + _builder._password);
  517. return httpInvoker.invoke();
  518. }
  519. public void postAssetLibraryStructuredContentBatch(
  520. Long assetLibraryId, String callbackURL, Object object)
  521. throws Exception {
  522. HttpInvoker.HttpResponse httpResponse =
  523. postAssetLibraryStructuredContentBatchHttpResponse(
  524. assetLibraryId, callbackURL, object);
  525. String content = httpResponse.getContent();
  526. if ((httpResponse.getStatusCode() / 100) != 2) {
  527. _logger.log(
  528. Level.WARNING,
  529. "Unable to process HTTP response content: " + content);
  530. _logger.log(
  531. Level.WARNING,
  532. "HTTP response message: " + httpResponse.getMessage());
  533. _logger.log(
  534. Level.WARNING,
  535. "HTTP response status code: " +
  536. httpResponse.getStatusCode());
  537. throw new Problem.ProblemException(Problem.toDTO(content));
  538. }
  539. else {
  540. _logger.fine("HTTP response content: " + content);
  541. _logger.fine(
  542. "HTTP response message: " + httpResponse.getMessage());
  543. _logger.fine(
  544. "HTTP response status code: " +
  545. httpResponse.getStatusCode());
  546. }
  547. }
  548. public HttpInvoker.HttpResponse
  549. postAssetLibraryStructuredContentBatchHttpResponse(
  550. Long assetLibraryId, String callbackURL, Object object)
  551. throws Exception {
  552. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  553. httpInvoker.body(object.toString(), "application/json");
  554. if (_builder._locale != null) {
  555. httpInvoker.header(
  556. "Accept-Language", _builder._locale.toLanguageTag());
  557. }
  558. for (Map.Entry<String, String> entry :
  559. _builder._headers.entrySet()) {
  560. httpInvoker.header(entry.getKey(), entry.getValue());
  561. }
  562. for (Map.Entry<String, String> entry :
  563. _builder._parameters.entrySet()) {
  564. httpInvoker.parameter(entry.getKey(), entry.getValue());
  565. }
  566. httpInvoker.httpMethod(HttpInvoker.HttpMethod.POST);
  567. if (callbackURL != null) {
  568. httpInvoker.parameter(
  569. "callbackURL", String.valueOf(callbackURL));
  570. }
  571. httpInvoker.path(
  572. _builder._scheme + "://" + _builder._host + ":" +
  573. _builder._port + _builder._contextPath +
  574. "/o/headless-delivery/v1.0/asset-libraries/{assetLibraryId}/structured-contents/batch");
  575. httpInvoker.path("assetLibraryId", assetLibraryId);
  576. httpInvoker.userNameAndPassword(
  577. _builder._login + ":" + _builder._password);
  578. return httpInvoker.invoke();
  579. }
  580. public void deleteAssetLibraryStructuredContentByExternalReferenceCode(
  581. Long assetLibraryId, String externalReferenceCode)
  582. throws Exception {
  583. HttpInvoker.HttpResponse httpResponse =
  584. deleteAssetLibraryStructuredContentByExternalReferenceCodeHttpResponse(
  585. assetLibraryId, externalReferenceCode);
  586. String content = httpResponse.getContent();
  587. if ((httpResponse.getStatusCode() / 100) != 2) {
  588. _logger.log(
  589. Level.WARNING,
  590. "Unable to process HTTP response content: " + content);
  591. _logger.log(
  592. Level.WARNING,
  593. "HTTP response message: " + httpResponse.getMessage());
  594. _logger.log(
  595. Level.WARNING,
  596. "HTTP response status code: " +
  597. httpResponse.getStatusCode());
  598. throw new Problem.ProblemException(Problem.toDTO(content));
  599. }
  600. else {
  601. _logger.fine("HTTP response content: " + content);
  602. _logger.fine(
  603. "HTTP response message: " + httpResponse.getMessage());
  604. _logger.fine(
  605. "HTTP response status code: " +
  606. httpResponse.getStatusCode());
  607. }
  608. try {
  609. return;
  610. }
  611. catch (Exception e) {
  612. _logger.log(
  613. Level.WARNING,
  614. "Unable to process HTTP response: " + content, e);
  615. throw new Problem.ProblemException(Problem.toDTO(content));
  616. }
  617. }
  618. public HttpInvoker.HttpResponse
  619. deleteAssetLibraryStructuredContentByExternalReferenceCodeHttpResponse(
  620. Long assetLibraryId, String externalReferenceCode)
  621. throws Exception {
  622. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  623. if (_builder._locale != null) {
  624. httpInvoker.header(
  625. "Accept-Language", _builder._locale.toLanguageTag());
  626. }
  627. for (Map.Entry<String, String> entry :
  628. _builder._headers.entrySet()) {
  629. httpInvoker.header(entry.getKey(), entry.getValue());
  630. }
  631. for (Map.Entry<String, String> entry :
  632. _builder._parameters.entrySet()) {
  633. httpInvoker.parameter(entry.getKey(), entry.getValue());
  634. }
  635. httpInvoker.httpMethod(HttpInvoker.HttpMethod.DELETE);
  636. httpInvoker.path(
  637. _builder._scheme + "://" + _builder._host + ":" +
  638. _builder._port + _builder._contextPath +
  639. "/o/headless-delivery/v1.0/asset-libraries/{assetLibraryId}/structured-contents/by-external-reference-code/{externalReferenceCode}");
  640. httpInvoker.path("assetLibraryId", assetLibraryId);
  641. httpInvoker.path("externalReferenceCode", externalReferenceCode);
  642. httpInvoker.userNameAndPassword(
  643. _builder._login + ":" + _builder._password);
  644. return httpInvoker.invoke();
  645. }
  646. public StructuredContent
  647. getAssetLibraryStructuredContentByExternalReferenceCode(
  648. Long assetLibraryId, String externalReferenceCode)
  649. throws Exception {
  650. HttpInvoker.HttpResponse httpResponse =
  651. getAssetLibraryStructuredContentByExternalReferenceCodeHttpResponse(
  652. assetLibraryId, externalReferenceCode);
  653. String content = httpResponse.getContent();
  654. if ((httpResponse.getStatusCode() / 100) != 2) {
  655. _logger.log(
  656. Level.WARNING,
  657. "Unable to process HTTP response content: " + content);
  658. _logger.log(
  659. Level.WARNING,
  660. "HTTP response message: " + httpResponse.getMessage());
  661. _logger.log(
  662. Level.WARNING,
  663. "HTTP response status code: " +
  664. httpResponse.getStatusCode());
  665. throw new Problem.ProblemException(Problem.toDTO(content));
  666. }
  667. else {
  668. _logger.fine("HTTP response content: " + content);
  669. _logger.fine(
  670. "HTTP response message: " + httpResponse.getMessage());
  671. _logger.fine(
  672. "HTTP response status code: " +
  673. httpResponse.getStatusCode());
  674. }
  675. try {
  676. return StructuredContentSerDes.toDTO(content);
  677. }
  678. catch (Exception e) {
  679. _logger.log(
  680. Level.WARNING,
  681. "Unable to process HTTP response: " + content, e);
  682. throw new Problem.ProblemException(Problem.toDTO(content));
  683. }
  684. }
  685. public HttpInvoker.HttpResponse
  686. getAssetLibraryStructuredContentByExternalReferenceCodeHttpResponse(
  687. Long assetLibraryId, String externalReferenceCode)
  688. throws Exception {
  689. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  690. if (_builder._locale != null) {
  691. httpInvoker.header(
  692. "Accept-Language", _builder._locale.toLanguageTag());
  693. }
  694. for (Map.Entry<String, String> entry :
  695. _builder._headers.entrySet()) {
  696. httpInvoker.header(entry.getKey(), entry.getValue());
  697. }
  698. for (Map.Entry<String, String> entry :
  699. _builder._parameters.entrySet()) {
  700. httpInvoker.parameter(entry.getKey(), entry.getValue());
  701. }
  702. httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
  703. httpInvoker.path(
  704. _builder._scheme + "://" + _builder._host + ":" +
  705. _builder._port + _builder._contextPath +
  706. "/o/headless-delivery/v1.0/asset-libraries/{assetLibraryId}/structured-contents/by-external-reference-code/{externalReferenceCode}");
  707. httpInvoker.path("assetLibraryId", assetLibraryId);
  708. httpInvoker.path("externalReferenceCode", externalReferenceCode);
  709. httpInvoker.userNameAndPassword(
  710. _builder._login + ":" + _builder._password);
  711. return httpInvoker.invoke();
  712. }
  713. public StructuredContent
  714. putAssetLibraryStructuredContentByExternalReferenceCode(
  715. Long assetLibraryId, String externalReferenceCode,
  716. StructuredContent structuredContent)
  717. throws Exception {
  718. HttpInvoker.HttpResponse httpResponse =
  719. putAssetLibraryStructuredContentByExternalReferenceCodeHttpResponse(
  720. assetLibraryId, externalReferenceCode, structuredContent);
  721. String content = httpResponse.getContent();
  722. if ((httpResponse.getStatusCode() / 100) != 2) {
  723. _logger.log(
  724. Level.WARNING,
  725. "Unable to process HTTP response content: " + content);
  726. _logger.log(
  727. Level.WARNING,
  728. "HTTP response message: " + httpResponse.getMessage());
  729. _logger.log(
  730. Level.WARNING,
  731. "HTTP response status code: " +
  732. httpResponse.getStatusCode());
  733. throw new Problem.ProblemException(Problem.toDTO(content));
  734. }
  735. else {
  736. _logger.fine("HTTP response content: " + content);
  737. _logger.fine(
  738. "HTTP response message: " + httpResponse.getMessage());
  739. _logger.fine(
  740. "HTTP response status code: " +
  741. httpResponse.getStatusCode());
  742. }
  743. try {
  744. return StructuredContentSerDes.toDTO(content);
  745. }
  746. catch (Exception e) {
  747. _logger.log(
  748. Level.WARNING,
  749. "Unable to process HTTP response: " + content, e);
  750. throw new Problem.ProblemException(Problem.toDTO(content));
  751. }
  752. }
  753. public HttpInvoker.HttpResponse
  754. putAssetLibraryStructuredContentByExternalReferenceCodeHttpResponse(
  755. Long assetLibraryId, String externalReferenceCode,
  756. StructuredContent structuredContent)
  757. throws Exception {
  758. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  759. httpInvoker.body(structuredContent.toString(), "application/json");
  760. if (_builder._locale != null) {
  761. httpInvoker.header(
  762. "Accept-Language", _builder._locale.toLanguageTag());
  763. }
  764. for (Map.Entry<String, String> entry :
  765. _builder._headers.entrySet()) {
  766. httpInvoker.header(entry.getKey(), entry.getValue());
  767. }
  768. for (Map.Entry<String, String> entry :
  769. _builder._parameters.entrySet()) {
  770. httpInvoker.parameter(entry.getKey(), entry.getValue());
  771. }
  772. httpInvoker.httpMethod(HttpInvoker.HttpMethod.PUT);
  773. httpInvoker.path(
  774. _builder._scheme + "://" + _builder._host + ":" +
  775. _builder._port + _builder._contextPath +
  776. "/o/headless-delivery/v1.0/asset-libraries/{assetLibraryId}/structured-contents/by-external-reference-code/{externalReferenceCode}");
  777. httpInvoker.path("assetLibraryId", assetLibraryId);
  778. httpInvoker.path("externalReferenceCode", externalReferenceCode);
  779. httpInvoker.userNameAndPassword(
  780. _builder._login + ":" + _builder._password);
  781. return httpInvoker.invoke();
  782. }
  783. public Page<Permission> getAssetLibraryStructuredContentPermissionsPage(
  784. Long assetLibraryId, String roleNames)
  785. throws Exception {
  786. HttpInvoker.HttpResponse httpResponse =
  787. getAssetLibraryStructuredContentPermissionsPageHttpResponse(
  788. assetLibraryId, roleNames);
  789. String content = httpResponse.getContent();
  790. if ((httpResponse.getStatusCode() / 100) != 2) {
  791. _logger.log(
  792. Level.WARNING,
  793. "Unable to process HTTP response content: " + content);
  794. _logger.log(
  795. Level.WARNING,
  796. "HTTP response message: " + httpResponse.getMessage());
  797. _logger.log(
  798. Level.WARNING,
  799. "HTTP response status code: " +
  800. httpResponse.getStatusCode());
  801. throw new Problem.ProblemException(Problem.toDTO(content));
  802. }
  803. else {
  804. _logger.fine("HTTP response content: " + content);
  805. _logger.fine(
  806. "HTTP response message: " + httpResponse.getMessage());
  807. _logger.fine(
  808. "HTTP response status code: " +
  809. httpResponse.getStatusCode());
  810. }
  811. try {
  812. return Page.of(content, Permission::toDTO);
  813. }
  814. catch (Exception e) {
  815. _logger.log(
  816. Level.WARNING,
  817. "Unable to process HTTP response: " + content, e);
  818. throw new Problem.ProblemException(Problem.toDTO(content));
  819. }
  820. }
  821. public HttpInvoker.HttpResponse
  822. getAssetLibraryStructuredContentPermissionsPageHttpResponse(
  823. Long assetLibraryId, String roleNames)
  824. throws Exception {
  825. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  826. if (_builder._locale != null) {
  827. httpInvoker.header(
  828. "Accept-Language", _builder._locale.toLanguageTag());
  829. }
  830. for (Map.Entry<String, String> entry :
  831. _builder._headers.entrySet()) {
  832. httpInvoker.header(entry.getKey(), entry.getValue());
  833. }
  834. for (Map.Entry<String, String> entry :
  835. _builder._parameters.entrySet()) {
  836. httpInvoker.parameter(entry.getKey(), entry.getValue());
  837. }
  838. httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
  839. if (roleNames != null) {
  840. httpInvoker.parameter("roleNames", String.valueOf(roleNames));
  841. }
  842. httpInvoker.path(
  843. _builder._scheme + "://" + _builder._host + ":" +
  844. _builder._port + _builder._contextPath +
  845. "/o/headless-delivery/v1.0/asset-libraries/{assetLibraryId}/structured-contents/permissions");
  846. httpInvoker.path("assetLibraryId", assetLibraryId);
  847. httpInvoker.userNameAndPassword(
  848. _builder._login + ":" + _builder._password);
  849. return httpInvoker.invoke();
  850. }
  851. public Page<Permission> putAssetLibraryStructuredContentPermissionsPage(
  852. Long assetLibraryId, Permission[] permissions)
  853. throws Exception {
  854. HttpInvoker.HttpResponse httpResponse =
  855. putAssetLibraryStructuredContentPermissionsPageHttpResponse(
  856. assetLibraryId, permissions);
  857. String content = httpResponse.getContent();
  858. if ((httpResponse.getStatusCode() / 100) != 2) {
  859. _logger.log(
  860. Level.WARNING,
  861. "Unable to process HTTP response content: " + content);
  862. _logger.log(
  863. Level.WARNING,
  864. "HTTP response message: " + httpResponse.getMessage());
  865. _logger.log(
  866. Level.WARNING,
  867. "HTTP response status code: " +
  868. httpResponse.getStatusCode());
  869. throw new Problem.ProblemException(Problem.toDTO(content));
  870. }
  871. else {
  872. _logger.fine("HTTP response content: " + content);
  873. _logger.fine(
  874. "HTTP response message: " + httpResponse.getMessage());
  875. _logger.fine(
  876. "HTTP response status code: " +
  877. httpResponse.getStatusCode());
  878. }
  879. try {
  880. return Page.of(content, Permission::toDTO);
  881. }
  882. catch (Exception e) {
  883. _logger.log(
  884. Level.WARNING,
  885. "Unable to process HTTP response: " + content, e);
  886. throw new Problem.ProblemException(Problem.toDTO(content));
  887. }
  888. }
  889. public HttpInvoker.HttpResponse
  890. putAssetLibraryStructuredContentPermissionsPageHttpResponse(
  891. Long assetLibraryId, Permission[] permissions)
  892. throws Exception {
  893. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  894. httpInvoker.body(
  895. Stream.of(
  896. permissions
  897. ).map(
  898. value -> String.valueOf(value)
  899. ).collect(
  900. Collectors.toList()
  901. ).toString(),
  902. "application/json");
  903. if (_builder._locale != null) {
  904. httpInvoker.header(
  905. "Accept-Language", _builder._locale.toLanguageTag());
  906. }
  907. for (Map.Entry<String, String> entry :
  908. _builder._headers.entrySet()) {
  909. httpInvoker.header(entry.getKey(), entry.getValue());
  910. }
  911. for (Map.Entry<String, String> entry :
  912. _builder._parameters.entrySet()) {
  913. httpInvoker.parameter(entry.getKey(), entry.getValue());
  914. }
  915. httpInvoker.httpMethod(HttpInvoker.HttpMethod.PUT);
  916. httpInvoker.path(
  917. _builder._scheme + "://" + _builder._host + ":" +
  918. _builder._port + _builder._contextPath +
  919. "/o/headless-delivery/v1.0/asset-libraries/{assetLibraryId}/structured-contents/permissions");
  920. httpInvoker.path("assetLibraryId", assetLibraryId);
  921. httpInvoker.userNameAndPassword(
  922. _builder._login + ":" + _builder._password);
  923. return httpInvoker.invoke();
  924. }
  925. public Page<StructuredContent>
  926. getContentStructureStructuredContentsPage(
  927. Long contentStructureId, String search,
  928. List<String> aggregations, String filterString,
  929. Pagination pagination, String sortString)
  930. throws Exception {
  931. HttpInvoker.HttpResponse httpResponse =
  932. getContentStructureStructuredContentsPageHttpResponse(
  933. contentStructureId, search, aggregations, filterString,
  934. pagination, sortString);
  935. String content = httpResponse.getContent();
  936. if ((httpResponse.getStatusCode() / 100) != 2) {
  937. _logger.log(
  938. Level.WARNING,
  939. "Unable to process HTTP response content: " + content);
  940. _logger.log(
  941. Level.WARNING,
  942. "HTTP response message: " + httpResponse.getMessage());
  943. _logger.log(
  944. Level.WARNING,
  945. "HTTP response status code: " +
  946. httpResponse.getStatusCode());
  947. throw new Problem.ProblemException(Problem.toDTO(content));
  948. }
  949. else {
  950. _logger.fine("HTTP response content: " + content);
  951. _logger.fine(
  952. "HTTP response message: " + httpResponse.getMessage());
  953. _logger.fine(
  954. "HTTP response status code: " +
  955. httpResponse.getStatusCode());
  956. }
  957. try {
  958. return Page.of(content, StructuredContentSerDes::toDTO);
  959. }
  960. catch (Exception e) {
  961. _logger.log(
  962. Level.WARNING,
  963. "Unable to process HTTP response: " + content, e);
  964. throw new Problem.ProblemException(Problem.toDTO(content));
  965. }
  966. }
  967. public HttpInvoker.HttpResponse
  968. getContentStructureStructuredContentsPageHttpResponse(
  969. Long contentStructureId, String search,
  970. List<String> aggregations, String filterString,
  971. Pagination pagination, String sortString)
  972. throws Exception {
  973. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  974. if (_builder._locale != null) {
  975. httpInvoker.header(
  976. "Accept-Language", _builder._locale.toLanguageTag());
  977. }
  978. for (Map.Entry<String, String> entry :
  979. _builder._headers.entrySet()) {
  980. httpInvoker.header(entry.getKey(), entry.getValue());
  981. }
  982. for (Map.Entry<String, String> entry :
  983. _builder._parameters.entrySet()) {
  984. httpInvoker.parameter(entry.getKey(), entry.getValue());
  985. }
  986. httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
  987. if (search != null) {
  988. httpInvoker.parameter("search", String.valueOf(search));
  989. }
  990. if (filterString != null) {
  991. httpInvoker.parameter("filter", filterString);
  992. }
  993. if (pagination != null) {
  994. httpInvoker.parameter(
  995. "page", String.valueOf(pagination.getPage()));
  996. httpInvoker.parameter(
  997. "pageSize", String.valueOf(pagination.getPageSize()));
  998. }
  999. if (sortString != null) {
  1000. httpInvoker.parameter("sort", sortString);
  1001. }
  1002. httpInvoker.path(
  1003. _builder._scheme + "://" + _builder._host + ":" +
  1004. _builder._port + _builder._contextPath +
  1005. "/o/headless-delivery/v1.0/content-structures/{contentStructureId}/structured-contents");
  1006. httpInvoker.path("contentStructureId", contentStructureId);
  1007. httpInvoker.userNameAndPassword(
  1008. _builder._login + ":" + _builder._password);
  1009. return httpInvoker.invoke();
  1010. }
  1011. public Page<StructuredContent> getSiteStructuredContentsPage(
  1012. Long siteId, Boolean flatten, String search,
  1013. List<String> aggregations, String filterString,
  1014. Pagination pagination, String sortString)
  1015. throws Exception {
  1016. HttpInvoker.HttpResponse httpResponse =
  1017. getSiteStructuredContentsPageHttpResponse(
  1018. siteId, flatten, search, aggregations, filterString,
  1019. pagination, sortString);
  1020. String content = httpResponse.getContent();
  1021. if ((httpResponse.getStatusCode() / 100) != 2) {
  1022. _logger.log(
  1023. Level.WARNING,
  1024. "Unable to process HTTP response content: " + content);
  1025. _logger.log(
  1026. Level.WARNING,
  1027. "HTTP response message: " + httpResponse.getMessage());
  1028. _logger.log(
  1029. Level.WARNING,
  1030. "HTTP response status code: " +
  1031. httpResponse.getStatusCode());
  1032. throw new Problem.ProblemException(Problem.toDTO(content));
  1033. }
  1034. else {
  1035. _logger.fine("HTTP response content: " + content);
  1036. _logger.fine(
  1037. "HTTP response message: " + httpResponse.getMessage());
  1038. _logger.fine(
  1039. "HTTP response status code: " +
  1040. httpResponse.getStatusCode());
  1041. }
  1042. try {
  1043. return Page.of(content, StructuredContentSerDes::toDTO);
  1044. }
  1045. catch (Exception e) {
  1046. _logger.log(
  1047. Level.WARNING,
  1048. "Unable to process HTTP response: " + content, e);
  1049. throw new Problem.ProblemException(Problem.toDTO(content));
  1050. }
  1051. }
  1052. public HttpInvoker.HttpResponse
  1053. getSiteStructuredContentsPageHttpResponse(
  1054. Long siteId, Boolean flatten, String search,
  1055. List<String> aggregations, String filterString,
  1056. Pagination pagination, String sortString)
  1057. throws Exception {
  1058. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  1059. if (_builder._locale != null) {
  1060. httpInvoker.header(
  1061. "Accept-Language", _builder._locale.toLanguageTag());
  1062. }
  1063. for (Map.Entry<String, String> entry :
  1064. _builder._headers.entrySet()) {
  1065. httpInvoker.header(entry.getKey(), entry.getValue());
  1066. }
  1067. for (Map.Entry<String, String> entry :
  1068. _builder._parameters.entrySet()) {
  1069. httpInvoker.parameter(entry.getKey(), entry.getValue());
  1070. }
  1071. httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
  1072. if (flatten != null) {
  1073. httpInvoker.parameter("flatten", String.valueOf(flatten));
  1074. }
  1075. if (search != null) {
  1076. httpInvoker.parameter("search", String.valueOf(search));
  1077. }
  1078. if (filterString != null) {
  1079. httpInvoker.parameter("filter", filterString);
  1080. }
  1081. if (pagination != null) {
  1082. httpInvoker.parameter(
  1083. "page", String.valueOf(pagination.getPage()));
  1084. httpInvoker.parameter(
  1085. "pageSize", String.valueOf(pagination.getPageSize()));
  1086. }
  1087. if (sortString != null) {
  1088. httpInvoker.parameter("sort", sortString);
  1089. }
  1090. httpInvoker.path(
  1091. _builder._scheme + "://" + _builder._host + ":" +
  1092. _builder._port + _builder._contextPath +
  1093. "/o/headless-delivery/v1.0/sites/{siteId}/structured-contents");
  1094. httpInvoker.path("siteId", siteId);
  1095. httpInvoker.userNameAndPassword(
  1096. _builder._login + ":" + _builder._password);
  1097. return httpInvoker.invoke();
  1098. }
  1099. public StructuredContent postSiteStructuredContent(
  1100. Long siteId, StructuredContent structuredContent)
  1101. throws Exception {
  1102. HttpInvoker.HttpResponse httpResponse =
  1103. postSiteStructuredContentHttpResponse(
  1104. siteId, structuredContent);
  1105. String content = httpResponse.getContent();
  1106. if ((httpResponse.getStatusCode() / 100) != 2) {
  1107. _logger.log(
  1108. Level.WARNING,
  1109. "Unable to process HTTP response content: " + content);
  1110. _logger.log(
  1111. Level.WARNING,
  1112. "HTTP response message: " + httpResponse.getMessage());
  1113. _logger.log(
  1114. Level.WARNING,
  1115. "HTTP response status code: " +
  1116. httpResponse.getStatusCode());
  1117. throw new Problem.ProblemException(Problem.toDTO(content));
  1118. }
  1119. else {
  1120. _logger.fine("HTTP response content: " + content);
  1121. _logger.fine(
  1122. "HTTP response message: " + httpResponse.getMessage());
  1123. _logger.fine(
  1124. "HTTP response status code: " +
  1125. httpResponse.getStatusCode());
  1126. }
  1127. try {
  1128. return StructuredContentSerDes.toDTO(content);
  1129. }
  1130. catch (Exception e) {
  1131. _logger.log(
  1132. Level.WARNING,
  1133. "Unable to process HTTP response: " + content, e);
  1134. throw new Problem.ProblemException(Problem.toDTO(content));
  1135. }
  1136. }
  1137. public HttpInvoker.HttpResponse postSiteStructuredContentHttpResponse(
  1138. Long siteId, StructuredContent structuredContent)
  1139. throws Exception {
  1140. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  1141. httpInvoker.body(structuredContent.toString(), "application/json");
  1142. if (_builder._locale != null) {
  1143. httpInvoker.header(
  1144. "Accept-Language", _builder._locale.toLanguageTag());
  1145. }
  1146. for (Map.Entry<String, String> entry :
  1147. _builder._headers.entrySet()) {
  1148. httpInvoker.header(entry.getKey(), entry.getValue());
  1149. }
  1150. for (Map.Entry<String, String> entry :
  1151. _builder._parameters.entrySet()) {
  1152. httpInvoker.parameter(entry.getKey(), entry.getValue());
  1153. }
  1154. httpInvoker.httpMethod(HttpInvoker.HttpMethod.POST);
  1155. httpInvoker.path(
  1156. _builder._scheme + "://" + _builder._host + ":" +
  1157. _builder._port + _builder._contextPath +
  1158. "/o/headless-delivery/v1.0/sites/{siteId}/structured-contents");
  1159. httpInvoker.path("siteId", siteId);
  1160. httpInvoker.userNameAndPassword(
  1161. _builder._login + ":" + _builder._password);
  1162. return httpInvoker.invoke();
  1163. }
  1164. public void postSiteStructuredContentBatch(
  1165. Long siteId, String callbackURL, Object object)
  1166. throws Exception {
  1167. HttpInvoker.HttpResponse httpResponse =
  1168. postSiteStructuredContentBatchHttpResponse(
  1169. siteId, callbackURL, object);
  1170. String content = httpResponse.getContent();
  1171. if ((httpResponse.getStatusCode() / 100) != 2) {
  1172. _logger.log(
  1173. Level.WARNING,
  1174. "Unable to process HTTP response content: " + content);
  1175. _logger.log(
  1176. Level.WARNING,
  1177. "HTTP response message: " + httpResponse.getMessage());
  1178. _logger.log(
  1179. Level.WARNING,
  1180. "HTTP response status code: " +
  1181. httpResponse.getStatusCode());
  1182. throw new Problem.ProblemException(Problem.toDTO(content));
  1183. }
  1184. else {
  1185. _logger.fine("HTTP response content: " + content);
  1186. _logger.fine(
  1187. "HTTP response message: " + httpResponse.getMessage());
  1188. _logger.fine(
  1189. "HTTP response status code: " +
  1190. httpResponse.getStatusCode());
  1191. }
  1192. }
  1193. public HttpInvoker.HttpResponse
  1194. postSiteStructuredContentBatchHttpResponse(
  1195. Long siteId, String callbackURL, Object object)
  1196. throws Exception {
  1197. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  1198. httpInvoker.body(object.toString(), "application/json");
  1199. if (_builder._locale != null) {
  1200. httpInvoker.header(
  1201. "Accept-Language", _builder._locale.toLanguageTag());
  1202. }
  1203. for (Map.Entry<String, String> entry :
  1204. _builder._headers.entrySet()) {
  1205. httpInvoker.header(entry.getKey(), entry.getValue());
  1206. }
  1207. for (Map.Entry<String, String> entry :
  1208. _builder._parameters.entrySet()) {
  1209. httpInvoker.parameter(entry.getKey(), entry.getValue());
  1210. }
  1211. httpInvoker.httpMethod(HttpInvoker.HttpMethod.POST);
  1212. if (callbackURL != null) {
  1213. httpInvoker.parameter(
  1214. "callbackURL", String.valueOf(callbackURL));
  1215. }
  1216. httpInvoker.path(
  1217. _builder._scheme + "://" + _builder._host + ":" +
  1218. _builder._port + _builder._contextPath +
  1219. "/o/headless-delivery/v1.0/sites/{siteId}/structured-contents/batch");
  1220. httpInvoker.path("siteId", siteId);
  1221. httpInvoker.userNameAndPassword(
  1222. _builder._login + ":" + _builder._password);
  1223. return httpInvoker.invoke();
  1224. }
  1225. public void deleteSiteStructuredContentByExternalReferenceCode(
  1226. Long siteId, String externalReferenceCode)
  1227. throws Exception {
  1228. HttpInvoker.HttpResponse httpResponse =
  1229. deleteSiteStructuredContentByExternalReferenceCodeHttpResponse(
  1230. siteId, externalReferenceCode);
  1231. String content = httpResponse.getContent();
  1232. if ((httpResponse.getStatusCode() / 100) != 2) {
  1233. _logger.log(
  1234. Level.WARNING,
  1235. "Unable to process HTTP response content: " + content);
  1236. _logger.log(
  1237. Level.WARNING,
  1238. "HTTP response message: " + httpResponse.getMessage());
  1239. _logger.log(
  1240. Level.WARNING,
  1241. "HTTP response status code: " +
  1242. httpResponse.getStatusCode());
  1243. throw new Problem.ProblemException(Problem.toDTO(content));
  1244. }
  1245. else {
  1246. _logger.fine("HTTP response content: " + content);
  1247. _logger.fine(
  1248. "HTTP response message: " + httpResponse.getMessage());
  1249. _logger.fine(
  1250. "HTTP response status code: " +
  1251. httpResponse.getStatusCode());
  1252. }
  1253. try {
  1254. return;
  1255. }
  1256. catch (Exception e) {
  1257. _logger.log(
  1258. Level.WARNING,
  1259. "Unable to process HTTP response: " + content, e);
  1260. throw new Problem.ProblemException(Problem.toDTO(content));
  1261. }
  1262. }
  1263. public HttpInvoker.HttpResponse
  1264. deleteSiteStructuredContentByExternalReferenceCodeHttpResponse(
  1265. Long siteId, String externalReferenceCode)
  1266. throws Exception {
  1267. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  1268. if (_builder._locale != null) {
  1269. httpInvoker.header(
  1270. "Accept-Language", _builder._locale.toLanguageTag());
  1271. }
  1272. for (Map.Entry<String, String> entry :
  1273. _builder._headers.entrySet()) {
  1274. httpInvoker.header(entry.getKey(), entry.getValue());
  1275. }
  1276. for (Map.Entry<String, String> entry :
  1277. _builder._parameters.entrySet()) {
  1278. httpInvoker.parameter(entry.getKey(), entry.getValue());
  1279. }
  1280. httpInvoker.httpMethod(HttpInvoker.HttpMethod.DELETE);
  1281. httpInvoker.path(
  1282. _builder._scheme + "://" + _builder._host + ":" +
  1283. _builder._port + _builder._contextPath +
  1284. "/o/headless-delivery/v1.0/sites/{siteId}/structured-contents/by-external-reference-code/{externalReferenceCode}");
  1285. httpInvoker.path("siteId", siteId);
  1286. httpInvoker.path("externalReferenceCode", externalReferenceCode);
  1287. httpInvoker.userNameAndPassword(
  1288. _builder._login + ":" + _builder._password);
  1289. return httpInvoker.invoke();
  1290. }
  1291. public StructuredContent
  1292. getSiteStructuredContentByExternalReferenceCode(
  1293. Long siteId, String externalReferenceCode)
  1294. throws Exception {
  1295. HttpInvoker.HttpResponse httpResponse =
  1296. getSiteStructuredContentByExternalReferenceCodeHttpResponse(
  1297. siteId, externalReferenceCode);
  1298. String content = httpResponse.getContent();
  1299. if ((httpResponse.getStatusCode() / 100) != 2) {
  1300. _logger.log(
  1301. Level.WARNING,
  1302. "Unable to process HTTP response content: " + content);
  1303. _logger.log(
  1304. Level.WARNING,
  1305. "HTTP response message: " + httpResponse.getMessage());
  1306. _logger.log(
  1307. Level.WARNING,
  1308. "HTTP response status code: " +
  1309. httpResponse.getStatusCode());
  1310. throw new Problem.ProblemException(Problem.toDTO(content));
  1311. }
  1312. else {
  1313. _logger.fine("HTTP response content: " + content);
  1314. _logger.fine(
  1315. "HTTP response message: " + httpResponse.getMessage());
  1316. _logger.fine(
  1317. "HTTP response status code: " +
  1318. httpResponse.getStatusCode());
  1319. }
  1320. try {
  1321. return StructuredContentSerDes.toDTO(content);
  1322. }
  1323. catch (Exception e