Compare commits
No commits in common. "maint/lp" and "master" have entirely different histories.
|
@ -1,4 +1,4 @@
|
|||
package de.ctdo.bunti.control;
|
||||
package de.ctdo.bunti;
|
||||
|
||||
import java.util.Map;
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
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;
|
||||
|
@ -9,7 +8,12 @@ import java.util.Map;
|
|||
|
||||
public interface BuntiController {
|
||||
|
||||
Collection<BuntiDevice> getAllDevices();
|
||||
BuntiDevice getDeviceById(int deviceId);
|
||||
|
||||
boolean updateDeviceData(int deviceId, Map<String, Object> options);
|
||||
DeviceUpdate getDeviceValues(int deviceId);
|
||||
|
||||
Collection<Room> getAllRooms();
|
||||
Room getRoomById(int roomId);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package de.ctdo.bunti.control;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import de.ctdo.bunti.model.*;
|
||||
import de.ctdo.bunti.dao.RoomsDAO;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -10,24 +11,34 @@ import org.springframework.context.ApplicationEventPublisher;
|
|||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import de.ctdo.bunti.DeviceChangedEvent;
|
||||
import de.ctdo.bunti.dao.BuntiDevicesDAO;
|
||||
import de.ctdo.bunti.model.*;
|
||||
|
||||
@Component
|
||||
public class BuntiControllerImpl implements BuntiController, ApplicationEventPublisherAware {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(BuntiControllerImpl.class);
|
||||
private ApplicationEventPublisher applicationEventPublisher = null;
|
||||
|
||||
@Autowired
|
||||
private BuntiDevicesDAO devicesDAO;
|
||||
private RoomsDAO roomsDAO;
|
||||
|
||||
|
||||
@Autowired
|
||||
private DeviceValueCache deviceCache;
|
||||
public final void setDevicesDAO(BuntiDevicesDAO devicesDAO) {
|
||||
this.devicesDAO = devicesDAO;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public final void setRoomsDAO(RoomsDAO roomsDAO) {
|
||||
this.roomsDAO = roomsDAO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
|
||||
this.applicationEventPublisher = publisher;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final boolean updateDeviceData(int deviceId, Map<String, Object> options) {
|
||||
BuntiDevice device = devicesDAO.getDeviceById(deviceId);
|
||||
|
@ -35,10 +46,6 @@ public class BuntiControllerImpl implements BuntiController, ApplicationEventPu
|
|||
if (device != null) {
|
||||
LOGGER.debug("publishEvent in BuntiController");
|
||||
|
||||
deviceCache.updateData(deviceId, options);
|
||||
|
||||
device.setValuesFromOptions(options) ;
|
||||
|
||||
this.applicationEventPublisher.publishEvent(new DeviceChangedEvent(this, device, options));
|
||||
|
||||
return true;
|
||||
|
@ -48,8 +55,23 @@ public class BuntiControllerImpl implements BuntiController, ApplicationEventPu
|
|||
}
|
||||
|
||||
@Override
|
||||
public DeviceUpdate getDeviceValues(int deviceId) {
|
||||
return deviceCache.getData(deviceId);
|
||||
public Collection<Room> getAllRooms() {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package de.ctdo.bunti.dao;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import de.ctdo.bunti.model.BuntiDMXDevice;
|
||||
import de.ctdo.bunti.model.BuntiDevice;
|
||||
import de.ctdo.bunti.model.*;
|
||||
|
||||
public interface BuntiDevicesDAO {
|
||||
|
||||
|
@ -14,6 +14,4 @@ public interface BuntiDevicesDAO {
|
|||
void addDevice(BuntiDevice device);
|
||||
void removeDevice(int deviceId);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,48 +2,35 @@ package de.ctdo.bunti.dao;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import de.ctdo.bunti.model.BuntiDMXDevice;
|
||||
import de.ctdo.bunti.model.BuntiDevice;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import de.ctdo.bunti.model.*;
|
||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
@Repository
|
||||
public final class BuntiDevicesDAOImpl implements BuntiDevicesDAO {
|
||||
private EntityManager em;
|
||||
|
||||
@PersistenceContext
|
||||
public void setEntityManager(EntityManager entityManager) {
|
||||
this.em = entityManager;
|
||||
}
|
||||
public final class BuntiDevicesDAOImpl extends HibernateDaoSupport implements BuntiDevicesDAO {
|
||||
|
||||
@Override
|
||||
public List<BuntiDMXDevice> getAllDMXDevices() {
|
||||
//TODO: hier noch nur die DMX Geräte suchen!
|
||||
return em.createQuery("SELECT d FROM BuntiDevice d").getResultList();
|
||||
return getHibernateTemplate().loadAll(BuntiDMXDevice.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BuntiDevice> getAllDevices() {
|
||||
return em.createQuery("SELECT d FROM BuntiDevice d").getResultList();
|
||||
return getHibernateTemplate().loadAll(BuntiDevice.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuntiDevice getDeviceById(int deviceId) {
|
||||
return em.find(BuntiDevice.class, deviceId);
|
||||
return getHibernateTemplate().get(BuntiDevice.class,deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDevice(BuntiDevice device) {
|
||||
em.persist(device);
|
||||
getHibernateTemplate().save(device);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeDevice(int deviceId) {
|
||||
em.remove(getDeviceById(deviceId));
|
||||
getHibernateTemplate().delete(getDeviceById(deviceId));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,6 @@ import java.util.List;
|
|||
public interface RoomsDAO {
|
||||
List<Room> getRooms();
|
||||
Room getRoom(int id);
|
||||
void addRoom(Room room);
|
||||
Room addRoom(Room room);
|
||||
void removeRoom(int id);
|
||||
}
|
||||
|
|
|
@ -1,38 +1,29 @@
|
|||
package de.ctdo.bunti.dao;
|
||||
|
||||
import de.ctdo.bunti.model.Room;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public final class RoomsDAOImpl implements RoomsDAO {
|
||||
private EntityManager em;
|
||||
|
||||
@PersistenceContext
|
||||
public void setEntityManager(EntityManager entityManager) {
|
||||
this.em = entityManager;
|
||||
}
|
||||
public final class RoomsDAOImpl extends HibernateDaoSupport implements RoomsDAO {
|
||||
|
||||
@Override
|
||||
public List<Room> getRooms() {
|
||||
return em.createQuery("SELECT r FROM Room r").getResultList();
|
||||
return getHibernateTemplate().loadAll(Room.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Room getRoom(int id) {
|
||||
return em.find(Room.class, id);
|
||||
return getHibernateTemplate().get(Room.class, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRoom(Room room) {
|
||||
em.persist(room);
|
||||
public Room addRoom(Room room) {
|
||||
getHibernateTemplate().save(room);
|
||||
return room;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRoom(int id) {
|
||||
em.remove(getRoom(id));
|
||||
getHibernateTemplate().delete(getRoom(id));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package de.ctdo.bunti.devices;
|
||||
|
||||
|
||||
|
||||
public interface DeviceMixer {
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
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.Collections;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
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.model.BuntiDMXDevice;
|
||||
import de.ctdo.bunti.model.BuntiDevice;
|
||||
|
@ -40,7 +40,6 @@ public class DMXMixerImpl implements DMXMixer, ApplicationListener<DeviceChanged
|
|||
|
||||
@Scheduled(fixedDelay = NET_SEND_INTERVAL)
|
||||
public final void sendOutDMXBuffer() {
|
||||
/*
|
||||
if (dmxMap.size() == 0) {
|
||||
initDMXData();
|
||||
}
|
||||
|
@ -49,7 +48,7 @@ public class DMXMixerImpl implements DMXMixer, ApplicationListener<DeviceChanged
|
|||
LOGGER.debug("sending DMX Data");
|
||||
artNetSender.sendDMXData(dmxMap, artNetDeviceAddress);
|
||||
hasDataChanged = false;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,16 +59,16 @@ public class DMXMixerImpl implements DMXMixer, ApplicationListener<DeviceChanged
|
|||
|
||||
BuntiDMXDevice dmxDev = (BuntiDMXDevice) device;
|
||||
|
||||
//if (dmxDev.setValuesFromOptions(options)) {
|
||||
if (dmxDev.setValuesFromOptions(options)) {
|
||||
|
||||
dmxMap.putAll(dmxDev.getChannelData());
|
||||
|
||||
LOGGER.info("setValuesFromOptions on " + device);
|
||||
return true;
|
||||
//}
|
||||
}
|
||||
|
||||
// LOGGER.info("setValuesFromOptions on " + device + " failed");
|
||||
// return false;
|
||||
LOGGER.info("setValuesFromOptions on " + device + " failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package de.ctdo.bunti.model;
|
||||
package de.ctdo.bunti.dmx.model;
|
||||
|
||||
public class DMXChannel {
|
||||
private int offset;
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package de.ctdo.bunti.model;
|
||||
|
||||
import de.ctdo.bunti.dmx.DMX;
|
||||
import de.ctdo.bunti.dmx.model.DMXChannel;
|
||||
import de.ctdo.bunti.dmx.DMXChannels;
|
||||
import org.codehaus.jackson.annotate.JsonIgnore;
|
||||
import org.hibernate.annotations.Entity;
|
||||
|
@ -48,7 +49,7 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
|
|||
* @param value The channel value to set.
|
||||
* @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);
|
||||
if (dx != null) {
|
||||
dx.setValue(DMX.sanitizeDMXValue(value));
|
||||
|
@ -65,7 +66,7 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
|
|||
*/
|
||||
@JsonIgnore
|
||||
@Transient
|
||||
public final int getChannelValueByName(String name) {
|
||||
protected final int getChannelValueByName(String name) {
|
||||
DMXChannel dx = dmxChannels.getChannelByName(name);
|
||||
if (dx != null) {
|
||||
return dx.getValue();
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.util.Map;
|
|||
@Entity
|
||||
@Table(name = "devices")
|
||||
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
|
||||
public class BuntiDevice {
|
||||
public abstract class BuntiDevice {
|
||||
private int id;
|
||||
private String deviceName;
|
||||
private String picture;
|
||||
|
@ -85,12 +85,12 @@ public class BuntiDevice {
|
|||
/**
|
||||
* Switch this device off.
|
||||
*/
|
||||
public void switchOff() {}
|
||||
public abstract void switchOff();
|
||||
|
||||
/**
|
||||
* Switch this device on.
|
||||
*/
|
||||
public void switchOn() {}
|
||||
public abstract void switchOn();
|
||||
|
||||
/**
|
||||
* The the internal options corresponding to the given Key Value Map
|
||||
|
@ -98,15 +98,11 @@ public class BuntiDevice {
|
|||
* @param options The options Map.
|
||||
* @return True on success. False otherwise.
|
||||
*/
|
||||
public boolean setValuesFromOptions(Map<String, Object> options) {
|
||||
return false;
|
||||
}
|
||||
public abstract boolean setValuesFromOptions(Map<String, Object> options);
|
||||
|
||||
|
||||
@Transient
|
||||
public Map<String, Object> getOptions() {
|
||||
return null;
|
||||
}
|
||||
public abstract Map<String, Object> getOptions();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package de.ctdo.bunti.model;
|
||||
|
||||
import de.ctdo.bunti.dmx.DMX;
|
||||
import de.ctdo.bunti.dmx.model.DMXChannel;
|
||||
import org.codehaus.jackson.annotate.JsonIgnore;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package de.ctdo.bunti.model;
|
||||
|
||||
import de.ctdo.bunti.dmx.DMX;
|
||||
import de.ctdo.bunti.dmx.model.DMXChannel;
|
||||
import org.codehaus.jackson.annotate.JsonIgnore;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package de.ctdo.bunti.web;
|
||||
|
||||
import de.ctdo.bunti.control.BuntiController;
|
||||
import de.ctdo.bunti.model.DeviceUpdate;
|
||||
import de.ctdo.bunti.web.model.DeviceUpdates;
|
||||
import de.ctdo.bunti.webmodel.DeviceUpdate;
|
||||
import de.ctdo.bunti.webmodel.DeviceUpdates;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -13,28 +13,21 @@ import org.springframework.web.bind.annotation.*;
|
|||
@RequestMapping(value = "/control")
|
||||
public class DeviceControlController {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(DeviceControlController.class);
|
||||
|
||||
@Autowired
|
||||
private BuntiController controller;
|
||||
|
||||
@Autowired
|
||||
public final void setController(BuntiController controller) {
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/devices", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public String setDevices(@RequestBody DeviceUpdates updates) {
|
||||
LOGGER.info("handle POST /devices" + " request update=" + updates.toString() );
|
||||
public void setDevices(@RequestBody DeviceUpdates updates) {
|
||||
LOGGER.info("handle PUT /devices" + " request update=" + updates.toString() );
|
||||
|
||||
for (DeviceUpdate update: updates.getUpdates()) {
|
||||
LOGGER.info("Update deviceId=" + update.getDeviceId());
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,26 +11,28 @@ import java.util.Collection;
|
|||
@Controller
|
||||
@RequestMapping(value = "/devices")
|
||||
public class DevicesController {
|
||||
@Autowired
|
||||
private BuntiDevicesDAO devicesDAO;
|
||||
|
||||
@Autowired
|
||||
public void setDevicesDAO(BuntiDevicesDAO devicesDAO) {
|
||||
this.devicesDAO = devicesDAO;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Collection<BuntiDevice> getAll() {
|
||||
public @ResponseBody Collection<BuntiDevice> getAll() {
|
||||
return devicesDAO.getAllDevices();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public BuntiDevice getDeviceById(@PathVariable("id") int id) {
|
||||
public @ResponseBody BuntiDevice getDeviceById(@PathVariable("id") int id) {
|
||||
return devicesDAO.getDeviceById(id);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public String setDevices(@RequestBody BuntiDevice device) {
|
||||
public @ResponseBody BuntiDevice setDevices(@RequestBody BuntiDevice device) {
|
||||
devicesDAO.addDevice(device);
|
||||
return "{\"status\":\"OK\"}";
|
||||
return device;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -13,24 +13,26 @@ import java.util.List;
|
|||
@Controller
|
||||
@RequestMapping(value = "/rooms")
|
||||
public class RoomsController {
|
||||
@Autowired
|
||||
private RoomsDAO roomsDAO;
|
||||
|
||||
@Autowired
|
||||
public void setRoomsDAO(RoomsDAO roomsDAO) {
|
||||
this.roomsDAO = roomsDAO;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Collection<Room> getAll() {
|
||||
public @ResponseBody Collection<Room> getAll() {
|
||||
return roomsDAO.getRooms();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Room getRoomById(@PathVariable("id") int id) {
|
||||
public @ResponseBody Room getRoomById(@PathVariable("id") int id) {
|
||||
return roomsDAO.getRoom(id);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{id}/devices", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public List<BuntiDevice> getDevicesFromRoom(@PathVariable("id") int id) {
|
||||
public @ResponseBody
|
||||
List<BuntiDevice> getDevicesFromRoom(@PathVariable("id") int id) {
|
||||
Room room = roomsDAO.getRoom(id);
|
||||
|
||||
if(room != null) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package de.ctdo.bunti.model;
|
||||
package de.ctdo.bunti.webmodel;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
package de.ctdo.bunti.web.model;
|
||||
|
||||
import de.ctdo.bunti.model.DeviceUpdate;
|
||||
package de.ctdo.bunti.webmodel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -28,5 +26,4 @@ public class DeviceUpdates {
|
|||
public void setTimeStamp(long timeStamp) {
|
||||
this.timeStamp = timeStamp;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,46 +1,43 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
||||
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
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
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"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc">
|
||||
|
||||
<jdbc:embedded-database id="dataSource" type="H2">
|
||||
<jdbc:script location="classpath:init_schema.sql" />
|
||||
<jdbc:script location="classpath:init_data.sql" />
|
||||
</jdbc:embedded-database>
|
||||
|
||||
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
|
||||
<property name="packagesToScan" value="de.ctdo.bunti.dmx.model" />
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="jpaVendorAdapter">
|
||||
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
|
||||
<property name="showSql" value="true" />
|
||||
<property name="generateDdl" value="false" />
|
||||
<!-- <property name="database" value="DERBY" />-->
|
||||
<property name="database" value="H2" />
|
||||
</bean>
|
||||
<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
|
||||
<property name="packagesToScan" value="de.ctdo.bunti.model"/>
|
||||
<property name="hibernateProperties">
|
||||
<props>
|
||||
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
|
||||
<prop key="hibernate.show_sql">true</prop>
|
||||
<!--<prop key="hibernate.hbm2ddl.auto">create</prop>-->
|
||||
</props>
|
||||
</property>
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
|
||||
<property name="entityManagerFactory" ref="entityManagerFactory" />
|
||||
<property name="jpaDialect">
|
||||
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
|
||||
</property>
|
||||
<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 class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
|
||||
|
||||
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
|
||||
<property name="sessionFactory" ref="hibernateSessionFactory" />
|
||||
</bean>
|
||||
|
||||
|
||||
<tx:annotation-driven />
|
||||
|
||||
|
||||
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -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 devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress, hostname, port)
|
||||
values ('Par56Spot',null,'Lampe1',null, 1, null, null);
|
||||
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress, hostname, port)
|
||||
values ('Par56Spot',null,'Lampe2',null, 6, null, null);
|
||||
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress, hostname, port)
|
||||
values ('Par56Spot',null,'Lampe3',null, 11, null, null);
|
||||
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress, hostname, port)
|
||||
values ('Par56Spot',null,'Lampe4',null, 16, null, null);
|
||||
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress)
|
||||
values ('Par56Spot',null,'Lampe1',null, 1);
|
||||
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress)
|
||||
values ('Par56Spot',null,'Lampe2',null, 6);
|
||||
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress)
|
||||
values ('Par56Spot',null,'Lampe3',null, 11);
|
||||
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress)
|
||||
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);
|
||||
|
||||
|
|
|
@ -10,8 +10,6 @@ create table devices (DTYPE varchar(31) not null,
|
|||
deviceName varchar(255),
|
||||
picture varchar(255),
|
||||
startAddress integer,
|
||||
hostname varchar(255),
|
||||
port integer,
|
||||
primary key (BUNTIDEVICE_ID));
|
||||
|
||||
create table rooms (ROOM_ID integer generated by default as identity (start with 1),
|
||||
|
|
|
@ -1,44 +1,40 @@
|
|||
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.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
//@ContextConfiguration(locations = { "classpath:/META-INF/spring/root-context.xml","classpath:/de/ctdo/bunti/hibernate-test-context.xml" })
|
||||
//@RunWith(SpringJUnit4ClassRunner.class)
|
||||
//public class BuntiControllerImplTest {
|
||||
|
||||
@ContextConfiguration(locations = { "classpath:/META-INF/spring/root-context.xml","classpath:/de/ctdo/bunti/hibernate-test-context.xml" })
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class BuntiControllerImplTest {
|
||||
|
||||
@Autowired
|
||||
BuntiController dut;
|
||||
|
||||
@Autowired
|
||||
BuntiDevicesDAO dao;
|
||||
|
||||
@Test
|
||||
public void test1() throws Exception {
|
||||
|
||||
BuntiDevice dev = dao.getDeviceById(2);
|
||||
DeviceUpdate upt = dut.getDeviceValues(2);
|
||||
|
||||
Map<String, Object> data = new HashMap<String, Object>();
|
||||
data.put("red", 10);
|
||||
data.put("green", 20);
|
||||
data.put("blue", 30);
|
||||
|
||||
dut.updateDeviceData(2, data);
|
||||
|
||||
upt = dut.getDeviceValues(2);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// @Autowired
|
||||
// BuntiController dut;
|
||||
//
|
||||
// @Test
|
||||
// public void testUpdateDeviceData() throws Exception {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testGetAllRooms() throws Exception {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testGetRoomById() throws Exception {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testGetAllDevices() throws Exception {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testGetDeviceById() throws Exception {
|
||||
//
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
@ -23,13 +24,13 @@ public class BuntiDevicesDAOImplTest {
|
|||
@Test
|
||||
public void testGetAllDMXDevices() throws Exception {
|
||||
List<BuntiDMXDevice> deviceList = dut.getAllDMXDevices();
|
||||
assertEquals(5, deviceList.size());
|
||||
assertEquals(4, deviceList.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllDevices() throws Exception {
|
||||
List<BuntiDevice> deviceList = dut.getAllDevices();
|
||||
assertEquals(5, deviceList.size());
|
||||
assertEquals(4, deviceList.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
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.Test;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
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.Test;
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package de.ctdo.bunti.dmx;
|
||||
|
||||
import de.ctdo.bunti.model.BuntiDevice;
|
||||
import de.ctdo.bunti.model.Par56Spot;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package de.ctdo.bunti.model;
|
||||
|
||||
import de.ctdo.bunti.model.BuntiDMXDevice;
|
||||
import de.ctdo.bunti.model.DMXChannel;
|
||||
import de.ctdo.bunti.model.Par56Spot;
|
||||
import de.ctdo.bunti.dmx.model.DMXChannel;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package de.ctdo.bunti.model;
|
||||
|
||||
import de.ctdo.bunti.model.Par56Spot;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import static junit.framework.Assert.*;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package de.ctdo.bunti.model;
|
||||
|
||||
import de.ctdo.bunti.model.Strobe1500;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
|
@ -1,45 +1,39 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
||||
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
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-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">
|
||||
|
||||
<jdbc:embedded-database id="dataSource" type="H2">
|
||||
<jdbc:script location="classpath:init_schema.sql" />
|
||||
<jdbc:script location="classpath:init_data.sql" />
|
||||
</jdbc:embedded-database>
|
||||
|
||||
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
|
||||
<property name="packagesToScan" value="de.ctdo.bunti.model" />
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="jpaVendorAdapter">
|
||||
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
|
||||
<property name="showSql" value="true" />
|
||||
<property name="generateDdl" value="false" />
|
||||
<!-- <property name="database" value="DERBY" />-->
|
||||
<property name="database" value="H2" />
|
||||
</bean>
|
||||
<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
|
||||
<property name="packagesToScan" value="de.ctdo.bunti.model"/>
|
||||
<property name="hibernateProperties">
|
||||
<props>
|
||||
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
|
||||
<prop key="hibernate.show_sql">true</prop>
|
||||
<!--<prop key="hibernate.hbm2ddl.auto">create</prop>-->
|
||||
</props>
|
||||
</property>
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
|
||||
<property name="entityManagerFactory" ref="entityManagerFactory" />
|
||||
<property name="jpaDialect">
|
||||
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
|
||||
</property>
|
||||
|
||||
<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 id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
|
||||
<property name="sessionFactory" ref="hibernateSessionFactory" />
|
||||
</bean>
|
||||
|
||||
<tx:annotation-driven />
|
||||
|
||||
<context:component-scan base-package="de.ctdo.bunti.dao" />
|
||||
|
||||
</beans>
|
Loading…
Reference in New Issue