Commit 40460148b49364c66c4e05954af26ae372c9b3da

Authored by mfcb
1 parent 5de3209e

Merged latest changes.

# Conflicts:
#	services/MainBot/src/main/java/de/bht/beuthbot/scheduler/SchedulerBean.java
#	services/MainBot/src/main/java/de/bht/beuthbot/scheduler/model/Reminder.java
#	services/MainBot/src/main/resources/de/bht/beuthbot/drools/Canteen.drl
services/Common/src/main/java/de/bht/beuthbot/model/entities/Reminder.java
@@ -4,6 +4,7 @@ import de.bht.beuthbot.model.Messenger; @@ -4,6 +4,7 @@ import de.bht.beuthbot.model.Messenger;
4 import de.bht.beuthbot.model.enumeration.ReminderCycle; 4 import de.bht.beuthbot.model.enumeration.ReminderCycle;
5 5
6 import java.time.LocalDate; 6 import java.time.LocalDate;
  7 +import java.time.LocalDateTime;
7 import java.util.Map; 8 import java.util.Map;
8 9
9 /** 10 /**
@@ -19,9 +20,9 @@ public interface Reminder extends EntityBase { @@ -19,9 +20,9 @@ public interface Reminder extends EntityBase {
19 20
20 void setReminderCycle(ReminderCycle reminderCycle); 21 void setReminderCycle(ReminderCycle reminderCycle);
21 22
22 - LocalDate getCycleTime(); 23 + LocalDateTime getCycleDate();
23 24
24 - void setCycleTime(LocalDate cycleTime); 25 + void setCycleDate(LocalDateTime cycleDate);
25 26
26 Messenger getMessenger(); 27 Messenger getMessenger();
27 28
services/Common/src/main/java/de/bht/beuthbot/model/entities/ReminderImpl.java
@@ -8,6 +8,7 @@ import javax.persistence.ElementCollection; @@ -8,6 +8,7 @@ import javax.persistence.ElementCollection;
8 import javax.persistence.Entity; 8 import javax.persistence.Entity;
9 import javax.persistence.Table; 9 import javax.persistence.Table;
10 import java.time.LocalDate; 10 import java.time.LocalDate;
  11 +import java.time.LocalDateTime;
11 import java.util.Map; 12 import java.util.Map;
12 13
13 /** 14 /**
@@ -21,7 +22,7 @@ public class ReminderImpl extends EntityBaseImpl implements Reminder { @@ -21,7 +22,7 @@ public class ReminderImpl extends EntityBaseImpl implements Reminder {
21 22
22 private ReminderCycle reminderCycle; 23 private ReminderCycle reminderCycle;
23 24
24 - private LocalDate cycleTime; 25 + private LocalDateTime cycleDate;
25 26
26 private Messenger messenger; 27 private Messenger messenger;
27 28
@@ -52,13 +53,13 @@ public class ReminderImpl extends EntityBaseImpl implements Reminder { @@ -52,13 +53,13 @@ public class ReminderImpl extends EntityBaseImpl implements Reminder {
52 } 53 }
53 54
54 @Override 55 @Override
55 - public LocalDate getCycleTime() {  
56 - return cycleTime; 56 + public LocalDateTime getCycleDate() {
  57 + return cycleDate;
57 } 58 }
58 59
59 @Override 60 @Override
60 - public void setCycleTime(LocalDate cycleTime) {  
61 - this.cycleTime = cycleTime; 61 + public void setCycleDate(LocalDateTime cycleDate) {
  62 + this.cycleDate = cycleDate;
62 } 63 }
63 64
64 @Override 65 @Override
services/MainBot/src/main/java/de/bht/beuthbot/scheduler/SchedulerBean.java
@@ -2,14 +2,15 @@ package de.bht.beuthbot.scheduler; @@ -2,14 +2,15 @@ package de.bht.beuthbot.scheduler;
2 2
3 import de.bht.beuthbot.attachments.AttachmentStore; 3 import de.bht.beuthbot.attachments.AttachmentStore;
4 import de.bht.beuthbot.daos.AppUserDAO; 4 import de.bht.beuthbot.daos.AppUserDAO;
  5 +import de.bht.beuthbot.daos.ReminderDAO;
5 import de.bht.beuthbot.jms.Target; 6 import de.bht.beuthbot.jms.Target;
6 import de.bht.beuthbot.model.Attachment; 7 import de.bht.beuthbot.model.Attachment;
7 import de.bht.beuthbot.model.EntityName; 8 import de.bht.beuthbot.model.EntityName;
8 import de.bht.beuthbot.model.Intent; 9 import de.bht.beuthbot.model.Intent;
9 import de.bht.beuthbot.model.Messenger; 10 import de.bht.beuthbot.model.Messenger;
10 import de.bht.beuthbot.model.entities.AppUser; 11 import de.bht.beuthbot.model.entities.AppUser;
11 -import de.bht.beuthbot.scheduler.model.Reminder;  
12 -import de.bht.beuthbot.scheduler.model.ReminderCycle; 12 +import de.bht.beuthbot.model.entities.Reminder;
  13 +import de.bht.beuthbot.model.enumeration.ReminderCycle;
13 import de.bht.beuthbot.utils.DateStringExtractor; 14 import de.bht.beuthbot.utils.DateStringExtractor;
14 import org.slf4j.Logger; 15 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory; 16 import org.slf4j.LoggerFactory;
@@ -228,16 +229,21 @@ public class SchedulerBean { @@ -228,16 +229,21 @@ public class SchedulerBean {
228 logger.debug("Creating reminder with date " + cycleDate.toString() + " and time " + cycleTime.minusHours(1).toString()); //For some reason the server time is off by an hour, so we need to subtract it from the cycleTime 229 logger.debug("Creating reminder with date " + cycleDate.toString() + " and time " + cycleTime.minusHours(1).toString()); //For some reason the server time is off by an hour, so we need to subtract it from the cycleTime
229 230
230 Reminder reminder = reminderDAO.createReminder(); 231 Reminder reminder = reminderDAO.createReminder();
  232 + logger.debug("resulting DAO object: " + reminder);
231 reminder.setUserId(user.getId()); 233 reminder.setUserId(user.getId());
232 reminder.setReminderCycle(cycle); 234 reminder.setReminderCycle(cycle);
233 - reminder.setCycleTime(cycleDate); 235 + reminder.setCycleDate(cycleDate);
234 reminder.setMessenger(messenger); 236 reminder.setMessenger(messenger);
235 reminder.setIntent(intent); 237 reminder.setIntent(intent);
236 reminder.setEntities(entities); 238 reminder.setEntities(entities);
237 239
238 - return reminderDAO.saveOrUpdate(reminder); 240 + Reminder reminder1 = reminderDAO.saveOrUpdate(reminder);
  241 +
  242 +
  243 +
  244 + return reminder1;
  245 +
239 246
240 - //TODO: Insert the new Reminder into Database  
241 } 247 }
242 248
243 public boolean deleteReminder(TaskMessage message, AppUser user) { 249 public boolean deleteReminder(TaskMessage message, AppUser user) {
@@ -246,8 +252,8 @@ public class SchedulerBean { @@ -246,8 +252,8 @@ public class SchedulerBean {
246 List<Reminder> reminders = reminderDAO.findAll(); 252 List<Reminder> reminders = reminderDAO.findAll();
247 logger.debug("Number of reminders: " + reminders.size()); 253 logger.debug("Number of reminders: " + reminders.size());
248 for(Reminder reminder : reminders) { 254 for(Reminder reminder : reminders) {
249 - logger.debug("Found reminder for this user:" + reminder.getUser().getTelegramUserId());  
250 - if(reminder.getUser().getTelegramUserId().equals(user.getTelegramUserId()) || reminder.getUser().getFacebookUserId().equals(user.getFacebookUserId())) { 255 + logger.debug("Found reminder for this user:" + reminder.getUserId());
  256 + if(reminder.getUserId() == user.getId()) {
251 logger.debug("Found reminder of this user"); 257 logger.debug("Found reminder of this user");
252 reminders.remove(reminder); 258 reminders.remove(reminder);
253 deletedReminders++; 259 deletedReminders++;
services/MainBot/src/main/resources/de/bht/beuthbot/drools/Canteen.drl
@@ -32,17 +32,16 @@ import de.bht.beuthbot.drools.model.DroolsMessage; @@ -32,17 +32,16 @@ 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 de.bht.beuthbot.scheduler.model.ReminderCycle;  
36 import java.util.Date; 35 import java.util.Date;
37 import java.text.SimpleDateFormat; 36 import java.text.SimpleDateFormat;
38 import java.text.ParseException; 37 import java.text.ParseException;
39 import de.bht.beuthbot.model.Messenger; 38 import de.bht.beuthbot.model.Messenger;
40 -import de.bht.beuthbot.scheduler.model.Reminder;  
41 39
42 import java.time.DayOfWeek; 40 import java.time.DayOfWeek;
43 import java.time.LocalDate; 41 import java.time.LocalDate;
44 import de.bht.beuthbot.utils.DateStringExtractor; 42 import de.bht.beuthbot.utils.DateStringExtractor;
45 -import java.time.format.DateTimeFormatter; 43 +import java.time.format.DateTimeFormatter
  44 +import de.bht.beuthbot.model.entities.Reminder;
46 45
47 global de.bht.beuthbot.canteen.model.CanteenData canteenData; 46 global de.bht.beuthbot.canteen.model.CanteenData canteenData;
48 global de.bht.beuthbot.model.entities.AppUser user; 47 global de.bht.beuthbot.model.entities.AppUser user;
@@ -139,7 +138,7 @@ rule &quot;Create reminder&quot; @@ -139,7 +138,7 @@ rule &quot;Create reminder&quot;
139 TaskMessage message = new TaskMessage(m); 138 TaskMessage message = new TaskMessage(m);
140 Reminder reminder = s.createReminder(message, user); 139 Reminder reminder = s.createReminder(message, user);
141 String messageText = ""; 140 String messageText = "";
142 - if(reminder.getIntent() == Intent.SHOW_FOOD.getText()) { 141 + if(reminder.getIntent().equals(Intent.SHOW_FOOD.getText())
143 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!";
144 } else { 143 } else {
145 messageText = "Es war mir leider nicht möglich eine Erinnerung für dich anzulegen. Versuche es bitte noch einmal."; 144 messageText = "Es war mir leider nicht möglich eine Erinnerung für dich anzulegen. Versuche es bitte noch einmal.";
services/Telegram/src/main/java/de/bht/beuthbot/messenger/telegram/TelegramReceiveAdapter.java
@@ -41,6 +41,7 @@ import javax.ws.rs.Path; @@ -41,6 +41,7 @@ import javax.ws.rs.Path;
41 import javax.ws.rs.core.MediaType; 41 import javax.ws.rs.core.MediaType;
42 import javax.ws.rs.core.Response; 42 import javax.ws.rs.core.Response;
43 import java.time.LocalDate; 43 import java.time.LocalDate;
  44 +import java.time.LocalDateTime;
44 import java.util.HashMap; 45 import java.util.HashMap;
45 import java.util.List; 46 import java.util.List;
46 47
@@ -178,7 +179,7 @@ public class TelegramReceiveAdapter { @@ -178,7 +179,7 @@ public class TelegramReceiveAdapter {
178 Reminder reminder = reminderDAO.createReminder(); 179 Reminder reminder = reminderDAO.createReminder();
179 reminder.setMessenger(Messenger.TELEGRAM); 180 reminder.setMessenger(Messenger.TELEGRAM);
180 reminder.setReminderCycle(ReminderCycle.DAILY); 181 reminder.setReminderCycle(ReminderCycle.DAILY);
181 - reminder.setCycleTime(LocalDate.now()); 182 + reminder.setCycleDate(LocalDateTime.now());
182 Long userId = userList.get(0).getId(); 183 Long userId = userList.get(0).getId();
183 reminder.setUserId(userId); 184 reminder.setUserId(userId);
184 reminder.setIntent("Intent"); 185 reminder.setIntent("Intent");