001/*
002 *  Copyright 2010 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.web.service;
017
018import java.util.List;
019import java.util.Map;
020
021import org.apache.solr.common.SolrInputDocument;
022
023import org.ametys.core.ui.ClientSideElement.Script;
024import org.ametys.core.ui.ClientSideElement.ScriptFile;
025import org.ametys.runtime.i18n.I18nizableText;
026import org.ametys.runtime.model.Model;
027import org.ametys.runtime.model.ModelItem;
028import org.ametys.runtime.model.View;
029import org.ametys.runtime.util.Labelable;
030import org.ametys.web.repository.page.Page;
031import org.ametys.web.repository.page.ZoneItem;
032
033/**
034 * Interface representing a business service. <br>
035 * A service is identified by a name and a Cocoon-URL.<br>
036 * This URL correspond to a pipeline called by a page template.<br>
037 * URL must be relative to the sitemap of the service.
038 */
039public interface Service extends Model, Labelable
040{
041    /**
042     * Returns the plugin's name.
043     * @return the plugin's name.
044     */
045    public String getPluginName();
046    
047    /**
048     * Retrieves the category of the service.
049     * @return the category.
050     */
051    I18nizableText getCategory();
052    
053    /**
054     * Retrieves the CSS class to use for glyph icon
055     * @return the glyph name.
056     */
057    public String getIconGlyph();
058    
059    /**
060     * Retrieves the CSS class to use for decorator above the main icon
061     * @return the glyph name.
062     */
063    public String getIconDecorator();
064    
065    /**
066     * Retrieves the URL of the icon without the context path.
067     * @return the icon URL for the small image 16x16.
068     */
069    public String getSmallIcon();
070
071    /**
072     * Retrieves the URL of the icon without the context path.
073     * @return the icon URL for the medium image 32x32.
074     */
075    public String getMediumIcon();
076    
077    /**
078     * Retrieves the URL of the icon without the context path.
079     * @return the icon URL for the large image 48x48.
080     */
081    public String getLargeIcon();
082    
083    /**
084     * Gets the height of the creation dialog box.
085     * @return the height of the creation dialog box
086     */
087    public Integer getCreationBoxHeight();
088    
089    /**
090     * Gets the width of the creation dialog box.
091     * @return the width of the creation dialog box
092     */
093    public Integer getCreationBoxWidth();
094    
095    /**
096     * Returns the list of CSS files needed to correctly display the service's in BO, such as the service's icon
097     * @return The list of CSS files needed. Must not be null.
098     */
099    List<ScriptFile> getCSSFiles();
100    
101    /**
102     * Returns the service's Cocoon-URL.
103     * @return the service's Cocoon-URL.
104     */
105    public String getURL();
106    
107    /**
108     * Retrieves the service's parameters definitions
109     * @return the service's parameters definitions
110     */
111    public Map<String, ModelItem> getParameters();
112    
113    /**
114     * Retrieves the service's view
115     * @return the service's view
116     */
117    public View getView();
118    
119    /**
120     * This method return the script that will be used to display parameters field.
121     * @return The script. Can be null.
122     */
123    public Script getParametersScript();
124    
125    /**
126     * Get whether the service is private, i.e. should not be created by
127     * the regular service interface.
128     * @return true if the service is private, false if it is public.
129     */
130    public boolean isPrivate();
131    
132    /**
133     * Get the right needed to create an instance of this service.
134     * @return the right needed to create an instance of this service. If null is returned, no right is needed.
135     */
136    public String getRight();
137    
138    /**
139     * Returns true if the result of this service may be cached, depending on the {@link ZoneItem} containing an instance of this service.
140     * @param currentPage the current {@link Page} containing the service.
141     * @param zoneItem the {@link ZoneItem} containing an instance of this service.<br>
142     *                 N.B: The ZoneItem can belong to a page that is not the current page, when it is inherited.
143     * @return true if the result of this service may be cached.
144     */
145    public boolean isCacheable(Page currentPage, ZoneItem zoneItem);
146    
147    /**
148     * Fill the index with service data.<br>
149     * This method is called during the containing page indexation process.
150     * @param zoneItem the {@link ZoneItem} containing an instance of this service.
151     * @param document the solr document for the containing {@link Page}.
152     */
153    public void index(ZoneItem zoneItem, SolrInputDocument document);
154    
155    public default String getFamilyId()
156    {
157        return ServiceExtensionPoint.ROLE;
158    }
159}