1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.recastbots.service;
35
36 import fr.paris.lutece.plugins.chatbot.service.BotService;
37 import fr.paris.lutece.plugins.chatbot.service.bot.ChatBot;
38 import fr.paris.lutece.plugins.recastbots.business.RecastBot;
39 import fr.paris.lutece.plugins.recastbots.business.RecastBotHome;
40 import fr.paris.lutece.portal.service.i18n.I18nService;
41 import fr.paris.lutece.util.ReferenceList;
42 import java.util.Locale;
43
44
45
46
47 public class BotRegistrationService
48 {
49
50 private static final String MESSAGE_STATUS_ENABLED = "recastbots.bot_status.enabled";
51 private static final String MESSAGE_STATUS_DISABLED = "recastbots.bot_status.disabled";
52 private static final String MESSAGE_MODE_STANDARD = "recastbots.mode.standard";
53 private static final String MESSAGE_MODE_STANDALONE = "recastbots.mode.standalone";
54
55 private static final int STATUS_ENABLED = 1;
56 private static final int STATUS_DISABLED = 0;
57 private static final int MODE_STANDARD = 0;
58 private static final int MODE_STANDALONE = 1;
59
60 private static ReferenceList _listStatus;
61
62
63
64
65 public static void registerAllBots( )
66 {
67 for ( RecastBot bot : RecastBotHome.getRecastBotsList( ) )
68 {
69 ChatBot chatbot = new BotInstance( bot );
70 BotService.register( chatbot );
71 }
72 }
73
74
75
76
77
78
79
80
81 public static ReferenceList getBotsStatusList( Locale locale )
82 {
83 if ( _listStatus == null )
84 {
85 _listStatus = new ReferenceList( );
86 _listStatus.addItem( STATUS_DISABLED, I18nService.getLocalizedString( MESSAGE_STATUS_DISABLED, locale ) );
87 _listStatus.addItem( STATUS_ENABLED, I18nService.getLocalizedString( MESSAGE_STATUS_ENABLED, locale ) );
88 }
89 return _listStatus;
90 }
91
92
93
94
95
96
97
98
99
100 public static void register( BotInstance botInstance, int nStatus )
101 {
102 if ( nStatus == STATUS_ENABLED )
103 {
104 BotService.register( botInstance );
105 }
106 }
107
108
109
110
111
112
113
114 public static void unregister( String strBotKey )
115 {
116 BotService.unregister( strBotKey );
117 }
118
119 public static ReferenceList getModes( Locale locale )
120 {
121 ReferenceList list = new ReferenceList( );
122
123 list.addItem( MODE_STANDARD, I18nService.getLocalizedString( MESSAGE_MODE_STANDARD, locale ) );
124 list.addItem( MODE_STANDALONE, I18nService.getLocalizedString( MESSAGE_MODE_STANDALONE, locale ) );
125
126 return list;
127 }
128 }