Compare commits

..

No commits in common. "maint/lp" and "master" have entirely different histories.

43 changed files with 277 additions and 613 deletions

View File

@ -1,4 +1,4 @@
package de.ctdo.bunti.control; package de.ctdo.bunti;
import java.util.Map; import java.util.Map;

View File

@ -1,7 +1,6 @@
package de.ctdo.bunti.control; package de.ctdo.bunti.control;
import de.ctdo.bunti.model.BuntiDevice; import de.ctdo.bunti.model.BuntiDevice;
import de.ctdo.bunti.model.DeviceUpdate;
import de.ctdo.bunti.model.Room; import de.ctdo.bunti.model.Room;
import java.util.Collection; import java.util.Collection;
@ -9,7 +8,12 @@ import java.util.Map;
public interface BuntiController { public interface BuntiController {
Collection<BuntiDevice> getAllDevices();
BuntiDevice getDeviceById(int deviceId);
boolean updateDeviceData(int deviceId, Map<String, Object> options); boolean updateDeviceData(int deviceId, Map<String, Object> options);
DeviceUpdate getDeviceValues(int deviceId);
Collection<Room> getAllRooms();
Room getRoomById(int roomId);
} }

View File

@ -1,8 +1,9 @@
package de.ctdo.bunti.control; package de.ctdo.bunti.control;
import java.util.Collection;
import java.util.Map; import java.util.Map;
import de.ctdo.bunti.model.*; import de.ctdo.bunti.dao.RoomsDAO;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -10,24 +11,34 @@ import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware; import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import de.ctdo.bunti.DeviceChangedEvent;
import de.ctdo.bunti.dao.BuntiDevicesDAO; import de.ctdo.bunti.dao.BuntiDevicesDAO;
import de.ctdo.bunti.model.*;
@Component @Component
public class BuntiControllerImpl implements BuntiController, ApplicationEventPublisherAware { public class BuntiControllerImpl implements BuntiController, ApplicationEventPublisherAware {
private static final Logger LOGGER = LoggerFactory.getLogger(BuntiControllerImpl.class); private static final Logger LOGGER = LoggerFactory.getLogger(BuntiControllerImpl.class);
private ApplicationEventPublisher applicationEventPublisher = null; private ApplicationEventPublisher applicationEventPublisher = null;
@Autowired
private BuntiDevicesDAO devicesDAO; private BuntiDevicesDAO devicesDAO;
private RoomsDAO roomsDAO;
@Autowired
public final void setDevicesDAO(BuntiDevicesDAO devicesDAO) {
this.devicesDAO = devicesDAO;
}
@Autowired @Autowired
private DeviceValueCache deviceCache; public final void setRoomsDAO(RoomsDAO roomsDAO) {
this.roomsDAO = roomsDAO;
}
@Override @Override
public final void setApplicationEventPublisher(ApplicationEventPublisher publisher) { public final void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
this.applicationEventPublisher = publisher; this.applicationEventPublisher = publisher;
} }
@Override @Override
public final boolean updateDeviceData(int deviceId, Map<String, Object> options) { public final boolean updateDeviceData(int deviceId, Map<String, Object> options) {
BuntiDevice device = devicesDAO.getDeviceById(deviceId); BuntiDevice device = devicesDAO.getDeviceById(deviceId);
@ -35,10 +46,6 @@ public class BuntiControllerImpl implements BuntiController, ApplicationEventPu
if (device != null) { if (device != null) {
LOGGER.debug("publishEvent in BuntiController"); LOGGER.debug("publishEvent in BuntiController");
deviceCache.updateData(deviceId, options);
device.setValuesFromOptions(options) ;
this.applicationEventPublisher.publishEvent(new DeviceChangedEvent(this, device, options)); this.applicationEventPublisher.publishEvent(new DeviceChangedEvent(this, device, options));
return true; return true;
@ -48,8 +55,23 @@ public class BuntiControllerImpl implements BuntiController, ApplicationEventPu
} }
@Override @Override
public DeviceUpdate getDeviceValues(int deviceId) { public Collection<Room> getAllRooms() {
return deviceCache.getData(deviceId); return roomsDAO.getRooms();
}
@Override
public Room getRoomById(int roomId) {
return roomsDAO.getRoom(roomId);
}
@Override
public Collection<BuntiDevice> getAllDevices() {
return devicesDAO.getAllDevices();
}
@Override
public BuntiDevice getDeviceById(int deviceId) {
return devicesDAO.getDeviceById(deviceId);
} }
} }

View File

@ -1,52 +0,0 @@
package de.ctdo.bunti.control;
import de.ctdo.bunti.dao.BuntiDevicesDAO;
import de.ctdo.bunti.model.BuntiDevice;
import de.ctdo.bunti.model.DeviceUpdate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
@Component
public class DeviceValueCache {
@Autowired
private BuntiDevicesDAO devicesDAO;
private Map<Integer, Map<String, Object>> deviceCache;
private void init() {
deviceCache = new HashMap<Integer, Map<String, Object>>();
for(BuntiDevice device: devicesDAO.getAllDevices()) {
deviceCache.put(device.getId(), device.getOptions());
}
}
public void updateData(int deviceId, Map<String, Object> options) {
if(deviceCache == null) init();
Map<String, Object> cached = deviceCache.get(deviceId);
if(cached == null ) {
cached = new HashMap<String, Object>();
deviceCache.put(deviceId, cached);
}
cached.putAll(options);
}
public DeviceUpdate getData(int deviceId) {
if(deviceCache == null) init();
Map<String, Object> cached = deviceCache.get(deviceId);
DeviceUpdate du = new DeviceUpdate();
du.setDeviceId(deviceId);
du.setOptions(cached);
return du;
}
}

View File

@ -1,9 +1,9 @@
package de.ctdo.bunti.dao; package de.ctdo.bunti.dao;
import java.util.Collection;
import java.util.List; import java.util.List;
import de.ctdo.bunti.model.BuntiDMXDevice; import de.ctdo.bunti.model.*;
import de.ctdo.bunti.model.BuntiDevice;
public interface BuntiDevicesDAO { public interface BuntiDevicesDAO {
@ -13,7 +13,5 @@ public interface BuntiDevicesDAO {
void addDevice(BuntiDevice device); void addDevice(BuntiDevice device);
void removeDevice(int deviceId); void removeDevice(int deviceId);
} }

View File

@ -2,48 +2,35 @@ package de.ctdo.bunti.dao;
import java.util.List; import java.util.List;
import de.ctdo.bunti.model.BuntiDMXDevice; import de.ctdo.bunti.model.*;
import de.ctdo.bunti.model.BuntiDevice; import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Repository public final class BuntiDevicesDAOImpl extends HibernateDaoSupport implements BuntiDevicesDAO {
public final class BuntiDevicesDAOImpl implements BuntiDevicesDAO {
private EntityManager em;
@PersistenceContext
public void setEntityManager(EntityManager entityManager) {
this.em = entityManager;
}
@Override @Override
public List<BuntiDMXDevice> getAllDMXDevices() { public List<BuntiDMXDevice> getAllDMXDevices() {
//TODO: hier noch nur die DMX Geräte suchen! return getHibernateTemplate().loadAll(BuntiDMXDevice.class);
return em.createQuery("SELECT d FROM BuntiDevice d").getResultList();
} }
@Override @Override
public List<BuntiDevice> getAllDevices() { public List<BuntiDevice> getAllDevices() {
return em.createQuery("SELECT d FROM BuntiDevice d").getResultList(); return getHibernateTemplate().loadAll(BuntiDevice.class);
} }
@Override @Override
public BuntiDevice getDeviceById(int deviceId) { public BuntiDevice getDeviceById(int deviceId) {
return em.find(BuntiDevice.class, deviceId); return getHibernateTemplate().get(BuntiDevice.class,deviceId);
} }
@Override @Override
public void addDevice(BuntiDevice device) { public void addDevice(BuntiDevice device) {
em.persist(device); getHibernateTemplate().save(device);
} }
@Override @Override
public void removeDevice(int deviceId) { public void removeDevice(int deviceId) {
em.remove(getDeviceById(deviceId)); getHibernateTemplate().delete(getDeviceById(deviceId));
} }
} }

View File

@ -7,6 +7,6 @@ import java.util.List;
public interface RoomsDAO { public interface RoomsDAO {
List<Room> getRooms(); List<Room> getRooms();
Room getRoom(int id); Room getRoom(int id);
void addRoom(Room room); Room addRoom(Room room);
void removeRoom(int id); void removeRoom(int id);
} }

View File

@ -1,38 +1,29 @@
package de.ctdo.bunti.dao; package de.ctdo.bunti.dao;
import de.ctdo.bunti.model.Room; import de.ctdo.bunti.model.Room;
import org.springframework.stereotype.Repository; import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List; import java.util.List;
@Repository public final class RoomsDAOImpl extends HibernateDaoSupport implements RoomsDAO {
public final class RoomsDAOImpl implements RoomsDAO {
private EntityManager em;
@PersistenceContext
public void setEntityManager(EntityManager entityManager) {
this.em = entityManager;
}
@Override @Override
public List<Room> getRooms() { public List<Room> getRooms() {
return em.createQuery("SELECT r FROM Room r").getResultList(); return getHibernateTemplate().loadAll(Room.class);
} }
@Override @Override
public Room getRoom(int id) { public Room getRoom(int id) {
return em.find(Room.class, id); return getHibernateTemplate().get(Room.class, id);
} }
@Override @Override
public void addRoom(Room room) { public Room addRoom(Room room) {
em.persist(room); getHibernateTemplate().save(room);
return room;
} }
@Override @Override
public void removeRoom(int id) { public void removeRoom(int id) {
em.remove(getRoom(id)); getHibernateTemplate().delete(getRoom(id));
} }
} }

View File

@ -0,0 +1,9 @@
package de.ctdo.bunti.devices;
public interface DeviceMixer {
}

View File

@ -0,0 +1,25 @@
package de.ctdo.bunti.devices;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import de.ctdo.bunti.DeviceChangedEvent;
import de.ctdo.bunti.model.BuntiSwitchingDevice;
@Component
public class DeviceMixerImpl implements DeviceMixer, ApplicationListener<DeviceChangedEvent> {
@Override
public final void onApplicationEvent(DeviceChangedEvent arg0) {
if( arg0.getDevice() instanceof BuntiSwitchingDevice) {
BuntiSwitchingDevice switchDev = (BuntiSwitchingDevice)arg0.getDevice();
switchDev.setValuesFromOptions(arg0.getOptions());
}
}
}

View File

@ -1,6 +1,6 @@
package de.ctdo.bunti.dmx; package de.ctdo.bunti.dmx;
import de.ctdo.bunti.model.DMXChannel; import de.ctdo.bunti.dmx.model.DMXChannel;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;

View File

@ -1,6 +1,6 @@
package de.ctdo.bunti.dmx; package de.ctdo.bunti.dmx;
import de.ctdo.bunti.control.DeviceChangedEvent; import de.ctdo.bunti.DeviceChangedEvent;
import de.ctdo.bunti.artnet.SimpleArtNetSender; import de.ctdo.bunti.artnet.SimpleArtNetSender;
import de.ctdo.bunti.model.BuntiDMXDevice; import de.ctdo.bunti.model.BuntiDMXDevice;
import de.ctdo.bunti.model.BuntiDevice; import de.ctdo.bunti.model.BuntiDevice;
@ -40,7 +40,6 @@ public class DMXMixerImpl implements DMXMixer, ApplicationListener<DeviceChanged
@Scheduled(fixedDelay = NET_SEND_INTERVAL) @Scheduled(fixedDelay = NET_SEND_INTERVAL)
public final void sendOutDMXBuffer() { public final void sendOutDMXBuffer() {
/*
if (dmxMap.size() == 0) { if (dmxMap.size() == 0) {
initDMXData(); initDMXData();
} }
@ -49,7 +48,7 @@ public class DMXMixerImpl implements DMXMixer, ApplicationListener<DeviceChanged
LOGGER.debug("sending DMX Data"); LOGGER.debug("sending DMX Data");
artNetSender.sendDMXData(dmxMap, artNetDeviceAddress); artNetSender.sendDMXData(dmxMap, artNetDeviceAddress);
hasDataChanged = false; hasDataChanged = false;
}*/ }
} }
@Override @Override
@ -60,16 +59,16 @@ public class DMXMixerImpl implements DMXMixer, ApplicationListener<DeviceChanged
BuntiDMXDevice dmxDev = (BuntiDMXDevice) device; BuntiDMXDevice dmxDev = (BuntiDMXDevice) device;
//if (dmxDev.setValuesFromOptions(options)) { if (dmxDev.setValuesFromOptions(options)) {
dmxMap.putAll(dmxDev.getChannelData()); dmxMap.putAll(dmxDev.getChannelData());
LOGGER.info("setValuesFromOptions on " + device); LOGGER.info("setValuesFromOptions on " + device);
return true; return true;
//} }
// LOGGER.info("setValuesFromOptions on " + device + " failed"); LOGGER.info("setValuesFromOptions on " + device + " failed");
// return false; return false;
} }
@Override @Override

