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

com.liferay.apio.architect.representor.BaseRepresentor Maven / Gradle / Ivy

There is a newer version: 7.4.3.112-ga112
Show newest version
/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.liferay.apio.architect.representor;

import aQute.bnd.annotation.ProviderType;

import com.liferay.apio.architect.alias.BinaryFunction;
import com.liferay.apio.architect.alias.representor.FieldFunction;
import com.liferay.apio.architect.alias.representor.NestedFieldFunction;
import com.liferay.apio.architect.alias.representor.NestedListFieldFunction;
import com.liferay.apio.architect.file.BinaryFile;
import com.liferay.apio.architect.identifier.Identifier;
import com.liferay.apio.architect.language.AcceptLanguage;
import com.liferay.apio.architect.related.RelatedCollection;
import com.liferay.apio.architect.related.RelatedModel;

import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Stream;

/**
 * Base class for {@code Representors}.
 *
 * 

* Descendants of this class holds information about the metadata supported for * a resource. *

* *

* Only two descendants are allowed: {@link Representor} and {@link * NestedRepresentor}. *

* * @author Alejandro Hernández * @param the model's type */ @ProviderType public interface BaseRepresentor { /** * Returns the list that contains the application relative URL field names * and the functions to get those fields. * * @return the list */ public List> getApplicationRelativeURLFunctions(); /** * Returns a binary resource linked to a model, if present; returns {@code * Optional#empty} otherwise. * * @param binaryId the ID of the binary resource * @return the binary resource, if present; {@code Optional#empty()} * otherwise */ public Optional> getBinaryFunction(String binaryId); /** * Returns the binary functions linked to a model. * * @return the binary functions linked to a model */ public List> getBinaryFunctions(); /** * Returns the list containing the boolean field names and the functions to * get those fields. * * @return the list containing the boolean field names and functions */ public List> getBooleanFunctions(); /** * Returns the list containing the boolean list field names and the * functions to get those fields. * * @return the list containing the boolean list field names and functions */ public List>> getBooleanListFunctions(); /** * Returns the list containing the links field names and the functions to * get those links. * * @return the list containing the links field names and functions */ public List> getLinkFunctions(); /** * Returns a map containing the localized string field names and the * functions to get those fields. * * @return the list containing the localized string field names and * functions */ public List>> getLocalizedStringFunctions(); /** * Returns the list of nested field functions. * * @return the list */ public List> getNestedFieldFunctions(); /** * Returns the list of nested list field functions. * * @return the list */ public List> getNestedListFieldFunctions(); /** * Returns the list containing the number field names and the functions to * get those fields. * * @return the list containing the number field names and functions */ public List> getNumberFunctions(); /** * Returns the list containing the number list field names and the functions * to get those fields. * * @return the list containing the number list field names and functions */ public List>> getNumberListFunctions(); /** * Returns the primary type. * * @return the primary type */ public String getPrimaryType(); /** * Returns the related collections. * * @return the related collections */ public Stream> getRelatedCollections(); /** * Returns the related models. * * @return the related models */ public List> getRelatedModels(); /** * Returns the list containing the relative URL field names and the * functions to get those fields. * * @return the list containing the relative URL field names and functions */ public List> getRelativeURLFunctions(); /** * Returns the list containing the string field names and the functions to * get those fields. * * @return the list containing the string field names and functions */ public List> getStringFunctions(); /** * Returns the list containing the string list field names and the functions * to get those fields. * * @return the list containing the string list field names and functions */ public List>> getStringListFunctions(); /** * Returns the types. * * @return the types */ public List getTypes(); /** * Whether this representor is a {@link NestedRepresentor}. * * @return {@code true} if this this representor is a nested representor; * {@code false} otherwise */ public boolean isNested(); @ProviderType public interface BaseFirstStep , U extends BaseFirstStep> { /** * Adds information about a resource's application relative URL field. * This field's value will be represented as an absolute URI, by * prefixing it with the application URL. * *

* URLs returned by this function should already be encoded (to check * for potential security holes). *

* * @param key the field's name * @param function the function used to get the relative URL * @return the builder's step */ public U addApplicationRelativeURL( String key, Function function); /** * Adds binary files to a resource. * * @param key the binary resource's name * @param binaryFunction the function used to get the binaries * @return the builder's step */ public U addBinary(String key, BinaryFunction binaryFunction); /** * Adds information about a resource's boolean field. * * @param key the field's name * @param function the function used to get the boolean value * @return the builder's step */ public U addBoolean(String key, Function function); /** * Adds information about a resource's boolean list field. * * @param key the field's name * @param function the function used to get the boolean list * @return the builder's step */ public U addBooleanList( String key, Function> function); /** * Adds information about a resource's date field. * * @param key the field's name * @param function the function used to get the date value * @return the builder's step */ public U addDate(String key, Function function); /** * Adds information about a resource link. * * @param key the field's name * @param url the link's URL * @return the builder's step */ public U addLink(String key, String url); /** * Adds information about an embeddable related resource. * * @param key the relation's name * @param identifierClass the related resource identifier's class * @param modelToIdentifierFunction the function used to get the * related resource's identifier * @return the builder's step */ public U addLinkedModel( String key, Class> identifierClass, Function modelToIdentifierFunction); /** * Provides information about a resource localized string field. * * @param key the field's name * @param stringFunction the function used to get the string value * @return builder's step */ public U addLocalizedStringByLanguage( String key, BiFunction stringFunction); /** * Provides information about a resource localized string field. * * @param key the field's name * @param stringFunction the function used to get the string value * @return builder's step */ public U addLocalizedStringByLocale( String key, BiFunction stringFunction); /** * Provides information about a nested field. * * @param key the field's name * @param transformFunction the function that transforms the model into * the model used inside the nested representor * @param function the function that creates the nested representor * @return the builder's step */ public U addNested( String key, Function transformFunction, Function, NestedRepresentor> function); /** * Adds a nested list field to the representor. * * @param key the field's name * @param transformFunction the function that transforms the model into * the list whose models are used inside the nested representor * @param function the function that creates the nested representor for * each model */ public U addNestedList( String key, Function> transformFunction, Function, NestedRepresentor> function); /** * Adds information about a resource's number field. * * @param key the field's name * @param function the function used to get the number's value * @return the builder's step */ public U addNumber(String key, Function function); /** * Adds information about a resource's number list field. * * @param key the field's name * @param function the function used to get the number list * @return the builder's step */ public U addNumberList(String key, Function> function); /** * Adds information about a related collection. * * @param key the relation's name * @param itemIdentifierClass the class of the collection items' * identifier * @return the builder's step */ public > U addRelatedCollection( String key, Class itemIdentifierClass, Function modelToIdentifierFunction); /** * Adds information about a resource's relative URL field. This field's * value will be represented as an absolute URI, by prefixing it with * the server URL. * *

* URLs returned by this function should already be encoded (to check * for potential security holes). *

* * @param key the field's name * @param function the function used to get the relative URL * @return the builder's step */ public U addRelativeURL(String key, Function function); /** * Adds information about a resource's string field. * * @param key the field's name * @param function the function used to get the string's value * @return the builder's step */ public U addString(String key, Function function); /** * Adds information about a resource's string list field. * * @param key the field's name * @param function the function used to get the string list * @return the builder's step */ public U addStringList(String key, Function> function); /** * Constructs and returns a {@link NestedRepresentor} instance with the * information provided to the builder. * * @return the {@code Representor} instance */ public S build(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy