diff --git a/src/main/java/de/ctdo/bunti/control/BuntiController.java b/src/main/java/de/ctdo/bunti/control/BuntiController.java index 0374d7c..79e0f72 100644 --- a/src/main/java/de/ctdo/bunti/control/BuntiController.java +++ b/src/main/java/de/ctdo/bunti/control/BuntiController.java @@ -1,6 +1,7 @@ package de.ctdo.bunti.control; import de.ctdo.bunti.model.BuntiDevice; +import de.ctdo.bunti.model.DeviceUpdate; import de.ctdo.bunti.model.Room; import java.util.Collection; @@ -16,4 +17,6 @@ public interface BuntiController { Collection getAllRooms(); Room getRoomById(int roomId); + DeviceUpdate getDeviceValues(int deviceId); + } diff --git a/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java b/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java index 2b388d9..3dc4a0a 100644 --- a/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java +++ b/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java @@ -1,10 +1,12 @@ package de.ctdo.bunti.control; import java.util.Collection; +import java.util.HashMap; import java.util.Map; import de.ctdo.bunti.dao.RoomsDAO; import de.ctdo.bunti.model.*; +import org.apache.commons.collections.map.HashedMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -20,6 +22,7 @@ public class BuntiControllerImpl implements BuntiController, ApplicationEventPu private ApplicationEventPublisher applicationEventPublisher = null; private BuntiDevicesDAO devicesDAO; private RoomsDAO roomsDAO; + private Map> deviceCache = new HashMap>(); @Autowired @@ -45,6 +48,15 @@ public class BuntiControllerImpl implements BuntiController, ApplicationEventPu if (device != null) { LOGGER.debug("publishEvent in BuntiController"); + Map cached = deviceCache.get(deviceId); + if(cached == null ) { + cached = new HashMap(); + deviceCache.put(deviceId, cached); + } + cached.putAll(options); + + device.setValuesFromOptions(options) ; + this.applicationEventPublisher.publishEvent(new DeviceChangedEvent(this, device, options)); return true; @@ -53,6 +65,16 @@ public class BuntiControllerImpl implements BuntiController, ApplicationEventPu return false; } + @Override + public DeviceUpdate getDeviceValues(int deviceId) { + Map cached = deviceCache.get(deviceId); + + DeviceUpdate du = new DeviceUpdate(); + du.setDeviceId(deviceId); + du.setOptions(cached); + return du; + } + @Override public Collection getAllRooms() { return roomsDAO.getRooms(); diff --git a/src/main/java/de/ctdo/bunti/dmx/DMXMixerImpl.java b/src/main/java/de/ctdo/bunti/dmx/DMXMixerImpl.java index da35663..305ed71 100644 --- a/src/main/java/de/ctdo/bunti/dmx/DMXMixerImpl.java +++ b/src/main/java/de/ctdo/bunti/dmx/DMXMixerImpl.java @@ -40,6 +40,7 @@ public class DMXMixerImpl implements DMXMixer, ApplicationListener getAll() { - return devicesDAO.getAllDevices(); + return buntiController.getAllDevices(); } @RequestMapping(value = "/{id}", method = RequestMethod.GET) @ResponseBody public BuntiDevice getDeviceById(@PathVariable("id") int id) { - return devicesDAO.getDeviceById(id); + return buntiController.getDeviceById(id); } @RequestMapping(value = "", method = RequestMethod.POST) @ResponseBody public BuntiDevice setDevices(@RequestBody BuntiDevice device) { - devicesDAO.addDevice(device); + //buntiController.addDevice(device); return device; } } diff --git a/src/main/java/de/ctdo/bunti/web/model/DeviceUpdates.java b/src/main/java/de/ctdo/bunti/web/model/DeviceUpdates.java index c673ccd..e95aa80 100644 --- a/src/main/java/de/ctdo/bunti/web/model/DeviceUpdates.java +++ b/src/main/java/de/ctdo/bunti/web/model/DeviceUpdates.java @@ -1,5 +1,7 @@ package de.ctdo.bunti.web.model; +import de.ctdo.bunti.model.DeviceUpdate; + import java.util.ArrayList; import java.util.List;