/modules/apps/object/object-admin-rest-client/src/main/java/com/liferay/object/admin/rest/client/resource/v1_0/ObjectValidationRuleResource.java

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