moved model classes, extended Ethersex Device section
This commit is contained in:
parent
ed69f6a0e3
commit
a5329a0bcc
|
@ -4,6 +4,7 @@ import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import de.ctdo.bunti.dao.RoomsDAO;
|
import de.ctdo.bunti.dao.RoomsDAO;
|
||||||
|
import de.ctdo.bunti.model.*;
|
||||||
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;
|
||||||
|
@ -12,7 +13,6 @@ import org.springframework.context.ApplicationEventPublisherAware;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
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 {
|
||||||
|
|
|
@ -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.*;
|
import de.ctdo.bunti.model.BuntiDMXDevice;
|
||||||
|
import de.ctdo.bunti.model.BuntiDevice;
|
||||||
|
|
||||||
public interface BuntiDevicesDAO {
|
public interface BuntiDevicesDAO {
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package de.ctdo.bunti.dmx;
|
package de.ctdo.bunti.dmx;
|
||||||
|
|
||||||
import de.ctdo.bunti.dmx.model.DMXChannel;
|
import de.ctdo.bunti.model.DMXChannel;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
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.context.ApplicationListener;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class EthersexMixerImpl implements EthersexMixer, ApplicationListener<DeviceChangedEvent> {
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(EthersexMixerImpl.class);
|
||||||
|
private boolean hasDataChanged = true;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final boolean updateDevice(BuntiDevice device, Map<String, Object> options) {
|
||||||
|
if(device == null || options == null || options.size() == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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,9 +1,7 @@
|
||||||
package de.ctdo.bunti.dmx.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 de.ctdo.bunti.model.BuntiDevice;
|
|
||||||
import org.codehaus.jackson.annotate.JsonIgnore;
|
import org.codehaus.jackson.annotate.JsonIgnore;
|
||||||
import org.hibernate.annotations.Entity;
|
import org.hibernate.annotations.Entity;
|
||||||
|
|
|
@ -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 abstract class BuntiDevice {
|
public 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 abstract class BuntiDevice {
|
||||||
/**
|
/**
|
||||||
* Switch this device off.
|
* Switch this device off.
|
||||||
*/
|
*/
|
||||||
public abstract void switchOff();
|
public void switchOff() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Switch this device on.
|
* Switch this device on.
|
||||||
*/
|
*/
|
||||||
public abstract void switchOn();
|
public 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,11 +98,15 @@ public abstract 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 abstract boolean setValuesFromOptions(Map<String, Object> options);
|
public boolean setValuesFromOptions(Map<String, Object> options) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
public abstract Map<String, Object> getOptions();
|
public Map<String, Object> getOptions() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,91 @@
|
||||||
|
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 static 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package de.ctdo.bunti.dmx.model;
|
package de.ctdo.bunti.model;
|
||||||
|
|
||||||
public class DMXChannel {
|
public class DMXChannel {
|
||||||
private int offset;
|
private int offset;
|
|
@ -1,14 +1,7 @@
|
||||||
package de.ctdo.bunti.ethersex.model;
|
package de.ctdo.bunti.model;
|
||||||
|
|
||||||
import de.ctdo.bunti.dmx.DMX;
|
|
||||||
import de.ctdo.bunti.dmx.model.DMXChannel;
|
|
||||||
import de.ctdo.bunti.model.BuntiDevice;
|
|
||||||
import org.codehaus.jackson.annotate.JsonIgnore;
|
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Transient;
|
import javax.persistence.Transient;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Lampel extends BuntiEthersexDevice {
|
public class Lampel extends BuntiEthersexDevice {
|
|
@ -1,4 +1,4 @@
|
||||||
package de.ctdo.bunti.dmx.model;
|
package de.ctdo.bunti.model;
|
||||||
|
|
||||||
import de.ctdo.bunti.dmx.DMX;
|
import de.ctdo.bunti.dmx.DMX;
|
||||||
import org.codehaus.jackson.annotate.JsonIgnore;
|
import org.codehaus.jackson.annotate.JsonIgnore;
|
|
@ -1,4 +1,4 @@
|
||||||
package de.ctdo.bunti.dmx.model;
|
package de.ctdo.bunti.model;
|
||||||
|
|
||||||
import de.ctdo.bunti.dmx.DMX;
|
import de.ctdo.bunti.dmx.DMX;
|
||||||
import org.codehaus.jackson.annotate.JsonIgnore;
|
import org.codehaus.jackson.annotate.JsonIgnore;
|
|
@ -19,7 +19,7 @@
|
||||||
</jdbc:embedded-database>
|
</jdbc:embedded-database>
|
||||||
|
|
||||||
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
|
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
|
||||||
<property name="packagesToScan" value="de.ctdo.bunti.model" />
|
<property name="packagesToScan" value="de.ctdo.bunti.dmx.model" />
|
||||||
<property name="dataSource" ref="dataSource" />
|
<property name="dataSource" ref="dataSource" />
|
||||||
<property name="jpaVendorAdapter">
|
<property name="jpaVendorAdapter">
|
||||||
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
|
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
|
||||||
|
@ -40,7 +40,6 @@
|
||||||
|
|
||||||
<tx:annotation-driven />
|
<tx:annotation-driven />
|
||||||
|
|
||||||
<context:component-scan base-package="de.ctdo.bunti.dao" />
|
|
||||||
|
|
||||||
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
|
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
|
||||||
|
|
||||||
|
|
|
@ -6,14 +6,18 @@ 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)
|
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress, hostname, port)
|
||||||
values ('Par56Spot',null,'Lampe1',null, 1);
|
values ('Par56Spot',null,'Lampe1',null, 1, null, null);
|
||||||
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress)
|
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress, hostname, port)
|
||||||
values ('Par56Spot',null,'Lampe2',null, 6);
|
values ('Par56Spot',null,'Lampe2',null, 6, null, null);
|
||||||
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress)
|
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress, hostname, port)
|
||||||
values ('Par56Spot',null,'Lampe3',null, 11);
|
values ('Par56Spot',null,'Lampe3',null, 11, null, null);
|
||||||
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress)
|
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress, hostname, port)
|
||||||
values ('Par56Spot',null,'Lampe4',null, 16);
|
values ('Par56Spot',null,'Lampe4',null, 16, null, null);
|
||||||
|
|
||||||
|
|
||||||
|
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, 1);
|
||||||
|
|
|
@ -10,6 +10,8 @@ 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),
|
||||||
|
|
|
@ -8,7 +8,6 @@ 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;
|
||||||
|
@ -24,13 +23,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(4, deviceList.size());
|
assertEquals(5, 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(4, deviceList.size());
|
assertEquals(5, deviceList.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package de.ctdo.bunti.dmx;
|
package de.ctdo.bunti.dmx;
|
||||||
|
|
||||||
import de.ctdo.bunti.dmx.model.DMXChannel;
|
import de.ctdo.bunti.model.DMXChannel;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package de.ctdo.bunti.dmx;
|
package de.ctdo.bunti.dmx;
|
||||||
|
|
||||||
import de.ctdo.bunti.dmx.model.DMXChannel;
|
import de.ctdo.bunti.model.DMXChannel;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
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;
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package de.ctdo.bunti.model;
|
package de.ctdo.bunti.model;
|
||||||
|
|
||||||
import de.ctdo.bunti.dmx.model.DMXChannel;
|
import de.ctdo.bunti.model.BuntiDMXDevice;
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
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.*;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
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;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue