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

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