PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/vilmospapp/liferay-portal
Java | 445 lines | 329 code | 99 blank | 17 comment | 35 complexity | d41dd4713e919929f9f2e492fac9c19a 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.vulcan.graphql.annotation.GraphQLField;
  21. import com.liferay.portal.vulcan.graphql.annotation.GraphQLName;
  22. import com.liferay.portal.vulcan.util.ObjectMapperUtil;
  23. import io.swagger.v3.oas.annotations.media.Schema;
  24. import java.io.Serializable;
  25. import java.util.Iterator;
  26. import java.util.Map;
  27. import java.util.Objects;
  28. import java.util.Set;
  29. import javax.annotation.Generated;
  30. import javax.validation.Valid;
  31. import javax.xml.bind.annotation.XmlRootElement;
  32. /**
  33. * @author Javier Gamarra
  34. * @generated
  35. */
  36. @Generated("")
  37. @GraphQLName(
  38. description = "Rendered content, which results from using a template or display page to process the content and return HTML.",
  39. value = "RenderedContent"
  40. )
  41. @JsonFilter("Liferay.Vulcan")
  42. @XmlRootElement(name = "RenderedContent")
  43. public class RenderedContent implements Serializable {
  44. public static RenderedContent toDTO(String json) {
  45. return ObjectMapperUtil.readValue(RenderedContent.class, json);
  46. }
  47. @Schema(
  48. description = "The ID of the template or display page used to render the content."
  49. )
  50. public String getContentTemplateId() {
  51. return contentTemplateId;
  52. }
  53. public void setContentTemplateId(String contentTemplateId) {
  54. this.contentTemplateId = contentTemplateId;
  55. }
  56. @JsonIgnore
  57. public void setContentTemplateId(
  58. UnsafeSupplier<String, Exception> contentTemplateIdUnsafeSupplier) {
  59. try {
  60. contentTemplateId = contentTemplateIdUnsafeSupplier.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 ID of the template or display page used to render the content."
  71. )
  72. @JsonProperty(access = JsonProperty.Access.READ_ONLY)
  73. protected String contentTemplateId;
  74. @Schema(
  75. description = "The name of the template or display page used to render the content."
  76. )
  77. public String getContentTemplateName() {
  78. return contentTemplateName;
  79. }
  80. public void setContentTemplateName(String contentTemplateName) {
  81. this.contentTemplateName = contentTemplateName;
  82. }
  83. @JsonIgnore
  84. public void setContentTemplateName(
  85. UnsafeSupplier<String, Exception> contentTemplateNameUnsafeSupplier) {
  86. try {
  87. contentTemplateName = contentTemplateNameUnsafeSupplier.get();
  88. }
  89. catch (RuntimeException re) {
  90. throw re;
  91. }
  92. catch (Exception e) {
  93. throw new RuntimeException(e);
  94. }
  95. }
  96. @GraphQLField(
  97. description = "The name of the template or display page used to render the content."
  98. )
  99. @JsonProperty(access = JsonProperty.Access.READ_WRITE)
  100. protected String contentTemplateName;
  101. @Schema(
  102. description = "The localized names of the template or display page used to render the content."
  103. )
  104. @Valid
  105. public Map<String, String> getContentTemplateName_i18n() {
  106. return contentTemplateName_i18n;
  107. }
  108. public void setContentTemplateName_i18n(
  109. Map<String, String> contentTemplateName_i18n) {
  110. this.contentTemplateName_i18n = contentTemplateName_i18n;
  111. }
  112. @JsonIgnore
  113. public void setContentTemplateName_i18n(
  114. UnsafeSupplier<Map<String, String>, Exception>
  115. contentTemplateName_i18nUnsafeSupplier) {
  116. try {
  117. contentTemplateName_i18n =
  118. contentTemplateName_i18nUnsafeSupplier.get();
  119. }
  120. catch (RuntimeException re) {
  121. throw re;
  122. }
  123. catch (Exception e) {
  124. throw new RuntimeException(e);
  125. }
  126. }
  127. @GraphQLField(
  128. description = "The localized names of the template or display page used to render the content."
  129. )
  130. @JsonProperty(access = JsonProperty.Access.READ_WRITE)
  131. protected Map<String, String> contentTemplateName_i18n;
  132. @Schema(
  133. description = "Specifies if the template or display page are marked as default to display the content."
  134. )
  135. public Boolean getMarkedAsDefault() {
  136. return markedAsDefault;
  137. }
  138. public void setMarkedAsDefault(Boolean markedAsDefault) {
  139. this.markedAsDefault = markedAsDefault;
  140. }
  141. @JsonIgnore
  142. public void setMarkedAsDefault(
  143. UnsafeSupplier<Boolean, Exception> markedAsDefaultUnsafeSupplier) {
  144. try {
  145. markedAsDefault = markedAsDefaultUnsafeSupplier.get();
  146. }
  147. catch (RuntimeException re) {
  148. throw re;
  149. }
  150. catch (Exception e) {
  151. throw new RuntimeException(e);
  152. }
  153. }
  154. @GraphQLField(
  155. description = "Specifies if the template or display page are marked as default to display the content."
  156. )
  157. @JsonProperty(access = JsonProperty.Access.READ_WRITE)
  158. protected Boolean markedAsDefault;
  159. @Schema(description = "An absolute URL to the rendered content.")
  160. public String getRenderedContentURL() {
  161. return renderedContentURL;
  162. }
  163. public void setRenderedContentURL(String renderedContentURL) {
  164. this.renderedContentURL = renderedContentURL;
  165. }
  166. @JsonIgnore
  167. public void setRenderedContentURL(
  168. UnsafeSupplier<String, Exception> renderedContentURLUnsafeSupplier) {
  169. try {
  170. renderedContentURL = renderedContentURLUnsafeSupplier.get();
  171. }
  172. catch (RuntimeException re) {
  173. throw re;
  174. }
  175. catch (Exception e) {
  176. throw new RuntimeException(e);
  177. }
  178. }
  179. @GraphQLField(description = "An absolute URL to the rendered content.")
  180. @JsonProperty(access = JsonProperty.Access.READ_WRITE)
  181. protected String renderedContentURL;
  182. @Schema(
  183. description = "Optional field with the rendered content, can be embedded with nestedFields."
  184. )
  185. public String getRenderedContentValue() {
  186. return renderedContentValue;
  187. }
  188. public void setRenderedContentValue(String renderedContentValue) {
  189. this.renderedContentValue = renderedContentValue;
  190. }
  191. @JsonIgnore
  192. public void setRenderedContentValue(
  193. UnsafeSupplier<String, Exception> renderedContentValueUnsafeSupplier) {
  194. try {
  195. renderedContentValue = renderedContentValueUnsafeSupplier.get();
  196. }
  197. catch (RuntimeException re) {
  198. throw re;
  199. }
  200. catch (Exception e) {
  201. throw new RuntimeException(e);
  202. }
  203. }
  204. @GraphQLField(
  205. description = "Optional field with the rendered content, can be embedded with nestedFields."
  206. )
  207. @JsonProperty(access = JsonProperty.Access.READ_WRITE)
  208. protected String renderedContentValue;
  209. @Override
  210. public boolean equals(Object object) {
  211. if (this == object) {
  212. return true;
  213. }
  214. if (!(object instanceof RenderedContent)) {
  215. return false;
  216. }
  217. RenderedContent renderedContent = (RenderedContent)object;
  218. return Objects.equals(toString(), renderedContent.toString());
  219. }
  220. @Override
  221. public int hashCode() {
  222. String string = toString();
  223. return string.hashCode();
  224. }
  225. public String toString() {
  226. StringBundler sb = new StringBundler();
  227. sb.append("{");
  228. if (contentTemplateId != null) {
  229. if (sb.length() > 1) {
  230. sb.append(", ");
  231. }
  232. sb.append("\"contentTemplateId\": ");
  233. sb.append("\"");
  234. sb.append(_escape(contentTemplateId));
  235. sb.append("\"");
  236. }
  237. if (contentTemplateName != null) {
  238. if (sb.length() > 1) {
  239. sb.append(", ");
  240. }
  241. sb.append("\"contentTemplateName\": ");
  242. sb.append("\"");
  243. sb.append(_escape(contentTemplateName));
  244. sb.append("\"");
  245. }
  246. if (contentTemplateName_i18n != null) {
  247. if (sb.length() > 1) {
  248. sb.append(", ");
  249. }
  250. sb.append("\"contentTemplateName_i18n\": ");
  251. sb.append(_toJSON(contentTemplateName_i18n));
  252. }
  253. if (markedAsDefault != null) {
  254. if (sb.length() > 1) {
  255. sb.append(", ");
  256. }
  257. sb.append("\"markedAsDefault\": ");
  258. sb.append(markedAsDefault);
  259. }
  260. if (renderedContentURL != null) {
  261. if (sb.length() > 1) {
  262. sb.append(", ");
  263. }
  264. sb.append("\"renderedContentURL\": ");
  265. sb.append("\"");
  266. sb.append(_escape(renderedContentURL));
  267. sb.append("\"");
  268. }
  269. if (renderedContentValue != null) {
  270. if (sb.length() > 1) {
  271. sb.append(", ");
  272. }
  273. sb.append("\"renderedContentValue\": ");
  274. sb.append("\"");
  275. sb.append(_escape(renderedContentValue));
  276. sb.append("\"");
  277. }
  278. sb.append("}");
  279. return sb.toString();
  280. }
  281. @Schema(
  282. accessMode = Schema.AccessMode.READ_ONLY,
  283. defaultValue = "com.liferay.headless.delivery.dto.v1_0.RenderedContent",
  284. name = "x-class-name"
  285. )
  286. public String xClassName;
  287. private static String _escape(Object object) {
  288. String string = String.valueOf(object);
  289. return string.replaceAll("\"", "\\\\\"");
  290. }
  291. private static boolean _isArray(Object value) {
  292. if (value == null) {
  293. return false;
  294. }
  295. Class<?> clazz = value.getClass();
  296. return clazz.isArray();
  297. }
  298. private static String _toJSON(Map<String, ?> map) {
  299. StringBuilder sb = new StringBuilder("{");
  300. @SuppressWarnings("unchecked")
  301. Set set = map.entrySet();
  302. @SuppressWarnings("unchecked")
  303. Iterator<Map.Entry<String, ?>> iterator = set.iterator();
  304. while (iterator.hasNext()) {
  305. Map.Entry<String, ?> entry = iterator.next();
  306. sb.append("\"");
  307. sb.append(entry.getKey());
  308. sb.append("\": ");
  309. Object value = entry.getValue();
  310. if (_isArray(value)) {
  311. sb.append("[");
  312. Object[] valueArray = (Object[])value;
  313. for (int i = 0; i < valueArray.length; i++) {
  314. if (valueArray[i] instanceof String) {
  315. sb.append("\"");
  316. sb.append(valueArray[i]);
  317. sb.append("\"");
  318. }
  319. else {
  320. sb.append(valueArray[i]);
  321. }
  322. if ((i + 1) < valueArray.length) {
  323. sb.append(", ");
  324. }
  325. }
  326. sb.append("]");
  327. }
  328. else if (value instanceof Map) {
  329. sb.append(_toJSON((Map<String, ?>)value));
  330. }
  331. else if (value instanceof String) {
  332. sb.append("\"");
  333. sb.append(value);
  334. sb.append("\"");
  335. }
  336. else {
  337. sb.append(value);
  338. }
  339. if (iterator.hasNext()) {
  340. sb.append(", ");
  341. }
  342. }
  343. sb.append("}");
  344. return sb.toString();
  345. }
  346. }