001/*
002 * (C) Copyright 2010-2016 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *   Nuxeo - initial API and implementation
018 */
019package org.nuxeo.ecm.platform.rendition.service;
020
021import java.io.Serializable;
022import java.util.List;
023import java.util.Map;
024
025import org.nuxeo.ecm.core.api.DocumentModel;
026import org.nuxeo.ecm.core.api.DocumentRef;
027import org.nuxeo.ecm.platform.rendition.Rendition;
028
029/**
030 * Service handling Rendition Definitions and actual render based on a Rendition Definition
031 *
032 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
033 * @author <a href="mailto:tdelprat@nuxeo.com">Tiry</a>
034 * @since 5.4.1
035 */
036public interface RenditionService {
037
038    /**
039     * Returns a {@code List} of registered {@code RenditionDefinition}. The order of the List does not depend on the
040     * registering order.
041     *
042     * @deprecated since 7.2 because unused
043     */
044    @Deprecated
045    List<RenditionDefinition> getDeclaredRenditionDefinitions();
046
047    /**
048     * Returns a {@code List} of registered {@code RenditionDefinition} matching a given provider type
049     *
050     * @deprecated since 7.2 because unused
051     */
052    @Deprecated
053    List<RenditionDefinition> getDeclaredRenditionDefinitionsForProviderType(String providerType);
054
055    /**
056     * Returns a {@code List} of {@code RenditionDefinition} available on the given Document. The order of the List does
057     * not depend on the registering order.
058     */
059    List<RenditionDefinition> getAvailableRenditionDefinitions(DocumentModel doc);
060
061    /**
062     * Returns the {@code RenditionDefinition} available on the given document for the given rendition definition name.
063     *
064     * @since 10.10
065     */
066    RenditionDefinition getAvailableRenditionDefinition(DocumentModel doc, String renditionName);
067
068    /**
069     * Render a document based on the given rendition definition name and returns the stored Rendition
070     * {@link DocumentRef}.
071     * <p>
072     * Only the user launching the render operation has the Read right on the returned document.
073     *
074     * @param sourceDocument the document to render
075     * @param renditionDefinitionName the rendition definition to use
076     * @return the {@code DocumentRef} of the newly created Rendition document.
077     */
078    DocumentRef storeRendition(DocumentModel sourceDocument, String renditionDefinitionName);
079
080    /**
081     * Return the {@link Rendition} object for the given {@link DocumentModel} and a rendition definition name.
082     * <p>
083     * A stored rendition is returned if found and up to date, a new Rendition is created otherwise.
084     *
085     * @param doc the document to render
086     * @param renditionName the name of the rendition definition
087     * @return the {@link Rendition} object
088     */
089    Rendition getRendition(DocumentModel doc, String renditionName);
090
091    /**
092     * Same as {@link #getDefaultRendition(DocumentModel, String, boolean, Map)} with store parameter set to false.
093     *
094     * @param doc the document to render
095     * @param reason the reason the rendition is being rendered (optional)
096     * @param extendedInfos map of extended info added in the default rendition computation (optional)
097     * @since 9.10
098     * @return the default {@link Rendition} object
099     */
100    Rendition getDefaultRendition(DocumentModel doc, String reason, Map<String, Serializable> extendedInfos);
101
102    /**
103     * Return the default {@link Rendition} object for the given {@link DocumentModel}.
104     * <p>
105     * A stored rendition is returned if found and up to date, a new Rendition is created otherwise.
106     *
107     * @param doc the document to render
108     * @param reason the reason the rendition is being rendered (optional)
109     * @param store indicates if the rendition must be stored
110     * @param extendedInfos map of extended info added in the default rendition computation (optional)
111     * @since 10.3
112     * @return the default {@link Rendition} object
113     */
114    Rendition getDefaultRendition(DocumentModel doc, String reason, boolean store,
115            Map<String, Serializable> extendedInfos);
116
117    /**
118     * Return the {@link Rendition} object for the given {@link DocumentModel} and a rendition definition name.
119     * <p>
120     * A stored rendition is returned if found and up to date, a new (live) Rendition is created and returned otherwise.
121     * <p>
122     * If store parameter is true, the new created rendition is stored too unless it is marked as stale.
123     *
124     * @param doc the document to render
125     * @param renditionName the name of the rendition definition
126     * @param store indicates if the rendition must be stored
127     * @return the {@link Rendition} object
128     */
129    Rendition getRendition(DocumentModel doc, String renditionName, boolean store);
130
131    /**
132     * Returns a {@code List} of {@code Rendition} available on the given Document.
133     * <p>
134     * The order of the List does not depend on the registering order.
135     * <p>
136     * The returned rendition may be live or stored
137     */
138    List<Rendition> getAvailableRenditions(DocumentModel doc);
139
140    /**
141     * Returns a {@code List} of {@code Rendition} available on the given Document.
142     * <p>
143     * If {@code onlyVisible} is true, returns only the rendition marked as visible.
144     * <p>
145     * The order of the List does not depend on the registering order.
146     * <p>
147     * The returned rendition may be live or stored
148     *
149     * @since 7.2
150     */
151    List<Rendition> getAvailableRenditions(DocumentModel doc, boolean onlyVisible);
152
153    /**
154     * Query and delete stored renditions where the related version or live document does not exist anymore.
155     *
156     * @since 8.4
157     */
158    void deleteStoredRenditions(String repositoryName);
159
160    /**
161     * Publish a document's rendition. If the rendition name is not given, it publishes its default rendition obtained
162     * from {@link #getDefaultRendition(DocumentModel, String, Map)}.
163     *
164     * @param doc the document to be published
165     * @param target the location where to publish
166     * @param renditionName the rendition to be published
167     * @param override if true, will remove existing publication of the document
168     * @return the published document
169     * @since 10.3
170     */
171    DocumentModel publishRendition(DocumentModel doc, DocumentModel target, String renditionName, boolean override);
172}