Commit 8199f65654deb7a9984ed36e27ce0c5fc1c91998
1 parent
44dff023
replaced user id with user in reminder and chatmessage
Showing
12 changed files
with
104 additions
and
156 deletions
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 | package de.bht.beuthbot.daos; | 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 | import javax.ejb.Remote; | 5 | import javax.ejb.Remote; |
6 | 6 | ||
@@ -8,7 +8,7 @@ import javax.ejb.Remote; | @@ -8,7 +8,7 @@ import javax.ejb.Remote; | ||
8 | * Created by Stephan Hausdörfer on 19.01.2018. | 8 | * Created by Stephan Hausdörfer on 19.01.2018. |
9 | */ | 9 | */ |
10 | @Remote | 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 | package de.bht.beuthbot.daos; | 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 | import javax.ejb.Stateless; | 6 | import javax.ejb.Stateless; |
7 | 7 | ||
@@ -9,10 +9,10 @@ import javax.ejb.Stateless; | @@ -9,10 +9,10 @@ import javax.ejb.Stateless; | ||
9 | * Created by Stephan Hausdörfer on 19.01.2018. | 9 | * Created by Stephan Hausdörfer on 19.01.2018. |
10 | */ | 10 | */ |
11 | @Stateless | 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 | @Override | 14 | @Override |
15 | - public LogMessage createMessage() { | ||
16 | - return new LogMessageImpl(); | 15 | + public ChatMessage createMessage() { |
16 | + return new ChatMessageImpl(); | ||
17 | } | 17 | } |
18 | } | 18 | } |
19 | \ No newline at end of file | 19 | \ No newline at end of file |
services/Common/src/main/java/de/bht/beuthbot/model/entities/AppUser.java
1 | package de.bht.beuthbot.model.entities; | 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 | * Created by Benjamin Rühl on 19.11.2017. | 8 | * Created by Benjamin Rühl on 19.11.2017. |
5 | */ | 9 | */ |
@@ -20,4 +24,10 @@ public interface AppUser extends EntityBase { | @@ -20,4 +24,10 @@ public interface AppUser extends EntityBase { | ||
20 | void setProperty(GenericEntityAttribute property); | 24 | void setProperty(GenericEntityAttribute property); |
21 | 25 | ||
22 | void setProperty(String propertyName, Object propertyValue); | 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 | package de.bht.beuthbot.model.entities; | 1 | package de.bht.beuthbot.model.entities; |
2 | 2 | ||
3 | +import de.bht.beuthbot.model.Messenger; | ||
3 | import de.bht.beuthbot.persistence.GenericEntityAccessFacade; | 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 | * Created by Benjamin Rühl on 19.11.2017. | 11 | * Created by Benjamin Rühl on 19.11.2017. |
@@ -23,6 +23,12 @@ public class AppUserImpl extends EntityBaseImpl implements AppUser { | @@ -23,6 +23,12 @@ public class AppUserImpl extends EntityBaseImpl implements AppUser { | ||
23 | @OneToOne(cascade = CascadeType.ALL) | 23 | @OneToOne(cascade = CascadeType.ALL) |
24 | private GenericEntity additionalData; | 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 | public AppUserImpl() { | 32 | public AppUserImpl() { |
27 | additionalData = new GenericEntity(); | 33 | additionalData = new GenericEntity(); |
28 | additionalData.setName("User"); | 34 | additionalData.setName("User"); |
@@ -58,11 +64,31 @@ public class AppUserImpl extends EntityBaseImpl implements AppUser { | @@ -58,11 +64,31 @@ public class AppUserImpl extends EntityBaseImpl implements AppUser { | ||
58 | GenericEntityAccessFacade.setAttribute(additionalData, propertyName, propertyValue); | 64 | GenericEntityAccessFacade.setAttribute(additionalData, propertyName, propertyValue); |
59 | } | 65 | } |
60 | 66 | ||
67 | + @Override | ||
61 | public void setFacebookUserId(String facebookUserId) { | 68 | public void setFacebookUserId(String facebookUserId) { |
62 | this.facebookUserId = facebookUserId; | 69 | this.facebookUserId = facebookUserId; |
63 | } | 70 | } |
64 | 71 | ||
72 | + @Override | ||
65 | public void setTelegramUserId(String telegramUserId) { | 73 | public void setTelegramUserId(String telegramUserId) { |
66 | this.telegramUserId = telegramUserId; | 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 | \ No newline at end of file | 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,11 +3,11 @@ package de.bht.beuthbot.model.entities; | ||
3 | /** | 3 | /** |
4 | * Created by Stephan Hausdörfer on 19.01.2018. | 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 | String getMessage(); | 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 | package de.bht.beuthbot.model.entities; | 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 | * Created by Stephan Hausdörfer on 19.01.2018. | 6 | * Created by Stephan Hausdörfer on 19.01.2018. |
8 | */ | 7 | */ |
9 | @Entity | 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 | private String message; | 16 | private String message; |
16 | 17 | ||
17 | - | ||
18 | @Override | 18 | @Override |
19 | - public long getUserId() { | ||
20 | - return userId; | 19 | + public AppUser getUser() { |
20 | + return user; | ||
21 | } | 21 | } |
22 | 22 | ||
23 | @Override | 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 | @Override | 28 | @Override |
services/Common/src/main/java/de/bht/beuthbot/model/entities/Reminder.java
1 | package de.bht.beuthbot.model.entities; | 1 | package de.bht.beuthbot.model.entities; |
2 | 2 | ||
3 | -import de.bht.beuthbot.model.Messenger; | ||
4 | import de.bht.beuthbot.model.enumeration.ReminderCycle; | 3 | import de.bht.beuthbot.model.enumeration.ReminderCycle; |
5 | 4 | ||
6 | -import java.time.LocalDate; | ||
7 | import java.time.LocalDateTime; | 5 | import java.time.LocalDateTime; |
8 | import java.util.Map; | 6 | import java.util.Map; |
9 | 7 | ||
@@ -12,9 +10,9 @@ import java.util.Map; | @@ -12,9 +10,9 @@ import java.util.Map; | ||
12 | */ | 10 | */ |
13 | public interface Reminder extends EntityBase { | 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 | ReminderCycle getReminderCycle(); | 17 | ReminderCycle getReminderCycle(); |
20 | 18 | ||
@@ -22,11 +20,7 @@ public interface Reminder extends EntityBase { | @@ -22,11 +20,7 @@ public interface Reminder extends EntityBase { | ||
22 | 20 | ||
23 | LocalDateTime getCycleDate(); | 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 | String getIntent(); | 25 | String getIntent(); |
32 | 26 | ||
@@ -35,4 +29,4 @@ public interface Reminder extends EntityBase { | @@ -35,4 +29,4 @@ public interface Reminder extends EntityBase { | ||
35 | Map<String, String> getEntities(); | 29 | Map<String, String> getEntities(); |
36 | 30 | ||
37 | void setEntities(Map<String, String> entities); | 31 | void setEntities(Map<String, String> entities); |
38 | -} | 32 | -} |
33 | +} | ||
39 | \ No newline at end of file | 34 | \ No newline at end of file |
services/Common/src/main/java/de/bht/beuthbot/model/entities/ReminderImpl.java
1 | package de.bht.beuthbot.model.entities; | 1 | package de.bht.beuthbot.model.entities; |
2 | 2 | ||
3 | -import de.bht.beuthbot.model.Messenger; | ||
4 | import de.bht.beuthbot.model.enumeration.ReminderCycle; | 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 | import java.time.LocalDateTime; | 6 | import java.time.LocalDateTime; |
12 | import java.util.Map; | 7 | import java.util.Map; |
13 | 8 | ||
@@ -18,14 +13,14 @@ import java.util.Map; | @@ -18,14 +13,14 @@ import java.util.Map; | ||
18 | @Table(name = "reminder") | 13 | @Table(name = "reminder") |
19 | public class ReminderImpl extends EntityBaseImpl implements Reminder { | 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 | private ReminderCycle reminderCycle; | 20 | private ReminderCycle reminderCycle; |
24 | 21 | ||
25 | private LocalDateTime cycleDate; | 22 | private LocalDateTime cycleDate; |
26 | 23 | ||
27 | - private Messenger messenger; | ||
28 | - | ||
29 | private String intent; | 24 | private String intent; |
30 | 25 | ||
31 | @ElementCollection | 26 | @ElementCollection |
@@ -33,13 +28,13 @@ public class ReminderImpl extends EntityBaseImpl implements Reminder { | @@ -33,13 +28,13 @@ public class ReminderImpl extends EntityBaseImpl implements Reminder { | ||
33 | private Map<String, String> entities; | 28 | private Map<String, String> entities; |
34 | 29 | ||
35 | @Override | 30 | @Override |
36 | - public long getUserId() { | ||
37 | - return userId; | 31 | + public AppUser getUser() { |
32 | + return user; | ||
38 | } | 33 | } |
39 | 34 | ||
40 | @Override | 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 | @Override | 40 | @Override |
@@ -58,21 +53,11 @@ public class ReminderImpl extends EntityBaseImpl implements Reminder { | @@ -58,21 +53,11 @@ public class ReminderImpl extends EntityBaseImpl implements Reminder { | ||
58 | } | 53 | } |
59 | 54 | ||
60 | @Override | 55 | @Override |
61 | - public void setCycleDate(LocalDateTime cycleDate) { | 56 | + public void setCycleTime(LocalDateTime cycleDate) { |
62 | this.cycleDate = cycleDate; | 57 | this.cycleDate = cycleDate; |
63 | } | 58 | } |
64 | 59 | ||
65 | @Override | 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 | public String getIntent() { | 61 | public String getIntent() { |
77 | return intent; | 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 +7,7 @@ import de.bht.beuthbot.canteen.Parser; | ||
7 | import de.bht.beuthbot.canteen.model.CanteenData; | 7 | import de.bht.beuthbot.canteen.model.CanteenData; |
8 | import de.bht.beuthbot.conf.Application; | 8 | import de.bht.beuthbot.conf.Application; |
9 | import de.bht.beuthbot.daos.AppUserDAO; | 9 | import de.bht.beuthbot.daos.AppUserDAO; |
10 | -import de.bht.beuthbot.daos.LogMessageDAO; | 10 | +import de.bht.beuthbot.daos.ChatMessageDAO; |
11 | import de.bht.beuthbot.drools.model.DroolsMessage; | 11 | import de.bht.beuthbot.drools.model.DroolsMessage; |
12 | import de.bht.beuthbot.jms.ProcessQueue; | 12 | import de.bht.beuthbot.jms.ProcessQueue; |
13 | import de.bht.beuthbot.jms.ProcessQueueMessageProtocol; | 13 | import de.bht.beuthbot.jms.ProcessQueueMessageProtocol; |
@@ -15,9 +15,9 @@ import de.bht.beuthbot.jms.Target; | @@ -15,9 +15,9 @@ import de.bht.beuthbot.jms.Target; | ||
15 | import de.bht.beuthbot.jms.TaskMessage; | 15 | import de.bht.beuthbot.jms.TaskMessage; |
16 | import de.bht.beuthbot.model.Messenger; | 16 | import de.bht.beuthbot.model.Messenger; |
17 | import de.bht.beuthbot.model.entities.AppUser; | 17 | import de.bht.beuthbot.model.entities.AppUser; |
18 | - | ||
19 | -import de.bht.beuthbot.model.entities.LogMessage; | ||
20 | import de.bht.beuthbot.scheduler.SchedulerBean; | 18 | import de.bht.beuthbot.scheduler.SchedulerBean; |
19 | +import de.bht.beuthbot.model.entities.ChatMessage; | ||
20 | + | ||
21 | import org.kie.api.KieServices; | 21 | import org.kie.api.KieServices; |
22 | import org.kie.api.runtime.KieContainer; | 22 | import org.kie.api.runtime.KieContainer; |
23 | import org.kie.api.runtime.KieSession; | 23 | import org.kie.api.runtime.KieSession; |
@@ -73,8 +73,8 @@ public class DroolsService implements MessageListener { | @@ -73,8 +73,8 @@ public class DroolsService implements MessageListener { | ||
73 | @Resource(lookup = "java:global/global/AppUserDAOImpl") | 73 | @Resource(lookup = "java:global/global/AppUserDAOImpl") |
74 | private AppUserDAO userDAO; | 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 | @Inject | 79 | @Inject |
80 | private SchedulerBean schedulerBean; | 80 | private SchedulerBean schedulerBean; |
@@ -149,10 +149,10 @@ public class DroolsService implements MessageListener { | @@ -149,10 +149,10 @@ public class DroolsService implements MessageListener { | ||
149 | } | 149 | } |
150 | AppUser finishedUser = userDAO.saveOrUpdate(tempUser); | 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 | ksession.setGlobal("canteenData", canteenData); | 157 | ksession.setGlobal("canteenData", canteenData); |
158 | ksession.setGlobal("user", finishedUser); | 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,36 +4,29 @@ 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.daos.ReminderDAO; |
6 | import de.bht.beuthbot.jms.Target; | 6 | import de.bht.beuthbot.jms.Target; |
7 | -import de.bht.beuthbot.model.Attachment; | ||
8 | import de.bht.beuthbot.model.EntityName; | 7 | import de.bht.beuthbot.model.EntityName; |
9 | -import de.bht.beuthbot.model.Intent; | ||
10 | import de.bht.beuthbot.model.Messenger; | 8 | import de.bht.beuthbot.model.Messenger; |
11 | import de.bht.beuthbot.model.entities.AppUser; | 9 | import de.bht.beuthbot.model.entities.AppUser; |
12 | import de.bht.beuthbot.model.entities.Reminder; | 10 | import de.bht.beuthbot.model.entities.Reminder; |
13 | import de.bht.beuthbot.model.enumeration.ReminderCycle; | 11 | import de.bht.beuthbot.model.enumeration.ReminderCycle; |
14 | import de.bht.beuthbot.utils.DateStringExtractor; | 12 | import de.bht.beuthbot.utils.DateStringExtractor; |
13 | + | ||
15 | import org.slf4j.Logger; | 14 | import org.slf4j.Logger; |
16 | import org.slf4j.LoggerFactory; | 15 | import org.slf4j.LoggerFactory; |
17 | 16 | ||
18 | import de.bht.beuthbot.conf.Application; | 17 | import de.bht.beuthbot.conf.Application; |
19 | -import de.bht.beuthbot.conf.Configuration; | ||
20 | import de.bht.beuthbot.jms.ProcessQueue; | 18 | import de.bht.beuthbot.jms.ProcessQueue; |
21 | import de.bht.beuthbot.jms.TaskMessage; | 19 | import de.bht.beuthbot.jms.TaskMessage; |
22 | 20 | ||
23 | -import java.text.ParseException; | ||
24 | import java.text.SimpleDateFormat; | 21 | import java.text.SimpleDateFormat; |
25 | import java.time.LocalDate; | 22 | import java.time.LocalDate; |
26 | import java.time.LocalDateTime; | 23 | import java.time.LocalDateTime; |
27 | import java.time.LocalTime; | 24 | import java.time.LocalTime; |
28 | import java.time.format.DateTimeFormatter; | 25 | import java.time.format.DateTimeFormatter; |
29 | -import java.time.temporal.TemporalAccessor; | ||
30 | import java.util.*; | 26 | import java.util.*; |
31 | import javax.annotation.PostConstruct; | 27 | import javax.annotation.PostConstruct; |
32 | import javax.annotation.Resource; | 28 | import javax.annotation.Resource; |
33 | import javax.ejb.*; | 29 | import javax.ejb.*; |
34 | -import javax.ejb.Timer; | ||
35 | -import javax.ws.rs.GET; | ||
36 | -import javax.ws.rs.Path; | ||
37 | 30 | ||
38 | @Singleton | 31 | @Singleton |
39 | @Startup | 32 | @Startup |
@@ -65,7 +58,6 @@ public class SchedulerBean { | @@ -65,7 +58,6 @@ public class SchedulerBean { | ||
65 | @Resource(lookup = "java:global/global/ReminderDAOImpl") | 58 | @Resource(lookup = "java:global/global/ReminderDAOImpl") |
66 | private ReminderDAO reminderDAO; | 59 | private ReminderDAO reminderDAO; |
67 | 60 | ||
68 | - | ||
69 | boolean isActive = true; | 61 | boolean isActive = true; |
70 | 62 | ||
71 | public SchedulerBean() { | 63 | public SchedulerBean() { |
@@ -95,9 +87,9 @@ public class SchedulerBean { | @@ -95,9 +87,9 @@ public class SchedulerBean { | ||
95 | //Check if date time now equals reminder date time | 87 | //Check if date time now equals reminder date time |
96 | if(dateNow.format(formatter).equals(reminderDate.format(formatter))) { | 88 | if(dateNow.format(formatter).equals(reminderDate.format(formatter))) { |
97 | Long messageID = 1L; | 89 | Long messageID = 1L; |
98 | - AppUser user = userDAO.findById(reminder.getUserId()); | 90 | + AppUser user = userDAO.findById(reminder.getUser().getId()); |
99 | Long messengerId = Long.valueOf(user.getFacebookUserId() == null ? user.getTelegramUserId() : user.getFacebookUserId()); | 91 | Long messengerId = Long.valueOf(user.getFacebookUserId() == null ? user.getTelegramUserId() : user.getFacebookUserId()); |
100 | - Messenger messenger = reminder.getMessenger(); | 92 | + Messenger messenger = user.getMessenger(); |
101 | String text = ""; | 93 | String text = ""; |
102 | String intent = reminder.getIntent(); | 94 | String intent = reminder.getIntent(); |
103 | Map entities = reminder.getEntities(); | 95 | Map entities = reminder.getEntities(); |
@@ -122,11 +114,6 @@ public class SchedulerBean { | @@ -122,11 +114,6 @@ public class SchedulerBean { | ||
122 | public Reminder createReminder(TaskMessage message, AppUser user) { | 114 | public Reminder createReminder(TaskMessage message, AppUser user) { |
123 | logger.debug("Creating reminder"); | 115 | logger.debug("Creating reminder"); |
124 | 116 | ||
125 | - Messenger messenger = message.getMessenger(); | ||
126 | - | ||
127 | - | ||
128 | - //Figure out when to remind the user | ||
129 | - | ||
130 | //Set reminder cycle to one shot as a default | 117 | //Set reminder cycle to one shot as a default |
131 | ReminderCycle cycle = ReminderCycle.ONCE; | 118 | ReminderCycle cycle = ReminderCycle.ONCE; |
132 | //Extract the Date from the message | 119 | //Extract the Date from the message |
@@ -211,7 +198,6 @@ public class SchedulerBean { | @@ -211,7 +198,6 @@ public class SchedulerBean { | ||
211 | //Figure out what we're reminding the user of | 198 | //Figure out what we're reminding the user of |
212 | String intent = message.getEntities().getOrDefault("event","FALLBACK"); | 199 | String intent = message.getEntities().getOrDefault("event","FALLBACK"); |
213 | 200 | ||
214 | - | ||
215 | Map<String, String> entities = new HashMap<>(); | 201 | Map<String, String> entities = new HashMap<>(); |
216 | entities.put(EntityName.DATE.getText(), cycleDate.toLocalDate().toString()); | 202 | entities.put(EntityName.DATE.getText(), cycleDate.toLocalDate().toString()); |
217 | entities.put(EntityName.TIME.getText(), cycleTime.toString()); | 203 | entities.put(EntityName.TIME.getText(), cycleTime.toString()); |
@@ -221,16 +207,13 @@ public class SchedulerBean { | @@ -221,16 +207,13 @@ public class SchedulerBean { | ||
221 | 207 | ||
222 | Reminder reminder = reminderDAO.createReminder(); | 208 | Reminder reminder = reminderDAO.createReminder(); |
223 | logger.debug("resulting DAO object: " + reminder); | 209 | logger.debug("resulting DAO object: " + reminder); |
224 | - reminder.setUserId(user.getId()); | 210 | + reminder.setUser(user); |
225 | reminder.setReminderCycle(cycle); | 211 | reminder.setReminderCycle(cycle); |
226 | - reminder.setCycleDate(cycleDate); | ||
227 | - reminder.setMessenger(messenger); | 212 | + reminder.setCycleTime(cycleDate); |
228 | reminder.setIntent(intent); | 213 | reminder.setIntent(intent); |
229 | reminder.setEntities(entities); | 214 | reminder.setEntities(entities); |
230 | 215 | ||
231 | return reminderDAO.saveOrUpdate(reminder); | 216 | return reminderDAO.saveOrUpdate(reminder); |
232 | - | ||
233 | - | ||
234 | } | 217 | } |
235 | 218 | ||
236 | public boolean deleteReminder(TaskMessage message, AppUser user) { | 219 | public boolean deleteReminder(TaskMessage message, AppUser user) { |
@@ -239,8 +222,8 @@ public class SchedulerBean { | @@ -239,8 +222,8 @@ public class SchedulerBean { | ||
239 | List<Reminder> reminders = reminderDAO.findAll(); | 222 | List<Reminder> reminders = reminderDAO.findAll(); |
240 | logger.debug("Number of reminders: " + reminders.size()); | 223 | logger.debug("Number of reminders: " + reminders.size()); |
241 | for(Reminder reminder : reminders) { | 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 | logger.debug("Found reminder of this user"); | 227 | logger.debug("Found reminder of this user"); |
245 | reminders.remove(reminder); | 228 | reminders.remove(reminder); |
246 | deletedReminders++; | 229 | deletedReminders++; |
services/MainBot/src/main/resources/de/bht/beuthbot/drools/Canteen.drl
@@ -20,8 +20,13 @@ import java.util.List; | @@ -20,8 +20,13 @@ import java.util.List; | ||
20 | import java.util.ArrayList; | 20 | import java.util.ArrayList; |
21 | import java.util.Arrays; | 21 | import java.util.Arrays; |
22 | import java.util.HashMap; | 22 | import java.util.HashMap; |
23 | - | ||
24 | import java.time.LocalDate; | 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 | import de.bht.beuthbot.canteen.model.Dish; | 31 | import de.bht.beuthbot.canteen.model.Dish; |
27 | import de.bht.beuthbot.canteen.model.DishType; | 32 | import de.bht.beuthbot.canteen.model.DishType; |
@@ -29,18 +34,9 @@ import de.bht.beuthbot.canteen.model.CanteenData; | @@ -29,18 +34,9 @@ import de.bht.beuthbot.canteen.model.CanteenData; | ||
29 | import de.bht.beuthbot.model.Intent; | 34 | import de.bht.beuthbot.model.Intent; |
30 | import de.bht.beuthbot.model.EntityName; | 35 | import de.bht.beuthbot.model.EntityName; |
31 | import de.bht.beuthbot.drools.model.DroolsMessage; | 36 | import de.bht.beuthbot.drools.model.DroolsMessage; |
32 | - | ||
33 | -//import de.bht.beuthbot.scheduler.SchedulerBean; | ||
34 | import de.bht.beuthbot.jms.TaskMessage; | 37 | import de.bht.beuthbot.jms.TaskMessage; |
35 | -import java.util.Date; | ||
36 | -import java.text.SimpleDateFormat; | ||
37 | -import java.text.ParseException; | ||
38 | import de.bht.beuthbot.model.Messenger; | 38 | import de.bht.beuthbot.model.Messenger; |
39 | - | ||
40 | -import java.time.DayOfWeek; | ||
41 | -import java.time.LocalDate; | ||
42 | import de.bht.beuthbot.utils.DateStringExtractor; | 39 | import de.bht.beuthbot.utils.DateStringExtractor; |
43 | -import java.time.format.DateTimeFormatter | ||
44 | import de.bht.beuthbot.model.entities.Reminder; | 40 | import de.bht.beuthbot.model.entities.Reminder; |
45 | import de.bht.beuthbot.model.enumeration.ReminderCycle; | 41 | import de.bht.beuthbot.model.enumeration.ReminderCycle; |
46 | 42 | ||
@@ -48,7 +44,6 @@ global de.bht.beuthbot.canteen.model.CanteenData canteenData; | @@ -48,7 +44,6 @@ global de.bht.beuthbot.canteen.model.CanteenData canteenData; | ||
48 | global de.bht.beuthbot.model.entities.AppUser user; | 44 | global de.bht.beuthbot.model.entities.AppUser user; |
49 | global de.bht.beuthbot.scheduler.SchedulerBean schedulerBean; | 45 | global de.bht.beuthbot.scheduler.SchedulerBean schedulerBean; |
50 | 46 | ||
51 | - | ||
52 | // ---------------------- GREETING ------------------------------------ | 47 | // ---------------------- GREETING ------------------------------------ |
53 | rule "Hello Drools" | 48 | rule "Hello Drools" |
54 | dialect "java" | 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,11 +10,12 @@ import com.pengrad.telegrambot.request.GetFile; | ||
10 | import com.pengrad.telegrambot.request.SetWebhook; | 10 | import com.pengrad.telegrambot.request.SetWebhook; |
11 | import com.pengrad.telegrambot.response.BaseResponse; | 11 | import com.pengrad.telegrambot.response.BaseResponse; |
12 | import com.pengrad.telegrambot.response.GetFileResponse; | 12 | import com.pengrad.telegrambot.response.GetFileResponse; |
13 | + | ||
13 | import de.bht.beuthbot.attachments.AttachmentStore; | 14 | import de.bht.beuthbot.attachments.AttachmentStore; |
14 | import de.bht.beuthbot.conf.Application; | 15 | import de.bht.beuthbot.conf.Application; |
15 | import de.bht.beuthbot.conf.Configuration; | 16 | import de.bht.beuthbot.conf.Configuration; |
16 | import de.bht.beuthbot.daos.AppUserDAO; | 17 | import de.bht.beuthbot.daos.AppUserDAO; |
17 | -import de.bht.beuthbot.daos.LogMessageDAO; | 18 | +import de.bht.beuthbot.daos.ChatMessageDAO; |
18 | import de.bht.beuthbot.daos.ReminderDAO; | 19 | import de.bht.beuthbot.daos.ReminderDAO; |
19 | import de.bht.beuthbot.jms.ProcessQueue; | 20 | import de.bht.beuthbot.jms.ProcessQueue; |
20 | import de.bht.beuthbot.jms.TaskMessage; | 21 | import de.bht.beuthbot.jms.TaskMessage; |
@@ -25,10 +26,11 @@ import de.bht.beuthbot.model.Attachment; | @@ -25,10 +26,11 @@ import de.bht.beuthbot.model.Attachment; | ||
25 | import de.bht.beuthbot.model.AttachmentType; | 26 | import de.bht.beuthbot.model.AttachmentType; |
26 | import de.bht.beuthbot.model.Messenger; | 27 | import de.bht.beuthbot.model.Messenger; |
27 | import de.bht.beuthbot.model.entities.AppUser; | 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 | import de.bht.beuthbot.model.entities.Reminder; | 30 | import de.bht.beuthbot.model.entities.Reminder; |
30 | import de.bht.beuthbot.model.enumeration.ReminderCycle; | 31 | import de.bht.beuthbot.model.enumeration.ReminderCycle; |
31 | import org.apache.http.HttpStatus; | 32 | import org.apache.http.HttpStatus; |
33 | + | ||
32 | import org.slf4j.Logger; | 34 | import org.slf4j.Logger; |
33 | import org.slf4j.LoggerFactory; | 35 | import org.slf4j.LoggerFactory; |
34 | 36 | ||
@@ -40,7 +42,6 @@ import javax.ws.rs.POST; | @@ -40,7 +42,6 @@ import javax.ws.rs.POST; | ||
40 | import javax.ws.rs.Path; | 42 | import javax.ws.rs.Path; |
41 | import javax.ws.rs.core.MediaType; | 43 | import javax.ws.rs.core.MediaType; |
42 | import javax.ws.rs.core.Response; | 44 | import javax.ws.rs.core.Response; |
43 | -import java.time.LocalDate; | ||
44 | import java.time.LocalDateTime; | 45 | import java.time.LocalDateTime; |
45 | import java.util.HashMap; | 46 | import java.util.HashMap; |
46 | import java.util.List; | 47 | import java.util.List; |
@@ -78,8 +79,8 @@ public class TelegramReceiveAdapter { | @@ -78,8 +79,8 @@ public class TelegramReceiveAdapter { | ||
78 | private ReminderDAO reminderDAO; | 79 | private ReminderDAO reminderDAO; |
79 | 80 | ||
80 | /** Injected AppUserDAO */ | 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 | * Initialize TelegramBot with Token | 86 | * Initialize TelegramBot with Token |
@@ -155,54 +156,7 @@ public class TelegramReceiveAdapter { | @@ -155,54 +156,7 @@ public class TelegramReceiveAdapter { | ||
155 | return null; | 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 | * RESTEasy HTTP Post to set Webhook | 161 | * RESTEasy HTTP Post to set Webhook |
208 | */ | 162 | */ |