All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.liferay.headless.delivery.dto.v1_0.PageDefinition Maven / Gradle / Ivy

The newest version!
/**
 * SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
 * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
 */

package com.liferay.headless.delivery.dto.v1_0;

import com.fasterxml.jackson.annotation.JsonFilter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

import com.liferay.petra.function.UnsafeSupplier;
import com.liferay.petra.string.StringBundler;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.vulcan.graphql.annotation.GraphQLField;
import com.liferay.portal.vulcan.graphql.annotation.GraphQLName;
import com.liferay.portal.vulcan.util.ObjectMapperUtil;

import jakarta.annotation.Generated;

import jakarta.validation.Valid;

import jakarta.xml.bind.annotation.XmlRootElement;

import java.io.Serializable;

import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Supplier;

/**
 * @author Javier Gamarra
 * @generated
 */
@Generated("")
@GraphQLName(
	description = "Represent a definition of a Page.", value = "PageDefinition"
)
@JsonFilter("Liferay.Vulcan")
@XmlRootElement(name = "PageDefinition")
public class PageDefinition implements Serializable {

	public static PageDefinition toDTO(String json) {
		return ObjectMapperUtil.readValue(PageDefinition.class, json);
	}

	public static PageDefinition unsafeToDTO(String json) {
		return ObjectMapperUtil.unsafeReadValue(PageDefinition.class, json);
	}

	@io.swagger.v3.oas.annotations.media.Schema(
		description = "The page's page element."
	)
	@Valid
	public PageElement getPageElement() {
		if (_pageElementSupplier != null) {
			pageElement = _pageElementSupplier.get();

			_pageElementSupplier = null;
		}

		return pageElement;
	}

	public void setPageElement(PageElement pageElement) {
		this.pageElement = pageElement;

		_pageElementSupplier = null;
	}

	@JsonIgnore
	public void setPageElement(
		UnsafeSupplier pageElementUnsafeSupplier) {

		_pageElementSupplier = () -> {
			try {
				return pageElementUnsafeSupplier.get();
			}
			catch (RuntimeException runtimeException) {
				throw runtimeException;
			}
			catch (Exception exception) {
				throw new RuntimeException(exception);
			}
		};
	}

	@GraphQLField(description = "The page's page element.")
	@JsonProperty(access = JsonProperty.Access.READ_WRITE)
	protected PageElement pageElement;

	@JsonIgnore
	private Supplier _pageElementSupplier;

	@io.swagger.v3.oas.annotations.media.Schema(
		description = "A list of the page rules this page has."
	)
	@Valid
	public PageRule[] getPageRules() {
		if (_pageRulesSupplier != null) {
			pageRules = _pageRulesSupplier.get();

			_pageRulesSupplier = null;
		}

		return pageRules;
	}

	public void setPageRules(PageRule[] pageRules) {
		this.pageRules = pageRules;

		_pageRulesSupplier = null;
	}

	@JsonIgnore
	public void setPageRules(
		UnsafeSupplier pageRulesUnsafeSupplier) {

		_pageRulesSupplier = () -> {
			try {
				return pageRulesUnsafeSupplier.get();
			}
			catch (RuntimeException runtimeException) {
				throw runtimeException;
			}
			catch (Exception exception) {
				throw new RuntimeException(exception);
			}
		};
	}

	@GraphQLField(description = "A list of the page rules this page has.")
	@JsonProperty(access = JsonProperty.Access.READ_WRITE)
	protected PageRule[] pageRules;

	@JsonIgnore
	private Supplier _pageRulesSupplier;

	@io.swagger.v3.oas.annotations.media.Schema(
		description = "The page's settings."
	)
	@Valid
	public Settings getSettings() {
		if (_settingsSupplier != null) {
			settings = _settingsSupplier.get();

			_settingsSupplier = null;
		}

		return settings;
	}

	public void setSettings(Settings settings) {
		this.settings = settings;

		_settingsSupplier = null;
	}

	@JsonIgnore
	public void setSettings(
		UnsafeSupplier settingsUnsafeSupplier) {

		_settingsSupplier = () -> {
			try {
				return settingsUnsafeSupplier.get();
			}
			catch (RuntimeException runtimeException) {
				throw runtimeException;
			}
			catch (Exception exception) {
				throw new RuntimeException(exception);
			}
		};
	}

	@GraphQLField(description = "The page's settings.")
	@JsonProperty(access = JsonProperty.Access.READ_WRITE)
	protected Settings settings;

	@JsonIgnore
	private Supplier _settingsSupplier;

	@io.swagger.v3.oas.annotations.media.Schema(
		description = "The version of the JSON generated by page definition."
	)
	public Double getVersion() {
		if (_versionSupplier != null) {
			version = _versionSupplier.get();

			_versionSupplier = null;
		}

		return version;
	}

