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.util.List;
022
023import org.nuxeo.ecm.core.api.DocumentModel;
024import org.nuxeo.ecm.core.api.DocumentRef;
025import org.nuxeo.ecm.platform.rendition.Rendition;
026
027/**
028 * Service handling Rendition Definitions and actual render based on a Rendition Definition
029 *
030 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
031 * @author <a href="mailto:tdelprat@nuxeo.com">Tiry</a>
032 * @since 5.4.1
033 */
034public interface RenditionService {
035
036    /**
037     * Returns a {@code List} of registered {@code RenditionDefinition}. The order of the List does not depend on the
038     * registering order.
039     *
040     * @deprecated since 7.2 because unused
041     */
042    @Deprecated
043    List<RenditionDefinition> getDeclaredRenditionDefinitions();
044
045    /**
046     * Returns a {@code List} of registered {@code RenditionDefinition} matching a given provider type
047     *
048     * @deprecated since 7.2 because unused
049     */
050    @Deprecated
051    List<RenditionDefinition> getDeclaredRenditionDefinitionsForProviderType(String providerType);
052
053    /**
054     * Returns a {@code List} of {@code RenditionDefinition} available on the given Document. The order of the List does
055     * not depend on the registering order.
056     */
057    List<RenditionDefinition> getAvailableRenditionDefinitions(DocumentModel doc);
058
059    /**
060     * Render a document based on the given rendition definition name and returns the stored Rendition
061     * {@link DocumentRef}.
062     * <p>
063     * Only the user launching the render operation has the Read right on the returned document.
064     *
065     * @param sourceDocument the document to render
066     * @param renditionDefinitionName the rendition definition to use
067     * @return the {@code DocumentRef} of the newly created Rendition document.
068     */
069    DocumentRef storeRendition(DocumentModel sourceDocument, String renditionDefinitionName);
070
071    /**
072     * Return the {@link Rendition} object for the given {@link DocumentModel} and a rendition definition name.
073     * <p>
074     * A stored rendition is returned if found and up to date, a new Rendition is created otherwise.
075     *
076     * @param doc the document to render
077     * @param renditionName the name of the rendition definition
078     * @return the {@link Rendition} object
079     */
080    Rendition getRendition(DocumentModel doc, String renditionName);
081
082    /**
083     * Return the {@link Rendition} object for the given {@link DocumentModel} and a rendition definition name.
084     * <p>
085     * A stored rendition is returned if found and up to date, a new (live) Rendition is created otherwise.
086     * <p>
087     * If store parameter is true, the new created rendition is stored too and returned
088     *
089     * @param doc the document to render
090     * @param renditionName the name of the rendition definition
091     * @param store indicates if the rendition must be stored
092     * @return the {@link Rendition} object
093     */
094    Rendition getRendition(DocumentModel doc, String renditionName, boolean store);
095
096    /**
097     * Returns a {@code List} of {@code Rendition} available on the given Document.
098     * <p>
099     * The order of the List does not depend on the registering order.
100     * <p>
101     * The returned rendition may be live or stored
102     */
103    List<Rendition> getAvailableRenditions(DocumentModel doc);
104
105    /**
106     * Returns a {@code List} of {@code Rendition} available on the given Document.
107     * <p>
108     * If {@code onlyVisible} is true, returns only the rendition marked as visible.
109     * <p>
110     * The order of the List does not depend on the registering order.
111     * <p>
112     * The returned rendition may be live or stored
113     *
114     * @since 7.2
115     */
116    List<Rendition> getAvailableRenditions(DocumentModel doc, boolean onlyVisible);
117
118    /**
119     * Query and delete stored renditions where the related version or live document does not exist anymore.
120     *
121     * @since 8.4
122     */
123    void deleteStoredRenditions(String repositoryName);
124}