PageRenderTime 46ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/apps/headless/headless-delivery/headless-delivery-api/src/main/java/com/liferay/headless/delivery/dto/v1_0/Settings.java

https://github.com/jrhoun/liferay-portal
Java | 480 lines | 357 code | 106 blank | 17 comment | 42 complexity | da5f060015fccd5fbbec8eb24b811359 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.delivery.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.json.JSONFactoryUtil;
  21. import com.liferay.portal.kernel.util.StringUtil;
  22. import com.liferay.portal.vulcan.graphql.annotation.GraphQLField;
  23. import com.liferay.portal.vulcan.graphql.annotation.GraphQLName;
  24. import com.liferay.portal.vulcan.util.ObjectMapperUtil;
  25. import io.swagger.v3.oas.annotations.media.Schema;
  26. import java.io.Serializable;
  27. import java.util.Iterator;
  28. import java.util.Map;
  29. import java.util.Objects;
  30. import java.util.Set;
  31. import javax.annotation.Generated;
  32. import javax.validation.Valid;
  33. import javax.xml.bind.annotation.XmlRootElement;
  34. /**
  35. * @author Javier Gamarra
  36. * @generated
  37. */
  38. @Generated("")
  39. @GraphQLName(
  40. description = "Represents the settings of a page.", value = "Settings"
  41. )
  42. @JsonFilter("Liferay.Vulcan")
  43. @XmlRootElement(name = "Settings")
  44. public class Settings implements Serializable {
  45. public static Settings toDTO(String json) {
  46. return ObjectMapperUtil.readValue(Settings.class, json);
  47. }
  48. public static Settings unsafeToDTO(String json) {
  49. return ObjectMapperUtil.unsafeReadValue(Settings.class, json);
  50. }
  51. @Schema(description = "The page's color scheme name.")
  52. public String getColorSchemeName() {
  53. return colorSchemeName;
  54. }
  55. public void setColorSchemeName(String colorSchemeName) {
  56. this.colorSchemeName = colorSchemeName;
  57. }
  58. @JsonIgnore
  59. public void setColorSchemeName(
  60. UnsafeSupplier<String, Exception> colorSchemeNameUnsafeSupplier) {
  61. try {
  62. colorSchemeName = colorSchemeNameUnsafeSupplier.get();
  63. }
  64. catch (RuntimeException re) {
  65. throw re;
  66. }
  67. catch (Exception e) {
  68. throw new RuntimeException(e);
  69. }
  70. }
  71. @GraphQLField(description = "The page's color scheme name.")
  72. @JsonProperty(access = JsonProperty.Access.READ_WRITE)
  73. protected String colorSchemeName;
  74. @Schema(description = "The page's CSS.")
  75. public String getCss() {
  76. return css;
  77. }
  78. public void setCss(String css) {
  79. this.css = css;
  80. }
  81. @JsonIgnore
  82. public void setCss(UnsafeSupplier<String, Exception> cssUnsafeSupplier) {
  83. try {
  84. css = cssUnsafeSupplier.get();
  85. }
  86. catch (RuntimeException re) {
  87. throw re;
  88. }
  89. catch (Exception e) {
  90. throw new RuntimeException(e);
  91. }
  92. }
  93. @GraphQLField(description = "The page's CSS.")
  94. @JsonProperty(access = JsonProperty.Access.READ_WRITE)
  95. protected String css;
  96. @Schema(description = "The page's JavaScript.")
  97. public String getJavascript() {
  98. return javascript;
  99. }
  100. public void setJavascript(String javascript) {
  101. this.javascript = javascript;
  102. }
  103. @JsonIgnore
  104. public void setJavascript(
  105. UnsafeSupplier<String, Exception> javascriptUnsafeSupplier) {
  106. try {
  107. javascript = javascriptUnsafeSupplier.get();
  108. }
  109. catch (RuntimeException re) {
  110. throw re;
  111. }
  112. catch (Exception e) {
  113. throw new RuntimeException(e);
  114. }
  115. }
  116. @GraphQLField(description = "The page's JavaScript.")
  117. @JsonProperty(access = JsonProperty.Access.READ_WRITE)
  118. protected String javascript;
  119. @Schema(description = "The page's master page.")
  120. @Valid
  121. public MasterPage getMasterPage() {
  122. return masterPage;
  123. }
  124. public void setMasterPage(MasterPage masterPage) {
  125. this.masterPage = masterPage;
  126. }
  127. @JsonIgnore
  128. public void setMasterPage(
  129. UnsafeSupplier<MasterPage, Exception> masterPageUnsafeSupplier) {
  130. try {
  131. masterPage = masterPageUnsafeSupplier.get();
  132. }
  133. catch (RuntimeException re) {
  134. throw re;
  135. }
  136. catch (Exception e) {
  137. throw new RuntimeException(e);
  138. }
  139. }
  140. @GraphQLField(description = "The page's master page.")
  141. @JsonProperty(access = JsonProperty.Access.READ_WRITE)
  142. protected MasterPage masterPage;
  143. @Schema(description = "The StyleBook that is applied to the page.")
  144. @Valid
  145. public StyleBook getStyleBook() {
  146. return styleBook;
  147. }
  148. public void setStyleBook(StyleBook styleBook) {
  149. this.styleBook = styleBook;
  150. }
  151. @JsonIgnore
  152. public void setStyleBook(
  153. UnsafeSupplier<StyleBook, Exception> styleBookUnsafeSupplier) {
  154. try {
  155. styleBook = styleBookUnsafeSupplier.get();
  156. }
  157. catch (RuntimeException re) {
  158. throw re;
  159. }
  160. catch (Exception e) {
  161. throw new RuntimeException(e);
  162. }
  163. }
  164. @GraphQLField(description = "The StyleBook that is applied to the page.")
  165. @JsonProperty(access = JsonProperty.Access.READ_WRITE)
  166. protected StyleBook styleBook;
  167. @Schema(description = "The page's theme name.")
  168. public String getThemeName() {
  169. return themeName;
  170. }
  171. public void setThemeName(String themeName) {
  172. this.themeName = themeName;
  173. }
  174. @JsonIgnore
  175. public void setThemeName(
  176. UnsafeSupplier<String, Exception> themeNameUnsafeSupplier) {
  177. try {
  178. themeName = themeNameUnsafeSupplier.get();
  179. }
  180. catch (RuntimeException re) {
  181. throw re;
  182. }
  183. catch (Exception e) {
  184. throw new RuntimeException(e);
  185. }
  186. }
  187. @GraphQLField(description = "The page's theme name.")
  188. @JsonProperty(access = JsonProperty.Access.READ_WRITE)
  189. protected String themeName;
  190. @Schema(description = "The page's theme settings.")
  191. @Valid
  192. public Object getThemeSettings() {
  193. return themeSettings;
  194. }
  195. public void setThemeSettings(Object themeSettings) {
  196. this.themeSettings = themeSettings;
  197. }
  198. @JsonIgnore
  199. public void setThemeSettings(
  200. UnsafeSupplier<Object, Exception> themeSettingsUnsafeSupplier) {
  201. try {
  202. themeSettings = themeSettingsUnsafeSupplier.get();
  203. }
  204. catch (RuntimeException re) {
  205. throw re;
  206. }
  207. catch (Exception e) {
  208. throw new RuntimeException(e);
  209. }
  210. }
  211. @GraphQLField(description = "The page's theme settings.")
  212. @JsonProperty(access = JsonProperty.Access.READ_WRITE)
  213. protected Object themeSettings;
  214. @Override
  215. public boolean equals(Object object) {
  216. if (this == object) {
  217. return true;
  218. }
  219. if (!(object instanceof Settings)) {
  220. return false;
  221. }
  222. Settings settings = (Settings)object;
  223. return Objects.equals(toString(), settings.toString());
  224. }
  225. @Override
  226. public int hashCode() {
  227. String string = toString();
  228. return string.hashCode();
  229. }
  230. public String toString() {
  231. StringBundler sb = new StringBundler();
  232. sb.append("{");
  233. if (colorSchemeName != null) {
  234. if (sb.length() > 1) {
  235. sb.append(", ");
  236. }
  237. sb.append("\"colorSchemeName\": ");
  238. sb.append("\"");
  239. sb.append(_escape(colorSchemeName));
  240. sb.append("\"");
  241. }
  242. if (css != null) {
  243. if (sb.length() > 1) {
  244. sb.append(", ");
  245. }
  246. sb.append("\"css\": ");
  247. sb.append("\"");
  248. sb.append(_escape(css));
  249. sb.append("\"");
  250. }
  251. if (javascript != null) {
  252. if (sb.length() > 1) {
  253. sb.append(", ");
  254. }
  255. sb.append("\"javascript\": ");
  256. sb.append("\"");
  257. sb.append(_escape(javascript));
  258. sb.append("\"");
  259. }
  260. if (masterPage != null) {
  261. if (sb.length() > 1) {
  262. sb.append(", ");
  263. }
  264. sb.append("\"masterPage\": ");
  265. sb.append(String.valueOf(masterPage));
  266. }
  267. if (styleBook != null) {
  268. if (sb.length() > 1) {
  269. sb.append(", ");
  270. }
  271. sb.append("\"styleBook\": ");
  272. sb.append(String.valueOf(styleBook));
  273. }
  274. if (themeName != null) {
  275. if (sb.length() > 1) {
  276. sb.append(", ");
  277. }
  278. sb.append("\"themeName\": ");
  279. sb.append("\"");
  280. sb.append(_escape(themeName));
  281. sb.append("\"");
  282. }
  283. if (themeSettings != null) {
  284. if (sb.length() > 1) {
  285. sb.append(", ");
  286. }
  287. sb.append("\"themeSettings\": ");
  288. if (themeSettings instanceof Map) {
  289. sb.append(
  290. JSONFactoryUtil.createJSONObject((Map<?, ?>)themeSettings));
  291. }
  292. else if (themeSettings instanceof String) {
  293. sb.append("\"");
  294. sb.append(_escape((String)themeSettings));
  295. sb.append("\"");
  296. }
  297. else {
  298. sb.append(themeSettings);
  299. }
  300. }
  301. sb.append("}");
  302. return sb.toString();
  303. }
  304. @Schema(
  305. accessMode = Schema.AccessMode.READ_ONLY,
  306. defaultValue = "com.liferay.headless.delivery.dto.v1_0.Settings",
  307. name = "x-class-name"
  308. )
  309. public String xClassName;
  310. private static String _escape(Object object) {
  311. return StringUtil.replace(
  312. String.valueOf(object), _JSON_ESCAPE_STRINGS[0],
  313. _JSON_ESCAPE_STRINGS[1]);
  314. }
  315. private static boolean _isArray(Object value) {
  316. if (value == null) {
  317. return false;
  318. }
  319. Class<?> clazz = value.getClass();
  320. return clazz.isArray();
  321. }
  322. private static String _toJSON(Map<String, ?> map) {
  323. StringBuilder sb = new StringBuilder("{");
  324. @SuppressWarnings("unchecked")
  325. Set set = map.entrySet();
  326. @SuppressWarnings("unchecked")
  327. Iterator<Map.Entry<String, ?>> iterator = set.iterator();
  328. while (iterator.hasNext()) {
  329. Map.Entry<String, ?> entry = iterator.next();
  330. sb.append("\"");
  331. sb.append(_escape(entry.getKey()));
  332. sb.append("\": ");
  333. Object value = entry.getValue();
  334. if (_isArray(value)) {
  335. sb.append("[");
  336. Object[] valueArray = (Object[])value;
  337. for (int i = 0; i < valueArray.length; i++) {
  338. if (valueArray[i] instanceof String) {
  339. sb.append("\"");
  340. sb.append(valueArray[i]);
  341. sb.append("\"");
  342. }
  343. else {
  344. sb.append(valueArray[i]);
  345. }
  346. if ((i + 1) < valueArray.length) {
  347. sb.append(", ");
  348. }
  349. }
  350. sb.append("]");
  351. }
  352. else if (value instanceof Map) {
  353. sb.append(_toJSON((Map<String, ?>)value));
  354. }
  355. else if (value instanceof String) {
  356. sb.append("\"");
  357. sb.append(_escape(value));
  358. sb.append("\"");
  359. }
  360. else {
  361. sb.append(value);
  362. }
  363. if (iterator.hasNext()) {
  364. sb.append(", ");
  365. }
  366. }
  367. sb.append("}");
  368. return sb.toString();
  369. }
  370. private static final String[][] _JSON_ESCAPE_STRINGS = {
  371. {"\\", "\"", "\b", "\f", "\n", "\r", "\t"},
  372. {"\\\\", "\\\"", "\\b", "\\f", "\\n", "\\r", "\\t"}
  373. };
  374. }