001/*
002 * (C) Copyright 2010 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 *     Anahide Tchertchian
018 */
019package org.nuxeo.ecm.platform.query.api;
020
021import java.io.Serializable;
022import java.util.List;
023import java.util.Map;
024import java.util.Set;
025
026import org.nuxeo.ecm.core.api.DocumentModel;
027import org.nuxeo.ecm.core.api.SortInfo;
028
029/**
030 * @author Anahide Tchertchian
031 * @since 5.4
032 */
033public interface PageProviderService extends Serializable {
034
035    /**
036     * Name of the search document model context map property holding named parameters.
037     *
038     * @since 7.1
039     */
040    public static final String NAMED_PARAMETERS = "namedParameters";
041
042    /**
043     * Returns a named page provider definition.
044     * <p>
045     * Useful to share the definition between the page provider service, and the content view service (as content views
046     * can reference a named page provider that is already registered instead of redefining it).
047     *
048     * @since 5.4
049     * @param name the page provider name
050     * @return the page provider definition or null, if no page provider with this name was found.
051     */
052    PageProviderDefinition getPageProviderDefinition(String name);
053
054    /**
055     * Returns an instance of a page provider with given name and definition.
056     *
057     * @since 5.4
058     * @deprecated since 5.7: use
059     *             {@link #getPageProvider(String, PageProviderDefinition, DocumentModel, List, Long, Long, Map, Object...)}
060     *             with search document model as additional parameter
061     */
062    @Deprecated
063    PageProvider<?> getPageProvider(String name, PageProviderDefinition desc, List<SortInfo> sortInfos, Long pageSize,
064            Long currentPage, Map<String, Serializable> properties, Object... parameters);
065
066    /**
067     * Returns an instance of page provider with given name and definition.
068     * <p>
069     * Useful to share the definition between the page provider service, and the content view service (as content views
070     * can reference a named page provider that is already registered instead of redefining it).
071     * <p>
072     * If not null, parameters sortInfos and pageSize will override information computed in the XML file. If not null,
073     * currentPage will override default current page (0).
074     *
075     * @param name the name that will be set on the provider.
076     * @param desc the definition used to build the provider instance.
077     * @param searchDocument the search document to be used by the provider.
078     * @param sortInfos sort information to set on the provider instance.
079     * @param pageSize the provider page size.
080     * @param currentPage the provider current page index.
081     * @param properties the provider properties
082     * @param parameters the provider parameters.
083     * @return the page provider instance.
084     * @since 5.7
085     */
086    PageProvider<?> getPageProvider(String name, PageProviderDefinition desc, DocumentModel searchDocument,
087            List<SortInfo> sortInfos, Long pageSize, Long currentPage, Map<String, Serializable> properties,
088            Object... parameters);
089
090    /**
091     * Returns an instance of page provider with given name.
092     *
093     * @param name the page provider name
094     * @param sortInfos sort information to set on the provider instance.
095     * @param pageSize the provider page size.
096     * @param currentPage the provider current page index.
097     * @param properties the provider properties
098     * @param parameters the provider parameters.
099     * @return the page provider instance.
100     * @since 5.4
101     */
102    PageProvider<?> getPageProvider(String name, List<SortInfo> sortInfos, Long pageSize, Long currentPage,
103            Map<String, Serializable> properties, Object... parameters);
104
105    /**
106     * Returns an instance of page provider with given name.
107     *
108     * @see #getPageProvider(String, PageProviderDefinition, DocumentModel, List, Long, Long, Map, Object...)
109     * @since 5.7
110     */
111    PageProvider<?> getPageProvider(String name, DocumentModel searchDocument, List<SortInfo> sortInfos, Long pageSize,
112            Long currentPage, Map<String, Serializable> properties, Object... parameters);
113
114    /**
115     * Returns an instance of page provider with given name.
116     *
117     * @see #getPageProvider(String, PageProviderDefinition, DocumentModel, List, Long, Long, Map, Object...)
118     * @since 8.4
119     */
120    PageProvider<?> getPageProvider(String name, DocumentModel searchDocument, List<SortInfo> sortInfos, Long pageSize,
121            Long currentPage, Map<String, Serializable> properties, List<QuickFilter> quickFilters,
122            Object... parameters);
123
124    /**
125     * Returns an instance of page provider with given name.
126     *
127     * @see #getPageProvider(String, PageProviderDefinition, DocumentModel, List, Long, Long, Map, Object...)
128     * @since 8.4
129     */
130    PageProvider<?> getPageProvider(String name, PageProviderDefinition desc, DocumentModel searchDocument,
131            List<SortInfo> sortInfos, Long pageSize, Long currentPage, Map<String, Serializable> properties,
132            List<QuickFilter> quickFilters, Object... parameters);
133
134    /**
135     * @since 6.0
136     */
137    void registerPageProviderDefinition(PageProviderDefinition desc);
138
139    /**
140     * @since 6.0
141     */
142    void unregisterPageProviderDefinition(PageProviderDefinition desc);
143
144    /**
145     * Returns all the registered page provider names, or an empty set if no page provider is registered.
146     *
147     * @since 6.0
148     */
149    Set<String> getPageProviderDefinitionNames();
150
151}