/modules/dxp/apps/search-experiences/search-experiences-rest-client/src/main/java/com/liferay/search/experiences/rest/client/resource/v1_0/SXPElementResource.java

https://github.com/danielreuther/liferay-portal · Java · 1011 lines · 753 code · 241 blank · 17 comment · 85 complexity · 492a6bcf620993973e499738f731d628 MD5 · raw file

  1. /**
  2. * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
  3. *
  4. * The contents of this file are subject to the terms of the Liferay Enterprise
  5. * Subscription License ("License"). You may not use this file except in
  6. * compliance with the License. You can obtain a copy of the License by
  7. * contacting Liferay, Inc. See the License for the specific language governing
  8. * permissions and limitations under the License, including but not limited to
  9. * distribution rights of the Software.
  10. *
  11. *
  12. *
  13. */
  14. package com.liferay.search.experiences.rest.client.resource.v1_0;
  15. import com.liferay.search.experiences.rest.client.dto.v1_0.SXPElement;
  16. import com.liferay.search.experiences.rest.client.http.HttpInvoker;
  17. import com.liferay.search.experiences.rest.client.pagination.Page;
  18. import com.liferay.search.experiences.rest.client.pagination.Pagination;
  19. import com.liferay.search.experiences.rest.client.problem.Problem;
  20. import com.liferay.search.experiences.rest.client.serdes.v1_0.SXPElementSerDes;
  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 Brian Wing Shun Chan
  29. * @generated
  30. */
  31. @Generated("")
  32. public interface SXPElementResource {
  33. public static Builder builder() {
  34. return new Builder();
  35. }
  36. public Page<SXPElement> getSXPElementsPage(
  37. String search, String filterString, Pagination pagination,
  38. String sortString)
  39. throws Exception;
  40. public HttpInvoker.HttpResponse getSXPElementsPageHttpResponse(
  41. String search, String filterString, Pagination pagination,
  42. String sortString)
  43. throws Exception;
  44. public SXPElement postSXPElement(SXPElement sxpElement) throws Exception;
  45. public HttpInvoker.HttpResponse postSXPElementHttpResponse(
  46. SXPElement sxpElement)
  47. throws Exception;
  48. public void postSXPElementBatch(
  49. SXPElement sxpElement, String callbackURL, Object object)
  50. throws Exception;
  51. public HttpInvoker.HttpResponse postSXPElementBatchHttpResponse(
  52. SXPElement sxpElement, String callbackURL, Object object)
  53. throws Exception;
  54. public SXPElement postSXPElementValidate(String string) throws Exception;
  55. public HttpInvoker.HttpResponse postSXPElementValidateHttpResponse(
  56. String string)
  57. throws Exception;
  58. public void deleteSXPElement(Long sxpElementId) throws Exception;
  59. public HttpInvoker.HttpResponse deleteSXPElementHttpResponse(
  60. Long sxpElementId)
  61. throws Exception;
  62. public void deleteSXPElementBatch(
  63. Long sxpElementId, String callbackURL, Object object)
  64. throws Exception;
  65. public HttpInvoker.HttpResponse deleteSXPElementBatchHttpResponse(
  66. Long sxpElementId, String callbackURL, Object object)
  67. throws Exception;
  68. public SXPElement getSXPElement(Long sxpElementId) throws Exception;
  69. public HttpInvoker.HttpResponse getSXPElementHttpResponse(Long sxpElementId)
  70. throws Exception;
  71. public SXPElement patchSXPElement(Long sxpElementId, SXPElement sxpElement)
  72. throws Exception;
  73. public HttpInvoker.HttpResponse patchSXPElementHttpResponse(
  74. Long sxpElementId, SXPElement sxpElement)
  75. throws Exception;
  76. public SXPElement postSXPElementCopy(Long sxpElementId) throws Exception;
  77. public HttpInvoker.HttpResponse postSXPElementCopyHttpResponse(
  78. Long sxpElementId)
  79. throws Exception;
  80. public void getSXPElementExport(Long sxpElementId) throws Exception;
  81. public HttpInvoker.HttpResponse getSXPElementExportHttpResponse(
  82. Long sxpElementId)
  83. throws Exception;
  84. public static class Builder {
  85. public Builder authentication(String login, String password) {
  86. _login = login;
  87. _password = password;
  88. return this;
  89. }
  90. public SXPElementResource build() {
  91. return new SXPElementResourceImpl(this);
  92. }
  93. public Builder contextPath(String contextPath) {
  94. _contextPath = contextPath;
  95. return this;
  96. }
  97. public Builder endpoint(String host, int port, String scheme) {
  98. _host = host;
  99. _port = port;
  100. _scheme = scheme;
  101. return this;
  102. }
  103. public Builder header(String key, String value) {
  104. _headers.put(key, value);
  105. return this;
  106. }
  107. public Builder locale(Locale locale) {
  108. _locale = locale;
  109. return this;
  110. }
  111. public Builder parameter(String key, String value) {
  112. _parameters.put(key, value);
  113. return this;
  114. }
  115. public Builder parameters(String... parameters) {
  116. if ((parameters.length % 2) != 0) {
  117. throw new IllegalArgumentException(
  118. "Parameters length is not an even number");
  119. }
  120. for (int i = 0; i < parameters.length; i += 2) {
  121. String parameterName = String.valueOf(parameters[i]);
  122. String parameterValue = String.valueOf(parameters[i + 1]);
  123. _parameters.put(parameterName, parameterValue);
  124. }
  125. return this;
  126. }
  127. private Builder() {
  128. }
  129. private String _contextPath = "";
  130. private Map<String, String> _headers = new LinkedHashMap<>();
  131. private String _host = "localhost";
  132. private Locale _locale;
  133. private String _login = "";
  134. private String _password = "";
  135. private Map<String, String> _parameters = new LinkedHashMap<>();
  136. private int _port = 8080;
  137. private String _scheme = "http";
  138. }
  139. public static class SXPElementResourceImpl implements SXPElementResource {
  140. public Page<SXPElement> getSXPElementsPage(
  141. String search, String filterString, Pagination pagination,
  142. String sortString)
  143. throws Exception {
  144. HttpInvoker.HttpResponse httpResponse =
  145. getSXPElementsPageHttpResponse(
  146. search, filterString, pagination, sortString);
  147. String content = httpResponse.getContent();
  148. if ((httpResponse.getStatusCode() / 100) != 2) {
  149. _logger.log(
  150. Level.WARNING,
  151. "Unable to process HTTP response content: " + content);
  152. _logger.log(
  153. Level.WARNING,
  154. "HTTP response message: " + httpResponse.getMessage());
  155. _logger.log(
  156. Level.WARNING,
  157. "HTTP response status code: " +
  158. httpResponse.getStatusCode());
  159. throw new Problem.ProblemException(Problem.toDTO(content));
  160. }
  161. else {
  162. _logger.fine("HTTP response content: " + content);
  163. _logger.fine(
  164. "HTTP response message: " + httpResponse.getMessage());
  165. _logger.fine(
  166. "HTTP response status code: " +
  167. httpResponse.getStatusCode());
  168. }
  169. try {
  170. return Page.of(content, SXPElementSerDes::toDTO);
  171. }
  172. catch (Exception e) {
  173. _logger.log(
  174. Level.WARNING,
  175. "Unable to process HTTP response: " + content, e);
  176. throw new Problem.ProblemException(Problem.toDTO(content));
  177. }
  178. }
  179. public HttpInvoker.HttpResponse getSXPElementsPageHttpResponse(
  180. String search, String filterString, Pagination pagination,
  181. String sortString)
  182. throws Exception {
  183. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  184. if (_builder._locale != null) {
  185. httpInvoker.header(
  186. "Accept-Language", _builder._locale.toLanguageTag());
  187. }
  188. for (Map.Entry<String, String> entry :
  189. _builder._headers.entrySet()) {
  190. httpInvoker.header(entry.getKey(), entry.getValue());
  191. }
  192. for (Map.Entry<String, String> entry :
  193. _builder._parameters.entrySet()) {
  194. httpInvoker.parameter(entry.getKey(), entry.getValue());
  195. }
  196. httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
  197. if (search != null) {
  198. httpInvoker.parameter("search", String.valueOf(search));
  199. }
  200. if (filterString != null) {
  201. httpInvoker.parameter("filter", filterString);
  202. }
  203. if (pagination != null) {
  204. httpInvoker.parameter(
  205. "page", String.valueOf(pagination.getPage()));
  206. httpInvoker.parameter(
  207. "pageSize", String.valueOf(pagination.getPageSize()));
  208. }
  209. if (sortString != null) {
  210. httpInvoker.parameter("sort", sortString);
  211. }
  212. httpInvoker.path(
  213. _builder._scheme + "://" + _builder._host + ":" +
  214. _builder._port + _builder._contextPath +
  215. "/o/search-experiences-rest/v1.0/sxp-elements");
  216. httpInvoker.userNameAndPassword(
  217. _builder._login + ":" + _builder._password);
  218. return httpInvoker.invoke();
  219. }
  220. public SXPElement postSXPElement(SXPElement sxpElement)
  221. throws Exception {
  222. HttpInvoker.HttpResponse httpResponse = postSXPElementHttpResponse(
  223. sxpElement);
  224. String content = httpResponse.getContent();
  225. if ((httpResponse.getStatusCode() / 100) != 2) {
  226. _logger.log(
  227. Level.WARNING,
  228. "Unable to process HTTP response content: " + content);
  229. _logger.log(
  230. Level.WARNING,
  231. "HTTP response message: " + httpResponse.getMessage());
  232. _logger.log(
  233. Level.WARNING,
  234. "HTTP response status code: " +
  235. httpResponse.getStatusCode());
  236. throw new Problem.ProblemException(Problem.toDTO(content));
  237. }
  238. else {
  239. _logger.fine("HTTP response content: " + content);
  240. _logger.fine(
  241. "HTTP response message: " + httpResponse.getMessage());
  242. _logger.fine(
  243. "HTTP response status code: " +
  244. httpResponse.getStatusCode());
  245. }
  246. try {
  247. return SXPElementSerDes.toDTO(content);
  248. }
  249. catch (Exception e) {
  250. _logger.log(
  251. Level.WARNING,
  252. "Unable to process HTTP response: " + content, e);
  253. throw new Problem.ProblemException(Problem.toDTO(content));
  254. }
  255. }
  256. public HttpInvoker.HttpResponse postSXPElementHttpResponse(
  257. SXPElement sxpElement)
  258. throws Exception {
  259. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  260. httpInvoker.body(sxpElement.toString(), "application/json");
  261. if (_builder._locale != null) {
  262. httpInvoker.header(
  263. "Accept-Language", _builder._locale.toLanguageTag());
  264. }
  265. for (Map.Entry<String, String> entry :
  266. _builder._headers.entrySet()) {
  267. httpInvoker.header(entry.getKey(), entry.getValue());
  268. }
  269. for (Map.Entry<String, String> entry :
  270. _builder._parameters.entrySet()) {
  271. httpInvoker.parameter(entry.getKey(), entry.getValue());
  272. }
  273. httpInvoker.httpMethod(HttpInvoker.HttpMethod.POST);
  274. httpInvoker.path(
  275. _builder._scheme + "://" + _builder._host + ":" +
  276. _builder._port + _builder._contextPath +
  277. "/o/search-experiences-rest/v1.0/sxp-elements");
  278. httpInvoker.userNameAndPassword(
  279. _builder._login + ":" + _builder._password);
  280. return httpInvoker.invoke();
  281. }
  282. public void postSXPElementBatch(
  283. SXPElement sxpElement, String callbackURL, Object object)
  284. throws Exception {
  285. HttpInvoker.HttpResponse httpResponse =
  286. postSXPElementBatchHttpResponse(
  287. sxpElement, callbackURL, object);
  288. String content = httpResponse.getContent();
  289. if ((httpResponse.getStatusCode() / 100) != 2) {
  290. _logger.log(
  291. Level.WARNING,
  292. "Unable to process HTTP response content: " + content);
  293. _logger.log(
  294. Level.WARNING,
  295. "HTTP response message: " + httpResponse.getMessage());
  296. _logger.log(
  297. Level.WARNING,
  298. "HTTP response status code: " +
  299. httpResponse.getStatusCode());
  300. throw new Problem.ProblemException(Problem.toDTO(content));
  301. }
  302. else {
  303. _logger.fine("HTTP response content: " + content);
  304. _logger.fine(
  305. "HTTP response message: " + httpResponse.getMessage());
  306. _logger.fine(
  307. "HTTP response status code: " +
  308. httpResponse.getStatusCode());
  309. }
  310. }
  311. public HttpInvoker.HttpResponse postSXPElementBatchHttpResponse(
  312. SXPElement sxpElement, String callbackURL, Object object)
  313. throws Exception {
  314. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  315. httpInvoker.body(object.toString(), "application/json");
  316. if (_builder._locale != null) {
  317. httpInvoker.header(
  318. "Accept-Language", _builder._locale.toLanguageTag());
  319. }
  320. for (Map.Entry<String, String> entry :
  321. _builder._headers.entrySet()) {
  322. httpInvoker.header(entry.getKey(), entry.getValue());
  323. }
  324. for (Map.Entry<String, String> entry :
  325. _builder._parameters.entrySet()) {
  326. httpInvoker.parameter(entry.getKey(), entry.getValue());
  327. }
  328. httpInvoker.httpMethod(HttpInvoker.HttpMethod.POST);
  329. if (callbackURL != null) {
  330. httpInvoker.parameter(
  331. "callbackURL", String.valueOf(callbackURL));
  332. }
  333. httpInvoker.path(
  334. _builder._scheme + "://" + _builder._host + ":" +
  335. _builder._port + _builder._contextPath +
  336. "/o/search-experiences-rest/v1.0/sxp-elements/batch");
  337. httpInvoker.userNameAndPassword(
  338. _builder._login + ":" + _builder._password);
  339. return httpInvoker.invoke();
  340. }
  341. public SXPElement postSXPElementValidate(String string)
  342. throws Exception {
  343. HttpInvoker.HttpResponse httpResponse =
  344. postSXPElementValidateHttpResponse(string);
  345. String content = httpResponse.getContent();
  346. if ((httpResponse.getStatusCode() / 100) != 2) {
  347. _logger.log(
  348. Level.WARNING,
  349. "Unable to process HTTP response content: " + content);
  350. _logger.log(
  351. Level.WARNING,
  352. "HTTP response message: " + httpResponse.getMessage());
  353. _logger.log(
  354. Level.WARNING,
  355. "HTTP response status code: " +
  356. httpResponse.getStatusCode());
  357. throw new Problem.ProblemException(Problem.toDTO(content));
  358. }
  359. else {
  360. _logger.fine("HTTP response content: " + content);
  361. _logger.fine(
  362. "HTTP response message: " + httpResponse.getMessage());
  363. _logger.fine(
  364. "HTTP response status code: " +
  365. httpResponse.getStatusCode());
  366. }
  367. try {
  368. return SXPElementSerDes.toDTO(content);
  369. }
  370. catch (Exception e) {
  371. _logger.log(
  372. Level.WARNING,
  373. "Unable to process HTTP response: " + content, e);
  374. throw new Problem.ProblemException(Problem.toDTO(content));
  375. }
  376. }
  377. public HttpInvoker.HttpResponse postSXPElementValidateHttpResponse(
  378. String string)
  379. throws Exception {
  380. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  381. httpInvoker.body(string.toString(), "application/json");
  382. if (_builder._locale != null) {
  383. httpInvoker.header(
  384. "Accept-Language", _builder._locale.toLanguageTag());
  385. }
  386. for (Map.Entry<String, String> entry :
  387. _builder._headers.entrySet()) {
  388. httpInvoker.header(entry.getKey(), entry.getValue());
  389. }
  390. for (Map.Entry<String, String> entry :
  391. _builder._parameters.entrySet()) {
  392. httpInvoker.parameter(entry.getKey(), entry.getValue());
  393. }
  394. httpInvoker.httpMethod(HttpInvoker.HttpMethod.POST);
  395. httpInvoker.path(
  396. _builder._scheme + "://" + _builder._host + ":" +
  397. _builder._port + _builder._contextPath +
  398. "/o/search-experiences-rest/v1.0/sxp-elements/validate");
  399. httpInvoker.userNameAndPassword(
  400. _builder._login + ":" + _builder._password);
  401. return httpInvoker.invoke();
  402. }
  403. public void deleteSXPElement(Long sxpElementId) throws Exception {
  404. HttpInvoker.HttpResponse httpResponse =
  405. deleteSXPElementHttpResponse(sxpElementId);
  406. String content = httpResponse.getContent();
  407. if ((httpResponse.getStatusCode() / 100) != 2) {
  408. _logger.log(
  409. Level.WARNING,
  410. "Unable to process HTTP response content: " + content);
  411. _logger.log(
  412. Level.WARNING,
  413. "HTTP response message: " + httpResponse.getMessage());
  414. _logger.log(
  415. Level.WARNING,
  416. "HTTP response status code: " +
  417. httpResponse.getStatusCode());
  418. throw new Problem.ProblemException(Problem.toDTO(content));
  419. }
  420. else {
  421. _logger.fine("HTTP response content: " + content);
  422. _logger.fine(
  423. "HTTP response message: " + httpResponse.getMessage());
  424. _logger.fine(
  425. "HTTP response status code: " +
  426. httpResponse.getStatusCode());
  427. }
  428. try {
  429. return;
  430. }
  431. catch (Exception e) {
  432. _logger.log(
  433. Level.WARNING,
  434. "Unable to process HTTP response: " + content, e);
  435. throw new Problem.ProblemException(Problem.toDTO(content));
  436. }
  437. }
  438. public HttpInvoker.HttpResponse deleteSXPElementHttpResponse(
  439. Long sxpElementId)
  440. throws Exception {
  441. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  442. if (_builder._locale != null) {
  443. httpInvoker.header(
  444. "Accept-Language", _builder._locale.toLanguageTag());
  445. }
  446. for (Map.Entry<String, String> entry :
  447. _builder._headers.entrySet()) {
  448. httpInvoker.header(entry.getKey(), entry.getValue());
  449. }
  450. for (Map.Entry<String, String> entry :
  451. _builder._parameters.entrySet()) {
  452. httpInvoker.parameter(entry.getKey(), entry.getValue());
  453. }
  454. httpInvoker.httpMethod(HttpInvoker.HttpMethod.DELETE);
  455. httpInvoker.path(
  456. _builder._scheme + "://" + _builder._host + ":" +
  457. _builder._port + _builder._contextPath +
  458. "/o/search-experiences-rest/v1.0/sxp-elements/{sxpElementId}");
  459. httpInvoker.path("sxpElementId", sxpElementId);
  460. httpInvoker.userNameAndPassword(
  461. _builder._login + ":" + _builder._password);
  462. return httpInvoker.invoke();
  463. }
  464. public void deleteSXPElementBatch(
  465. Long sxpElementId, String callbackURL, Object object)
  466. throws Exception {
  467. HttpInvoker.HttpResponse httpResponse =
  468. deleteSXPElementBatchHttpResponse(
  469. sxpElementId, callbackURL, object);
  470. String content = httpResponse.getContent();
  471. if ((httpResponse.getStatusCode() / 100) != 2) {
  472. _logger.log(
  473. Level.WARNING,
  474. "Unable to process HTTP response content: " + content);
  475. _logger.log(
  476. Level.WARNING,
  477. "HTTP response message: " + httpResponse.getMessage());
  478. _logger.log(
  479. Level.WARNING,
  480. "HTTP response status code: " +
  481. httpResponse.getStatusCode());
  482. throw new Problem.ProblemException(Problem.toDTO(content));
  483. }
  484. else {
  485. _logger.fine("HTTP response content: " + content);
  486. _logger.fine(
  487. "HTTP response message: " + httpResponse.getMessage());
  488. _logger.fine(
  489. "HTTP response status code: " +
  490. httpResponse.getStatusCode());
  491. }
  492. }
  493. public HttpInvoker.HttpResponse deleteSXPElementBatchHttpResponse(
  494. Long sxpElementId, String callbackURL, Object object)
  495. throws Exception {
  496. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  497. httpInvoker.body(object.toString(), "application/json");
  498. if (_builder._locale != null) {
  499. httpInvoker.header(
  500. "Accept-Language", _builder._locale.toLanguageTag());
  501. }
  502. for (Map.Entry<String, String> entry :
  503. _builder._headers.entrySet()) {
  504. httpInvoker.header(entry.getKey(), entry.getValue());
  505. }
  506. for (Map.Entry<String, String> entry :
  507. _builder._parameters.entrySet()) {
  508. httpInvoker.parameter(entry.getKey(), entry.getValue());
  509. }
  510. httpInvoker.httpMethod(HttpInvoker.HttpMethod.DELETE);
  511. if (callbackURL != null) {
  512. httpInvoker.parameter(
  513. "callbackURL", String.valueOf(callbackURL));
  514. }
  515. httpInvoker.path(
  516. _builder._scheme + "://" + _builder._host + ":" +
  517. _builder._port + _builder._contextPath +
  518. "/o/search-experiences-rest/v1.0/sxp-elements/{sxpElementId}/batch");
  519. httpInvoker.path("sxpElementId", sxpElementId);
  520. httpInvoker.userNameAndPassword(
  521. _builder._login + ":" + _builder._password);
  522. return httpInvoker.invoke();
  523. }
  524. public SXPElement getSXPElement(Long sxpElementId) throws Exception {
  525. HttpInvoker.HttpResponse httpResponse = getSXPElementHttpResponse(
  526. sxpElementId);
  527. String content = httpResponse.getContent();
  528. if ((httpResponse.getStatusCode() / 100) != 2) {
  529. _logger.log(
  530. Level.WARNING,
  531. "Unable to process HTTP response content: " + content);
  532. _logger.log(
  533. Level.WARNING,
  534. "HTTP response message: " + httpResponse.getMessage());
  535. _logger.log(
  536. Level.WARNING,
  537. "HTTP response status code: " +
  538. httpResponse.getStatusCode());
  539. throw new Problem.ProblemException(Problem.toDTO(content));
  540. }
  541. else {
  542. _logger.fine("HTTP response content: " + content);
  543. _logger.fine(
  544. "HTTP response message: " + httpResponse.getMessage());
  545. _logger.fine(
  546. "HTTP response status code: " +
  547. httpResponse.getStatusCode());
  548. }
  549. try {
  550. return SXPElementSerDes.toDTO(content);
  551. }
  552. catch (Exception e) {
  553. _logger.log(
  554. Level.WARNING,
  555. "Unable to process HTTP response: " + content, e);
  556. throw new Problem.ProblemException(Problem.toDTO(content));
  557. }
  558. }
  559. public HttpInvoker.HttpResponse getSXPElementHttpResponse(
  560. Long sxpElementId)
  561. throws Exception {
  562. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  563. if (_builder._locale != null) {
  564. httpInvoker.header(
  565. "Accept-Language", _builder._locale.toLanguageTag());
  566. }
  567. for (Map.Entry<String, String> entry :
  568. _builder._headers.entrySet()) {
  569. httpInvoker.header(entry.getKey(), entry.getValue());
  570. }
  571. for (Map.Entry<String, String> entry :
  572. _builder._parameters.entrySet()) {
  573. httpInvoker.parameter(entry.getKey(), entry.getValue());
  574. }
  575. httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
  576. httpInvoker.path(
  577. _builder._scheme + "://" + _builder._host + ":" +
  578. _builder._port + _builder._contextPath +
  579. "/o/search-experiences-rest/v1.0/sxp-elements/{sxpElementId}");
  580. httpInvoker.path("sxpElementId", sxpElementId);
  581. httpInvoker.userNameAndPassword(
  582. _builder._login + ":" + _builder._password);
  583. return httpInvoker.invoke();
  584. }
  585. public SXPElement patchSXPElement(
  586. Long sxpElementId, SXPElement sxpElement)
  587. throws Exception {
  588. HttpInvoker.HttpResponse httpResponse = patchSXPElementHttpResponse(
  589. sxpElementId, sxpElement);
  590. String content = httpResponse.getContent();
  591. if ((httpResponse.getStatusCode() / 100) != 2) {
  592. _logger.log(
  593. Level.WARNING,
  594. "Unable to process HTTP response content: " + content);
  595. _logger.log(
  596. Level.WARNING,
  597. "HTTP response message: " + httpResponse.getMessage());
  598. _logger.log(
  599. Level.WARNING,
  600. "HTTP response status code: " +
  601. httpResponse.getStatusCode());
  602. throw new Problem.ProblemException(Problem.toDTO(content));
  603. }
  604. else {
  605. _logger.fine("HTTP response content: " + content);
  606. _logger.fine(
  607. "HTTP response message: " + httpResponse.getMessage());
  608. _logger.fine(
  609. "HTTP response status code: " +
  610. httpResponse.getStatusCode());
  611. }
  612. try {
  613. return SXPElementSerDes.toDTO(content);
  614. }
  615. catch (Exception e) {
  616. _logger.log(
  617. Level.WARNING,
  618. "Unable to process HTTP response: " + content, e);
  619. throw new Problem.ProblemException(Problem.toDTO(content));
  620. }
  621. }
  622. public HttpInvoker.HttpResponse patchSXPElementHttpResponse(
  623. Long sxpElementId, SXPElement sxpElement)
  624. throws Exception {
  625. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  626. httpInvoker.body(sxpElement.toString(), "application/json");
  627. if (_builder._locale != null) {
  628. httpInvoker.header(
  629. "Accept-Language", _builder._locale.toLanguageTag());
  630. }
  631. for (Map.Entry<String, String> entry :
  632. _builder._headers.entrySet()) {
  633. httpInvoker.header(entry.getKey(), entry.getValue());
  634. }
  635. for (Map.Entry<String, String> entry :
  636. _builder._parameters.entrySet()) {
  637. httpInvoker.parameter(entry.getKey(), entry.getValue());
  638. }
  639. httpInvoker.httpMethod(HttpInvoker.HttpMethod.PATCH);
  640. httpInvoker.path(
  641. _builder._scheme + "://" + _builder._host + ":" +
  642. _builder._port + _builder._contextPath +
  643. "/o/search-experiences-rest/v1.0/sxp-elements/{sxpElementId}");
  644. httpInvoker.path("sxpElementId", sxpElementId);
  645. httpInvoker.userNameAndPassword(
  646. _builder._login + ":" + _builder._password);
  647. return httpInvoker.invoke();
  648. }
  649. public SXPElement postSXPElementCopy(Long sxpElementId)
  650. throws Exception {
  651. HttpInvoker.HttpResponse httpResponse =
  652. postSXPElementCopyHttpResponse(sxpElementId);
  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 SXPElementSerDes.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 postSXPElementCopyHttpResponse(
  686. Long sxpElementId)
  687. throws Exception {
  688. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  689. if (_builder._locale != null) {
  690. httpInvoker.header(
  691. "Accept-Language", _builder._locale.toLanguageTag());
  692. }
  693. for (Map.Entry<String, String> entry :
  694. _builder._headers.entrySet()) {
  695. httpInvoker.header(entry.getKey(), entry.getValue());
  696. }
  697. for (Map.Entry<String, String> entry :
  698. _builder._parameters.entrySet()) {
  699. httpInvoker.parameter(entry.getKey(), entry.getValue());
  700. }
  701. httpInvoker.httpMethod(HttpInvoker.HttpMethod.POST);
  702. httpInvoker.path(
  703. _builder._scheme + "://" + _builder._host + ":" +
  704. _builder._port + _builder._contextPath +
  705. "/o/search-experiences-rest/v1.0/sxp-elements/{sxpElementId}/copy");
  706. httpInvoker.path("sxpElementId", sxpElementId);
  707. httpInvoker.userNameAndPassword(
  708. _builder._login + ":" + _builder._password);
  709. return httpInvoker.invoke();
  710. }
  711. public void getSXPElementExport(Long sxpElementId) throws Exception {
  712. HttpInvoker.HttpResponse httpResponse =
  713. getSXPElementExportHttpResponse(sxpElementId);
  714. String content = httpResponse.getContent();
  715. if ((httpResponse.getStatusCode() / 100) != 2) {
  716. _logger.log(
  717. Level.WARNING,
  718. "Unable to process HTTP response content: " + content);
  719. _logger.log(
  720. Level.WARNING,
  721. "HTTP response message: " + httpResponse.getMessage());
  722. _logger.log(
  723. Level.WARNING,
  724. "HTTP response status code: " +
  725. httpResponse.getStatusCode());
  726. throw new Problem.ProblemException(Problem.toDTO(content));
  727. }
  728. else {
  729. _logger.fine("HTTP response content: " + content);
  730. _logger.fine(
  731. "HTTP response message: " + httpResponse.getMessage());
  732. _logger.fine(
  733. "HTTP response status code: " +
  734. httpResponse.getStatusCode());
  735. }
  736. }
  737. public HttpInvoker.HttpResponse getSXPElementExportHttpResponse(
  738. Long sxpElementId)
  739. throws Exception {
  740. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  741. if (_builder._locale != null) {
  742. httpInvoker.header(
  743. "Accept-Language", _builder._locale.toLanguageTag());
  744. }
  745. for (Map.Entry<String, String> entry :
  746. _builder._headers.entrySet()) {
  747. httpInvoker.header(entry.getKey(), entry.getValue());
  748. }
  749. for (Map.Entry<String, String> entry :
  750. _builder._parameters.entrySet()) {
  751. httpInvoker.parameter(entry.getKey(), entry.getValue());
  752. }
  753. httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
  754. httpInvoker.path(
  755. _builder._scheme + "://" + _builder._host + ":" +
  756. _builder._port + _builder._contextPath +
  757. "/o/search-experiences-rest/v1.0/sxp-elements/{sxpElementId}/export");
  758. httpInvoker.path("sxpElementId", sxpElementId);
  759. httpInvoker.userNameAndPassword(
  760. _builder._login + ":" + _builder._password);
  761. return httpInvoker.invoke();
  762. }
  763. private SXPElementResourceImpl(Builder builder) {
  764. _builder = builder;
  765. }
  766. private static final Logger _logger = Logger.getLogger(
  767. SXPElementResource.class.getName());
  768. private Builder _builder;
  769. }
  770. }