001/*
002 *  Copyright 2015 Anyware Services
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 */
016package org.ametys.cms.search.ui.model;
017
018import java.util.Map;
019
020import org.ametys.cms.search.model.SearchModel;
021import org.ametys.cms.search.model.SearchModelCriterionDefinition;
022import org.ametys.cms.search.model.SearchModelHelper;
023import org.ametys.cms.search.ui.model.impl.DefaultSearchModelCriterionViewItem;
024import org.ametys.runtime.model.ElementDefinition;
025import org.ametys.runtime.model.ModelViewItem;
026import org.ametys.runtime.model.ViewItem;
027import org.ametys.runtime.model.ViewItemContainer;
028
029/**
030 * Search tool model.
031 */
032public interface SearchUIModel extends SearchModel
033{
034    default void addCriterion(SearchModelCriterionDefinition criterion, Map<String, Object> contextualParameters)
035    {
036        ModelViewItem<ElementDefinition> viewItem = new DefaultSearchModelCriterionViewItem();
037        viewItem.setDefinition(criterion);
038        
039        addCriterion(viewItem, contextualParameters);
040    }
041    
042    /**
043     * Add the given criterion to the simple criteria
044     * @param criterion the criterion to add
045     * @param contextualParameters the contextual parameters
046     */
047    default void addCriterion(ViewItem criterion, Map<String, Object> contextualParameters)
048    {
049        ViewItemContainer criteria = getCriteria(contextualParameters);
050        criteria.addViewItem(criterion);
051    }
052    
053    default void addFacetedCriterion(SearchModelCriterionDefinition criterion, Map<String, Object> contextualParameters)
054    {
055        SearchModelCriterionViewItem<ElementDefinition> viewItem = new DefaultSearchModelCriterionViewItem();
056        viewItem.setDefinition(criterion);
057        
058        addFacetedCriterion(viewItem, contextualParameters);
059    }
060    
061    /**
062     * Add the given criterion to the faceted criteria
063     * @param criterion the criterion to add
064     * @param contextualParameters the contextual parameters
065     */
066    default void addFacetedCriterion(SearchModelCriterionViewItem criterion, Map<String, Object> contextualParameters)
067    {
068        ViewItemContainer criteria = getFacetedCriteria(contextualParameters);
069        criteria.addViewItem(criterion);
070    }
071    
072    /**
073     * Retrieves the criteria in advanced mode
074     * @param contextualParameters the contextual parameters
075     * @return the criteria in advanced mode
076     */
077    ViewItemContainer getAdvancedCriteria(Map<String, Object> contextualParameters);
078    
079    /**
080     * Retrieves the advanced criterion with the given name
081     * @param name The name of the faceted criterion to retrieve
082     * @param contextualParameters the contextual parameters
083     * @return the advanced criterion or <code>null</code> if not found
084     */
085    default ModelViewItem getAdvancedCriterion(String name, Map<String, Object> contextualParameters)
086    {
087        ViewItemContainer criteria = getAdvancedCriteria(contextualParameters);
088        return SearchModelHelper.getCriterion(criteria, name);
089    }
090    
091    /**
092     * Add the given criterion to the advanced criteria
093     * @param criterion the criterion to add
094     * @param contextualParameters the contextual parameters
095     */
096    default void addAdvancedCriterion(SearchModelCriterionDefinition criterion, Map<String, Object> contextualParameters)
097    {
098        SearchModelCriterionViewItem<ElementDefinition> viewItem = new DefaultSearchModelCriterionViewItem();
099        viewItem.setDefinition(criterion);
100        
101        addAdvancedCriterion(viewItem, contextualParameters);
102    }
103    
104    /**
105     * Add the given criterion to the advanced criteria
106     * @param criterion the criterion to add
107     * @param contextualParameters the contextual parameters
108     */
109    default void addAdvancedCriterion(SearchModelCriterionViewItem criterion, Map<String, Object> contextualParameters)
110    {
111        ViewItemContainer criteria = getAdvancedCriteria(contextualParameters);
112        criteria.addViewItem(criterion);
113    }
114    
115    /**
116     * Get the page size.
117     * @param contextualParameters the contextual parameters.
118     * @return The page size, unlimited or default used when negative or 0.
119     */
120    int getPageSize(Map<String, Object> contextualParameters);
121    
122    /**
123     * Get the URL for search
124     * @param contextualParameters the contextual parameters
125     * @return the URL for search
126     */
127    String getSearchUrl(Map<String, Object> contextualParameters);
128    
129    /**
130     * Get the plugin name for search
131     * @param contextualParameters the contextual parameters
132     * @return the plugin name for search
133     */
134    String getSearchUrlPlugin(Map<String, Object> contextualParameters);
135    
136    /**
137     * Get the URL for CSV export of results
138     * @param contextualParameters the contextual parameters
139     * @return the URL for CSV export
140     */
141    String getExportCSVUrl(Map<String, Object> contextualParameters);
142    
143    /**
144     * Get the plugin name for CSV export of results
145     * @param contextualParameters the contextual parameters
146     * @return the plugin name for CSV export
147     */
148    String getExportCSVUrlPlugin(Map<String, Object> contextualParameters);
149    
150    /**
151     * Get the URL for DOC export of results
152     * @param contextualParameters the contextual parameters
153     * @return the URL for DOC export
154     */
155    String getExportDOCUrl(Map<String, Object> contextualParameters);
156
157    /**
158     * Get the plugin name for DOC export of results
159     * @param contextualParameters the contextual parameters
160     * @return the plugin name for DOC export
161     */
162    String getExportDOCUrlPlugin(Map<String, Object> contextualParameters);
163
164    /**
165     * Get the URL for XML export of results
166     * @param contextualParameters the contextual parameters
167     * @return the URL for XML export
168     */
169    String getExportXMLUrl(Map<String, Object> contextualParameters);
170    
171    /**
172     * Get the plugin name for XML export of results
173     * @param contextualParameters the contextual parameters
174     * @return the plugin name for XML export
175     */
176    String getExportXMLUrlPlugin(Map<String, Object> contextualParameters);
177    
178    /**
179     * Get the URL for PDF export of results
180     * @param contextualParameters the contextual parameters
181     * @return the URL for PDF export
182     */
183    String getExportPDFUrl(Map<String, Object> contextualParameters);
184    
185    /**
186     * Get the plugin name for PDF export of results
187     * @param contextualParameters the contextual parameters
188     * @return the plugin name for PDF export
189     */
190    String getExportPDFUrlPlugin(Map<String, Object> contextualParameters);
191    
192    /**
193     * Get the URL for print results
194     * @param contextualParameters the contextual parameters
195     * @return the URL for print results
196     */
197    String getPrintUrl(Map<String, Object> contextualParameters);
198    
199    /**
200     * Get the plugin name for print results
201     * @param contextualParameters the contextual parameters    
202     * @return the plugin name for print results
203     */
204    String getPrintUrlPlugin(Map<String, Object> contextualParameters);
205    
206    /**
207     * Get the name of the view to use for summary of the content.
208     * @return the name of the view to use for summary of the content. Can be null.
209     */
210    String getSummaryView();
211}