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.botpress.service;
35
36 import fr.paris.lutece.plugins.botpress.business.BPBot;
37 import fr.paris.lutece.plugins.botpress.business.BPBotHome;
38 import fr.paris.lutece.plugins.chatbot.service.BotService;
39 import fr.paris.lutece.plugins.chatbot.service.bot.ChatBot;
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 = "botpress.bot_status.enabled";
51 private static final String MESSAGE_STATUS_DISABLED = "botpress.bot_status.disabled";
52 private static final String MESSAGE_MODE_STANDARD = "botpress.mode.standard";
53 private static final String MESSAGE_MODE_STANDALONE = "botpress.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 private BotRegistrationService()
64 {
65 }
66
67
68
69
70 public static void registerAllBots( )
71 {
72 for ( BPBot bot : BPBotHome.getBPBotsList( ) )
73 {
74 ChatBot chatbot = new BotInstance( bot );
75 BotService.register( chatbot );
76 }
77 }
78
79
80
81
82
83
84
85
86 public static synchronized ReferenceList getBotsStatusList( Locale locale )
87 {
88 if ( _listStatus == null )
89 {
90 _listStatus = new ReferenceList( );
91 _listStatus.addItem( STATUS_DISABLED, I18nService.getLocalizedString( MESSAGE_STATUS_DISABLED, locale ) );
92 _listStatus.addItem( STATUS_ENABLED, I18nService.getLocalizedString( MESSAGE_STATUS_ENABLED, locale ) );
93 }
94 return _listStatus;
95 }
96
97
98
99
100
101
102
103
104
105 public static void register( BotInstance botInstance, int nStatus )
106 {
107 if ( nStatus == STATUS_ENABLED )
108 {
109 BotService.register( botInstance );
110 }
111 }
112
113
114
115
116
117
118
119 public static void unregister( String strBotKey )
120 {
121 BotService.unregister( strBotKey );
122 }
123
124
125
126
127
128
129 public static ReferenceList getModes( Locale locale )
130 {
131 ReferenceList list = new ReferenceList( );
132
133 list.addItem( MODE_STANDARD, I18nService.getLocalizedString( MESSAGE_MODE_STANDARD, locale ) );
134 list.addItem( MODE_STANDALONE, I18nService.getLocalizedString( MESSAGE_MODE_STANDALONE, locale ) );
135
136 return list;
137 }
138 }