diff --git a/pom.xml b/pom.xml
index f5e5b40..5be7ad3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,42 +9,112 @@
3.0.5.RELEASE
7.2.0.v20101020
+ 1.6.4
-
- com.springsource.repository.bundles.release
- EBR Spring Release Repository
- http://repository.springsource.com/maven/bundles/release
-
+
+ org.jboss.repository.release
+ JBoss Maven Release Repository
+ https://repository.jboss.org/nexus/content/repositories/releases
+ false
+
+
+ org.springframework
+ spring-context
+ ${org.springframework.version}
+
+
+
+ commons-logging
+ commons-logging
+
+
+
+
+
+ org.springframework
+ spring-webmvc
+ ${org.springframework.version}
+
+
+
org.slf4j
slf4j-api
- 1.6.4
+ ${org.slf4j.version}
-
+
+ org.slf4j
+ jcl-over-slf4j
+ ${org.slf4j.version}
+ runtime
+
+
org.slf4j
slf4j-log4j12
- 1.6.4
+ ${org.slf4j.version}
+ runtime
-
+
log4j
log4j
1.2.16
+ runtime
+
+
+
+ javax.validation
+ validation-api
+ 1.0.0.GA
+
+
+
+ org.hibernate
+ hibernate-validator
+ 4.1.0.Final
+
+
+
+ joda-time
+ joda-time
+ 1.6.2
+ runtime
+
+
+
+ org.codehaus.jackson
+ jackson-mapper-asl
+ 1.6.4
+
+
+
+
+ javax.servlet
+ servlet-api
+ 2.5
+ provided
+
+
+ javax.servlet.jsp
+ jsp-api
+ 2.1
+ provided
+
+
+ javax.servlet
+ jstl
+ 1.2
+
+
- com.sun.grizzly
- grizzly-websockets
- 1.9.46
-
-
- net.sf.json-lib
- json-lib
- 2.4
- jdk15
+ junit
+ junit
+ 4.10
@@ -53,46 +123,6 @@
${jettyVersion}
-
-
- org.springframework
- spring-core
- ${org.springframework.version}
-
-
-
- org.springframework
- spring-context
- ${org.springframework.version}
-
-
-
- org.springframework
- spring-webmvc
- ${org.springframework.version}
-
-
-
- org.springframework
- spring-oxm
- ${org.springframework.version}
-
-
-
- junit
- junit
- 4.10
-
-
- javax.validation
- validation-api
- 1.0.0.GA
-
-
- com.thoughtworks.xstream
- xstream
- 1.3.1
-
@@ -100,22 +130,33 @@
org.apache.maven.plugins
maven-compiler-plugin
- 2.3.2
1.6
+
- org.apache.maven.plugins
- maven-checkstyle-plugin
- 2.9.1
+ org.apache.maven.plugins
+ maven-dependency-plugin
+
+
+ install
+ install
+
+ sources
+
+
+
org.mortbay.jetty
jetty-maven-plugin
${jettyVersion}
+
+ 5
+
diff --git a/src/main/java/de/ctdo/bunti/control/BuntiController.java b/src/main/java/de/ctdo/bunti/control/BuntiController.java
index 3530ce1..ae9f0f1 100644
--- a/src/main/java/de/ctdo/bunti/control/BuntiController.java
+++ b/src/main/java/de/ctdo/bunti/control/BuntiController.java
@@ -10,6 +10,6 @@ public interface BuntiController {
Collection getAllDevices();
BuntiDevice getDeviceById(int deviceId);
- boolean setDevice(int deviceId, Map options);
+ boolean updateDeviceData(int deviceId, Map options);
}
diff --git a/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java b/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java
index c3f0a2f..a4b67b4 100644
--- a/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java
+++ b/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java
@@ -26,16 +26,18 @@ public class BuntiControllerImpl implements BuntiController, ApplicationEventPub
}
@Override
- public Collection getAllDevices() {
- return devicesDAO.getAllDevices();
+ public final void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
+ this.applicationEventPublisher = publisher;
}
+
@Override
- public final boolean setDevice(int deviceId, Map options) {
+ public final boolean updateDeviceData(int deviceId, Map options) {
BuntiDevice device = devicesDAO.getDeviceById(deviceId);
if (device != null) {
this.applicationEventPublisher.publishEvent(new DeviceChangedEvent(this, device, options));
+
LOGGER.debug("publishEvent in BuntiController");
return true;
}
@@ -43,19 +45,14 @@ public class BuntiControllerImpl implements BuntiController, ApplicationEventPub
return false;
}
+ @Override
+ public Collection getAllDevices() {
+ return devicesDAO.getAllDevices();
+ }
+
@Override
public BuntiDevice getDeviceById(int deviceId) {
return devicesDAO.getDeviceById(deviceId);
}
- @Override
- public final void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
- this.applicationEventPublisher = publisher;
- }
-
- // public void sendBroadcastMessage(String message) {
- // for (BroadcastListener l : listeners) {
- // l.Broadcast(message);
- // }
- // }
}
diff --git a/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAOImpl.java b/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAOImpl.java
index 5e85c66..a142599 100644
--- a/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAOImpl.java
+++ b/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAOImpl.java
@@ -13,7 +13,7 @@ import org.springframework.stereotype.Repository;
@Repository
public final class BuntiDevicesDAOImpl implements BuntiDevicesDAO {
- private Logger logger = LoggerFactory.getLogger(getClass());
+ private static final Logger LOGGER = LoggerFactory.getLogger(BuntiDevicesDAOImpl.class);
private List devices = new ArrayList();
public BuntiDevicesDAOImpl() {
@@ -30,7 +30,7 @@ public final class BuntiDevicesDAOImpl implements BuntiDevicesDAO {
devices.add(new Par56Spot(deviceID++, 16, "Par56 Lampe 4"));
devices.add(new Strobe1500(deviceID++, 21, "Stroboskop 1"));
devices.add(new Par56Spot(deviceID, 508, "Par56 Lampe 5"));
- logger.debug("added dummy devices in DAO");
+ LOGGER.debug("added dummy devices in DAO");
}
diff --git a/src/main/java/de/ctdo/bunti/dmx/DMXMixerImpl.java b/src/main/java/de/ctdo/bunti/dmx/DMXMixerImpl.java
index 7a32102..5a6cf67 100644
--- a/src/main/java/de/ctdo/bunti/dmx/DMXMixerImpl.java
+++ b/src/main/java/de/ctdo/bunti/dmx/DMXMixerImpl.java
@@ -15,7 +15,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-@Component
public class DMXMixerImpl implements DMXMixer, ApplicationListener {
private static final Logger LOGGER = LoggerFactory.getLogger(DMXMixerImpl.class);
private static final int NET_SEND_INTERVAL = 100;
@@ -28,6 +27,7 @@ public class DMXMixerImpl implements DMXMixer, ApplicationListener DMX.DMX_CHANNEL_INDEX_MAX) {
@@ -50,7 +51,6 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
DMXChannel dx = dmxChannels.getChannelByName(name);
if (dx != null) {
dx.setValue(DMX.sanitizeDMXValue(value));
- lastChangedNow();
return true;
}
return false;
@@ -74,6 +74,7 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
* Collect the DMX Channel Data with correct DMX512 calculated offsets
* @return The channel data with startaddress+offset of every channel
*/
+ @JsonIgnore
public Map getChannelData() {
Map map = new HashMap();
diff --git a/src/main/java/de/ctdo/bunti/model/BuntiDevice.java b/src/main/java/de/ctdo/bunti/model/BuntiDevice.java
index 88b1990..4d1665b 100644
--- a/src/main/java/de/ctdo/bunti/model/BuntiDevice.java
+++ b/src/main/java/de/ctdo/bunti/model/BuntiDevice.java
@@ -1,41 +1,55 @@
package de.ctdo.bunti.model;
-import com.thoughtworks.xstream.annotations.XStreamAlias;
-
import java.util.Map;
-@XStreamAlias("buntiDevice")
+/**
+ * A physical device type in the bunti system.
+ * Maybe this is a lamp, or a switchable power source, or a strobe, ...
+ * @author lucas
+ */
public abstract class BuntiDevice {
private int deviceId;
private String deviceName;
- private long lastChanged;
-
- public BuntiDevice(int deviceId, String deviceName, long lastChanged) {
- this.deviceId = deviceId;
- this.deviceName = deviceName;
- this.lastChanged = lastChanged;
- }
public BuntiDevice(int deviceId, String deviceName) {
- this(deviceId, deviceName, System.currentTimeMillis());
+ this.deviceId = deviceId;
+ this.deviceName = deviceName;
}
+ /**
+ * Get the type of this device
+ * @return a string with the class name (=the Type)
+ */
+ @SuppressWarnings("UnusedDeclaration")
+ public final String getType() {
+ String FQClassName = this.getClass().getName();
+ int firstChar = FQClassName.lastIndexOf ('.') + 1;
+ if ( firstChar > 0 ) {
+ FQClassName = FQClassName.substring ( firstChar );
+ }
+ return FQClassName;
+ }
+
+ /**
+ * Gets the device Id
+ * @return the device Id
+ */
public final int getDeviceId() {
return deviceId;
}
- public final long getLastChanged() {
- return lastChanged;
- }
-
- protected final void lastChangedNow() {
- this.lastChanged = System.currentTimeMillis();
- }
-
+ /**
+ * Gets the device name
+ * @return The name of the device
+ */
public final String getDeviceName() {
return deviceName;
}
+ /**
+ * Sets the device Name
+ * @param deviceName a String with the device name
+ */
public final void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
diff --git a/src/main/java/de/ctdo/bunti/model/BuntiSwitchingDevice.java b/src/main/java/de/ctdo/bunti/model/BuntiSwitchingDevice.java
index b9b5bba..1dfe65d 100644
--- a/src/main/java/de/ctdo/bunti/model/BuntiSwitchingDevice.java
+++ b/src/main/java/de/ctdo/bunti/model/BuntiSwitchingDevice.java
@@ -5,10 +5,6 @@ import java.util.Map;
public abstract class BuntiSwitchingDevice extends BuntiDevice {
- public BuntiSwitchingDevice(int deviceId, String deviceName, long lastChanged) {
- super(deviceId, deviceName, lastChanged);
- }
-
public BuntiSwitchingDevice(int deviceId, String deviceName) {
super(deviceId, deviceName);
}
diff --git a/src/main/java/de/ctdo/bunti/web/RestController.java b/src/main/java/de/ctdo/bunti/web/RestController.java
index adeea60..bc68cb3 100644
--- a/src/main/java/de/ctdo/bunti/web/RestController.java
+++ b/src/main/java/de/ctdo/bunti/web/RestController.java
@@ -1,20 +1,27 @@
package de.ctdo.bunti.web;
import de.ctdo.bunti.control.BuntiController;
+import de.ctdo.bunti.model.BuntiDevice;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
-import org.springframework.web.servlet.ModelAndView;
+
+import javax.validation.Validator;
+import java.util.Collection;
+import java.util.Map;
@Controller
public class RestController {
-// private Validator validator;
+ private static final Logger LOGGER = LoggerFactory.getLogger(RestController.class);
+ private Validator validator;
private BuntiController controller;
-// @Autowired
-// public void setValidator(Validator validator) {
-// this.validator = validator;
-// }
+ @Autowired
+ public void setValidator(Validator validator) {
+ this.validator = validator;
+ }
@Autowired
public final void setController(BuntiController controller) {
@@ -23,23 +30,23 @@ public class RestController {
@RequestMapping(value = "/devices", method = RequestMethod.GET)
- public final ModelAndView getAll() {
- return new ModelAndView("deviceList", "deviceList", controller.getAllDevices());
+ public @ResponseBody Collection getAll() {
+ LOGGER.info("handle GET /devices request");
+ return controller.getAllDevices();
}
@RequestMapping(value = "/devices/{id}", method = RequestMethod.GET)
- public final ModelAndView getDeviceById(@PathVariable("id") int id) {
- return new ModelAndView("device", "device", controller.getDeviceById(id));
+ public @ResponseBody BuntiDevice getDeviceById(@PathVariable("id") int id) {
+ LOGGER.info("handle GET /devices/" + id + " request");
+ return controller.getDeviceById(id);
}
-// @RequestMapping(value = "/devices/{id}", method = RequestMethod.PUT)
-// public String setDeviceById(@ModelAttribute @Valid DeviceUpdate update, BindingResult errors) {
-// if (errors.hasErrors()) {
-// return "redirect:/index.html";
-// } else {
-// controller.setDevice(update.getDeviceId(), update.getOptions());
-// return "redirect:devices/" + update.getDeviceId();
-// }
-// }
+ @RequestMapping(value = "/devices/{id}", method = RequestMethod.PUT)
+ public String setDeviceById(@PathVariable("id") int id, @RequestBody Map update) {
+ LOGGER.info("handle PUT /devices/" + id + " request update=" + update.toString() );
+
+ controller.updateDeviceData(id, update);
+ return "redirect:devices/" + id;
+ }
}
diff --git a/src/main/java/de/ctdo/bunti/web/json/ConversionServiceAwareObjectMapper.java b/src/main/java/de/ctdo/bunti/web/json/ConversionServiceAwareObjectMapper.java
new file mode 100644
index 0000000..1af58a2
--- /dev/null
+++ b/src/main/java/de/ctdo/bunti/web/json/ConversionServiceAwareObjectMapper.java
@@ -0,0 +1,25 @@
+package de.ctdo.bunti.web.json;
+
+//import org.codehaus.jackson.map.AnnotationIntrospector;
+//import org.codehaus.jackson.map.DeserializationConfig;
+//import org.codehaus.jackson.map.ObjectMapper;
+//import org.codehaus.jackson.map.SerializationConfig;
+//import org.codehaus.jackson.map.introspect.VisibilityChecker;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.core.convert.ConversionService;
+//
+///**
+// * A custom Jackson ObjectMapper that installs JSON serialization/deserialization support
+// * for properties annotated with Spring format annotations such as @DateTimeFormat and @NumberFormat.
+// */
+//public class ConversionServiceAwareObjectMapper extends ObjectMapper {
+//
+// @Autowired
+// public ConversionServiceAwareObjectMapper(ConversionService conversionService) {
+// AnnotationIntrospector introspector = AnnotationIntrospector.pair(new FormatAnnotationIntrospector(conversionService), DEFAULT_ANNOTATION_INTROSPECTOR);
+// SerializationConfig sconfig = new SerializationConfig(DEFAULT_INTROSPECTOR, introspector, VisibilityChecker.Std.defaultInstance(), null);
+// DeserializationConfig dconfig = new DeserializationConfig(DEFAULT_INTROSPECTOR, introspector, VisibilityChecker.Std.defaultInstance(), null);
+// setSerializationConfig(sconfig);
+// setDeserializationConfig(dconfig);
+// }
+//}
diff --git a/src/main/java/de/ctdo/bunti/web/json/ConvertingDeserializer.java b/src/main/java/de/ctdo/bunti/web/json/ConvertingDeserializer.java
new file mode 100644
index 0000000..8d352f5
--- /dev/null
+++ b/src/main/java/de/ctdo/bunti/web/json/ConvertingDeserializer.java
@@ -0,0 +1,31 @@
+package de.ctdo.bunti.web.json;
+//
+//import java.io.IOException;
+//
+//import org.codehaus.jackson.JsonParser;
+//import org.codehaus.jackson.JsonProcessingException;
+//import org.codehaus.jackson.map.DeserializationContext;
+//import org.codehaus.jackson.map.JsonDeserializer;
+//import org.springframework.core.convert.ConversionService;
+//import org.springframework.core.convert.TypeDescriptor;
+//
+//final class ConvertingDeserializer extends JsonDeserializer