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 | 10 | import de.bht.beuthbot.canteen.Parser; |
11 | 11 | import de.bht.beuthbot.canteen.model.CanteenData; |
12 | 12 | import de.bht.beuthbot.conf.Application; |
13 | +import de.bht.beuthbot.daos.AppUserDAO; | |
13 | 14 | import de.bht.beuthbot.drools.model.DroolsMessage; |
14 | 15 | import de.bht.beuthbot.jms.ProcessQueue; |
15 | 16 | import de.bht.beuthbot.jms.ProcessQueueMessageProtocol; |
16 | 17 | import de.bht.beuthbot.jms.Target; |
17 | 18 | import de.bht.beuthbot.jms.TaskMessage; |
19 | +import de.bht.beuthbot.model.Messenger; | |
20 | +import de.bht.beuthbot.model.entities.AppUser; | |
18 | 21 | import org.kie.api.KieServices; |
19 | 22 | import org.kie.api.runtime.KieContainer; |
20 | 23 | import org.kie.api.runtime.KieSession; |
... | ... | @@ -28,6 +31,7 @@ import javax.inject.Inject; |
28 | 31 | import javax.jms.JMSException; |
29 | 32 | import javax.jms.Message; |
30 | 33 | import javax.jms.MessageListener; |
34 | +import java.util.List; | |
31 | 35 | |
32 | 36 | /** |
33 | 37 | * Created by sJantzen on 13.06.2017. |
... | ... | @@ -66,6 +70,9 @@ public class DroolsService implements MessageListener { |
66 | 70 | @Resource(lookup = "java:global/global/ApplicationBean") |
67 | 71 | private Application application; |
68 | 72 | |
73 | + @Resource(lookup = "java:global/global/AppUserDAOImpl") | |
74 | + private AppUserDAO userDAO; | |
75 | + | |
69 | 76 | @Inject |
70 | 77 | private Parser parser; |
71 | 78 | |
... | ... | @@ -114,7 +121,32 @@ public class DroolsService implements MessageListener { |
114 | 121 | // org/drools/examples/helloworld/HelloWorld.drl file |
115 | 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 | 148 | ksession.setGlobal("canteenData", canteenData); |
149 | + ksession.setGlobal("user", finishedUser); | |
118 | 150 | |
119 | 151 | // The application can insert facts into the session |
120 | 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 | 40 | import de.bht.beuthbot.scheduler.model.Reminder; |
41 | 41 | |
42 | 42 | global de.bht.beuthbot.canteen.model.CanteenData canteenData; |
43 | +global de.bht.beuthbot.model.entities.AppUser user; | |
43 | 44 | |
44 | 45 | // ---------------------- GREETING ------------------------------------ |
45 | 46 | rule "Hello Drools" |
... | ... | @@ -125,7 +126,7 @@ rule "Create reminder" |
125 | 126 | then |
126 | 127 | SchedulerBean s = new SchedulerBean(); |
127 | 128 | TaskMessage message = new TaskMessage(m); |
128 | - String messageText = s.createReminder(message); | |
129 | + String messageText = s.createReminder(message, user); | |
129 | 130 | m.setText(messageText); |
130 | 131 | |
131 | 132 | end | ... | ... |