some events
This commit is contained in:
1 parent
2b657edec9
commit
c6c68262c5
2 files changed
+59
-9
No files matched your search
@@ -38,14 +38,11 @@ public class EventController {
|
||||
EventManager eventManager;
|
||||
|
||||
|
||||
@RequestMapping(value = "/{doorId}/{userId}")
|
||||
@RequestMapping(value = "notifyServer")
|
||||
@ResponseBody
|
||||
public BaseResponse entryEventTrigger(@RequestParam("userId") long userId ,@RequestParam("doorId") long doorId) throws JSONException {
|
||||
|
||||
for(EntryEvent e: entryEventRepository.findAll()){
|
||||
if(e.getWho()==userId&&e.getDoor()==doorId)
|
||||
eventManager.sendNotification(e);
|
||||
}
|
||||
eventManager.processEvent(userId, doorId);
|
||||
return new BaseResponse().init(Constants.SUCCESS_TRUE);
|
||||
}
|
||||
|
||||
@@ -82,8 +79,8 @@ public class EventController {
|
||||
|
||||
@RequestMapping(value = "/MainDoorEntry/add")
|
||||
@ResponseBody
|
||||
public BaseResponse addMainDoorEntry(@RequestParam long doorId ) throws JSONException {
|
||||
mainDoorEntryEventRepository.save(new MainDoorEntryEvent(doorId));
|
||||
public BaseResponse addMainDoorEntry(@RequestParam long who ) throws JSONException {
|
||||
mainDoorEntryEventRepository.save(new MainDoorEntryEvent(who));
|
||||
return new BaseResponse().init(Constants.SUCCESS_TRUE);
|
||||
}
|
||||
|
||||
@@ -111,7 +108,9 @@ public class EventController {
|
||||
@RequestMapping(value = "/DoorLockedEntry/add")
|
||||
@ResponseBody
|
||||
public BaseResponse addDoorLockedEntry(@RequestParam long doorId, @RequestParam String why) throws JSONException {
|
||||
doorLockedEventRepository.save(new DoorLockedEvent(doorId,why));
|
||||
DoorLockedEvent ev = new DoorLockedEvent(doorId,why);
|
||||
doorLockedEventRepository.save(ev);
|
||||
eventManager.doorLockedEvent(ev);
|
||||
return new BaseResponse().init(Constants.SUCCESS_TRUE);
|
||||
}
|
||||
|
||||
@@ -130,7 +129,11 @@ public class EventController {
|
||||
@RequestMapping(value = "/DoorLockedEntry/remove/{id}")
|
||||
@ResponseBody
|
||||
public BaseResponse removeDoorLockedEntry(@PathVariable("id") long id) throws JSONException {
|
||||
doorLockedEventRepository.delete(id);
|
||||
DoorLockedEvent event = doorLockedEventRepository.findOne(id);
|
||||
if (event != null) {
|
||||
eventManager.doorUnlockedEvent(event);
|
||||
doorLockedEventRepository.delete(id);
|
||||
}
|
||||
return new BaseResponse().init(Constants.SUCCESS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
package application.events;
|
||||
|
||||
import application.events.impl.DoorLockedEvent;
|
||||
import application.events.impl.EntryEvent;
|
||||
import application.events.impl.MainDoorEntryEvent;
|
||||
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 java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -12,6 +18,23 @@ import java.util.Set;
|
||||
@Component
|
||||
public class EventManager {
|
||||
|
||||
@Autowired
|
||||
MainDoorEntryEventRepository mainDoorEntryEventRepository;
|
||||
|
||||
@Autowired
|
||||
DoorLockedEventRepository doorLockedEventRepository;
|
||||
|
||||
|
||||
@Autowired
|
||||
EntryEventRepository entryEventRepository;
|
||||
|
||||
@Autowired
|
||||
UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
DoorRepository doorRepository;
|
||||
|
||||
|
||||
Set<Class<? extends EventObject>> eventClassSet;
|
||||
Set<EventObject> eventsSet;
|
||||
public EventManager() {
|
||||
@@ -54,4 +77,28 @@ public class EventManager {
|
||||
public void sendNotification(EventObject eventObject){
|
||||
System.out.print(eventObject.createMessage());
|
||||
}
|
||||
|
||||
public void processEvent(long userId , long doorId){
|
||||
if(doorId==1){
|
||||
for(MainDoorEntryEvent e: mainDoorEntryEventRepository.findAll()){
|
||||
if(e.getWho()==userId){
|
||||
sendNotification(e);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
for (EntryEvent e : entryEventRepository.findAll()) {
|
||||
if (e.getWho() == userId && e.getDoor() == doorId)
|
||||
sendNotification(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void doorLockedEvent(DoorLockedEvent doorLockedEvent){
|
||||
System.out.print("lala");
|
||||
|
||||
}
|
||||
public void doorUnlockedEvent(DoorLockedEvent doorLockedEvent){
|
||||
System.out.print("lala");
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user