Commit e991e3f97f7faa2e2c5fd4628532ff52ed6a2654

Authored by mfcb
1 parent 94d8b527

Dependency-Injected SchedulerBean in DroolsService.

services/Common/src/main/java/de/bht/beuthbot/daos/ReminderDAOImpl.java
... ... @@ -3,6 +3,8 @@ package de.bht.beuthbot.daos;
3 3 import de.bht.beuthbot.model.entities.Reminder;
4 4 import de.bht.beuthbot.model.entities.ReminderImpl;
5 5  
  6 +
  7 +
6 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 17 import de.bht.beuthbot.model.entities.AppUser;
18 18  
19 19 import de.bht.beuthbot.model.entities.LogMessage;
  20 +import de.bht.beuthbot.scheduler.SchedulerBean;
20 21 import org.kie.api.KieServices;
21 22 import org.kie.api.runtime.KieContainer;
22 23 import org.kie.api.runtime.KieSession;
... ... @@ -76,6 +77,9 @@ public class DroolsService implements MessageListener {
76 77 private LogMessageDAO logMessageDAO;
77 78  
78 79 @Inject
  80 + private SchedulerBean schedulerBean;
  81 +
  82 + @Inject
79 83 private Parser parser;
80 84  
81 85 @Override
... ... @@ -152,6 +156,7 @@ public class DroolsService implements MessageListener {
152 156  
153 157 ksession.setGlobal("canteenData", canteenData);
154 158 ksession.setGlobal("user", finishedUser);
  159 + ksession.setGlobal("schedulerBean", schedulerBean);
155 160  
156 161 // The application can insert facts into the session
157 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 237 reminder.setIntent(intent);
238 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 30 import de.bht.beuthbot.model.EntityName;
31 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 34 import de.bht.beuthbot.jms.TaskMessage;
35 35 import java.util.Date;
36 36 import java.text.SimpleDateFormat;
... ... @@ -45,7 +45,7 @@ import de.bht.beuthbot.model.entities.Reminder;
45 45  
46 46 global de.bht.beuthbot.canteen.model.CanteenData canteenData;
47 47 global de.bht.beuthbot.model.entities.AppUser user;
48   -
  48 +global de.bht.beuthbot.scheduler.SchedulerBean schedulerBean;
49 49  
50 50  
51 51 // ---------------------- GREETING ------------------------------------
... ... @@ -134,9 +134,9 @@ rule "Create reminder"
134 134 m : DroolsMessage(getIntent().equals(Intent.CREATE_REMINDER.getText()))
135 135  
136 136 then
137   - SchedulerBean s = new SchedulerBean();
  137 + //SchedulerBean s = new SchedulerBean();
138 138 TaskMessage message = new TaskMessage(m);
139   - Reminder reminder = s.createReminder(message, user);
  139 + Reminder reminder = schedulerBean.createReminder(message, user);
140 140 String messageText = "";
141 141 if(reminder.getIntent().equals(Intent.SHOW_FOOD.getText())) {
142 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 152 when
153 153 m : DroolsMessage(getIntent().equals(Intent.DELETE_REMINDER.getText()))
154 154 then
155   - SchedulerBean s = new SchedulerBean();
156 155 TaskMessage message = new TaskMessage(m);
157   - boolean didDelete = s.deleteReminder(message, user);
  156 + boolean didDelete = schedulerBean.deleteReminder(message, user);
158 157 String messageText = "";
159 158 if(didDelete) {
160 159 messageText = "Ich werde dir von nun an keine Erinnerungen mehr schicken!";
... ...