/modules/dxp/apps/portal-workflow/portal-workflow-metrics-rest-client/src/main/java/com/liferay/portal/workflow/metrics/rest/client/resource/v1_0/ProcessResource.java

http://github.com/liferay/liferay-portal · Java · 793 lines · 583 code · 193 blank · 17 comment · 65 complexity · e542b7e3aec3a2f87de78619674bfb4d 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.portal.workflow.metrics.rest.client.resource.v1_0;
  15. import com.liferay.portal.workflow.metrics.rest.client.dto.v1_0.Process;
  16. import com.liferay.portal.workflow.metrics.rest.client.http.HttpInvoker;
  17. import com.liferay.portal.workflow.metrics.rest.client.problem.Problem;
  18. import java.util.LinkedHashMap;
  19. import java.util.Locale;
  20. import java.util.Map;
  21. import java.util.logging.Level;
  22. import java.util.logging.Logger;
  23. import javax.annotation.Generated;
  24. /**
  25. * @author Rafael Praxedes
  26. * @generated
  27. */
  28. @Generated("")
  29. public interface ProcessResource {
  30. public static Builder builder() {
  31. return new Builder();
  32. }
  33. public Process postProcess(Process process) throws Exception;
  34. public HttpInvoker.HttpResponse postProcessHttpResponse(Process process)
  35. throws Exception;
  36. public void postProcessBatch(String callbackURL, Object object)
  37. throws Exception;
  38. public HttpInvoker.HttpResponse postProcessBatchHttpResponse(
  39. String callbackURL, Object object)
  40. throws Exception;
  41. public void deleteProcess(Long processId) throws Exception;
  42. public HttpInvoker.HttpResponse deleteProcessHttpResponse(Long processId)
  43. throws Exception;
  44. public void deleteProcessBatch(String callbackURL, Object object)
  45. throws Exception;
  46. public HttpInvoker.HttpResponse deleteProcessBatchHttpResponse(
  47. String callbackURL, Object object)
  48. throws Exception;
  49. public Process getProcess(Long processId) throws Exception;
  50. public HttpInvoker.HttpResponse getProcessHttpResponse(Long processId)
  51. throws Exception;
  52. public void putProcess(Long processId, Process process) throws Exception;
  53. public HttpInvoker.HttpResponse putProcessHttpResponse(
  54. Long processId, Process process)
  55. throws Exception;
  56. public void putProcessBatch(String callbackURL, Object object)
  57. throws Exception;
  58. public HttpInvoker.HttpResponse putProcessBatchHttpResponse(
  59. String callbackURL, Object object)
  60. throws Exception;
  61. public String getProcessTitle(Long processId) throws Exception;
  62. public HttpInvoker.HttpResponse getProcessTitleHttpResponse(Long processId)
  63. throws Exception;
  64. public static class Builder {
  65. public Builder authentication(String login, String password) {
  66. _login = login;
  67. _password = password;
  68. return this;
  69. }
  70. public ProcessResource build() {
  71. return new ProcessResourceImpl(this);
  72. }
  73. public Builder endpoint(String host, int port, String scheme) {
  74. _host = host;
  75. _port = port;
  76. _scheme = scheme;
  77. return this;
  78. }
  79. public Builder header(String key, String value) {
  80. _headers.put(key, value);
  81. return this;
  82. }
  83. public Builder locale(Locale locale) {
  84. _locale = locale;
  85. return this;
  86. }
  87. public Builder parameter(String key, String value) {
  88. _parameters.put(key, value);
  89. return this;
  90. }
  91. public Builder parameters(String... parameters) {
  92. if ((parameters.length % 2) != 0) {
  93. throw new IllegalArgumentException(
  94. "Parameters length is not an even number");
  95. }
  96. for (int i = 0; i < parameters.length; i += 2) {
  97. String parameterName = String.valueOf(parameters[i]);
  98. String parameterValue = String.valueOf(parameters[i + 1]);
  99. _parameters.put(parameterName, parameterValue);
  100. }
  101. return this;
  102. }
  103. private Builder() {
  104. }
  105. private Map<String, String> _headers = new LinkedHashMap<>();
  106. private String _host = "localhost";
  107. private Locale _locale;
  108. private String _login = "";
  109. private String _password = "";
  110. private Map<String, String> _parameters = new LinkedHashMap<>();
  111. private int _port = 8080;
  112. private String _scheme = "http";
  113. }
  114. public static class ProcessResourceImpl implements ProcessResource {
  115. public Process postProcess(Process process) throws Exception {
  116. HttpInvoker.HttpResponse httpResponse = postProcessHttpResponse(
  117. process);
  118. String content = httpResponse.getContent();
  119. if ((httpResponse.getStatusCode() / 100) != 2) {
  120. _logger.log(
  121. Level.WARNING,
  122. "Unable to process HTTP response content: " + content);
  123. _logger.log(
  124. Level.WARNING,
  125. "HTTP response message: " + httpResponse.getMessage());
  126. _logger.log(
  127. Level.WARNING,
  128. "HTTP response status code: " +
  129. httpResponse.getStatusCode());
  130. throw new Problem.ProblemException(Problem.toDTO(content));
  131. }
  132. else {
  133. _logger.fine("HTTP response content: " + content);
  134. _logger.fine(
  135. "HTTP response message: " + httpResponse.getMessage());
  136. _logger.fine(
  137. "HTTP response status code: " +
  138. httpResponse.getStatusCode());
  139. }
  140. try {
  141. return com.liferay.portal.workflow.metrics.rest.client.serdes.
  142. v1_0.ProcessSerDes.toDTO(content);
  143. }
  144. catch (Exception e) {
  145. _logger.log(
  146. Level.WARNING,
  147. "Unable to process HTTP response: " + content, e);
  148. throw new Problem.ProblemException(Problem.toDTO(content));
  149. }
  150. }
  151. public HttpInvoker.HttpResponse postProcessHttpResponse(Process process)
  152. throws Exception {
  153. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  154. httpInvoker.body(process.toString(), "application/json");
  155. if (_builder._locale != null) {
  156. httpInvoker.header(
  157. "Accept-Language", _builder._locale.toLanguageTag());
  158. }
  159. for (Map.Entry<String, String> entry :
  160. _builder._headers.entrySet()) {
  161. httpInvoker.header(entry.getKey(), entry.getValue());
  162. }
  163. for (Map.Entry<String, String> entry :
  164. _builder._parameters.entrySet()) {
  165. httpInvoker.parameter(entry.getKey(), entry.getValue());
  166. }
  167. httpInvoker.httpMethod(HttpInvoker.HttpMethod.POST);
  168. httpInvoker.path(
  169. _builder._scheme + "://" + _builder._host + ":" +
  170. _builder._port +
  171. "/o/portal-workflow-metrics/v1.0/processes");
  172. httpInvoker.userNameAndPassword(
  173. _builder._login + ":" + _builder._password);
  174. return httpInvoker.invoke();
  175. }
  176. public void postProcessBatch(String callbackURL, Object object)
  177. throws Exception {
  178. HttpInvoker.HttpResponse httpResponse =
  179. postProcessBatchHttpResponse(callbackURL, object);
  180. String content = httpResponse.getContent();
  181. if ((httpResponse.getStatusCode() / 100) != 2) {
  182. _logger.log(
  183. Level.WARNING,
  184. "Unable to process HTTP response content: " + content);
  185. _logger.log(
  186. Level.WARNING,
  187. "HTTP response message: " + httpResponse.getMessage());
  188. _logger.log(
  189. Level.WARNING,
  190. "HTTP response status code: " +
  191. httpResponse.getStatusCode());
  192. throw new Problem.ProblemException(Problem.toDTO(content));
  193. }
  194. else {
  195. _logger.fine("HTTP response content: " + content);
  196. _logger.fine(
  197. "HTTP response message: " + httpResponse.getMessage());
  198. _logger.fine(
  199. "HTTP response status code: " +
  200. httpResponse.getStatusCode());
  201. }
  202. }
  203. public HttpInvoker.HttpResponse postProcessBatchHttpResponse(
  204. String callbackURL, Object object)
  205. throws Exception {
  206. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  207. httpInvoker.body(object.toString(), "application/json");
  208. if (_builder._locale != null) {
  209. httpInvoker.header(
  210. "Accept-Language", _builder._locale.toLanguageTag());
  211. }
  212. for (Map.Entry<String, String> entry :
  213. _builder._headers.entrySet()) {
  214. httpInvoker.header(entry.getKey(), entry.getValue());
  215. }
  216. for (Map.Entry<String, String> entry :
  217. _builder._parameters.entrySet()) {
  218. httpInvoker.parameter(entry.getKey(), entry.getValue());
  219. }
  220. httpInvoker.httpMethod(HttpInvoker.HttpMethod.POST);
  221. if (callbackURL != null) {
  222. httpInvoker.parameter(
  223. "callbackURL", String.valueOf(callbackURL));
  224. }
  225. httpInvoker.path(
  226. _builder._scheme + "://" + _builder._host + ":" +
  227. _builder._port +
  228. "/o/portal-workflow-metrics/v1.0/processes/batch");
  229. httpInvoker.userNameAndPassword(
  230. _builder._login + ":" + _builder._password);
  231. return httpInvoker.invoke();
  232. }
  233. public void deleteProcess(Long processId) throws Exception {
  234. HttpInvoker.HttpResponse httpResponse = deleteProcessHttpResponse(
  235. processId);
  236. String content = httpResponse.getContent();
  237. if ((httpResponse.getStatusCode() / 100) != 2) {
  238. _logger.log(
  239. Level.WARNING,
  240. "Unable to process HTTP response content: " + content);
  241. _logger.log(
  242. Level.WARNING,
  243. "HTTP response message: " + httpResponse.getMessage());
  244. _logger.log(
  245. Level.WARNING,
  246. "HTTP response status code: " +
  247. httpResponse.getStatusCode());
  248. throw new Problem.ProblemException(Problem.toDTO(content));
  249. }
  250. else {
  251. _logger.fine("HTTP response content: " + content);
  252. _logger.fine(
  253. "HTTP response message: " + httpResponse.getMessage());
  254. _logger.fine(
  255. "HTTP response status code: " +
  256. httpResponse.getStatusCode());
  257. }
  258. try {
  259. return;
  260. }
  261. catch (Exception e) {
  262. _logger.log(
  263. Level.WARNING,
  264. "Unable to process HTTP response: " + content, e);
  265. throw new Problem.ProblemException(Problem.toDTO(content));
  266. }
  267. }
  268. public HttpInvoker.HttpResponse deleteProcessHttpResponse(
  269. Long processId)
  270. throws Exception {
  271. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  272. if (_builder._locale != null) {
  273. httpInvoker.header(
  274. "Accept-Language", _builder._locale.toLanguageTag());
  275. }
  276. for (Map.Entry<String, String> entry :
  277. _builder._headers.entrySet()) {
  278. httpInvoker.header(entry.getKey(), entry.getValue());
  279. }
  280. for (Map.Entry<String, String> entry :
  281. _builder._parameters.entrySet()) {
  282. httpInvoker.parameter(entry.getKey(), entry.getValue());
  283. }
  284. httpInvoker.httpMethod(HttpInvoker.HttpMethod.DELETE);
  285. httpInvoker.path(
  286. _builder._scheme + "://" + _builder._host + ":" +
  287. _builder._port +
  288. "/o/portal-workflow-metrics/v1.0/processes/{processId}");
  289. httpInvoker.path("processId", processId);
  290. httpInvoker.userNameAndPassword(
  291. _builder._login + ":" + _builder._password);
  292. return httpInvoker.invoke();
  293. }
  294. public void deleteProcessBatch(String callbackURL, Object object)
  295. throws Exception {
  296. HttpInvoker.HttpResponse httpResponse =
  297. deleteProcessBatchHttpResponse(callbackURL, object);
  298. String content = httpResponse.getContent();
  299. if ((httpResponse.getStatusCode() / 100) != 2) {
  300. _logger.log(
  301. Level.WARNING,
  302. "Unable to process HTTP response content: " + content);
  303. _logger.log(
  304. Level.WARNING,
  305. "HTTP response message: " + httpResponse.getMessage());
  306. _logger.log(
  307. Level.WARNING,
  308. "HTTP response status code: " +
  309. httpResponse.getStatusCode());
  310. throw new Problem.ProblemException(Problem.toDTO(content));
  311. }
  312. else {
  313. _logger.fine("HTTP response content: " + content);
  314. _logger.fine(
  315. "HTTP response message: " + httpResponse.getMessage());
  316. _logger.fine(
  317. "HTTP response status code: " +
  318. httpResponse.getStatusCode());
  319. }
  320. }
  321. public HttpInvoker.HttpResponse deleteProcessBatchHttpResponse(
  322. String callbackURL, Object object)
  323. throws Exception {
  324. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  325. httpInvoker.body(object.toString(), "application/json");
  326. if (_builder._locale != null) {
  327. httpInvoker.header(
  328. "Accept-Language", _builder._locale.toLanguageTag());
  329. }
  330. for (Map.Entry<String, String> entry :
  331. _builder._headers.entrySet()) {
  332. httpInvoker.header(entry.getKey(), entry.getValue());
  333. }
  334. for (Map.Entry<String, String> entry :
  335. _builder._parameters.entrySet()) {
  336. httpInvoker.parameter(entry.getKey(), entry.getValue());
  337. }
  338. httpInvoker.httpMethod(HttpInvoker.HttpMethod.DELETE);
  339. if (callbackURL != null) {
  340. httpInvoker.parameter(
  341. "callbackURL", String.valueOf(callbackURL));
  342. }
  343. httpInvoker.path(
  344. _builder._scheme + "://" + _builder._host + ":" +
  345. _builder._port +
  346. "/o/portal-workflow-metrics/v1.0/processes/batch");
  347. httpInvoker.userNameAndPassword(
  348. _builder._login + ":" + _builder._password);
  349. return httpInvoker.invoke();
  350. }
  351. public Process getProcess(Long processId) throws Exception {
  352. HttpInvoker.HttpResponse httpResponse = getProcessHttpResponse(
  353. processId);
  354. String content = httpResponse.getContent();
  355. if ((httpResponse.getStatusCode() / 100) != 2) {
  356. _logger.log(
  357. Level.WARNING,
  358. "Unable to process HTTP response content: " + content);
  359. _logger.log(
  360. Level.WARNING,
  361. "HTTP response message: " + httpResponse.getMessage());
  362. _logger.log(
  363. Level.WARNING,
  364. "HTTP response status code: " +
  365. httpResponse.getStatusCode());
  366. throw new Problem.ProblemException(Problem.toDTO(content));
  367. }
  368. else {
  369. _logger.fine("HTTP response content: " + content);
  370. _logger.fine(
  371. "HTTP response message: " + httpResponse.getMessage());
  372. _logger.fine(
  373. "HTTP response status code: " +
  374. httpResponse.getStatusCode());
  375. }
  376. try {
  377. return com.liferay.portal.workflow.metrics.rest.client.serdes.
  378. v1_0.ProcessSerDes.toDTO(content);
  379. }
  380. catch (Exception e) {
  381. _logger.log(
  382. Level.WARNING,
  383. "Unable to process HTTP response: " + content, e);
  384. throw new Problem.ProblemException(Problem.toDTO(content));
  385. }
  386. }
  387. public HttpInvoker.HttpResponse getProcessHttpResponse(Long processId)
  388. throws Exception {
  389. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  390. if (_builder._locale != null) {
  391. httpInvoker.header(
  392. "Accept-Language", _builder._locale.toLanguageTag());
  393. }
  394. for (Map.Entry<String, String> entry :
  395. _builder._headers.entrySet()) {
  396. httpInvoker.header(entry.getKey(), entry.getValue());
  397. }
  398. for (Map.Entry<String, String> entry :
  399. _builder._parameters.entrySet()) {
  400. httpInvoker.parameter(entry.getKey(), entry.getValue());
  401. }
  402. httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
  403. httpInvoker.path(
  404. _builder._scheme + "://" + _builder._host + ":" +
  405. _builder._port +
  406. "/o/portal-workflow-metrics/v1.0/processes/{processId}");
  407. httpInvoker.path("processId", processId);
  408. httpInvoker.userNameAndPassword(
  409. _builder._login + ":" + _builder._password);
  410. return httpInvoker.invoke();
  411. }
  412. public void putProcess(Long processId, Process process)
  413. throws Exception {
  414. HttpInvoker.HttpResponse httpResponse = putProcessHttpResponse(
  415. processId, process);
  416. String content = httpResponse.getContent();
  417. if ((httpResponse.getStatusCode() / 100) != 2) {
  418. _logger.log(
  419. Level.WARNING,
  420. "Unable to process HTTP response content: " + content);
  421. _logger.log(
  422. Level.WARNING,
  423. "HTTP response message: " + httpResponse.getMessage());
  424. _logger.log(
  425. Level.WARNING,
  426. "HTTP response status code: " +
  427. httpResponse.getStatusCode());
  428. throw new Problem.ProblemException(Problem.toDTO(content));
  429. }
  430. else {
  431. _logger.fine("HTTP response content: " + content);
  432. _logger.fine(
  433. "HTTP response message: " + httpResponse.getMessage());
  434. _logger.fine(
  435. "HTTP response status code: " +
  436. httpResponse.getStatusCode());
  437. }
  438. try {
  439. return;
  440. }
  441. catch (Exception e) {
  442. _logger.log(
  443. Level.WARNING,
  444. "Unable to process HTTP response: " + content, e);
  445. throw new Problem.ProblemException(Problem.toDTO(content));
  446. }
  447. }
  448. public HttpInvoker.HttpResponse putProcessHttpResponse(
  449. Long processId, Process process)
  450. throws Exception {
  451. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  452. httpInvoker.body(process.toString(), "application/json");
  453. if (_builder._locale != null) {
  454. httpInvoker.header(
  455. "Accept-Language", _builder._locale.toLanguageTag());
  456. }
  457. for (Map.Entry<String, String> entry :
  458. _builder._headers.entrySet()) {
  459. httpInvoker.header(entry.getKey(), entry.getValue());
  460. }
  461. for (Map.Entry<String, String> entry :
  462. _builder._parameters.entrySet()) {
  463. httpInvoker.parameter(entry.getKey(), entry.getValue());
  464. }
  465. httpInvoker.httpMethod(HttpInvoker.HttpMethod.PUT);
  466. httpInvoker.path(
  467. _builder._scheme + "://" + _builder._host + ":" +
  468. _builder._port +
  469. "/o/portal-workflow-metrics/v1.0/processes/{processId}");
  470. httpInvoker.path("processId", processId);
  471. httpInvoker.userNameAndPassword(
  472. _builder._login + ":" + _builder._password);
  473. return httpInvoker.invoke();
  474. }
  475. public void putProcessBatch(String callbackURL, Object object)
  476. throws Exception {
  477. HttpInvoker.HttpResponse httpResponse = putProcessBatchHttpResponse(
  478. callbackURL, object);
  479. String content = httpResponse.getContent();
  480. if ((httpResponse.getStatusCode() / 100) != 2) {
  481. _logger.log(
  482. Level.WARNING,
  483. "Unable to process HTTP response content: " + content);
  484. _logger.log(
  485. Level.WARNING,
  486. "HTTP response message: " + httpResponse.getMessage());
  487. _logger.log(
  488. Level.WARNING,
  489. "HTTP response status code: " +
  490. httpResponse.getStatusCode());
  491. throw new Problem.ProblemException(Problem.toDTO(content));
  492. }
  493. else {
  494. _logger.fine("HTTP response content: " + content);
  495. _logger.fine(
  496. "HTTP response message: " + httpResponse.getMessage());
  497. _logger.fine(
  498. "HTTP response status code: " +
  499. httpResponse.getStatusCode());
  500. }
  501. }
  502. public HttpInvoker.HttpResponse putProcessBatchHttpResponse(
  503. String callbackURL, Object object)
  504. throws Exception {
  505. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  506. httpInvoker.body(object.toString(), "application/json");
  507. if (_builder._locale != null) {
  508. httpInvoker.header(
  509. "Accept-Language", _builder._locale.toLanguageTag());
  510. }
  511. for (Map.Entry<String, String> entry :
  512. _builder._headers.entrySet()) {
  513. httpInvoker.header(entry.getKey(), entry.getValue());
  514. }
  515. for (Map.Entry<String, String> entry :
  516. _builder._parameters.entrySet()) {
  517. httpInvoker.parameter(entry.getKey(), entry.getValue());
  518. }
  519. httpInvoker.httpMethod(HttpInvoker.HttpMethod.PUT);
  520. if (callbackURL != null) {
  521. httpInvoker.parameter(
  522. "callbackURL", String.valueOf(callbackURL));
  523. }
  524. httpInvoker.path(
  525. _builder._scheme + "://" + _builder._host + ":" +
  526. _builder._port +
  527. "/o/portal-workflow-metrics/v1.0/processes/batch");
  528. httpInvoker.userNameAndPassword(
  529. _builder._login + ":" + _builder._password);
  530. return httpInvoker.invoke();
  531. }
  532. public String getProcessTitle(Long processId) throws Exception {
  533. HttpInvoker.HttpResponse httpResponse = getProcessTitleHttpResponse(
  534. processId);
  535. String content = httpResponse.getContent();
  536. if ((httpResponse.getStatusCode() / 100) != 2) {
  537. _logger.log(
  538. Level.WARNING,
  539. "Unable to process HTTP response content: " + content);
  540. _logger.log(
  541. Level.WARNING,
  542. "HTTP response message: " + httpResponse.getMessage());
  543. _logger.log(
  544. Level.WARNING,
  545. "HTTP response status code: " +
  546. httpResponse.getStatusCode());
  547. throw new Problem.ProblemException(Problem.toDTO(content));
  548. }
  549. else {
  550. _logger.fine("HTTP response content: " + content);
  551. _logger.fine(
  552. "HTTP response message: " + httpResponse.getMessage());
  553. _logger.fine(
  554. "HTTP response status code: " +
  555. httpResponse.getStatusCode());
  556. }
  557. try {
  558. return content;
  559. }
  560. catch (Exception e) {
  561. _logger.log(
  562. Level.WARNING,
  563. "Unable to process HTTP response: " + content, e);
  564. throw new Problem.ProblemException(Problem.toDTO(content));
  565. }
  566. }
  567. public HttpInvoker.HttpResponse getProcessTitleHttpResponse(
  568. Long processId)
  569. throws Exception {
  570. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  571. if (_builder._locale != null) {
  572. httpInvoker.header(
  573. "Accept-Language", _builder._locale.toLanguageTag());
  574. }
  575. for (Map.Entry<String, String> entry :
  576. _builder._headers.entrySet()) {
  577. httpInvoker.header(entry.getKey(), entry.getValue());
  578. }
  579. for (Map.Entry<String, String> entry :
  580. _builder._parameters.entrySet()) {
  581. httpInvoker.parameter(entry.getKey(), entry.getValue());
  582. }
  583. httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
  584. httpInvoker.path(
  585. _builder._scheme + "://" + _builder._host + ":" +
  586. _builder._port +
  587. "/o/portal-workflow-metrics/v1.0/processes/{processId}/title");
  588. httpInvoker.path("processId", processId);
  589. httpInvoker.userNameAndPassword(
  590. _builder._login + ":" + _builder._password);
  591. return httpInvoker.invoke();
  592. }
  593. private ProcessResourceImpl(Builder builder) {
  594. _builder = builder;
  595. }
  596. private static final Logger _logger = Logger.getLogger(
  597. ProcessResource.class.getName());
  598. private Builder _builder;
  599. }
  600. }