	public void setVersion(Double version) {
		this.version = version;

		_versionSupplier = null;
	}

	@JsonIgnore
	public void setVersion(
		UnsafeSupplier versionUnsafeSupplier) {

		_versionSupplier = () -> {
			try {
				return versionUnsafeSupplier.get();
			}
			catch (RuntimeException runtimeException) {
				throw runtimeException;
			}
			catch (Exception exception) {
				throw new RuntimeException(exception);
			}
		};
	}

	@GraphQLField(
		description = "The version of the JSON generated by page definition."
	)
	@JsonProperty(access = JsonProperty.Access.READ_WRITE)
	protected Double version;

	@JsonIgnore
	private Supplier _versionSupplier;

	@Override
	public boolean equals(Object object) {
		if (this == object) {
			return true;
		}

		if (!(object instanceof PageDefinition)) {
			return false;
		}

		PageDefinition pageDefinition = (PageDefinition)object;

		return Objects.equals(toString(), pageDefinition.toString());
	}

	@Override
	public int hashCode() {
		String string = toString();

		return string.hashCode();
	}

	public String toString() {
		StringBundler sb = new StringBundler();

		sb.append("{");

		PageElement pageElement = getPageElement();

		if (pageElement != null) {
			if (sb.length() > 1) {
				sb.append(", ");
			}

			sb.append("\"pageElement\": ");

			sb.append(String.valueOf(pageElement));
		}

		PageRule[] pageRules = getPageRules();

		if (pageRules != null) {
			if (sb.length() > 1) {
				sb.append(", ");
			}

			sb.append("\"pageRules\": ");

			sb.append("[");

			for (int i = 0; i < pageRules.length; i++) {
				sb.append(String.valueOf(pageRules[i]));

				if ((i + 1) < pageRules.length) {
					sb.append(", ");
				}
			}

			sb.append("]");
		}

		Settings settings = getSettings();

		if (settings != null) {
			if (sb.length() > 1) {
				sb.append(", ");
			}

			sb.append("\"settings\": ");

			sb.append(String.valueOf(settings));
		}

		Double version = getVersion();

		if (version != null) {
			if (sb.length() > 1) {
				sb.append(", ");
			}

			sb.append("\"version\": ");

			sb.append(version);
		}

		sb.append("}");

		return sb.toString();
	}

	@io.swagger.v3.oas.annotations.media.Schema(
		accessMode = io.swagger.v3.oas.annotations.media.Schema.AccessMode.READ_ONLY,
		defaultValue = "com.liferay.headless.delivery.dto.v1_0.PageDefinition",
		name = "x-class-name"
	)
	public String xClassName;

	private static String _escape(Object object) {
		return StringUtil.replace(
			String.valueOf(object), _JSON_ESCAPE_STRINGS[0],
			_JSON_ESCAPE_STRINGS[1]);
	}

	private static boolean _isArray(Object value) {
		if (value == null) {
			return false;
		}

		Class clazz = value.getClass();

		return clazz.isArray();
	}

	private static String _toJSON(Map map) {
		StringBuilder sb = new StringBuilder("{");

		@SuppressWarnings("unchecked")
		Set set = map.entrySet();

		@SuppressWarnings("unchecked")
		Iterator> iterator = set.iterator();

		while (iterator.hasNext()) {
			Map.Entry entry = iterator.next();

			sb.append("\"");
			sb.append(_escape(entry.getKey()));
			sb.append("\": ");

			Object value = entry.getValue();

			if (_isArray(value)) {
				sb.append("[");

				Object[] valueArray = (Object[])value;

				for (int i = 0; i < valueArray.length; i++) {
					if (valueArray[i] instanceof Map) {
						sb.append(_toJSON((Map)valueArray[i]));
					}
					else if (valueArray[i] instanceof String) {
						sb.append("\"");
						sb.append(valueArray[i]);
						sb.append("\"");
					}
					else {
						sb.append(valueArray[i]);
					}

					if ((i + 1) < valueArray.length) {
						sb.append(", ");
					}
				}

				sb.append("]");
			}
			else if (value instanceof Map) {
				sb.append(_toJSON((Map)value));
			}
			else if (value instanceof String) {
				sb.append("\"");
				sb.append(_escape(value));
				sb.append("\"");
			}
			else {
				sb.append(value);
			}

			if (iterator.hasNext()) {
				sb.append(", ");
			}
		}

		sb.append("}");

		return sb.toString();
	}

	private static final String[][] _JSON_ESCAPE_STRINGS = {
		{"\\", "\"", "\b", "\f", "\n", "\r", "\t"},
		{"\\\\", "\\\"", "\\b", "\\f", "\\n", "\\r", "\\t"}
	};

	private Map _extendedProperties;

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy