View Javadoc
1   /*
2    * Copyright (c) 2002-2017, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.chatbot.service.bot;
35  
36  import fr.paris.lutece.portal.service.i18n.I18nService;
37  
38  import java.io.Serializable;
39  import java.util.List;
40  import java.util.Locale;
41  
42  /**
43   * Bot
44   */
45  public abstract class AbstractChatBot implements ChatBot, Serializable
46  {
47      private static final String URL_DEFAULT_BOT_AVATAR = "images/skin/plugins/chatbot/bot-avatar.png";
48      private static final long serialVersionUID = 1L;
49      private String _strKey;
50      private String _strName;
51      private String _strDescription;
52      private String _strNameI18nKey;
53      private String _strDescriptionI18nKey;
54      private String _strBotAvatarUrl;
55      private List<String> _listAvailableLanguages;
56      private boolean _bStandalone;
57      private String _strWelcomeMessage;
58  
59      /**
60       * Returns the Key
61       * 
62       * @return The Key
63       */
64      @Override
65      public String getKey( )
66      {
67          return _strKey;
68      }
69  
70      /**
71       * Sets the Key
72       * 
73       * @param strKey
74       *            The Key
75       */
76      public void setKey( String strKey )
77      {
78          _strKey = strKey;
79      }
80  
81      /**
82       * Returns the Name
83       * 
84       * @param locale
85       *            The locale
86       * @return The Name
87       */
88      @Override
89      public String getName( Locale locale )
90      {
91          String strName;
92  
93          if ( _strNameI18nKey != null )
94          {
95              strName = I18nService.getLocalizedString( _strNameI18nKey, locale );
96          }
97          else
98          {
99              strName = _strName;
100         }
101 
102         return strName;
103     }
104 
105     /**
106      * Sets the Name
107      * 
108      * @param strName
109      *            The Name
110      */
111     public void setName( String strName )
112     {
113         _strName = strName;
114     }
115 
116     /**
117      * Returns the Description
118      * 
119      * @param locale
120      *            The locale
121      * @return The Description
122      */
123     @Override
124     public String getDescription( Locale locale )
125     {
126         String strDescription;
127 
128         if ( _strDescriptionI18nKey != null )
129         {
130             strDescription = I18nService.getLocalizedString( _strDescriptionI18nKey, locale );
131         }
132         else
133         {
134             strDescription = _strDescription;
135         }
136 
137         return strDescription;
138     }
139 
140     /**
141      * Sets the Description
142      * 
143      * @param strDescription
144      *            The Description
145      */
146     public void setDescription( String strDescription )
147     {
148         _strDescription = strDescription;
149     }
150 
151     /**
152      * Returns the NameI18nKey
153      * 
154      * @return The NameI18nKey
155      */
156     public String getNameI18nKey( )
157     {
158         return _strNameI18nKey;
159     }
160 
161     /**
162      * Sets the NameI18nKey
163      * 
164      * @param strNameI18nKey
165      *            The NameI18nKey
166      */
167     public void setNameI18nKey( String strNameI18nKey )
168     {
169         _strNameI18nKey = strNameI18nKey;
170     }
171 
172     /**
173      * Returns the DescriptionI18nKey
174      * 
175      * @return The DescriptionI18nKey
176      */
177     public String getDescriptionI18nKey( )
178     {
179         return _strDescriptionI18nKey;
180     }
181 
182     /**
183      * Sets the DescriptionI18nKey
184      * 
185      * @param strDescriptionI18nKey
186      *            The DescriptionI18nKey
187      */
188     public void setDescriptionI18nKey( String strDescriptionI18nKey )
189     {
190         _strDescriptionI18nKey = strDescriptionI18nKey;
191     }
192 
193     /**
194      * Returns the BotAvatarUrl
195      * 
196      * @return The BotAvatarUrl
197      */
198     @Override
199     public String getAvatarUrl( )
200     {
201         if ( _strBotAvatarUrl == null || _strBotAvatarUrl.equals( "" ) )
202         {
203             _strBotAvatarUrl = URL_DEFAULT_BOT_AVATAR;
204         }
205 
206         return _strBotAvatarUrl;
207     }
208 
209     /**
210      * Sets the BotAvatarUrl
211      * 
212      * @param strBotAvatarUrl
213      *            The BotAvatarUrl
214      */
215     public void setAvatarUrl( String strBotAvatarUrl )
216     {
217         _strBotAvatarUrl = strBotAvatarUrl;
218     }
219 
220     /**
221      * Set available languages list
222      * 
223      * @param listAvailableLanguages
224      *            available languages list
225      */
226     public void setListAvailableLanguages( List<String> listAvailableLanguages )
227     {
228         _listAvailableLanguages = listAvailableLanguages;
229     }
230 
231     /**
232      * {@inheritDoc }
233      */
234     @Override
235     public List<String> getAvailableLanguages( )
236     {
237         return _listAvailableLanguages;
238     }
239 
240     /**
241      * {@inheritDoc }
242      */
243     @Override
244     public boolean isStandalone( )
245     {
246         return _bStandalone;
247     }
248 
249     /**
250      * Sets the Standalone
251      *
252      * @param bStandalone
253      *            The Standalone
254      */
255     public void setStandalone( boolean bStandalone )
256     {
257         _bStandalone = bStandalone;
258     }
259 
260     /**
261      * Returns the WelcomeMessage
262      * 
263      * @return The WelcomeMessage
264      */
265     @Override
266     public String getWelcomeMessage( )
267     {
268         return _strWelcomeMessage;
269     }
270 
271     /**
272      * Sets the WelcomeMessage
273      * 
274      * @param strWelcomeMessage
275      *            The WelcomeMessage
276      */
277     public void setWelcomeMessage( String strWelcomeMessage )
278     {
279         _strWelcomeMessage = strWelcomeMessage;
280     }
281 
282 
283     /**
284      * {@inheritDoc }
285      */
286     @Override
287     public void reset( String strConversationId )
288     {
289         
290     }
291 }