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

https://github.com/danielreuther/liferay-portal · Java · 1021 lines · 761 code · 243 blank · 17 comment · 85 complexity · e1c71a54fee20bea090f338ddfcbc8bd 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.SXPBlueprint;
  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.SXPBlueprintSerDes;
  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 SXPBlueprintResource {
  33. public static Builder builder() {
  34. return new Builder();
  35. }
  36. public Page<SXPBlueprint> getSXPBlueprintsPage(
  37. String search, String filterString, Pagination pagination,
  38. String sortString)
  39. throws Exception;
  40. public HttpInvoker.HttpResponse getSXPBlueprintsPageHttpResponse(
  41. String search, String filterString, Pagination pagination,
  42. String sortString)
  43. throws Exception;
  44. public SXPBlueprint postSXPBlueprint(SXPBlueprint sxpBlueprint)
  45. throws Exception;
  46. public HttpInvoker.HttpResponse postSXPBlueprintHttpResponse(
  47. SXPBlueprint sxpBlueprint)
  48. throws Exception;
  49. public void postSXPBlueprintBatch(
  50. SXPBlueprint sxpBlueprint, String callbackURL, Object object)
  51. throws Exception;
  52. public HttpInvoker.HttpResponse postSXPBlueprintBatchHttpResponse(
  53. SXPBlueprint sxpBlueprint, String callbackURL, Object object)
  54. throws Exception;
  55. public SXPBlueprint postSXPBlueprintValidate(String string)
  56. throws Exception;
  57. public HttpInvoker.HttpResponse postSXPBlueprintValidateHttpResponse(
  58. String string)
  59. throws Exception;
  60. public void deleteSXPBlueprint(Long sxpBlueprintId) throws Exception;
  61. public HttpInvoker.HttpResponse deleteSXPBlueprintHttpResponse(
  62. Long sxpBlueprintId)
  63. throws Exception;
  64. public void deleteSXPBlueprintBatch(
  65. Long sxpBlueprintId, String callbackURL, Object object)
  66. throws Exception;
  67. public HttpInvoker.HttpResponse deleteSXPBlueprintBatchHttpResponse(
  68. Long sxpBlueprintId, String callbackURL, Object object)
  69. throws Exception;
  70. public SXPBlueprint getSXPBlueprint(Long sxpBlueprintId) throws Exception;
  71. public HttpInvoker.HttpResponse getSXPBlueprintHttpResponse(
  72. Long sxpBlueprintId)
  73. throws Exception;
  74. public SXPBlueprint patchSXPBlueprint(
  75. Long sxpBlueprintId, SXPBlueprint sxpBlueprint)
  76. throws Exception;
  77. public HttpInvoker.HttpResponse patchSXPBlueprintHttpResponse(
  78. Long sxpBlueprintId, SXPBlueprint sxpBlueprint)
  79. throws Exception;
  80. public SXPBlueprint postSXPBlueprintCopy(Long sxpBlueprintId)
  81. throws Exception;
  82. public HttpInvoker.HttpResponse postSXPBlueprintCopyHttpResponse(
  83. Long sxpBlueprintId)
  84. throws Exception;
  85. public void getSXPBlueprintExport(Long sxpBlueprintId) throws Exception;
  86. public HttpInvoker.HttpResponse getSXPBlueprintExportHttpResponse(
  87. Long sxpBlueprintId)
  88. throws Exception;
  89. public static class Builder {
  90. public Builder authentication(String login, String password) {
  91. _login = login;
  92. _password = password;
  93. return this;
  94. }
  95. public SXPBlueprintResource build() {
  96. return new SXPBlueprintResourceImpl(this);
  97. }
  98. public Builder contextPath(String contextPath) {
  99. _contextPath = contextPath;
  100. return this;
  101. }
  102. public Builder endpoint(String host, int port, String scheme) {
  103. _host = host;
  104. _port = port;
  105. _scheme = scheme;
  106. return this;
  107. }
  108. public Builder header(String key, String value) {
  109. _headers.put(key, value);
  110. return this;
  111. }
  112. public Builder locale(Locale locale) {
  113. _locale = locale;
  114. return this;
  115. }
  116. public Builder parameter(String key, String value) {
  117. _parameters.put(key, value);
  118. return this;
  119. }
  120. public Builder parameters(String... parameters) {
  121. if ((parameters.length % 2) != 0) {
  122. throw new IllegalArgumentException(
  123. "Parameters length is not an even number");
  124. }
  125. for (int i = 0; i < parameters.length; i += 2) {
  126. String parameterName = String.valueOf(parameters[i]);
  127. String parameterValue = String.valueOf(parameters[i + 1]);
  128. _parameters.put(parameterName, parameterValue);
  129. }
  130. return this;
  131. }
  132. private Builder() {
  133. }
  134. private String _contextPath = "";
  135. private Map<String, String> _headers = new LinkedHashMap<>();
  136. private String _host = "localhost";
  137. private Locale _locale;
  138. private String _login = "";
  139. private String _password = "";
  140. private Map<String, String> _parameters = new LinkedHashMap<>();
  141. private int _port = 8080;
  142. private String _scheme = "http";
  143. }
  144. public static class SXPBlueprintResourceImpl
  145. implements SXPBlueprintResource {
  146. public Page<SXPBlueprint> getSXPBlueprintsPage(
  147. String search, String filterString, Pagination pagination,
  148. String sortString)
  149. throws Exception {
  150. HttpInvoker.HttpResponse httpResponse =
  151. getSXPBlueprintsPageHttpResponse(
  152. search, filterString, pagination, sortString);
  153. String content = httpResponse.getContent();
  154. if ((httpResponse.getStatusCode() / 100) != 2) {
  155. _logger.log(
  156. Level.WARNING,
  157. "Unable to process HTTP response content: " + content);
  158. _logger.log(
  159. Level.WARNING,
  160. "HTTP response message: " + httpResponse.getMessage());
  161. _logger.log(
  162. Level.WARNING,
  163. "HTTP response status code: " +
  164. httpResponse.getStatusCode());
  165. throw new Problem.ProblemException(Problem.toDTO(content));
  166. }
  167. else {
  168. _logger.fine("HTTP response content: " + content);
  169. _logger.fine(
  170. "HTTP response message: " + httpResponse.getMessage());
  171. _logger.fine(
  172. "HTTP response status code: " +
  173. httpResponse.getStatusCode());
  174. }
  175. try {
  176. return Page.of(content, SXPBlueprintSerDes::toDTO);
  177. }
  178. catch (Exception e) {
  179. _logger.log(
  180. Level.WARNING,
  181. "Unable to process HTTP response: " + content, e);
  182. throw new Problem.ProblemException(Problem.toDTO(content));
  183. }
  184. }
  185. public HttpInvoker.HttpResponse getSXPBlueprintsPageHttpResponse(
  186. String search, String filterString, Pagination pagination,
  187. String sortString)
  188. throws Exception {
  189. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  190. if (_builder._locale != null) {
  191. httpInvoker.header(
  192. "Accept-Language", _builder._locale.toLanguageTag());
  193. }
  194. for (Map.Entry<String, String> entry :
  195. _builder._headers.entrySet()) {
  196. httpInvoker.header(entry.getKey(), entry.getValue());
  197. }
  198. for (Map.Entry<String, String> entry :
  199. _builder._parameters.entrySet()) {
  200. httpInvoker.parameter(entry.getKey(), entry.getValue());
  201. }
  202. httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
  203. if (search != null) {
  204. httpInvoker.parameter("search", String.valueOf(search));
  205. }
  206. if (filterString != null) {
  207. httpInvoker.parameter("filter", filterString);
  208. }
  209. if (pagination != null) {
  210. httpInvoker.parameter(
  211. "page", String.valueOf(pagination.getPage()));
  212. httpInvoker.parameter(
  213. "pageSize", String.valueOf(pagination.getPageSize()));
  214. }
  215. if (sortString != null) {
  216. httpInvoker.parameter("sort", sortString);
  217. }
  218. httpInvoker.path(
  219. _builder._scheme + "://" + _builder._host + ":" +
  220. _builder._port + _builder._contextPath +
  221. "/o/search-experiences-rest/v1.0/sxp-blueprints");
  222. httpInvoker.userNameAndPassword(
  223. _builder._login + ":" + _builder._password);
  224. return httpInvoker.invoke();
  225. }
  226. public SXPBlueprint postSXPBlueprint(SXPBlueprint sxpBlueprint)
  227. throws Exception {
  228. HttpInvoker.HttpResponse httpResponse =
  229. postSXPBlueprintHttpResponse(sxpBlueprint);
  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 SXPBlueprintSerDes.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 postSXPBlueprintHttpResponse(
  263. SXPBlueprint sxpBlueprint)
  264. throws Exception {
  265. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  266. httpInvoker.body(sxpBlueprint.toString(), "application/json");
  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.POST);
  280. httpInvoker.path(
  281. _builder._scheme + "://" + _builder._host + ":" +
  282. _builder._port + _builder._contextPath +
  283. "/o/search-experiences-rest/v1.0/sxp-blueprints");
  284. httpInvoker.userNameAndPassword(
  285. _builder._login + ":" + _builder._password);
  286. return httpInvoker.invoke();
  287. }
  288. public void postSXPBlueprintBatch(
  289. SXPBlueprint sxpBlueprint, String callbackURL, Object object)
  290. throws Exception {
  291. HttpInvoker.HttpResponse httpResponse =
  292. postSXPBlueprintBatchHttpResponse(
  293. sxpBlueprint, callbackURL, object);
  294. String content = httpResponse.getContent();
  295. if ((httpResponse.getStatusCode() / 100) != 2) {
  296. _logger.log(
  297. Level.WARNING,
  298. "Unable to process HTTP response content: " + content);
  299. _logger.log(
  300. Level.WARNING,
  301. "HTTP response message: " + httpResponse.getMessage());
  302. _logger.log(
  303. Level.WARNING,
  304. "HTTP response status code: " +
  305. httpResponse.getStatusCode());
  306. throw new Problem.ProblemException(Problem.toDTO(content));
  307. }
  308. else {
  309. _logger.fine("HTTP response content: " + content);
  310. _logger.fine(
  311. "HTTP response message: " + httpResponse.getMessage());
  312. _logger.fine(
  313. "HTTP response status code: " +
  314. httpResponse.getStatusCode());
  315. }
  316. }
  317. public HttpInvoker.HttpResponse postSXPBlueprintBatchHttpResponse(
  318. SXPBlueprint sxpBlueprint, String callbackURL, Object object)
  319. throws Exception {
  320. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  321. httpInvoker.body(object.toString(), "application/json");
  322. if (_builder._locale != null) {
  323. httpInvoker.header(
  324. "Accept-Language", _builder._locale.toLanguageTag());
  325. }
  326. for (Map.Entry<String, String> entry :
  327. _builder._headers.entrySet()) {
  328. httpInvoker.header(entry.getKey(), entry.getValue());
  329. }
  330. for (Map.Entry<String, String> entry :
  331. _builder._parameters.entrySet()) {
  332. httpInvoker.parameter(entry.getKey(), entry.getValue());
  333. }
  334. httpInvoker.httpMethod(HttpInvoker.HttpMethod.POST);
  335. if (callbackURL != null) {
  336. httpInvoker.parameter(
  337. "callbackURL", String.valueOf(callbackURL));
  338. }
  339. httpInvoker.path(
  340. _builder._scheme + "://" + _builder._host + ":" +
  341. _builder._port + _builder._contextPath +
  342. "/o/search-experiences-rest/v1.0/sxp-blueprints/batch");
  343. httpInvoker.userNameAndPassword(
  344. _builder._login + ":" + _builder._password);
  345. return httpInvoker.invoke();
  346. }
  347. public SXPBlueprint postSXPBlueprintValidate(String string)
  348. throws Exception {
  349. HttpInvoker.HttpResponse httpResponse =
  350. postSXPBlueprintValidateHttpResponse(string);
  351. String content = httpResponse.getContent();
  352. if ((httpResponse.getStatusCode() / 100) != 2) {
  353. _logger.log(
  354. Level.WARNING,
  355. "Unable to process HTTP response content: " + content);
  356. _logger.log(
  357. Level.WARNING,
  358. "HTTP response message: " + httpResponse.getMessage());
  359. _logger.log(
  360. Level.WARNING,
  361. "HTTP response status code: " +
  362. httpResponse.getStatusCode());
  363. throw new Problem.ProblemException(Problem.toDTO(content));
  364. }
  365. else {
  366. _logger.fine("HTTP response content: " + content);
  367. _logger.fine(
  368. "HTTP response message: " + httpResponse.getMessage());
  369. _logger.fine(
  370. "HTTP response status code: " +
  371. httpResponse.getStatusCode());
  372. }
  373. try {
  374. return SXPBlueprintSerDes.toDTO(content);
  375. }
  376. catch (Exception e) {
  377. _logger.log(
  378. Level.WARNING,
  379. "Unable to process HTTP response: " + content, e);
  380. throw new Problem.ProblemException(Problem.toDTO(content));
  381. }
  382. }
  383. public HttpInvoker.HttpResponse postSXPBlueprintValidateHttpResponse(
  384. String string)
  385. throws Exception {
  386. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  387. httpInvoker.body(string.toString(), "application/json");
  388. if (_builder._locale != null) {
  389. httpInvoker.header(
  390. "Accept-Language", _builder._locale.toLanguageTag());
  391. }
  392. for (Map.Entry<String, String> entry :
  393. _builder._headers.entrySet()) {
  394. httpInvoker.header(entry.getKey(), entry.getValue());
  395. }
  396. for (Map.Entry<String, String> entry :
  397. _builder._parameters.entrySet()) {
  398. httpInvoker.parameter(entry.getKey(), entry.getValue());
  399. }
  400. httpInvoker.httpMethod(HttpInvoker.HttpMethod.POST);
  401. httpInvoker.path(
  402. _builder._scheme + "://" + _builder._host + ":" +
  403. _builder._port + _builder._contextPath +
  404. "/o/search-experiences-rest/v1.0/sxp-blueprints/validate");
  405. httpInvoker.userNameAndPassword(
  406. _builder._login + ":" + _builder._password);
  407. return httpInvoker.invoke();
  408. }
  409. public void deleteSXPBlueprint(Long sxpBlueprintId) throws Exception {
  410. HttpInvoker.HttpResponse httpResponse =
  411. deleteSXPBlueprintHttpResponse(sxpBlueprintId);
  412. String content = httpResponse.getContent();
  413. if ((httpResponse.getStatusCode() / 100) != 2) {
  414. _logger.log(
  415. Level.WARNING,
  416. "Unable to process HTTP response content: " + content);
  417. _logger.log(
  418. Level.WARNING,
  419. "HTTP response message: " + httpResponse.getMessage());
  420. _logger.log(
  421. Level.WARNING,
  422. "HTTP response status code: " +
  423. httpResponse.getStatusCode());
  424. throw new Problem.ProblemException(Problem.toDTO(content));
  425. }
  426. else {
  427. _logger.fine("HTTP response content: " + content);
  428. _logger.fine(
  429. "HTTP response message: " + httpResponse.getMessage());
  430. _logger.fine(
  431. "HTTP response status code: " +
  432. httpResponse.getStatusCode());
  433. }
  434. try {
  435. return;
  436. }
  437. catch (Exception e) {
  438. _logger.log(
  439. Level.WARNING,
  440. "Unable to process HTTP response: " + content, e);
  441. throw new Problem.ProblemException(Problem.toDTO(content));
  442. }
  443. }
  444. public HttpInvoker.HttpResponse deleteSXPBlueprintHttpResponse(
  445. Long sxpBlueprintId)
  446. throws Exception {
  447. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  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. httpInvoker.path(
  462. _builder._scheme + "://" + _builder._host + ":" +
  463. _builder._port + _builder._contextPath +
  464. "/o/search-experiences-rest/v1.0/sxp-blueprints/{sxpBlueprintId}");
  465. httpInvoker.path("sxpBlueprintId", sxpBlueprintId);
  466. httpInvoker.userNameAndPassword(
  467. _builder._login + ":" + _builder._password);
  468. return httpInvoker.invoke();
  469. }
  470. public void deleteSXPBlueprintBatch(
  471. Long sxpBlueprintId, String callbackURL, Object object)
  472. throws Exception {
  473. HttpInvoker.HttpResponse httpResponse =
  474. deleteSXPBlueprintBatchHttpResponse(
  475. sxpBlueprintId, callbackURL, object);
  476. String content = httpResponse.getContent();
  477. if ((httpResponse.getStatusCode() / 100) != 2) {
  478. _logger.log(
  479. Level.WARNING,
  480. "Unable to process HTTP response content: " + content);
  481. _logger.log(
  482. Level.WARNING,
  483. "HTTP response message: " + httpResponse.getMessage());
  484. _logger.log(
  485. Level.WARNING,
  486. "HTTP response status code: " +
  487. httpResponse.getStatusCode());
  488. throw new Problem.ProblemException(Problem.toDTO(content));
  489. }
  490. else {
  491. _logger.fine("HTTP response content: " + content);
  492. _logger.fine(
  493. "HTTP response message: " + httpResponse.getMessage());
  494. _logger.fine(
  495. "HTTP response status code: " +
  496. httpResponse.getStatusCode());
  497. }
  498. }
  499. public HttpInvoker.HttpResponse deleteSXPBlueprintBatchHttpResponse(
  500. Long sxpBlueprintId, String callbackURL, Object object)
  501. throws Exception {
  502. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  503. httpInvoker.body(object.toString(), "application/json");
  504. if (_builder._locale != null) {
  505. httpInvoker.header(
  506. "Accept-Language", _builder._locale.toLanguageTag());
  507. }
  508. for (Map.Entry<String, String> entry :
  509. _builder._headers.entrySet()) {
  510. httpInvoker.header(entry.getKey(), entry.getValue());
  511. }
  512. for (Map.Entry<String, String> entry :
  513. _builder._parameters.entrySet()) {
  514. httpInvoker.parameter(entry.getKey(), entry.getValue());
  515. }
  516. httpInvoker.httpMethod(HttpInvoker.HttpMethod.DELETE);
  517. if (callbackURL != null) {
  518. httpInvoker.parameter(
  519. "callbackURL", String.valueOf(callbackURL));
  520. }
  521. httpInvoker.path(
  522. _builder._scheme + "://" + _builder._host + ":" +
  523. _builder._port + _builder._contextPath +
  524. "/o/search-experiences-rest/v1.0/sxp-blueprints/{sxpBlueprintId}/batch");
  525. httpInvoker.path("sxpBlueprintId", sxpBlueprintId);
  526. httpInvoker.userNameAndPassword(
  527. _builder._login + ":" + _builder._password);
  528. return httpInvoker.invoke();
  529. }
  530. public SXPBlueprint getSXPBlueprint(Long sxpBlueprintId)
  531. throws Exception {
  532. HttpInvoker.HttpResponse httpResponse = getSXPBlueprintHttpResponse(
  533. sxpBlueprintId);
  534. String content = httpResponse.getContent();
  535. if ((httpResponse.getStatusCode() / 100) != 2) {
  536. _logger.log(
  537. Level.WARNING,
  538. "Unable to process HTTP response content: " + content);
  539. _logger.log(
  540. Level.WARNING,
  541. "HTTP response message: " + httpResponse.getMessage());
  542. _logger.log(
  543. Level.WARNING,
  544. "HTTP response status code: " +
  545. httpResponse.getStatusCode());
  546. throw new Problem.ProblemException(Problem.toDTO(content));
  547. }
  548. else {
  549. _logger.fine("HTTP response content: " + content);
  550. _logger.fine(
  551. "HTTP response message: " + httpResponse.getMessage());
  552. _logger.fine(
  553. "HTTP response status code: " +
  554. httpResponse.getStatusCode());
  555. }
  556. try {
  557. return SXPBlueprintSerDes.toDTO(content);
  558. }
  559. catch (Exception e) {
  560. _logger.log(
  561. Level.WARNING,
  562. "Unable to process HTTP response: " + content, e);
  563. throw new Problem.ProblemException(Problem.toDTO(content));
  564. }
  565. }
  566. public HttpInvoker.HttpResponse getSXPBlueprintHttpResponse(
  567. Long sxpBlueprintId)
  568. throws Exception {
  569. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  570. if (_builder._locale != null) {
  571. httpInvoker.header(
  572. "Accept-Language", _builder._locale.toLanguageTag());
  573. }
  574. for (Map.Entry<String, String> entry :
  575. _builder._headers.entrySet()) {
  576. httpInvoker.header(entry.getKey(), entry.getValue());
  577. }
  578. for (Map.Entry<String, String> entry :
  579. _builder._parameters.entrySet()) {
  580. httpInvoker.parameter(entry.getKey(), entry.getValue());
  581. }
  582. httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
  583. httpInvoker.path(
  584. _builder._scheme + "://" + _builder._host + ":" +
  585. _builder._port + _builder._contextPath +
  586. "/o/search-experiences-rest/v1.0/sxp-blueprints/{sxpBlueprintId}");
  587. httpInvoker.path("sxpBlueprintId", sxpBlueprintId);
  588. httpInvoker.userNameAndPassword(
  589. _builder._login + ":" + _builder._password);
  590. return httpInvoker.invoke();
  591. }
  592. public SXPBlueprint patchSXPBlueprint(
  593. Long sxpBlueprintId, SXPBlueprint sxpBlueprint)
  594. throws Exception {
  595. HttpInvoker.HttpResponse httpResponse =
  596. patchSXPBlueprintHttpResponse(sxpBlueprintId, sxpBlueprint);
  597. String content = httpResponse.getContent();
  598. if ((httpResponse.getStatusCode() / 100) != 2) {
  599. _logger.log(
  600. Level.WARNING,
  601. "Unable to process HTTP response content: " + content);
  602. _logger.log(
  603. Level.WARNING,
  604. "HTTP response message: " + httpResponse.getMessage());
  605. _logger.log(
  606. Level.WARNING,
  607. "HTTP response status code: " +
  608. httpResponse.getStatusCode());
  609. throw new Problem.ProblemException(Problem.toDTO(content));
  610. }
  611. else {
  612. _logger.fine("HTTP response content: " + content);
  613. _logger.fine(
  614. "HTTP response message: " + httpResponse.getMessage());
  615. _logger.fine(
  616. "HTTP response status code: " +
  617. httpResponse.getStatusCode());
  618. }
  619. try {
  620. return SXPBlueprintSerDes.toDTO(content);
  621. }
  622. catch (Exception e) {
  623. _logger.log(
  624. Level.WARNING,
  625. "Unable to process HTTP response: " + content, e);
  626. throw new Problem.ProblemException(Problem.toDTO(content));
  627. }
  628. }
  629. public HttpInvoker.HttpResponse patchSXPBlueprintHttpResponse(
  630. Long sxpBlueprintId, SXPBlueprint sxpBlueprint)
  631. throws Exception {
  632. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  633. httpInvoker.body(sxpBlueprint.toString(), "application/json");
  634. if (_builder._locale != null) {
  635. httpInvoker.header(
  636. "Accept-Language", _builder._locale.toLanguageTag());
  637. }
  638. for (Map.Entry<String, String> entry :
  639. _builder._headers.entrySet()) {
  640. httpInvoker.header(entry.getKey(), entry.getValue());
  641. }
  642. for (Map.Entry<String, String> entry :
  643. _builder._parameters.entrySet()) {
  644. httpInvoker.parameter(entry.getKey(), entry.getValue());
  645. }
  646. httpInvoker.httpMethod(HttpInvoker.HttpMethod.PATCH);
  647. httpInvoker.path(
  648. _builder._scheme + "://" + _builder._host + ":" +
  649. _builder._port + _builder._contextPath +
  650. "/o/search-experiences-rest/v1.0/sxp-blueprints/{sxpBlueprintId}");
  651. httpInvoker.path("sxpBlueprintId", sxpBlueprintId);
  652. httpInvoker.userNameAndPassword(
  653. _builder._login + ":" + _builder._password);
  654. return httpInvoker.invoke();
  655. }
  656. public SXPBlueprint postSXPBlueprintCopy(Long sxpBlueprintId)
  657. throws Exception {
  658. HttpInvoker.HttpResponse httpResponse =
  659. postSXPBlueprintCopyHttpResponse(sxpBlueprintId);
  660. String content = httpResponse.getContent();
  661. if ((httpResponse.getStatusCode() / 100) != 2) {
  662. _logger.log(
  663. Level.WARNING,
  664. "Unable to process HTTP response content: " + content);
  665. _logger.log(
  666. Level.WARNING,
  667. "HTTP response message: " + httpResponse.getMessage());
  668. _logger.log(
  669. Level.WARNING,
  670. "HTTP response status code: " +
  671. httpResponse.getStatusCode());
  672. throw new Problem.ProblemException(Problem.toDTO(content));
  673. }
  674. else {
  675. _logger.fine("HTTP response content: " + content);
  676. _logger.fine(
  677. "HTTP response message: " + httpResponse.getMessage());
  678. _logger.fine(
  679. "HTTP response status code: " +
  680. httpResponse.getStatusCode());
  681. }
  682. try {
  683. return SXPBlueprintSerDes.toDTO(content);
  684. }
  685. catch (Exception e) {
  686. _logger.log(
  687. Level.WARNING,
  688. "Unable to process HTTP response: " + content, e);
  689. throw new Problem.ProblemException(Problem.toDTO(content));
  690. }
  691. }
  692. public HttpInvoker.HttpResponse postSXPBlueprintCopyHttpResponse(
  693. Long sxpBlueprintId)
  694. throws Exception {
  695. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  696. if (_builder._locale != null) {
  697. httpInvoker.header(
  698. "Accept-Language", _builder._locale.toLanguageTag());
  699. }
  700. for (Map.Entry<String, String> entry :
  701. _builder._headers.entrySet()) {
  702. httpInvoker.header(entry.getKey(), entry.getValue());
  703. }
  704. for (Map.Entry<String, String> entry :
  705. _builder._parameters.entrySet()) {
  706. httpInvoker.parameter(entry.getKey(), entry.getValue());
  707. }
  708. httpInvoker.httpMethod(HttpInvoker.HttpMethod.POST);
  709. httpInvoker.path(
  710. _builder._scheme + "://" + _builder._host + ":" +
  711. _builder._port + _builder._contextPath +
  712. "/o/search-experiences-rest/v1.0/sxp-blueprints/{sxpBlueprintId}/copy");
  713. httpInvoker.path("sxpBlueprintId", sxpBlueprintId);
  714. httpInvoker.userNameAndPassword(
  715. _builder._login + ":" + _builder._password);
  716. return httpInvoker.invoke();
  717. }
  718. public void getSXPBlueprintExport(Long sxpBlueprintId)
  719. throws Exception {
  720. HttpInvoker.HttpResponse httpResponse =
  721. getSXPBlueprintExportHttpResponse(sxpBlueprintId);
  722. String content = httpResponse.getContent();
  723. if ((httpResponse.getStatusCode() / 100) != 2) {
  724. _logger.log(
  725. Level.WARNING,
  726. "Unable to process HTTP response content: " + content);
  727. _logger.log(
  728. Level.WARNING,
  729. "HTTP response message: " + httpResponse.getMessage());
  730. _logger.log(
  731. Level.WARNING,
  732. "HTTP response status code: " +
  733. httpResponse.getStatusCode());
  734. throw new Problem.ProblemException(Problem.toDTO(content));
  735. }
  736. else {
  737. _logger.fine("HTTP response content: " + content);
  738. _logger.fine(
  739. "HTTP response message: " + httpResponse.getMessage());
  740. _logger.fine(
  741. "HTTP response status code: " +
  742. httpResponse.getStatusCode());
  743. }
  744. }
  745. public HttpInvoker.HttpResponse getSXPBlueprintExportHttpResponse(
  746. Long sxpBlueprintId)
  747. throws Exception {
  748. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  749. if (_builder._locale != null) {
  750. httpInvoker.header(
  751. "Accept-Language", _builder._locale.toLanguageTag());
  752. }
  753. for (Map.Entry<String, String> entry :
  754. _builder._headers.entrySet()) {
  755. httpInvoker.header(entry.getKey(), entry.getValue());
  756. }
  757. for (Map.Entry<String, String> entry :
  758. _builder._parameters.entrySet()) {
  759. httpInvoker.parameter(entry.getKey(), entry.getValue());
  760. }
  761. httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
  762. httpInvoker.path(
  763. _builder._scheme + "://" + _builder._host + ":" +
  764. _builder._port + _builder._contextPath +
  765. "/o/search-experiences-rest/v1.0/sxp-blueprints/{sxpBlueprintId}/export");
  766. httpInvoker.path("sxpBlueprintId", sxpBlueprintId);
  767. httpInvoker.userNameAndPassword(
  768. _builder._login + ":" + _builder._password);
  769. return httpInvoker.invoke();
  770. }
  771. private SXPBlueprintResourceImpl(Builder builder) {
  772. _builder = builder;
  773. }
  774. private static final Logger _logger = Logger.getLogger(
  775. SXPBlueprintResource.class.getName());
  776. private Builder _builder;
  777. }
  778. }