PageRenderTime 73ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/apps/headless/headless-admin-user/headless-admin-user-api/src/main/java/com/liferay/headless/admin/user/dto/v1_0/AccountRole.java

https://github.com/ealonso/liferay-portal
Java | 423 lines | 312 code | 94 blank | 17 comment | 35 complexity | d640e9525a56eb1b755d553423d6df72 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.dto.v1_0;
  15. import com.fasterxml.jackson.annotation.JsonFilter;
  16. import com.fasterxml.jackson.annotation.JsonIgnore;
  17. import com.fasterxml.jackson.annotation.JsonProperty;
  18. import com.liferay.petra.function.UnsafeSupplier;
  19. import com.liferay.petra.string.StringBundler;
  20. import com.liferay.portal.kernel.util.StringUtil;
  21. import com.liferay.portal.vulcan.graphql.annotation.GraphQLField;
  22. import com.liferay.portal.vulcan.graphql.annotation.GraphQLName;
  23. import com.liferay.portal.vulcan.util.ObjectMapperUtil;
  24. import io.swagger.v3.oas.annotations.media.Schema;
  25. import java.io.Serializable;
  26. import java.util.Iterator;
  27. import java.util.Map;
  28. import java.util.Objects;
  29. import java.util.Set;
  30. import javax.annotation.Generated;
  31. import javax.xml.bind.annotation.XmlRootElement;
  32. /**
  33. * @author Javier Gamarra
  34. * @generated
  35. */
  36. @Generated("")
  37. @GraphQLName(
  38. description = "A role that belongs to an account", value = "AccountRole"
  39. )
  40. @JsonFilter("Liferay.Vulcan")
  41. @XmlRootElement(name = "AccountRole")
  42. public class AccountRole implements Serializable {
  43. public static AccountRole toDTO(String json) {
  44. return ObjectMapperUtil.readValue(AccountRole.class, json);
  45. }
  46. public static AccountRole unsafeToDTO(String json) {
  47. return ObjectMapperUtil.unsafeReadValue(AccountRole.class, json);
  48. }
  49. @Schema(description = "The primary key of the account that owns this role.")
  50. public Long getAccountId() {
  51. return accountId;
  52. }
  53. public void setAccountId(Long accountId) {
  54. this.accountId = accountId;
  55. }
  56. @JsonIgnore
  57. public void setAccountId(
  58. UnsafeSupplier<Long, Exception> accountIdUnsafeSupplier) {
  59. try {
  60. accountId = accountIdUnsafeSupplier.get();
  61. }
  62. catch (RuntimeException re) {
  63. throw re;
  64. }
  65. catch (Exception e) {
  66. throw new RuntimeException(e);
  67. }
  68. }
  69. @GraphQLField(
  70. description = "The primary key of the account that owns this role."
  71. )
  72. @JsonProperty(access = JsonProperty.Access.READ_ONLY)
  73. protected Long accountId;
  74. @Schema
  75. public String getDescription() {
  76. return description;
  77. }
  78. public void setDescription(String description) {
  79. this.description = description;
  80. }
  81. @JsonIgnore
  82. public void setDescription(
  83. UnsafeSupplier<String, Exception> descriptionUnsafeSupplier) {
  84. try {
  85. description = descriptionUnsafeSupplier.get();
  86. }
  87. catch (RuntimeException re) {
  88. throw re;
  89. }
  90. catch (Exception e) {
  91. throw new RuntimeException(e);
  92. }
  93. }
  94. @GraphQLField
  95. @JsonProperty(access = JsonProperty.Access.READ_WRITE)
  96. protected String description;
  97. @Schema
  98. public String getDisplayName() {
  99. return displayName;
  100. }
  101. public void setDisplayName(String displayName) {
  102. this.displayName = displayName;
  103. }
  104. @JsonIgnore
  105. public void setDisplayName(
  106. UnsafeSupplier<String, Exception> displayNameUnsafeSupplier) {
  107. try {
  108. displayName = displayNameUnsafeSupplier.get();
  109. }
  110. catch (RuntimeException re) {
  111. throw re;
  112. }
  113. catch (Exception e) {
  114. throw new RuntimeException(e);
  115. }
  116. }
  117. @GraphQLField
  118. @JsonProperty(access = JsonProperty.Access.READ_WRITE)
  119. protected String displayName;
  120. @Schema
  121. public Long getId() {
  122. return id;
  123. }
  124. public void setId(Long id) {
  125. this.id = id;
  126. }
  127. @JsonIgnore
  128. public void setId(UnsafeSupplier<Long, Exception> idUnsafeSupplier) {
  129. try {
  130. id = idUnsafeSupplier.get();
  131. }
  132. catch (RuntimeException re) {
  133. throw re;
  134. }
  135. catch (Exception e) {
  136. throw new RuntimeException(e);
  137. }
  138. }
  139. @GraphQLField
  140. @JsonProperty(access = JsonProperty.Access.READ_ONLY)
  141. protected Long id;
  142. @Schema
  143. public String getName() {
  144. return name;
  145. }
  146. public void setName(String name) {
  147. this.name = name;
  148. }
  149. @JsonIgnore
  150. public void setName(UnsafeSupplier<String, Exception> nameUnsafeSupplier) {
  151. try {
  152. name = nameUnsafeSupplier.get();
  153. }
  154. catch (RuntimeException re) {
  155. throw re;
  156. }
  157. catch (Exception e) {
  158. throw new RuntimeException(e);
  159. }
  160. }
  161. @GraphQLField
  162. @JsonProperty(access = JsonProperty.Access.READ_WRITE)
  163. protected String name;
  164. @Schema(description = "The primary key of the underlying system role.")
  165. public Long getRoleId() {
  166. return roleId;
  167. }
  168. public void setRoleId(Long roleId) {
  169. this.roleId = roleId;
  170. }
  171. @JsonIgnore
  172. public void setRoleId(
  173. UnsafeSupplier<Long, Exception> roleIdUnsafeSupplier) {
  174. try {
  175. roleId = roleIdUnsafeSupplier.get();
  176. }
  177. catch (RuntimeException re) {
  178. throw re;
  179. }
  180. catch (Exception e) {
  181. throw new RuntimeException(e);
  182. }
  183. }
  184. @GraphQLField(
  185. description = "The primary key of the underlying system role."
  186. )
  187. @JsonProperty(access = JsonProperty.Access.READ_ONLY)
  188. protected Long roleId;
  189. @Override
  190. public boolean equals(Object object) {
  191. if (this == object) {
  192. return true;
  193. }
  194. if (!(object instanceof AccountRole)) {
  195. return false;
  196. }
  197. AccountRole accountRole = (AccountRole)object;
  198. return Objects.equals(toString(), accountRole.toString());
  199. }
  200. @Override
  201. public int hashCode() {
  202. String string = toString();
  203. return string.hashCode();
  204. }
  205. public String toString() {
  206. StringBundler sb = new StringBundler();
  207. sb.append("{");
  208. if (accountId != null) {
  209. if (sb.length() > 1) {
  210. sb.append(", ");
  211. }
  212. sb.append("\"accountId\": ");
  213. sb.append(accountId);
  214. }
  215. if (description != null) {
  216. if (sb.length() > 1) {
  217. sb.append(", ");
  218. }
  219. sb.append("\"description\": ");
  220. sb.append("\"");
  221. sb.append(_escape(description));
  222. sb.append("\"");
  223. }
  224. if (displayName != null) {
  225. if (sb.length() > 1) {
  226. sb.append(", ");
  227. }
  228. sb.append("\"displayName\": ");
  229. sb.append("\"");
  230. sb.append(_escape(displayName));
  231. sb.append("\"");
  232. }
  233. if (id != null) {
  234. if (sb.length() > 1) {
  235. sb.append(", ");
  236. }
  237. sb.append("\"id\": ");
  238. sb.append(id);
  239. }
  240. if (name != null) {
  241. if (sb.length() > 1) {
  242. sb.append(", ");
  243. }
  244. sb.append("\"name\": ");
  245. sb.append("\"");
  246. sb.append(_escape(name));
  247. sb.append("\"");
  248. }
  249. if (roleId != null) {
  250. if (sb.length() > 1) {
  251. sb.append(", ");
  252. }
  253. sb.append("\"roleId\": ");
  254. sb.append(roleId);
  255. }
  256. sb.append("}");
  257. return sb.toString();
  258. }
  259. @Schema(
  260. accessMode = Schema.AccessMode.READ_ONLY,
  261. defaultValue = "com.liferay.headless.admin.user.dto.v1_0.AccountRole",
  262. name = "x-class-name"
  263. )
  264. public String xClassName;
  265. private static String _escape(Object object) {
  266. return StringUtil.replace(
  267. String.valueOf(object), _JSON_ESCAPE_STRINGS[0],
  268. _JSON_ESCAPE_STRINGS[1]);
  269. }
  270. private static boolean _isArray(Object value) {
  271. if (value == null) {
  272. return false;
  273. }
  274. Class<?> clazz = value.getClass();
  275. return clazz.isArray();
  276. }
  277. private static String _toJSON(Map<String, ?> map) {
  278. StringBuilder sb = new StringBuilder("{");
  279. @SuppressWarnings("unchecked")
  280. Set set = map.entrySet();
  281. @SuppressWarnings("unchecked")
  282. Iterator<Map.Entry<String, ?>> iterator = set.iterator();
  283. while (iterator.hasNext()) {
  284. Map.Entry<String, ?> entry = iterator.next();
  285. sb.append("\"");
  286. sb.append(_escape(entry.getKey()));
  287. sb.append("\": ");
  288. Object value = entry.getValue();
  289. if (_isArray(value)) {
  290. sb.append("[");
  291. Object[] valueArray = (Object[])value;
  292. for (int i = 0; i < valueArray.length; i++) {
  293. if (valueArray[i] instanceof String) {
  294. sb.append("\"");
  295. sb.append(valueArray[i]);
  296. sb.append("\"");
  297. }
  298. else {
  299. sb.append(valueArray[i]);
  300. }
  301. if ((i + 1) < valueArray.length) {
  302. sb.append(", ");
  303. }
  304. }
  305. sb.append("]");
  306. }
  307. else if (value instanceof Map) {
  308. sb.append(_toJSON((Map<String, ?>)value));
  309. }
  310. else if (value instanceof String) {
  311. sb.append("\"");
  312. sb.append(_escape(value));
  313. sb.append("\"");
  314. }
  315. else {
  316. sb.append(value);
  317. }
  318. if (iterator.hasNext()) {
  319. sb.append(", ");
  320. }
  321. }
  322. sb.append("}");
  323. return sb.toString();
  324. }
  325. private static final String[][] _JSON_ESCAPE_STRINGS = {
  326. {"\\", "\"", "\b", "\f", "\n", "\r", "\t"},
  327. {"\\\\", "\\\"", "\\b", "\\f", "\\n", "\\r", "\\t"}
  328. };
  329. }