uwaga nie dziala

This commit is contained in:
lukasgol committed 2015-02-11 01:06:24 +01:00
1 parent a733249665
commit 1e281381f2
8 files changed
+232 -4

No files matched your search

@@ -0,0 +1,33 @@
package application;
import application.events.EventObject;
import org.reflections.Reflections;
import java.util.Set;
/**
* Created by lukasgol on 01.02.15.
*/
public class ClassFinder {
private static ClassFinder ourInstance = new ClassFinder();
public static ClassFinder getInstance() {
return ourInstance;
}
private ClassFinder() {
}
public static void main(String[] args
) throws IllegalAccessException, InstantiationException {
System.out.println("Class Finder started...");
Reflections reflections = new Reflections("application");
Set<Class<? extends EventObject>> classes = reflections.getSubTypesOf(EventObject.class);
for (Class<? extends EventObject> c : classes) {
EventObject obj=c.newInstance();
System.out.println(c);
}
System.out.println("Class Finder stoped");
}
}
+10 -4
View File
@@ -1,9 +1,10 @@
package application;
import application.repositories.DoorRepository;
import application.repositories.HistoryEntryRepository;
import application.repositories.RoleRepository;
import application.repositories.UserRepository;
import application.events.EventObject;
import application.events.impl.EntryEvent;
import application.events.impl.EventObjectImpl;
import application.model.User;
import application.repositories.*;
import application.utils.Initializer;
import application.utils.TokensGenerator;
import org.springframework.boot.SpringApplication;
@@ -42,8 +43,13 @@ public class Config extends SpringBootServletInitializer {
UserRepository userRepository = context.getBean(UserRepository.class);
RoleRepository roleRepository = context.getBean(RoleRepository.class);
DoorRepository doorRepository = context.getBean(DoorRepository.class);
EventRepositoriy eventRepositoriy = context.getBean(EventRepositoriy.class);
HistoryEntryRepository historyEntryRepository = context.getBean(HistoryEntryRepository.class);
new Initializer(roleRepository, userRepository, doorRepository, historyEntryRepository).init();
User user =new User("aa","bb","cc","dd");
eventRepositoriy.save(new EntryEvent(1,1,2));
eventRepositoriy.save(new EntryEvent(1,2,2));
eventRepositoriy.save(new EntryEvent(2,1,2));
}
@@ -0,0 +1,68 @@
package application.controllers;
import application.Constants;
import application.events.EventManager;
import application.events.EventObject;
import application.events.impl.EntryEvent;
import application.model.Door;
import application.model.User;
import application.network.response.BaseResponse;
import application.repositories.DoorRepository;
import application.repositories.EventRepositoriy;
import application.repositories.UserRepository;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.ArrayList;
import java.util.List;
/**
* Created by lukasgol on 10.02.15.
*/
@Controller
@RequestMapping(value="/event")
public class EventController {
@Autowired
EventRepositoriy eventRepositoriy;
@Autowired
UserRepository userRepository;
@Autowired
DoorRepository doorRepository;
@Autowired
EventManager eventManager;
@RequestMapping(value = "/eventEntry")
@ResponseBody
public BaseResponse entryEventTrigger(@RequestBody long userId, @RequestBody long doorId) throws JSONException {
for(EntryEvent e: eventRepositoriy.findAll()){
if(e.getWho()==userId&&e.getDoor()==doorId)
eventManager.sendNotification(e);
}
return new BaseResponse().init(Constants.SUCCESS_TRUE);
}
@RequestMapping(value = "/eventEntry/add")
@ResponseBody
public BaseResponse addEventTrigger(@RequestBody long userId, @RequestBody long doorId,@RequestBody long who) throws JSONException {
eventRepositoriy.save(new EntryEvent(doorId,who,userId));
return new BaseResponse().init(Constants.SUCCESS_TRUE);
}
@RequestMapping(value = "/eventEntry/getAll")
@ResponseBody
public Iterable<EntryEvent> getAll() throws JSONException {
Iterable<EntryEvent> a =eventRepositoriy.findAll();
return eventRepositoriy.findAll();
}
}
@@ -50,4 +50,8 @@ public class EventManager {
if(e.isValid())e.handleEvent();
}
}
public void sendNotification(EventObject eventObject){
System.out.print(eventObject.createMessage());
}
}
@@ -7,4 +7,5 @@ public interface EventObject {
public void validEvent();
public void handleEvent();
public boolean isValid();
public String createMessage();
}
@@ -0,0 +1,97 @@
package application.events.impl;
import application.events.EventObject;
import application.model.Door;
import application.model.User;
import application.repositories.DoorRepository;
import application.repositories.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import javax.persistence.*;
/**
* Created by lukasgol on 10.02.15.
*/
@Entity
public class EntryEvent implements EventObject {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long entryEventId;
@Basic
private Long door;
@Basic
private Long who;
@Basic
private Long user;
public EntryEvent(int i, int i1, int i2) {
this.door = Long.valueOf(i);
this.who = Long.valueOf(i1);
this.user = Long.valueOf(i2);
}
@Override
public void validEvent() {
}
@Override
public void handleEvent() {
}
@Override
public boolean isValid() {
return false;
}
public EntryEvent(Long door, Long user) {
this.door = door;
this.user = user;
}
public Long getDoor() {
return door;
}
public void setDoor(Long door) {
this.door = door;
}
public Long getUser() {
return user;
}
public void setUser(Long user) {
this.user = user;
}
public Long getWho() {
return who;
}
public void setWho(Long who) {
this.who = who;
}
public EntryEvent(Long door, Long who, Long user) {
this.door = door;
this.who = who;
this.user = user;
}
public EntryEvent() {
}
@Override
public String createMessage() {
return "User: "+who+" passed through door: " +door;
}
}
@@ -1,11 +1,14 @@
package application.events.impl;
import application.events.EventObject;
import application.model.User;
/**
* Created by lukasgol on 01.02.15.
*/
public class EventObjectImpl implements EventObject {
public User user;
@Override
public void validEvent() {
System.out.println("Chceking event: "+this.getClass().getName());
@@ -20,4 +23,9 @@ public class EventObjectImpl implements EventObject {
public boolean isValid() {
return true;
}
@Override
public String createMessage() {
return "User: "+user.getFirstName()+" "+user.getLastName()+" passed through door" ;
}
}
@@ -0,0 +1,11 @@
package application.repositories;
import application.events.impl.EntryEvent;
import org.springframework.data.repository.CrudRepository;
/**
* Created by lukasgol on 01.02.15.
*/
public interface EventRepositoriy extends CrudRepository<EntryEvent, Long>
{
}