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

com.liferay.apio.architect.representor.Representor 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.identifier.Identifier;

import java.util.function.Function;

/**
 * Holds information about the metadata supported for a resource.
 *
 * 

* Instances of this interface should always be created by using a {@link * Representor.Builder}. *

* * @author Alejandro Hernández * @param the model's type * @see Representor.Builder */ @ProviderType public interface Representor extends BaseRepresentor { /** * Returns the model's identifier. * * @param model the model instance * @return the model's identifier */ public Object getIdentifier(T model); /** * Creates generic representations of your domain models that Apio * hypermedia writers can understand. * * @param the model's type * @param the type of the model's identifier (e.g., {@code Long}, {@code * String}, etc.) */ @ProviderType public interface Builder { /** * Adds a type for the model. * * @param type the type name * @param types the rest of the types * @return the builder's step */ public IdentifierStep types(String type, String... types); } @ProviderType public interface FirstStep extends BaseFirstStep, FirstStep> { /** * Adds information about the bidirectional relation of a linked * resource in the actual resource and a collection of items in the * related resource. * * @param key the relation's name in the resource * @param relatedKey the relation's name in the related resource * @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 FirstStep addBidirectionalModel( String key, String relatedKey, Class> identifierClass, Function modelToIdentifierFunction); /** * 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 FirstStep addRelatedCollection( String key, Class itemIdentifierClass); } @ProviderType public interface IdentifierStep { /** * Provides a lambda function that can be used to obtain a model's * identifier. * * @param modelToIdentifierFunction lambda function used to obtain a * model's identifier * @return the builder's next step */ public FirstStep identifier( Function modelToIdentifierFunction); } }