some events
This commit is contained in:
1 parent
c6c68262c5
commit
0bc44cf04e
4 files changed
+32
-13
No files matched your search
@@ -46,10 +46,7 @@ public class Config extends SpringBootServletInitializer {
|
||||
EntryEventRepository entryEventRepository = context.getBean(EntryEventRepository.class);
|
||||
HistoryEntryRepository historyEntryRepository = context.getBean(HistoryEntryRepository.class);
|
||||
new Initializer(roleRepository, userRepository, doorRepository, historyEntryRepository).init();
|
||||
User user =new User("aa","bb","cc","dd");
|
||||
entryEventRepository.save(new EntryEvent(1,1,2));
|
||||
entryEventRepository.save(new EntryEvent(1,2,2));
|
||||
entryEventRepository.save(new EntryEvent(2,1,2));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -79,8 +79,8 @@ public class EventController {
|
||||
|
||||
@RequestMapping(value = "/MainDoorEntry/add")
|
||||
@ResponseBody
|
||||
public BaseResponse addMainDoorEntry(@RequestParam long who ) throws JSONException {
|
||||
mainDoorEntryEventRepository.save(new MainDoorEntryEvent(who));
|
||||
public BaseResponse addMainDoorEntry(@RequestParam long who,@RequestParam long userId ) throws JSONException {
|
||||
mainDoorEntryEventRepository.save(new MainDoorEntryEvent(who,userId));
|
||||
return new BaseResponse().init(Constants.SUCCESS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,13 @@ package application.events;
|
||||
import application.events.impl.DoorLockedEvent;
|
||||
import application.events.impl.EntryEvent;
|
||||
import application.events.impl.MainDoorEntryEvent;
|
||||
import application.model.User;
|
||||
import application.repositories.*;
|
||||
import org.reflections.Reflections;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -74,31 +76,35 @@ public class EventManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void sendNotification(EventObject eventObject){
|
||||
System.out.print(eventObject.createMessage());
|
||||
public void sendNotification(EventObject eventObject,User user){
|
||||
String uri = "https://android.googleapis.com/gcm/send";
|
||||
System.out.print(eventObject.createMessage() + user);
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
restTemplate.getForObject(uri,
|
||||
String.class);
|
||||
}
|
||||
|
||||
public void processEvent(long userId , long doorId){
|
||||
if(doorId==1){
|
||||
for(MainDoorEntryEvent e: mainDoorEntryEventRepository.findAll()){
|
||||
if(e.getWho()==userId){
|
||||
sendNotification(e);
|
||||
sendNotification(e,userRepository.findOne(e.getUser()));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
for (EntryEvent e : entryEventRepository.findAll()) {
|
||||
if (e.getWho() == userId && e.getDoor() == doorId)
|
||||
sendNotification(e);
|
||||
sendNotification(e,userRepository.findOne(e.getUser()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void doorLockedEvent(DoorLockedEvent doorLockedEvent){
|
||||
System.out.print("lala");
|
||||
|
||||
for(User user:userRepository.findAll()){
|
||||
sendNotification(doorLockedEvent,user);
|
||||
}
|
||||
}
|
||||
public void doorUnlockedEvent(DoorLockedEvent doorLockedEvent){
|
||||
System.out.print("lala");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,9 @@ public class MainDoorEntryEvent implements EventObject {
|
||||
@Basic
|
||||
private Long who;
|
||||
|
||||
@Basic
|
||||
private Long user;
|
||||
|
||||
@Override
|
||||
public void validEvent() {
|
||||
|
||||
@@ -61,5 +64,18 @@ public class MainDoorEntryEvent implements EventObject {
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public MainDoorEntryEvent(Long who, Long user) {
|
||||
this.who = who;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public Long getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(Long user) {
|
||||
this.user = user;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user