Commit f884f4b19f185e34dd2cf6eeaf39a79409368e8e
1 parent
60ae7aae
Reminder functional with User persistance
Showing
2 changed files
with
34 additions
and
1 deletions
services/MainBot/src/main/java/de/bht/beuthbot/drools/DroolsService.java
@@ -10,11 +10,14 @@ import de.bht.beuthbot.attachments.AttachmentStore; | @@ -10,11 +10,14 @@ import de.bht.beuthbot.attachments.AttachmentStore; | ||
10 | import de.bht.beuthbot.canteen.Parser; | 10 | import de.bht.beuthbot.canteen.Parser; |
11 | import de.bht.beuthbot.canteen.model.CanteenData; | 11 | import de.bht.beuthbot.canteen.model.CanteenData; |
12 | import de.bht.beuthbot.conf.Application; | 12 | import de.bht.beuthbot.conf.Application; |
13 | +import de.bht.beuthbot.daos.AppUserDAO; | ||
13 | import de.bht.beuthbot.drools.model.DroolsMessage; | 14 | import de.bht.beuthbot.drools.model.DroolsMessage; |
14 | import de.bht.beuthbot.jms.ProcessQueue; | 15 | import de.bht.beuthbot.jms.ProcessQueue; |
15 | import de.bht.beuthbot.jms.ProcessQueueMessageProtocol; | 16 | import de.bht.beuthbot.jms.ProcessQueueMessageProtocol; |
16 | import de.bht.beuthbot.jms.Target; | 17 | import de.bht.beuthbot.jms.Target; |
17 | import de.bht.beuthbot.jms.TaskMessage; | 18 | import de.bht.beuthbot.jms.TaskMessage; |
19 | +import de.bht.beuthbot.model.Messenger; | ||
20 | +import de.bht.beuthbot.model.entities.AppUser; | ||
18 | import org.kie.api.KieServices; | 21 | import org.kie.api.KieServices; |
19 | import org.kie.api.runtime.KieContainer; | 22 | import org.kie.api.runtime.KieContainer; |
20 | import org.kie.api.runtime.KieSession; | 23 | import org.kie.api.runtime.KieSession; |
@@ -28,6 +31,7 @@ import javax.inject.Inject; | @@ -28,6 +31,7 @@ import javax.inject.Inject; | ||
28 | import javax.jms.JMSException; | 31 | import javax.jms.JMSException; |
29 | import javax.jms.Message; | 32 | import javax.jms.Message; |
30 | import javax.jms.MessageListener; | 33 | import javax.jms.MessageListener; |
34 | +import java.util.List; | ||
31 | 35 | ||
32 | /** | 36 | /** |
33 | * Created by sJantzen on 13.06.2017. | 37 | * Created by sJantzen on 13.06.2017. |
@@ -66,6 +70,9 @@ public class DroolsService implements MessageListener { | @@ -66,6 +70,9 @@ public class DroolsService implements MessageListener { | ||
66 | @Resource(lookup = "java:global/global/ApplicationBean") | 70 | @Resource(lookup = "java:global/global/ApplicationBean") |
67 | private Application application; | 71 | private Application application; |
68 | 72 | ||
73 | + @Resource(lookup = "java:global/global/AppUserDAOImpl") | ||
74 | + private AppUserDAO userDAO; | ||
75 | + | ||
69 | @Inject | 76 | @Inject |
70 | private Parser parser; | 77 | private Parser parser; |
71 | 78 | ||
@@ -114,7 +121,32 @@ public class DroolsService implements MessageListener { | @@ -114,7 +121,32 @@ public class DroolsService implements MessageListener { | ||
114 | // org/drools/examples/helloworld/HelloWorld.drl file | 121 | // org/drools/examples/helloworld/HelloWorld.drl file |
115 | CanteenData canteenData = parser.parse(); | 122 | CanteenData canteenData = parser.parse(); |
116 | 123 | ||
124 | + //TODO userDAO.findByTelegramId & userDAO.findByFacebookId | ||
125 | + List<AppUser> allUsers = userDAO.findAll(); | ||
126 | + AppUser tempUser = null; | ||
127 | + | ||
128 | + for (AppUser user : allUsers) { | ||
129 | + if(botMessage.getMessenger() == Messenger.TELEGRAM) { | ||
130 | + tempUser = user.getTelegramUserId().equals(botMessage.getSenderID().toString()) ? user : null; | ||
131 | + } else if(botMessage.getMessenger() == Messenger.FACEBOOK) { | ||
132 | + tempUser = user.getFacebookUserId().equals(botMessage.getSenderID().toString()) ? user : null; | ||
133 | + } | ||
134 | + } | ||
135 | + | ||
136 | + if(tempUser == null) { | ||
137 | + tempUser = userDAO.createUser(); | ||
138 | + } | ||
139 | + if(botMessage.getMessenger() == Messenger.TELEGRAM) { | ||
140 | + tempUser.setTelegramUserId(botMessage.getSenderID().toString()); | ||
141 | + } else if(botMessage.getMessenger() == Messenger.FACEBOOK) { | ||
142 | + tempUser.setFacebookUserId(botMessage.getSenderID().toString()); | ||
143 | + } | ||
144 | + AppUser finishedUser = userDAO.saveOrUpdate(tempUser); | ||
145 | + | ||
146 | + | ||
147 | + | ||
117 | ksession.setGlobal("canteenData", canteenData); | 148 | ksession.setGlobal("canteenData", canteenData); |
149 | + ksession.setGlobal("user", finishedUser); | ||
118 | 150 | ||
119 | // The application can insert facts into the session | 151 | // The application can insert facts into the session |
120 | // Map incoming ApiAiMessages and RasaMessages to DroolsMessage | 152 | // Map incoming ApiAiMessages and RasaMessages to DroolsMessage |
services/MainBot/src/main/resources/de/bht/beuthbot/drools/Canteen.drl
@@ -40,6 +40,7 @@ import de.bht.beuthbot.model.Messenger | @@ -40,6 +40,7 @@ import de.bht.beuthbot.model.Messenger | ||
40 | import de.bht.beuthbot.scheduler.model.Reminder; | 40 | import de.bht.beuthbot.scheduler.model.Reminder; |
41 | 41 | ||
42 | global de.bht.beuthbot.canteen.model.CanteenData canteenData; | 42 | global de.bht.beuthbot.canteen.model.CanteenData canteenData; |
43 | +global de.bht.beuthbot.model.entities.AppUser user; | ||
43 | 44 | ||
44 | // ---------------------- GREETING ------------------------------------ | 45 | // ---------------------- GREETING ------------------------------------ |
45 | rule "Hello Drools" | 46 | rule "Hello Drools" |
@@ -125,7 +126,7 @@ rule "Create reminder" | @@ -125,7 +126,7 @@ rule "Create reminder" | ||
125 | then | 126 | then |
126 | SchedulerBean s = new SchedulerBean(); | 127 | SchedulerBean s = new SchedulerBean(); |
127 | TaskMessage message = new TaskMessage(m); | 128 | TaskMessage message = new TaskMessage(m); |
128 | - String messageText = s.createReminder(message); | 129 | + String messageText = s.createReminder(message, user); |
129 | m.setText(messageText); | 130 | m.setText(messageText); |
130 | 131 | ||
131 | end | 132 | end |