View File

@ -1,4 +1,4 @@
package de.ctdo.bunti.model; package de.ctdo.bunti.dmx.model;
public class DMXChannel { public class DMXChannel {
private int offset; private int offset;

View File

@ -1,30 +0,0 @@
package de.ctdo.bunti.ethersex;
import java.util.ArrayList;
import java.util.List;
/**
* @author: lucas
* @date: 26.03.12 00:52
*/
public class ECMDCommand {
private String command;
private List<String> parameters = new ArrayList<String>();
public String getCommand() {
return command;
}
public void setCommand(String command) {
this.command = command;
}
public List<String> getParameters() {
return parameters;
}
public void setParameters(List<String> parameters) {
this.parameters = parameters;
}
}

View File

@ -1,19 +0,0 @@
package de.ctdo.bunti.ethersex;
/**
* @author: lucas
* @date: 26.03.12 00:52
*/
public class ECMDResult {
private String resultString;
public String getResultString() {
return resultString;
}
public void setResultString(String resultString) {
this.resultString = resultString;
}
}

View File

@ -1,12 +0,0 @@
package de.ctdo.bunti.ethersex;
import java.io.IOException;
/**
* @author: lucas
* @date: 26.03.12 00:47
*/
public interface ECMDSender {
ECMDResult sendCommand(ECMDCommand command, String dest) throws IOException;
}

View File

@ -1,10 +0,0 @@
package de.ctdo.bunti.ethersex;
import de.ctdo.bunti.model.BuntiDevice;
import java.util.Map;
public interface EthersexMixer {
boolean updateDevice(BuntiDevice device, Map<String, Object> options);
}

View File

@ -1,57 +0,0 @@
package de.ctdo.bunti.ethersex;
import de.ctdo.bunti.control.DeviceChangedEvent;
import de.ctdo.bunti.model.BuntiEthersexDevice;
import de.ctdo.bunti.model.BuntiDevice;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import java.util.Map;
@Component
public class EthersexMixerImpl implements EthersexMixer, ApplicationListener<DeviceChangedEvent> {
private static final Logger LOGGER = LoggerFactory.getLogger(EthersexMixerImpl.class);
// private boolean hasDataChanged = true;
ECMDSender sender;
@Autowired
public void setECMDSender(ECMDSender sender) {
this.sender = sender;
}
@Override
public final boolean updateDevice(BuntiDevice device, Map<String, Object> options) {
if(device == null || options == null || options.size() == 0) {
return false;
}
BuntiEthersexDevice edev = (BuntiEthersexDevice) device;
// BuntiDMXDevice dmxDev = (BuntiDMXDevice) device;
//
// if (dmxDev.setValuesFromOptions(options)) {
//
// dmxMap.putAll(dmxDev.getChannelData());
//
// LOGGER.info("setValuesFromOptions on " + device);
// return true;
// }
LOGGER.info("setValuesFromOptions on " + device + " failed");
return false;
}
@Override
public final void onApplicationEvent(DeviceChangedEvent arg0) {
if (arg0.getDevice() instanceof BuntiEthersexDevice) {
updateDevice(arg0.getDevice(), arg0.getOptions());
}
}
}

View File

@ -1,56 +0,0 @@
package de.ctdo.bunti.ethersex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
/**
* @author: lucas
* @date: 26.03.12 00:54
*/
@Component
public class SimpleECMDSender implements ECMDSender {
private static final Logger LOGGER = LoggerFactory.getLogger(SimpleECMDSender.class);
private static final int ECMD_TCP_PORT = 2701;
@Override
public ECMDResult sendCommand(ECMDCommand command, String dest) {
try {
Socket client = new Socket(dest, ECMD_TCP_PORT);
client.setSoTimeout(2000);
DataOutputStream outToServer = new DataOutputStream(client.getOutputStream());
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(client.getInputStream()));
StringBuilder params = new StringBuilder();
for(String param: command.getParameters()) {
params.append(" ");
params.append(param);
}
outToServer.writeBytes(command.getCommand() + params.toString() + '\n');
ECMDResult result = new ECMDResult();
result.setResultString(inFromServer.readLine());
client.close();
return result;
} catch (IOException e) {
LOGGER.error("Could not send ECMDCommand to " + dest + " on port " + ECMD_TCP_PORT);
}
return null;
}
}

View File

@ -1,6 +1,7 @@
package de.ctdo.bunti.model; package de.ctdo.bunti.model;
import de.ctdo.bunti.dmx.DMX; import de.ctdo.bunti.dmx.DMX;
import de.ctdo.bunti.dmx.model.DMXChannel;
import de.ctdo.bunti.dmx.DMXChannels; import de.ctdo.bunti.dmx.DMXChannels;
import org.codehaus.jackson.annotate.JsonIgnore; import org.codehaus.jackson.annotate.JsonIgnore;
import org.hibernate.annotations.Entity; import org.hibernate.annotations.Entity;
@ -48,7 +49,7 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
* @param value The channel value to set. * @param value The channel value to set.
* @return True on success, otherwise false * @return True on success, otherwise false
*/ */
public final boolean setChannelValueByName(String name, int value) { protected final boolean setChannelValueByName(String name, int value) {
DMXChannel dx = dmxChannels.getChannelByName(name); DMXChannel dx = dmxChannels.getChannelByName(name);
if (dx != null) { if (dx != null) {
dx.setValue(DMX.sanitizeDMXValue(value)); dx.setValue(DMX.sanitizeDMXValue(value));
@ -65,7 +66,7 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
*/ */
@JsonIgnore @JsonIgnore
@Transient @Transient
public final int getChannelValueByName(String name) { protected final int getChannelValueByName(String name) {
DMXChannel dx = dmxChannels.getChannelByName(name); DMXChannel dx = dmxChannels.getChannelByName(name);
if (dx != null) { if (dx != null) {
return dx.getValue(); return dx.getValue();

View File

@ -11,7 +11,7 @@ import java.util.Map;
@Entity @Entity
@Table(name = "devices") @Table(name = "devices")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE) @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
public class BuntiDevice { public abstract class BuntiDevice {
private int id; private int id;
private String deviceName; private String deviceName;
private String picture; private String picture;
@ -85,12 +85,12 @@ public class BuntiDevice {
/** /**
* Switch this device off. * Switch this device off.
*/ */
public void switchOff() {} public abstract void switchOff();
/** /**
* Switch this device on. * Switch this device on.
*/ */
public void switchOn() {} public abstract void switchOn();
/** /**
* The the internal options corresponding to the given Key Value Map * The the internal options corresponding to the given Key Value Map
@ -98,15 +98,11 @@ public class BuntiDevice {
* @param options The options Map. * @param options The options Map.
* @return True on success. False otherwise. * @return True on success. False otherwise.
*/ */
public boolean setValuesFromOptions(Map<String, Object> options) { public abstract boolean setValuesFromOptions(Map<String, Object> options);
return false;
}
@Transient @Transient
public Map<String, Object> getOptions() { public abstract Map<String, Object> getOptions();
return null;
}
} }

View File

@ -1,91 +0,0 @@
package de.ctdo.bunti.model;
import de.ctdo.bunti.model.BuntiDevice;
import org.hibernate.annotations.Entity;
import javax.persistence.Transient;
import java.util.HashMap;
import java.util.Map;
@Entity
public abstract class BuntiEthersexDevice extends BuntiDevice {
private String hostname;
private int port;
private final Map<String, Integer> ports = new HashMap<String, Integer>();
public BuntiEthersexDevice() {
}
public String getHostname() {
return hostname;
}
public void setHostname(String hostname) {
this.hostname = hostname;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
public final boolean setPortByName(String name, int value) {
if (ports.containsKey(name)) {
ports.put(name, value);
return true;
}
return false;
}
@Transient
public final int getPortByName(String name) {
if (ports.containsKey(name)) {
return ports.get(name);
}
return 0;
}
@Override
public boolean setValuesFromOptions(Map<String, Object> options) {
for (Map.Entry<String, Object> opt : options.entrySet()) {
try {
int value = Integer.parseInt(opt.getValue().toString());
if (!setPortByName(opt.getKey(), value)) {
return false;
}
} catch (Exception e) {
return false;
}
}
return true;
}
@Override
public Map<String, Object> getOptions() {
Map<String, Object> options = new HashMap<String, Object>();
for(Map.Entry<String, Integer> p: ports.entrySet()) {
options.put(p.getKey(), p.getValue());
}
return options;
}
/**
* Add a channel to this DMX Device
* used internally by subclasses to define their structure
* @param channel DMXChannel to add (name and offset)
* @return True on success, false otherwise.
*/
public final void addPort(String channel) {
ports.put(channel, 0x00);
}
}

View File

@ -0,0 +1,41 @@
package de.ctdo.bunti.model;
import javax.persistence.Entity;
import javax.persistence.Transient;
import java.util.Map;
@Entity
public abstract class BuntiSwitchingDevice extends BuntiDevice {
private static final String OPTION_STATE = "state";
private boolean state = false;
public BuntiSwitchingDevice() {
}
@Override
public final boolean setValuesFromOptions(Map<String, Object> options) {
if(options.containsKey(OPTION_STATE)) {
try {
boolean value = Boolean.parseBoolean(options.get(OPTION_STATE).toString());
setState(value);
return true;
} catch (Exception e) {
return false;
}
}
return false;
}
@Transient
public boolean isState() {
return state;
}
public void setState(boolean state) {
this.state = state;
}
}

View File

@ -1,54 +0,0 @@
package de.ctdo.bunti.model;
import javax.persistence.Entity;
import javax.persistence.Transient;
@Entity
public class Lampel extends BuntiEthersexDevice {
private static final String PORTC = "2"; // TODO: rausfinden welche PortNummer das ist
public static final int LAMPEL_OFF = 0x00;
public static final int LAMPEL_RED = 0x80; // TODO: rausfinden ob die Reihenfolge stimmt
public static final int LAMPEL_YELLOW = 0x40;
public static final int LAMPEL_GREEN = 0x20;
public Lampel() {
addPort(PORTC);
}
@Transient
public int getLampelState() {
return getPortByName(PORTC);
}
public void setLampelState(int value) {
setPortByName(PORTC, value);
}
@Override
public final void switchOff() {
setPortByName(PORTC, LAMPEL_OFF);
}
@Override
public final void switchOn() {
setPortByName(PORTC, LAMPEL_GREEN | LAMPEL_RED | LAMPEL_YELLOW);
}
@Override
public final String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Lampel ");
sb.append(getId());
sb.append(", ");
sb.append(getDeviceName());
sb.append(" [");
sb.append(getPortByName(PORTC));
sb.append("]");
return sb.toString();
}
}

View File

@ -1,6 +1,7 @@
package de.ctdo.bunti.model; package de.ctdo.bunti.model;
import de.ctdo.bunti.dmx.DMX; import de.ctdo.bunti.dmx.DMX;
import de.ctdo.bunti.dmx.model.DMXChannel;
import org.codehaus.jackson.annotate.JsonIgnore; import org.codehaus.jackson.annotate.JsonIgnore;
import javax.persistence.Entity; import javax.persistence.Entity;

View File

@ -1,6 +1,7 @@
package de.ctdo.bunti.model; package de.ctdo.bunti.model;
import de.ctdo.bunti.dmx.DMX; import de.ctdo.bunti.dmx.DMX;
import de.ctdo.bunti.dmx.model.DMXChannel;
import org.codehaus.jackson.annotate.JsonIgnore; import org.codehaus.jackson.annotate.JsonIgnore;
import javax.persistence.Entity; import javax.persistence.Entity;

View File

@ -1,8 +1,8 @@
package de.ctdo.bunti.web; package de.ctdo.bunti.web;
import de.ctdo.bunti.control.BuntiController; import de.ctdo.bunti.control.BuntiController;
import de.ctdo.bunti.model.DeviceUpdate; import de.ctdo.bunti.webmodel.DeviceUpdate;
import de.ctdo.bunti.web.model.DeviceUpdates; import de.ctdo.bunti.webmodel.DeviceUpdates;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -13,28 +13,21 @@ import org.springframework.web.bind.annotation.*;
@RequestMapping(value = "/control") @RequestMapping(value = "/control")
public class DeviceControlController { public class DeviceControlController {
private static final Logger LOGGER = LoggerFactory.getLogger(DeviceControlController.class); private static final Logger LOGGER = LoggerFactory.getLogger(DeviceControlController.class);
@Autowired
private BuntiController controller; private BuntiController controller;
@Autowired
public final void setController(BuntiController controller) {
this.controller = controller;
}
@RequestMapping(value = "/devices", method = RequestMethod.POST) @RequestMapping(value = "/devices", method = RequestMethod.POST)
@ResponseBody public void setDevices(@RequestBody DeviceUpdates updates) {
public String setDevices(@RequestBody DeviceUpdates updates) { LOGGER.info("handle PUT /devices" + " request update=" + updates.toString() );
LOGGER.info("handle POST /devices" + " request update=" + updates.toString() );
for (DeviceUpdate update: updates.getUpdates()) { for (DeviceUpdate update: updates.getUpdates()) {
LOGGER.info("Update deviceId=" + update.getDeviceId()); LOGGER.info("Update deviceId=" + update.getDeviceId());
controller.updateDeviceData(update.getDeviceId(), update.getOptions()); controller.updateDeviceData(update.getDeviceId(), update.getOptions());
} }
return "{\"status\":\"OK\"}";
}
@RequestMapping(value = "/devices/{id}", method = RequestMethod.GET)
@ResponseBody
public DeviceUpdate getDeviceValues(@PathVariable("id") int id) {
LOGGER.info("handle GET /devices/{id} " + id );
return controller.getDeviceValues(id);
} }
} }

View File

@ -11,26 +11,28 @@ import java.util.Collection;
@Controller @Controller
@RequestMapping(value = "/devices") @RequestMapping(value = "/devices")
public class DevicesController { public class DevicesController {
@Autowired
private BuntiDevicesDAO devicesDAO; private BuntiDevicesDAO devicesDAO;
@Autowired
public void setDevicesDAO(BuntiDevicesDAO devicesDAO) {
this.devicesDAO = devicesDAO;
}
@RequestMapping(value = "", method = RequestMethod.GET) @RequestMapping(value = "", method = RequestMethod.GET)
@ResponseBody public @ResponseBody Collection<BuntiDevice> getAll() {
public Collection<BuntiDevice> getAll() {
return devicesDAO.getAllDevices(); return devicesDAO.getAllDevices();
} }
@RequestMapping(value = "/{id}", method = RequestMethod.GET) @RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody public @ResponseBody BuntiDevice getDeviceById(@PathVariable("id") int id) {
public BuntiDevice getDeviceById(@PathVariable("id") int id) {
return devicesDAO.getDeviceById(id); return devicesDAO.getDeviceById(id);
} }
@RequestMapping(value = "", method = RequestMethod.POST) @RequestMapping(value = "", method = RequestMethod.POST)
@ResponseBody public @ResponseBody BuntiDevice setDevices(@RequestBody BuntiDevice device) {
public String setDevices(@RequestBody BuntiDevice device) {
devicesDAO.addDevice(device); devicesDAO.addDevice(device);
return "{\"status\":\"OK\"}"; return device;
} }
} }

View File

@ -13,24 +13,26 @@ import java.util.List;
@Controller @Controller
@RequestMapping(value = "/rooms") @RequestMapping(value = "/rooms")
public class RoomsController { public class RoomsController {
@Autowired
private RoomsDAO roomsDAO; private RoomsDAO roomsDAO;
@Autowired
public void setRoomsDAO(RoomsDAO roomsDAO) {
this.roomsDAO = roomsDAO;
}
@RequestMapping(value = "", method = RequestMethod.GET) @RequestMapping(value = "", method = RequestMethod.GET)
@ResponseBody public @ResponseBody Collection<Room> getAll() {
public Collection<Room> getAll() {
return roomsDAO.getRooms(); return roomsDAO.getRooms();
} }
@RequestMapping(value = "/{id}", method = RequestMethod.GET) @RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody public @ResponseBody Room getRoomById(@PathVariable("id") int id) {
public Room getRoomById(@PathVariable("id") int id) {
return roomsDAO.getRoom(id); return roomsDAO.getRoom(id);
} }
@RequestMapping(value = "/{id}/devices", method = RequestMethod.GET) @RequestMapping(value = "/{id}/devices", method = RequestMethod.GET)
@ResponseBody public @ResponseBody
public List<BuntiDevice> getDevicesFromRoom(@PathVariable("id") int id) { List<BuntiDevice> getDevicesFromRoom(@PathVariable("id") int id) {
Room room = roomsDAO.getRoom(id); Room room = roomsDAO.getRoom(id);
if(room != null) { if(room != null) {

View File

@ -1,5 +1,6 @@
package de.ctdo.bunti.model; package de.ctdo.bunti.webmodel;
import java.io.Serializable;
import java.util.Map; import java.util.Map;

View File

@ -1,6 +1,4 @@
package de.ctdo.bunti.web.model; package de.ctdo.bunti.webmodel;
import de.ctdo.bunti.model.DeviceUpdate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -28,5 +26,4 @@ public class DeviceUpdates {
public void setTimeStamp(long timeStamp) { public void setTimeStamp(long timeStamp) {
this.timeStamp = timeStamp; this.timeStamp = timeStamp;
} }
} }

View File

@ -1,46 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
xmlns:tx="http://www.springframework.org/schema/tx" http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"
xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc">
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<jdbc:embedded-database id="dataSource" type="H2"> <jdbc:embedded-database id="dataSource" type="H2">
<jdbc:script location="classpath:init_schema.sql" /> <jdbc:script location="classpath:init_schema.sql" />
<jdbc:script location="classpath:init_data.sql" /> <jdbc:script location="classpath:init_data.sql" />
</jdbc:embedded-database> </jdbc:embedded-database>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="packagesToScan" value="de.ctdo.bunti.dmx.model" /> <property name="packagesToScan" value="de.ctdo.bunti.model"/>
<property name="dataSource" ref="dataSource" /> <property name="hibernateProperties">
<property name="jpaVendorAdapter"> <props>
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<property name="showSql" value="true" /> <prop key="hibernate.show_sql">true</prop>
<property name="generateDdl" value="false" /> <!--<prop key="hibernate.hbm2ddl.auto">create</prop>-->
<!-- <property name="database" value="DERBY" />--> </props>
<property name="database" value="H2" /> </property>
</bean> <property name="dataSource" ref="dataSource" />
</property> </bean>
<bean id="roomsDAO" class="de.ctdo.bunti.dao.RoomsDAOImpl">
<property name="sessionFactory" ref="hibernateSessionFactory" />
</bean>
<bean id="devicesDAO" class="de.ctdo.bunti.dao.BuntiDevicesDAOImpl">
<property name="sessionFactory" ref="hibernateSessionFactory" />
</bean> </bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="jpaDialect"> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" /> <property name="sessionFactory" ref="hibernateSessionFactory" />
</property>
</bean> </bean>
<tx:annotation-driven /> <tx:annotation-driven />
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
</beans> </beans>

View File

@ -6,22 +6,14 @@ insert into rooms (ROOM_ID, floor, roomName, xCord, yCord) values (null, '2. Eta
insert into rooms (ROOM_ID, floor, roomName, xCord, yCord) values (null, '2. Etage', 'Flur', '1', '1'); insert into rooms (ROOM_ID, floor, roomName, xCord, yCord) values (null, '2. Etage', 'Flur', '1', '1');
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress, hostname, port) insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress)
values ('Par56Spot',null,'Lampe1',null, 1, null, null); values ('Par56Spot',null,'Lampe1',null, 1);
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress, hostname, port) insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress)
values ('Par56Spot',null,'Lampe2',null, 6, null, null); values ('Par56Spot',null,'Lampe2',null, 6);
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress, hostname, port) insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress)
values ('Par56Spot',null,'Lampe3',null, 11, null, null); values ('Par56Spot',null,'Lampe3',null, 11);
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress, hostname, port) insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress)
values ('Par56Spot',null,'Lampe4',null, 16, null, null); values ('Par56Spot',null,'Lampe4',null, 16);
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress, hostname, port)
values ('Lampel',null,'Die Lampel',null, null, 'lampel.ctdo.de', 2701);
insert into ROOM_BUNTIDEVICE (ROOM_ID, BUNTIDEVICE_ID) VALUES (2, 1);
insert into ROOM_BUNTIDEVICE (ROOM_ID, BUNTIDEVICE_ID) VALUES (2, 2);
insert into ROOM_BUNTIDEVICE (ROOM_ID, BUNTIDEVICE_ID) VALUES (3, 3);
insert into ROOM_BUNTIDEVICE (ROOM_ID, BUNTIDEVICE_ID) VALUES (3, 4);

View File

@ -10,8 +10,6 @@ create table devices (DTYPE varchar(31) not null,
deviceName varchar(255), deviceName varchar(255),
picture varchar(255), picture varchar(255),
startAddress integer, startAddress integer,
hostname varchar(255),
port integer,
primary key (BUNTIDEVICE_ID)); primary key (BUNTIDEVICE_ID));
create table rooms (ROOM_ID integer generated by default as identity (start with 1), create table rooms (ROOM_ID integer generated by default as identity (start with 1),

View File

@ -1,44 +1,40 @@
package de.ctdo.bunti.control; package de.ctdo.bunti.control;
import de.ctdo.bunti.dao.BuntiDevicesDAO;
import de.ctdo.bunti.model.BuntiDevice;
import de.ctdo.bunti.model.DeviceUpdate;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.HashMap; //@ContextConfiguration(locations = { "classpath:/META-INF/spring/root-context.xml","classpath:/de/ctdo/bunti/hibernate-test-context.xml" })
import java.util.Map; //@RunWith(SpringJUnit4ClassRunner.class)
//public class BuntiControllerImplTest {
@ContextConfiguration(locations = { "classpath:/META-INF/spring/root-context.xml","classpath:/de/ctdo/bunti/hibernate-test-context.xml" }) // @Autowired
@RunWith(SpringJUnit4ClassRunner.class) // BuntiController dut;
public class BuntiControllerImplTest { //
// @Test
@Autowired // public void testUpdateDeviceData() throws Exception {
BuntiController dut; //
// }
@Autowired //
BuntiDevicesDAO dao; // @Test
// public void testGetAllRooms() throws Exception {
@Test //
public void test1() throws Exception { // }
//
BuntiDevice dev = dao.getDeviceById(2); // @Test
DeviceUpdate upt = dut.getDeviceValues(2); // public void testGetRoomById() throws Exception {
//
Map<String, Object> data = new HashMap<String, Object>(); // }
data.put("red", 10); //
data.put("green", 20); // @Test
data.put("blue", 30); // public void testGetAllDevices() throws Exception {
//
dut.updateDeviceData(2, data); // }
//
upt = dut.getDeviceValues(2); // @Test
// public void testGetDeviceById() throws Exception {
return; //
} // }
//}
}

View File

@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.Collection;
import java.util.List; import java.util.List;
import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals;
@ -23,13 +24,13 @@ public class BuntiDevicesDAOImplTest {
@Test @Test
public void testGetAllDMXDevices() throws Exception { public void testGetAllDMXDevices() throws Exception {
List<BuntiDMXDevice> deviceList = dut.getAllDMXDevices(); List<BuntiDMXDevice> deviceList = dut.getAllDMXDevices();
assertEquals(5, deviceList.size()); assertEquals(4, deviceList.size());
} }
@Test @Test
public void testGetAllDevices() throws Exception { public void testGetAllDevices() throws Exception {
List<BuntiDevice> deviceList = dut.getAllDevices(); List<BuntiDevice> deviceList = dut.getAllDevices();
assertEquals(5, deviceList.size()); assertEquals(4, deviceList.size());
} }
@Test @Test

View File

@ -1,6 +1,6 @@
package de.ctdo.bunti.dmx; package de.ctdo.bunti.dmx;
import de.ctdo.bunti.model.DMXChannel; import de.ctdo.bunti.dmx.model.DMXChannel;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;

View File

@ -1,6 +1,6 @@
package de.ctdo.bunti.dmx; package de.ctdo.bunti.dmx;
import de.ctdo.bunti.model.DMXChannel; import de.ctdo.bunti.dmx.model.DMXChannel;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;

View File

@ -1,5 +1,6 @@
package de.ctdo.bunti.dmx; package de.ctdo.bunti.dmx;
import de.ctdo.bunti.model.BuntiDevice;
import de.ctdo.bunti.model.Par56Spot; import de.ctdo.bunti.model.Par56Spot;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;

View File

@ -1,8 +1,6 @@
package de.ctdo.bunti.model; package de.ctdo.bunti.model;
import de.ctdo.bunti.model.BuntiDMXDevice; import de.ctdo.bunti.dmx.model.DMXChannel;
import de.ctdo.bunti.model.DMXChannel;
import de.ctdo.bunti.model.Par56Spot;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;

View File

@ -1,6 +1,5 @@
package de.ctdo.bunti.model; package de.ctdo.bunti.model;
import de.ctdo.bunti.model.Par56Spot;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import static junit.framework.Assert.*; import static junit.framework.Assert.*;

View File

@ -1,6 +1,5 @@
package de.ctdo.bunti.model; package de.ctdo.bunti.model;
import de.ctdo.bunti.model.Strobe1500;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;

View File

@ -1,45 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<jdbc:embedded-database id="dataSource" type="H2"> <jdbc:embedded-database id="dataSource" type="H2">
<jdbc:script location="classpath:init_schema.sql" /> <jdbc:script location="classpath:init_schema.sql" />
<jdbc:script location="classpath:init_data.sql" /> <jdbc:script location="classpath:init_data.sql" />
</jdbc:embedded-database> </jdbc:embedded-database>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="packagesToScan" value="de.ctdo.bunti.model" /> <property name="packagesToScan" value="de.ctdo.bunti.model"/>
<property name="dataSource" ref="dataSource" /> <property name="hibernateProperties">
<property name="jpaVendorAdapter"> <props>
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<property name="showSql" value="true" /> <prop key="hibernate.show_sql">true</prop>
<property name="generateDdl" value="false" /> <!--<prop key="hibernate.hbm2ddl.auto">create</prop>-->
<!-- <property name="database" value="DERBY" />--> </props>
<property name="database" value="H2" />
</bean>
</property> </property>
<property name="dataSource" ref="dataSource" />
</bean> </bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" /> <bean id="roomsDAO" class="de.ctdo.bunti.dao.RoomsDAOImpl">
<property name="jpaDialect"> <property name="sessionFactory" ref="hibernateSessionFactory" />
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" /> </bean>
</property>
<bean id="devicesDAO" class="de.ctdo.bunti.dao.BuntiDevicesDAOImpl">
<property name="sessionFactory" ref="hibernateSessionFactory" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="hibernateSessionFactory" />
</bean> </bean>
<tx:annotation-driven /> <tx:annotation-driven />
<context:component-scan base-package="de.ctdo.bunti.dao" />
</beans> </beans>