Commit 8199f65654deb7a9984ed36e27ce0c5fc1c91998

Authored by hausdoerfer
1 parent 44dff023

replaced user id with user in reminder and chatmessage

services/Common/src/main/java/de/bht/beuthbot/daos/LogMessageDAO.java renamed to services/Common/src/main/java/de/bht/beuthbot/daos/ChatMessageDAO.java
1 1 package de.bht.beuthbot.daos;
2 2  
3   -import de.bht.beuthbot.model.entities.LogMessage;
  3 +import de.bht.beuthbot.model.entities.ChatMessage;
4 4  
5 5 import javax.ejb.Remote;
6 6  
... ... @@ -8,7 +8,7 @@ import javax.ejb.Remote;
8 8 * Created by Stephan Hausdörfer on 19.01.2018.
9 9 */
10 10 @Remote
11   -public interface LogMessageDAO extends GenericDAO<LogMessage, Long> {
  11 +public interface ChatMessageDAO extends GenericDAO<ChatMessage, Long> {
12 12  
13   - LogMessage createMessage();
  13 + ChatMessage createMessage();
14 14 }
... ...
services/Common/src/main/java/de/bht/beuthbot/daos/LogMessageDAOImpl.java renamed to services/Common/src/main/java/de/bht/beuthbot/daos/ChatMessageDAOImpl.java
1 1 package de.bht.beuthbot.daos;
2 2  
3   -import de.bht.beuthbot.model.entities.LogMessage;
4   -import de.bht.beuthbot.model.entities.LogMessageImpl;
  3 +import de.bht.beuthbot.model.entities.ChatMessage;
  4 +import de.bht.beuthbot.model.entities.ChatMessageImpl;
5 5  
6 6 import javax.ejb.Stateless;
7 7  
... ... @@ -9,10 +9,10 @@ import javax.ejb.Stateless;
9 9 * Created by Stephan Hausdörfer on 19.01.2018.
10 10 */
11 11 @Stateless
12   -public class LogMessageDAOImpl extends GenericHibernateDAO<LogMessage, LogMessageImpl, Long> implements LogMessageDAO {
  12 +public class ChatMessageDAOImpl extends GenericHibernateDAO<ChatMessage, ChatMessageImpl, Long> implements ChatMessageDAO {
13 13  
14 14 @Override
15   - public LogMessage createMessage() {
16   - return new LogMessageImpl();
  15 + public ChatMessage createMessage() {
  16 + return new ChatMessageImpl();
17 17 }
18 18 }
19 19 \ No newline at end of file
... ...
services/Common/src/main/java/de/bht/beuthbot/model/entities/AppUser.java
1 1 package de.bht.beuthbot.model.entities;
2 2  
  3 +import de.bht.beuthbot.model.Messenger;
  4 +
  5 +import java.util.List;
  6 +
3 7 /**
4 8 * Created by Benjamin Rühl on 19.11.2017.
5 9 */
... ... @@ -20,4 +24,10 @@ public interface AppUser extends EntityBase {
20 24 void setProperty(GenericEntityAttribute property);
21 25  
22 26 void setProperty(String propertyName, Object propertyValue);
  27 +
  28 + List<Reminder> getReminders();
  29 +
  30 + List<ChatMessage> getChatMessages();
  31 +
  32 + Messenger getMessenger();
23 33 }
... ...
services/Common/src/main/java/de/bht/beuthbot/model/entities/AppUserImpl.java
1 1 package de.bht.beuthbot.model.entities;
2 2  
  3 +import de.bht.beuthbot.model.Messenger;
3 4 import de.bht.beuthbot.persistence.GenericEntityAccessFacade;
4 5  
5   -import javax.persistence.CascadeType;
6   -import javax.persistence.Entity;
7   -import javax.persistence.OneToOne;
8   -import javax.persistence.Table;
  6 +import javax.persistence.*;
  7 +import java.util.ArrayList;
  8 +import java.util.List;
9 9  
10 10 /**
11 11 * Created by Benjamin Rühl on 19.11.2017.
... ... @@ -23,6 +23,12 @@ public class AppUserImpl extends EntityBaseImpl implements AppUser {
23 23 @OneToOne(cascade = CascadeType.ALL)
24 24 private GenericEntity additionalData;
25 25  
  26 + @OneToMany(fetch=FetchType.LAZY, cascade = CascadeType.ALL, mappedBy="user")
  27 + private List<ReminderImpl> reminders;
  28 +
  29 + @OneToMany(fetch=FetchType.LAZY, cascade = CascadeType.ALL, mappedBy="user")
  30 + private List<ChatMessageImpl> chatMessages;
  31 +
26 32 public AppUserImpl() {
27 33 additionalData = new GenericEntity();
28 34 additionalData.setName("User");
... ... @@ -58,11 +64,31 @@ public class AppUserImpl extends EntityBaseImpl implements AppUser {
58 64 GenericEntityAccessFacade.setAttribute(additionalData, propertyName, propertyValue);
59 65 }
60 66  
  67 + @Override
61 68 public void setFacebookUserId(String facebookUserId) {
62 69 this.facebookUserId = facebookUserId;
63 70 }
64 71  
  72 + @Override
65 73 public void setTelegramUserId(String telegramUserId) {
66 74 this.telegramUserId = telegramUserId;
67 75 }
68   -}
  76 +
  77 + @Override
  78 + public List<Reminder> getReminders() {
  79 + return new ArrayList(reminders);
  80 + }
  81 +
  82 + @Override
  83 + public List<ChatMessage> getChatMessages() {
  84 + return new ArrayList(chatMessages);
  85 + }
  86 +
  87 + @Override
  88 + public Messenger getMessenger(){
  89 + if (!facebookUserId.isEmpty()) {
  90 + return Messenger.FACEBOOK;
  91 + }
  92 + return Messenger.TELEGRAM;
  93 + }
  94 +}
69 95 \ No newline at end of file
... ...
services/Common/src/main/java/de/bht/beuthbot/model/entities/LogMessage.java renamed to services/Common/src/main/java/de/bht/beuthbot/model/entities/ChatMessage.java
... ... @@ -3,11 +3,11 @@ package de.bht.beuthbot.model.entities;
3 3 /**
4 4 * Created by Stephan Hausdörfer on 19.01.2018.
5 5 */
6   -public interface LogMessage extends EntityBase {
  6 +public interface ChatMessage extends EntityBase {
7 7  
8   - long getUserId();
  8 + AppUser getUser();
9 9  
10   - void setUserId(long userId);
  10 + void setUser(AppUser user);
11 11  
12 12 String getMessage();
13 13  
... ...
services/Common/src/main/java/de/bht/beuthbot/model/entities/LogMessageImpl.java renamed to services/Common/src/main/java/de/bht/beuthbot/model/entities/ChatMessageImpl.java
1 1 package de.bht.beuthbot.model.entities;
2 2  
3   -import javax.persistence.Entity;
4   -import javax.persistence.Table;
  3 +import javax.persistence.*;
5 4  
6 5 /**
7 6 * Created by Stephan Hausdörfer on 19.01.2018.
8 7 */
9 8 @Entity
10   -@Table(name = "log_message")
11   -public class LogMessageImpl extends EntityBaseImpl implements LogMessage {
  9 +@Table(name = "chat_message")
  10 +public class ChatMessageImpl extends EntityBaseImpl implements ChatMessage {
12 11  
13   - private long userId;
  12 + @ManyToOne(fetch = FetchType.LAZY)
  13 + @JoinColumn(name = "userId")
  14 + private AppUserImpl user;
14 15  
15 16 private String message;
16 17  
17   -
18 18 @Override
19   - public long getUserId() {
20   - return userId;
  19 + public AppUser getUser() {
  20 + return user;
21 21 }
22 22  
23 23 @Override
24   - public void setUserId(long userId) {
25   - this.userId = userId;
  24 + public void setUser(AppUser user) {
  25 + this.user = (AppUserImpl) user;
26 26 }
27 27  
28 28 @Override
... ...
services/Common/src/main/java/de/bht/beuthbot/model/entities/Reminder.java
1 1 package de.bht.beuthbot.model.entities;
2 2  
3   -import de.bht.beuthbot.model.Messenger;
4 3 import de.bht.beuthbot.model.enumeration.ReminderCycle;
5 4  
6   -import java.time.LocalDate;
7 5 import java.time.LocalDateTime;
8 6 import java.util.Map;
9 7  
... ... @@ -12,9 +10,9 @@ import java.util.Map;
12 10 */
13 11 public interface Reminder extends EntityBase {
14 12  
15   - long getUserId();
  13 + AppUser getUser();
16 14  
17   - void setUserId(long userId);
  15 + void setUser(AppUser user);
18 16  
19 17 ReminderCycle getReminderCycle();
20 18  
... ... @@ -22,11 +20,7 @@ public interface Reminder extends EntityBase {
22 20  
23 21 LocalDateTime getCycleDate();
24 22  
25   - void setCycleDate(LocalDateTime cycleDate);
26   -
27   - Messenger getMessenger();
28   -
29   - void setMessenger(Messenger messenger);
  23 + void setCycleTime(LocalDateTime cycleDate);
30 24  
31 25 String getIntent();
32 26  
... ... @@ -35,4 +29,4 @@ public interface Reminder extends EntityBase {
35 29 Map<String, String> getEntities();
36 30  
37 31 void setEntities(Map<String, String> entities);
38 32 -}
  33 +}
39 34 \ No newline at end of file
... ...
services/Common/src/main/java/de/bht/beuthbot/model/entities/ReminderImpl.java
1 1 package de.bht.beuthbot.model.entities;
2 2  
3   -import de.bht.beuthbot.model.Messenger;
4 3 import de.bht.beuthbot.model.enumeration.ReminderCycle;
5 4  
6   -import javax.persistence.CollectionTable;
7   -import javax.persistence.ElementCollection;
8   -import javax.persistence.Entity;
9   -import javax.persistence.Table;
10   -import java.time.LocalDate;
  5 +import javax.persistence.*;
11 6 import java.time.LocalDateTime;
12 7 import java.util.Map;
13 8  
... ... @@ -18,14 +13,14 @@ import java.util.Map;
18 13 @Table(name = "reminder")
19 14 public class ReminderImpl extends EntityBaseImpl implements Reminder {
20 15  
21   - private long userId;
  16 + @ManyToOne(fetch = FetchType.LAZY)
  17 + @JoinColumn(name = "userId")
  18 + private AppUserImpl user;
22 19  
23 20 private ReminderCycle reminderCycle;
24 21  
25 22 private LocalDateTime cycleDate;
26 23  
27   - private Messenger messenger;
28   -
29 24 private String intent;
30 25  
31 26 @ElementCollection
... ... @@ -33,13 +28,13 @@ public class ReminderImpl extends EntityBaseImpl implements Reminder {
33 28 private Map<String, String> entities;
34 29  
35 30 @Override
36   - public long getUserId() {
37   - return userId;
  31 + public AppUser getUser() {
  32 + return user;
38 33 }
39 34  
40 35 @Override
41   - public void setUserId(long userId) {
42   - this.userId = userId;
  36 + public void setUser(AppUser user) {
  37 + this.user = (AppUserImpl) user;
43 38 }
44 39  
45 40 @Override
... ... @@ -58,21 +53,11 @@ public class ReminderImpl extends EntityBaseImpl implements Reminder {
58 53 }
59 54  
60 55 @Override
61   - public void setCycleDate(LocalDateTime cycleDate) {
  56 + public void setCycleTime(LocalDateTime cycleDate) {
62 57 this.cycleDate = cycleDate;
63 58 }
64 59  
65 60 @Override
66   - public Messenger getMessenger() {
67   - return messenger;
68   - }
69   -
70   - @Override
71   - public void setMessenger(Messenger messenger) {
72   - this.messenger = messenger;
73   - }
74   -
75   - @Override
76 61 public String getIntent() {
77 62 return intent;
78 63 }
... ...
services/MainBot/src/main/java/de/bht/beuthbot/drools/DroolsService.java
... ... @@ -7,7 +7,7 @@ import de.bht.beuthbot.canteen.Parser;
7 7 import de.bht.beuthbot.canteen.model.CanteenData;
8 8 import de.bht.beuthbot.conf.Application;
9 9 import de.bht.beuthbot.daos.AppUserDAO;
10   -import de.bht.beuthbot.daos.LogMessageDAO;
  10 +import de.bht.beuthbot.daos.ChatMessageDAO;
11 11 import de.bht.beuthbot.drools.model.DroolsMessage;
12 12 import de.bht.beuthbot.jms.ProcessQueue;
13 13 import de.bht.beuthbot.jms.ProcessQueueMessageProtocol;
... ... @@ -15,9 +15,9 @@ import de.bht.beuthbot.jms.Target;
15 15 import de.bht.beuthbot.jms.TaskMessage;
16 16 import de.bht.beuthbot.model.Messenger;
17 17 import de.bht.beuthbot.model.entities.AppUser;
18   -
19   -import de.bht.beuthbot.model.entities.LogMessage;
20 18 import de.bht.beuthbot.scheduler.SchedulerBean;
  19 +import de.bht.beuthbot.model.entities.ChatMessage;
  20 +
21 21 import org.kie.api.KieServices;
22 22 import org.kie.api.runtime.KieContainer;
23 23 import org.kie.api.runtime.KieSession;
... ... @@ -73,8 +73,8 @@ public class DroolsService implements MessageListener {
73 73 @Resource(lookup = "java:global/global/AppUserDAOImpl")
74 74 private AppUserDAO userDAO;
75 75  
76   - @Resource(lookup = "java:global/global/LogMessageDAOImpl")
77   - private LogMessageDAO logMessageDAO;
  76 + @Resource(lookup = "java:global/global/ChatMessageDAOImpl")
  77 + private ChatMessageDAO chatMessageDAO;
78 78  
79 79 @Inject
80 80 private SchedulerBean schedulerBean;
... ... @@ -149,10 +149,10 @@ public class DroolsService implements MessageListener {
149 149 }
150 150 AppUser finishedUser = userDAO.saveOrUpdate(tempUser);
151 151  
152   - LogMessage logMessage = logMessageDAO.createMessage();
153   - logMessage.setUserId(finishedUser.getId());
154   - logMessage.setMessage(botMessage.getText());
155   - logMessageDAO.saveOrUpdate(logMessage);
  152 + ChatMessage chatMessage = chatMessageDAO.createMessage();
  153 + chatMessage.setUser(finishedUser);
  154 + chatMessage.setMessage(botMessage.getText());
  155 + chatMessageDAO.saveOrUpdate(chatMessage);
156 156  
157 157 ksession.setGlobal("canteenData", canteenData);
158 158 ksession.setGlobal("user", finishedUser);
... ...
services/MainBot/src/main/java/de/bht/beuthbot/scheduler/SchedulerBean.java
... ... @@ -4,36 +4,29 @@ import de.bht.beuthbot.attachments.AttachmentStore;
4 4 import de.bht.beuthbot.daos.AppUserDAO;
5 5 import de.bht.beuthbot.daos.ReminderDAO;
6 6 import de.bht.beuthbot.jms.Target;
7   -import de.bht.beuthbot.model.Attachment;
8 7 import de.bht.beuthbot.model.EntityName;
9   -import de.bht.beuthbot.model.Intent;
10 8 import de.bht.beuthbot.model.Messenger;
11 9 import de.bht.beuthbot.model.entities.AppUser;
12 10 import de.bht.beuthbot.model.entities.Reminder;
13 11 import de.bht.beuthbot.model.enumeration.ReminderCycle;
14 12 import de.bht.beuthbot.utils.DateStringExtractor;
  13 +
15 14 import org.slf4j.Logger;
16 15 import org.slf4j.LoggerFactory;
17 16  
18 17 import de.bht.beuthbot.conf.Application;
19   -import de.bht.beuthbot.conf.Configuration;
20 18 import de.bht.beuthbot.jms.ProcessQueue;
21 19 import de.bht.beuthbot.jms.TaskMessage;
22 20  
23   -import java.text.ParseException;
24 21 import java.text.SimpleDateFormat;
25 22 import java.time.LocalDate;
26 23 import java.time.LocalDateTime;
27 24 import java.time.LocalTime;
28 25 import java.time.format.DateTimeFormatter;
29   -import java.time.temporal.TemporalAccessor;
30 26 import java.util.*;
31 27 import javax.annotation.PostConstruct;
32 28 import javax.annotation.Resource;
33 29 import javax.ejb.*;
34   -import javax.ejb.Timer;
35   -import javax.ws.rs.GET;
36   -import javax.ws.rs.Path;
37 30  
38 31 @Singleton
39 32 @Startup
... ... @@ -65,7 +58,6 @@ public class SchedulerBean {
65 58 @Resource(lookup = "java:global/global/ReminderDAOImpl")
66 59 private ReminderDAO reminderDAO;
67 60  
68   -
69 61 boolean isActive = true;
70 62  
71 63 public SchedulerBean() {
... ... @@ -95,9 +87,9 @@ public class SchedulerBean {
95 87 //Check if date time now equals reminder date time
96 88 if(dateNow.format(formatter).equals(reminderDate.format(formatter))) {
97 89 Long messageID = 1L;
98   - AppUser user = userDAO.findById(reminder.getUserId());
  90 + AppUser user = userDAO.findById(reminder.getUser().getId());
99 91 Long messengerId = Long.valueOf(user.getFacebookUserId() == null ? user.getTelegramUserId() : user.getFacebookUserId());
100   - Messenger messenger = reminder.getMessenger();
  92 + Messenger messenger = user.getMessenger();
101 93 String text = "";
102 94 String intent = reminder.getIntent();
103 95 Map entities = reminder.getEntities();
... ... @@ -122,11 +114,6 @@ public class SchedulerBean {
122 114 public Reminder createReminder(TaskMessage message, AppUser user) {
123 115 logger.debug("Creating reminder");
124 116  
125   - Messenger messenger = message.getMessenger();
126   -
127   -
128   - //Figure out when to remind the user
129   -
130 117 //Set reminder cycle to one shot as a default
131 118 ReminderCycle cycle = ReminderCycle.ONCE;
132 119 //Extract the Date from the message
... ... @@ -211,7 +198,6 @@ public class SchedulerBean {
211 198 //Figure out what we're reminding the user of
212 199 String intent = message.getEntities().getOrDefault("event","FALLBACK");
213 200  
214   -
215 201 Map<String, String> entities = new HashMap<>();
216 202 entities.put(EntityName.DATE.getText(), cycleDate.toLocalDate().toString());
217 203 entities.put(EntityName.TIME.getText(), cycleTime.toString());
... ... @@ -221,16 +207,13 @@ public class SchedulerBean {
221 207  
222 208 Reminder reminder = reminderDAO.createReminder();
223 209 logger.debug("resulting DAO object: " + reminder);
224   - reminder.setUserId(user.getId());
  210 + reminder.setUser(user);
225 211 reminder.setReminderCycle(cycle);
226   - reminder.setCycleDate(cycleDate);
227   - reminder.setMessenger(messenger);
  212 + reminder.setCycleTime(cycleDate);
228 213 reminder.setIntent(intent);
229 214 reminder.setEntities(entities);
230 215  
231 216 return reminderDAO.saveOrUpdate(reminder);
232   -
233   -
234 217 }
235 218  
236 219 public boolean deleteReminder(TaskMessage message, AppUser user) {
... ... @@ -239,8 +222,8 @@ public class SchedulerBean {
239 222 List<Reminder> reminders = reminderDAO.findAll();
240 223 logger.debug("Number of reminders: " + reminders.size());
241 224 for(Reminder reminder : reminders) {
242   - logger.debug("Found reminder for this user:" + reminder.getUserId());
243   - if(reminder.getUserId() == user.getId()) {
  225 + logger.debug("Found reminder for this user:" + reminder.getUser());
  226 + if(reminder.getUser().getId() == user.getId()) {
244 227 logger.debug("Found reminder of this user");
245 228 reminders.remove(reminder);
246 229 deletedReminders++;
... ...
services/MainBot/src/main/resources/de/bht/beuthbot/drools/Canteen.drl
... ... @@ -20,8 +20,13 @@ import java.util.List;
20 20 import java.util.ArrayList;
21 21 import java.util.Arrays;
22 22 import java.util.HashMap;
23   -
24 23 import java.time.LocalDate;
  24 +import java.time.DayOfWeek;
  25 +import java.time.LocalDate;
  26 +import java.time.format.DateTimeFormatter;
  27 +import java.util.Date;
  28 +import java.text.SimpleDateFormat;
  29 +import java.text.ParseException;
25 30  
26 31 import de.bht.beuthbot.canteen.model.Dish;
27 32 import de.bht.beuthbot.canteen.model.DishType;
... ... @@ -29,18 +34,9 @@ import de.bht.beuthbot.canteen.model.CanteenData;
29 34 import de.bht.beuthbot.model.Intent;
30 35 import de.bht.beuthbot.model.EntityName;
31 36 import de.bht.beuthbot.drools.model.DroolsMessage;
32   -
33   -//import de.bht.beuthbot.scheduler.SchedulerBean;
34 37 import de.bht.beuthbot.jms.TaskMessage;
35   -import java.util.Date;
36   -import java.text.SimpleDateFormat;
37   -import java.text.ParseException;
38 38 import de.bht.beuthbot.model.Messenger;
39   -
40   -import java.time.DayOfWeek;
41   -import java.time.LocalDate;
42 39 import de.bht.beuthbot.utils.DateStringExtractor;
43   -import java.time.format.DateTimeFormatter
44 40 import de.bht.beuthbot.model.entities.Reminder;
45 41 import de.bht.beuthbot.model.enumeration.ReminderCycle;
46 42  
... ... @@ -48,7 +44,6 @@ global de.bht.beuthbot.canteen.model.CanteenData canteenData;
48 44 global de.bht.beuthbot.model.entities.AppUser user;
49 45 global de.bht.beuthbot.scheduler.SchedulerBean schedulerBean;
50 46  
51   -
52 47 // ---------------------- GREETING ------------------------------------
53 48 rule "Hello Drools"
54 49 dialect "java"
... ...
services/Telegram/src/main/java/de/bht/beuthbot/messenger/telegram/TelegramReceiveAdapter.java
... ... @@ -10,11 +10,12 @@ import com.pengrad.telegrambot.request.GetFile;
10 10 import com.pengrad.telegrambot.request.SetWebhook;
11 11 import com.pengrad.telegrambot.response.BaseResponse;
12 12 import com.pengrad.telegrambot.response.GetFileResponse;
  13 +
13 14 import de.bht.beuthbot.attachments.AttachmentStore;
14 15 import de.bht.beuthbot.conf.Application;
15 16 import de.bht.beuthbot.conf.Configuration;
16 17 import de.bht.beuthbot.daos.AppUserDAO;
17   -import de.bht.beuthbot.daos.LogMessageDAO;
  18 +import de.bht.beuthbot.daos.ChatMessageDAO;
18 19 import de.bht.beuthbot.daos.ReminderDAO;
19 20 import de.bht.beuthbot.jms.ProcessQueue;
20 21 import de.bht.beuthbot.jms.TaskMessage;
... ... @@ -25,10 +26,11 @@ import de.bht.beuthbot.model.Attachment;
25 26 import de.bht.beuthbot.model.AttachmentType;
26 27 import de.bht.beuthbot.model.Messenger;
27 28 import de.bht.beuthbot.model.entities.AppUser;
28   -import de.bht.beuthbot.model.entities.LogMessage;
  29 +import de.bht.beuthbot.model.entities.ChatMessage;
29 30 import de.bht.beuthbot.model.entities.Reminder;
30 31 import de.bht.beuthbot.model.enumeration.ReminderCycle;
31 32 import org.apache.http.HttpStatus;
  33 +
32 34 import org.slf4j.Logger;
33 35 import org.slf4j.LoggerFactory;
34 36  
... ... @@ -40,7 +42,6 @@ import javax.ws.rs.POST;
40 42 import javax.ws.rs.Path;
41 43 import javax.ws.rs.core.MediaType;
42 44 import javax.ws.rs.core.Response;
43   -import java.time.LocalDate;
44 45 import java.time.LocalDateTime;
45 46 import java.util.HashMap;
46 47 import java.util.List;
... ... @@ -78,8 +79,8 @@ public class TelegramReceiveAdapter {
78 79 private ReminderDAO reminderDAO;
79 80  
80 81 /** Injected AppUserDAO */
81   - @Resource(lookup = "java:global/global/LogMessageDAOImpl")
82   - private LogMessageDAO logMessageDAO;
  82 + @Resource(lookup = "java:global/global/ChatMessageDAOImpl")
  83 + private ChatMessageDAO chatMessageDAO;
83 84  
84 85 /**
85 86 * Initialize TelegramBot with Token
... ... @@ -155,54 +156,7 @@ public class TelegramReceiveAdapter {
155 156 return null;
156 157 }
157 158 }
158   -
159   - /**
160   - * Test method for database
161   - * @return Http response
162   - */
163   - @GET
164   - @Path("/testDatabase")
165   - public Response testDatabase() {
166   - logger.info("testDatabase: Start");
167   - AppUser user = userDAO.createUser();
168   - user.setFacebookUserId("88");
169   - user.setTelegramUserId("99");
170   - user.setProperty("test_key", "test_value");
171   - userDAO.saveOrUpdate(user);
172   - logger.info("testDatabase: Speichern durchgefuehrt");
173   -
174   - List<AppUser> userList = userDAO.findAll();
175   - String result = userList.get(0).getTelegramUserId();
176   - logger.info("TelegramUserId: " + result);
177   - logger.info("testDatabase: Auslesen durchgefuehrt");
178   -
179   - Reminder reminder = reminderDAO.createReminder();
180   - reminder.setMessenger(Messenger.TELEGRAM);
181   - reminder.setReminderCycle(ReminderCycle.DAILY);
182   - reminder.setCycleDate(LocalDateTime.now());
183   - Long userId = userList.get(0).getId();
184   - reminder.setUserId(userId);
185   - reminder.setIntent("Intent");
186   - HashMap entities = new HashMap();
187   - entities.put("key1", "value2");
188   - entities.put("key2", "value2");
189   - reminder.setEntities(entities);
190   - reminderDAO.saveOrUpdate(reminder);
191   -
192   - List<Reminder> reminders = reminderDAO.findAll();
193   - Reminder reminderResult = reminders.get(0);
194   - logger.info("Reminder Cycle: " + reminderResult.getReminderCycle().toString());
195   - logger.info("Telegram ID via Reminder: " + userDAO.findById(reminderResult.getUserId()).getTelegramUserId());
196   -
197   - LogMessage logMessage = logMessageDAO.createMessage();
198   - logMessage.setUserId(userList.get(0).getId());
199   - logMessage.setMessage("Message");
200   - logMessageDAO.saveOrUpdate(logMessage);
201   -
202   - return Response.status(HttpStatus.SC_OK).build();
203   - }
204   -
205   -
  159 +
206 160 /**
207 161 * RESTEasy HTTP Post to set Webhook
208 162 */
... ...