/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/resource/v1_0/UserAccountResource.java

https://github.com/kiyoshilee/liferay-portal · Java · 501 lines · 350 code · 134 blank · 17 comment · 44 complexity · 953a4604d94f5826649cb491e9012149 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.headless.admin.user.client.resource.v1_0;
  15. import com.liferay.headless.admin.user.client.dto.v1_0.UserAccount;
  16. import com.liferay.headless.admin.user.client.http.HttpInvoker;
  17. import com.liferay.headless.admin.user.client.pagination.Page;
  18. import com.liferay.headless.admin.user.client.pagination.Pagination;
  19. import com.liferay.headless.admin.user.client.serdes.v1_0.UserAccountSerDes;
  20. import java.util.LinkedHashMap;
  21. import java.util.Locale;
  22. import java.util.Map;
  23. import java.util.logging.Level;
  24. import java.util.logging.Logger;
  25. import javax.annotation.Generated;
  26. /**
  27. * @author Javier Gamarra
  28. * @generated
  29. */
  30. @Generated("")
  31. public interface UserAccountResource {
  32. public static Builder builder() {
  33. return new Builder();
  34. }
  35. public UserAccount getMyUserAccount() throws Exception;
  36. public HttpInvoker.HttpResponse getMyUserAccountHttpResponse()
  37. throws Exception;
  38. public Page<UserAccount> getOrganizationUserAccountsPage(
  39. Long organizationId, String search, String filterString,
  40. Pagination pagination, String sortString)
  41. throws Exception;
  42. public HttpInvoker.HttpResponse getOrganizationUserAccountsPageHttpResponse(
  43. Long organizationId, String search, String filterString,
  44. Pagination pagination, String sortString)
  45. throws Exception;
  46. public Page<UserAccount> getSiteUserAccountsPage(
  47. Long siteId, String search, String filterString,
  48. Pagination pagination, String sortString)
  49. throws Exception;
  50. public HttpInvoker.HttpResponse getSiteUserAccountsPageHttpResponse(
  51. Long siteId, String search, String filterString,
  52. Pagination pagination, String sortString)
  53. throws Exception;
  54. public Page<UserAccount> getUserAccountsPage(
  55. String search, String filterString, Pagination pagination,
  56. String sortString)
  57. throws Exception;
  58. public HttpInvoker.HttpResponse getUserAccountsPageHttpResponse(
  59. String search, String filterString, Pagination pagination,
  60. String sortString)
  61. throws Exception;
  62. public UserAccount getUserAccount(Long userAccountId) throws Exception;
  63. public HttpInvoker.HttpResponse getUserAccountHttpResponse(
  64. Long userAccountId)
  65. throws Exception;
  66. public static class Builder {
  67. public Builder authentication(String login, String password) {
  68. _login = login;
  69. _password = password;
  70. return this;
  71. }
  72. public UserAccountResource build() {
  73. return new UserAccountResourceImpl(this);
  74. }
  75. public Builder endpoint(String host, int port, String scheme) {
  76. _host = host;
  77. _port = port;
  78. _scheme = scheme;
  79. return this;
  80. }
  81. public Builder header(String key, String value) {
  82. _headers.put(key, value);
  83. return this;
  84. }
  85. public Builder locale(Locale locale) {
  86. _locale = locale;
  87. return this;
  88. }
  89. public Builder parameter(String key, String value) {
  90. _parameters.put(key, value);
  91. return this;
  92. }
  93. private Builder() {
  94. }
  95. private Map<String, String> _headers = new LinkedHashMap<>();
  96. private String _host = "localhost";
  97. private Locale _locale;
  98. private String _login = "test@liferay.com";
  99. private String _password = "test";
  100. private Map<String, String> _parameters = new LinkedHashMap<>();
  101. private int _port = 8080;
  102. private String _scheme = "http";
  103. }
  104. public static class UserAccountResourceImpl implements UserAccountResource {
  105. public UserAccount getMyUserAccount() throws Exception {
  106. HttpInvoker.HttpResponse httpResponse =
  107. getMyUserAccountHttpResponse();
  108. String content = httpResponse.getContent();
  109. _logger.fine("HTTP response content: " + content);
  110. _logger.fine("HTTP response message: " + httpResponse.getMessage());
  111. _logger.fine(
  112. "HTTP response status code: " + httpResponse.getStatusCode());
  113. try {
  114. return UserAccountSerDes.toDTO(content);
  115. }
  116. catch (Exception e) {
  117. _logger.log(
  118. Level.WARNING,
  119. "Unable to process HTTP response: " + content, e);
  120. throw e;
  121. }
  122. }
  123. public HttpInvoker.HttpResponse getMyUserAccountHttpResponse()
  124. throws Exception {
  125. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  126. if (_builder._locale != null) {
  127. httpInvoker.header(
  128. "Accept-Language", _builder._locale.toLanguageTag());
  129. }
  130. for (Map.Entry<String, String> entry :
  131. _builder._headers.entrySet()) {
  132. httpInvoker.header(entry.getKey(), entry.getValue());
  133. }
  134. for (Map.Entry<String, String> entry :
  135. _builder._parameters.entrySet()) {
  136. httpInvoker.parameter(entry.getKey(), entry.getValue());
  137. }
  138. httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
  139. httpInvoker.path(
  140. _builder._scheme + "://" + _builder._host + ":" +
  141. _builder._port +
  142. "/o/headless-admin-user/v1.0/my-user-account");
  143. httpInvoker.userNameAndPassword(
  144. _builder._login + ":" + _builder._password);
  145. return httpInvoker.invoke();
  146. }
  147. public Page<UserAccount> getOrganizationUserAccountsPage(
  148. Long organizationId, String search, String filterString,
  149. Pagination pagination, String sortString)
  150. throws Exception {
  151. HttpInvoker.HttpResponse httpResponse =
  152. getOrganizationUserAccountsPageHttpResponse(
  153. organizationId, search, filterString, pagination,
  154. sortString);
  155. String content = httpResponse.getContent();
  156. _logger.fine("HTTP response content: " + content);
  157. _logger.fine("HTTP response message: " + httpResponse.getMessage());
  158. _logger.fine(
  159. "HTTP response status code: " + httpResponse.getStatusCode());
  160. return Page.of(content, UserAccountSerDes::toDTO);
  161. }
  162. public HttpInvoker.HttpResponse
  163. getOrganizationUserAccountsPageHttpResponse(
  164. Long organizationId, String search, String filterString,
  165. Pagination pagination, String sortString)
  166. throws Exception {
  167. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  168. if (_builder._locale != null) {
  169. httpInvoker.header(
  170. "Accept-Language", _builder._locale.toLanguageTag());
  171. }
  172. for (Map.Entry<String, String> entry :
  173. _builder._headers.entrySet()) {
  174. httpInvoker.header(entry.getKey(), entry.getValue());
  175. }
  176. for (Map.Entry<String, String> entry :
  177. _builder._parameters.entrySet()) {
  178. httpInvoker.parameter(entry.getKey(), entry.getValue());
  179. }
  180. httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
  181. if (search != null) {
  182. httpInvoker.parameter("search", String.valueOf(search));
  183. }
  184. if (filterString != null) {
  185. httpInvoker.parameter("filter", filterString);
  186. }
  187. if (pagination != null) {
  188. httpInvoker.parameter(
  189. "page", String.valueOf(pagination.getPage()));
  190. httpInvoker.parameter(
  191. "pageSize", String.valueOf(pagination.getPageSize()));
  192. }
  193. if (sortString != null) {
  194. httpInvoker.parameter("sort", sortString);
  195. }
  196. httpInvoker.path(
  197. _builder._scheme + "://" + _builder._host + ":" +
  198. _builder._port +
  199. "/o/headless-admin-user/v1.0/organizations/{organizationId}/user-accounts",
  200. organizationId);
  201. httpInvoker.userNameAndPassword(
  202. _builder._login + ":" + _builder._password);
  203. return httpInvoker.invoke();
  204. }
  205. public Page<UserAccount> getSiteUserAccountsPage(
  206. Long siteId, String search, String filterString,
  207. Pagination pagination, String sortString)
  208. throws Exception {
  209. HttpInvoker.HttpResponse httpResponse =
  210. getSiteUserAccountsPageHttpResponse(
  211. siteId, search, filterString, pagination, sortString);
  212. String content = httpResponse.getContent();
  213. _logger.fine("HTTP response content: " + content);
  214. _logger.fine("HTTP response message: " + httpResponse.getMessage());
  215. _logger.fine(
  216. "HTTP response status code: " + httpResponse.getStatusCode());
  217. return Page.of(content, UserAccountSerDes::toDTO);
  218. }
  219. public HttpInvoker.HttpResponse getSiteUserAccountsPageHttpResponse(
  220. Long siteId, String search, String filterString,
  221. Pagination pagination, String sortString)
  222. throws Exception {
  223. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  224. if (_builder._locale != null) {
  225. httpInvoker.header(
  226. "Accept-Language", _builder._locale.toLanguageTag());
  227. }
  228. for (Map.Entry<String, String> entry :
  229. _builder._headers.entrySet()) {
  230. httpInvoker.header(entry.getKey(), entry.getValue());
  231. }
  232. for (Map.Entry<String, String> entry :
  233. _builder._parameters.entrySet()) {
  234. httpInvoker.parameter(entry.getKey(), entry.getValue());
  235. }
  236. httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
  237. if (search != null) {
  238. httpInvoker.parameter("search", String.valueOf(search));
  239. }
  240. if (filterString != null) {
  241. httpInvoker.parameter("filter", filterString);
  242. }
  243. if (pagination != null) {
  244. httpInvoker.parameter(
  245. "page", String.valueOf(pagination.getPage()));
  246. httpInvoker.parameter(
  247. "pageSize", String.valueOf(pagination.getPageSize()));
  248. }
  249. if (sortString != null) {
  250. httpInvoker.parameter("sort", sortString);
  251. }
  252. httpInvoker.path(
  253. _builder._scheme + "://" + _builder._host + ":" +
  254. _builder._port +
  255. "/o/headless-admin-user/v1.0/sites/{siteId}/user-accounts",
  256. siteId);
  257. httpInvoker.userNameAndPassword(
  258. _builder._login + ":" + _builder._password);
  259. return httpInvoker.invoke();
  260. }
  261. public Page<UserAccount> getUserAccountsPage(
  262. String search, String filterString, Pagination pagination,
  263. String sortString)
  264. throws Exception {
  265. HttpInvoker.HttpResponse httpResponse =
  266. getUserAccountsPageHttpResponse(
  267. search, filterString, pagination, sortString);
  268. String content = httpResponse.getContent();
  269. _logger.fine("HTTP response content: " + content);
  270. _logger.fine("HTTP response message: " + httpResponse.getMessage());
  271. _logger.fine(
  272. "HTTP response status code: " + httpResponse.getStatusCode());
  273. return Page.of(content, UserAccountSerDes::toDTO);
  274. }
  275. public HttpInvoker.HttpResponse getUserAccountsPageHttpResponse(
  276. String search, String filterString, Pagination pagination,
  277. String sortString)
  278. throws Exception {
  279. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  280. if (_builder._locale != null) {
  281. httpInvoker.header(
  282. "Accept-Language", _builder._locale.toLanguageTag());
  283. }
  284. for (Map.Entry<String, String> entry :
  285. _builder._headers.entrySet()) {
  286. httpInvoker.header(entry.getKey(), entry.getValue());
  287. }
  288. for (Map.Entry<String, String> entry :
  289. _builder._parameters.entrySet()) {
  290. httpInvoker.parameter(entry.getKey(), entry.getValue());
  291. }
  292. httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
  293. if (search != null) {
  294. httpInvoker.parameter("search", String.valueOf(search));
  295. }
  296. if (filterString != null) {
  297. httpInvoker.parameter("filter", filterString);
  298. }
  299. if (pagination != null) {
  300. httpInvoker.parameter(
  301. "page", String.valueOf(pagination.getPage()));
  302. httpInvoker.parameter(
  303. "pageSize", String.valueOf(pagination.getPageSize()));
  304. }
  305. if (sortString != null) {
  306. httpInvoker.parameter("sort", sortString);
  307. }
  308. httpInvoker.path(
  309. _builder._scheme + "://" + _builder._host + ":" +
  310. _builder._port +
  311. "/o/headless-admin-user/v1.0/user-accounts");
  312. httpInvoker.userNameAndPassword(
  313. _builder._login + ":" + _builder._password);
  314. return httpInvoker.invoke();
  315. }
  316. public UserAccount getUserAccount(Long userAccountId) throws Exception {
  317. HttpInvoker.HttpResponse httpResponse = getUserAccountHttpResponse(
  318. userAccountId);
  319. String content = httpResponse.getContent();
  320. _logger.fine("HTTP response content: " + content);
  321. _logger.fine("HTTP response message: " + httpResponse.getMessage());
  322. _logger.fine(
  323. "HTTP response status code: " + httpResponse.getStatusCode());
  324. try {
  325. return UserAccountSerDes.toDTO(content);
  326. }
  327. catch (Exception e) {
  328. _logger.log(
  329. Level.WARNING,
  330. "Unable to process HTTP response: " + content, e);
  331. throw e;
  332. }
  333. }
  334. public HttpInvoker.HttpResponse getUserAccountHttpResponse(
  335. Long userAccountId)
  336. throws Exception {
  337. HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
  338. if (_builder._locale != null) {
  339. httpInvoker.header(
  340. "Accept-Language", _builder._locale.toLanguageTag());
  341. }
  342. for (Map.Entry<String, String> entry :
  343. _builder._headers.entrySet()) {
  344. httpInvoker.header(entry.getKey(), entry.getValue());
  345. }
  346. for (Map.Entry<String, String> entry :
  347. _builder._parameters.entrySet()) {
  348. httpInvoker.parameter(entry.getKey(), entry.getValue());
  349. }
  350. httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
  351. httpInvoker.path(
  352. _builder._scheme + "://" + _builder._host + ":" +
  353. _builder._port +
  354. "/o/headless-admin-user/v1.0/user-accounts/{userAccountId}",
  355. userAccountId);
  356. httpInvoker.userNameAndPassword(
  357. _builder._login + ":" + _builder._password);
  358. return httpInvoker.invoke();
  359. }
  360. private UserAccountResourceImpl(Builder builder) {
  361. _builder = builder;
  362. }
  363. private static final Logger _logger = Logger.getLogger(
  364. UserAccountResource.class.getName());
  365. private Builder _builder;
  366. }
  367. }