Commit e991e3f97f7faa2e2c5fd4628532ff52ed6a2654
1 parent
94d8b527
Dependency-Injected SchedulerBean in DroolsService.
Showing
4 changed files
with
13 additions
and
11 deletions
services/Common/src/main/java/de/bht/beuthbot/daos/ReminderDAOImpl.java
@@ -3,6 +3,8 @@ package de.bht.beuthbot.daos; | @@ -3,6 +3,8 @@ package de.bht.beuthbot.daos; | ||
3 | import de.bht.beuthbot.model.entities.Reminder; | 3 | import de.bht.beuthbot.model.entities.Reminder; |
4 | import de.bht.beuthbot.model.entities.ReminderImpl; | 4 | import de.bht.beuthbot.model.entities.ReminderImpl; |
5 | 5 | ||
6 | + | ||
7 | + | ||
6 | import javax.ejb.Stateless; | 8 | import javax.ejb.Stateless; |
7 | 9 | ||
8 | /** | 10 | /** |
services/MainBot/src/main/java/de/bht/beuthbot/drools/DroolsService.java
@@ -17,6 +17,7 @@ import de.bht.beuthbot.model.Messenger; | @@ -17,6 +17,7 @@ import de.bht.beuthbot.model.Messenger; | ||
17 | import de.bht.beuthbot.model.entities.AppUser; | 17 | import de.bht.beuthbot.model.entities.AppUser; |
18 | 18 | ||
19 | import de.bht.beuthbot.model.entities.LogMessage; | 19 | import de.bht.beuthbot.model.entities.LogMessage; |
20 | +import de.bht.beuthbot.scheduler.SchedulerBean; | ||
20 | import org.kie.api.KieServices; | 21 | import org.kie.api.KieServices; |
21 | import org.kie.api.runtime.KieContainer; | 22 | import org.kie.api.runtime.KieContainer; |
22 | import org.kie.api.runtime.KieSession; | 23 | import org.kie.api.runtime.KieSession; |
@@ -76,6 +77,9 @@ public class DroolsService implements MessageListener { | @@ -76,6 +77,9 @@ public class DroolsService implements MessageListener { | ||
76 | private LogMessageDAO logMessageDAO; | 77 | private LogMessageDAO logMessageDAO; |
77 | 78 | ||
78 | @Inject | 79 | @Inject |
80 | + private SchedulerBean schedulerBean; | ||
81 | + | ||
82 | + @Inject | ||
79 | private Parser parser; | 83 | private Parser parser; |
80 | 84 | ||
81 | @Override | 85 | @Override |
@@ -152,6 +156,7 @@ public class DroolsService implements MessageListener { | @@ -152,6 +156,7 @@ public class DroolsService implements MessageListener { | ||
152 | 156 | ||
153 | ksession.setGlobal("canteenData", canteenData); | 157 | ksession.setGlobal("canteenData", canteenData); |
154 | ksession.setGlobal("user", finishedUser); | 158 | ksession.setGlobal("user", finishedUser); |
159 | + ksession.setGlobal("schedulerBean", schedulerBean); | ||
155 | 160 | ||
156 | // The application can insert facts into the session | 161 | // The application can insert facts into the session |
157 | // Map incoming ApiAiMessages and RasaMessages to DroolsMessage | 162 | // Map incoming ApiAiMessages and RasaMessages to DroolsMessage |
services/MainBot/src/main/java/de/bht/beuthbot/scheduler/SchedulerBean.java
@@ -237,11 +237,7 @@ public class SchedulerBean { | @@ -237,11 +237,7 @@ public class SchedulerBean { | ||
237 | reminder.setIntent(intent); | 237 | reminder.setIntent(intent); |
238 | reminder.setEntities(entities); | 238 | reminder.setEntities(entities); |
239 | 239 | ||
240 | - Reminder reminder1 = reminderDAO.saveOrUpdate(reminder); | ||
241 | - | ||
242 | - | ||
243 | - | ||
244 | - return reminder1; | 240 | + return reminderDAO.saveOrUpdate(reminder); |
245 | 241 | ||
246 | 242 | ||
247 | } | 243 | } |
services/MainBot/src/main/resources/de/bht/beuthbot/drools/Canteen.drl
@@ -30,7 +30,7 @@ import de.bht.beuthbot.model.Intent; | @@ -30,7 +30,7 @@ import de.bht.beuthbot.model.Intent; | ||
30 | import de.bht.beuthbot.model.EntityName; | 30 | import de.bht.beuthbot.model.EntityName; |
31 | import de.bht.beuthbot.drools.model.DroolsMessage; | 31 | import de.bht.beuthbot.drools.model.DroolsMessage; |
32 | 32 | ||
33 | -import de.bht.beuthbot.scheduler.SchedulerBean; | 33 | +//import de.bht.beuthbot.scheduler.SchedulerBean; |
34 | import de.bht.beuthbot.jms.TaskMessage; | 34 | import de.bht.beuthbot.jms.TaskMessage; |
35 | import java.util.Date; | 35 | import java.util.Date; |
36 | import java.text.SimpleDateFormat; | 36 | import java.text.SimpleDateFormat; |
@@ -45,7 +45,7 @@ import de.bht.beuthbot.model.entities.Reminder; | @@ -45,7 +45,7 @@ import de.bht.beuthbot.model.entities.Reminder; | ||
45 | 45 | ||
46 | global de.bht.beuthbot.canteen.model.CanteenData canteenData; | 46 | global de.bht.beuthbot.canteen.model.CanteenData canteenData; |
47 | global de.bht.beuthbot.model.entities.AppUser user; | 47 | global de.bht.beuthbot.model.entities.AppUser user; |
48 | - | 48 | +global de.bht.beuthbot.scheduler.SchedulerBean schedulerBean; |
49 | 49 | ||
50 | 50 | ||
51 | // ---------------------- GREETING ------------------------------------ | 51 | // ---------------------- GREETING ------------------------------------ |
@@ -134,9 +134,9 @@ rule "Create reminder" | @@ -134,9 +134,9 @@ rule "Create reminder" | ||
134 | m : DroolsMessage(getIntent().equals(Intent.CREATE_REMINDER.getText())) | 134 | m : DroolsMessage(getIntent().equals(Intent.CREATE_REMINDER.getText())) |
135 | 135 | ||
136 | then | 136 | then |
137 | - SchedulerBean s = new SchedulerBean(); | 137 | + //SchedulerBean s = new SchedulerBean(); |
138 | TaskMessage message = new TaskMessage(m); | 138 | TaskMessage message = new TaskMessage(m); |
139 | - Reminder reminder = s.createReminder(message, user); | 139 | + Reminder reminder = schedulerBean.createReminder(message, user); |
140 | String messageText = ""; | 140 | String messageText = ""; |
141 | if(reminder.getIntent().equals(Intent.SHOW_FOOD.getText())) { | 141 | if(reminder.getIntent().equals(Intent.SHOW_FOOD.getText())) { |
142 | messageText = "Ich werde dir " + DateStringExtractor.getGermanWeekDayFromLocalDate(reminder.getCycleDate().toLocalDate(), true) + " um " + reminder.getCycleDate().toLocalTime().format(DateTimeFormatter.ofPattern("HH:mm")) + " Uhr den Mensaplan mitteilen!"; | 142 | messageText = "Ich werde dir " + DateStringExtractor.getGermanWeekDayFromLocalDate(reminder.getCycleDate().toLocalDate(), true) + " um " + reminder.getCycleDate().toLocalTime().format(DateTimeFormatter.ofPattern("HH:mm")) + " Uhr den Mensaplan mitteilen!"; |
@@ -152,9 +152,8 @@ rule "Delete reminder" | @@ -152,9 +152,8 @@ rule "Delete reminder" | ||
152 | when | 152 | when |
153 | m : DroolsMessage(getIntent().equals(Intent.DELETE_REMINDER.getText())) | 153 | m : DroolsMessage(getIntent().equals(Intent.DELETE_REMINDER.getText())) |
154 | then | 154 | then |
155 | - SchedulerBean s = new SchedulerBean(); | ||
156 | TaskMessage message = new TaskMessage(m); | 155 | TaskMessage message = new TaskMessage(m); |
157 | - boolean didDelete = s.deleteReminder(message, user); | 156 | + boolean didDelete = schedulerBean.deleteReminder(message, user); |
158 | String messageText = ""; | 157 | String messageText = ""; |
159 | if(didDelete) { | 158 | if(didDelete) { |
160 | messageText = "Ich werde dir von nun an keine Erinnerungen mehr schicken!"; | 159 | messageText = "Ich werde dir von nun an keine Erinnerungen mehr schicken!"; |