From 8c363fbf648e5254bf94bb6bc0feb72f4760b8de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=DF?= Date: Fri, 25 May 2012 15:52:42 +0200 Subject: [PATCH] =?UTF-8?q?Anderungen=20am=20Controller.=20Die=20Kanalwert?= =?UTF-8?q?e=20werden=20nicht=20in=20der=20DB=20gespeichert,=20deswegen=20?= =?UTF-8?q?bekommt=20man=20immer=200=20zurueck=20wenn=20man=20sich=20die?= =?UTF-8?q?=20Ger=C3=A4te=20holt.=20Leider=20nicht=20funktional=20soweit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ctdo/bunti/control/BuntiController.java | 3 +++ .../bunti/control/BuntiControllerImpl.java | 22 +++++++++++++++++++ .../java/de/ctdo/bunti/dmx/DMXMixerImpl.java | 11 +++++----- .../bunti/{web => }/model/DeviceUpdate.java | 2 +- .../bunti/web/DeviceControlController.java | 12 ++++++++-- .../de/ctdo/bunti/web/DevicesController.java | 13 ++++++++--- .../ctdo/bunti/web/model/DeviceUpdates.java | 2 ++ 7 files changed, 54 insertions(+), 11 deletions(-) rename src/main/java/de/ctdo/bunti/{web => }/model/DeviceUpdate.java (93%) 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;