refactoring of the controllers and some cleanup
This commit is contained in:
parent
0cb8e585af
commit
03ed17d10d
|
@ -1,14 +1,17 @@
|
||||||
package de.ctdo.bunti.dao;
|
package de.ctdo.bunti.dao;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import de.ctdo.bunti.model.*;
|
import de.ctdo.bunti.model.*;
|
||||||
|
|
||||||
public interface BuntiDevicesDAO {
|
public interface BuntiDevicesDAO {
|
||||||
|
|
||||||
Collection<BuntiDevice> getAllDevices();
|
List<BuntiDevice> getAllDevices();
|
||||||
Collection<BuntiDMXDevice> getAllDMXDevices();
|
List<BuntiDMXDevice> getAllDMXDevices();
|
||||||
BuntiDevice getDeviceById(int deviceId);
|
BuntiDevice getDeviceById(int deviceId);
|
||||||
|
|
||||||
|
void addDevice(BuntiDevice device);
|
||||||
|
void removeDevice(int deviceId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,63 +1,36 @@
|
||||||
package de.ctdo.bunti.dao;
|
package de.ctdo.bunti.dao;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import de.ctdo.bunti.model.*;
|
import de.ctdo.bunti.model.*;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||||
|
|
||||||
@Repository
|
|
||||||
public final class BuntiDevicesDAOImpl implements BuntiDevicesDAO {
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(BuntiDevicesDAOImpl.class);
|
|
||||||
private List<BuntiDevice> devices = new ArrayList<BuntiDevice>();
|
|
||||||
|
|
||||||
public BuntiDevicesDAOImpl() {
|
|
||||||
// addDummyDevices();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// private void addDummyDevices() {
|
public final class BuntiDevicesDAOImpl extends HibernateDaoSupport implements BuntiDevicesDAO {
|
||||||
// int deviceID = 0;
|
|
||||||
//
|
|
||||||
// devices.add(new Par56Spot(deviceID++, 1, "Par56 Lampe 1"));
|
|
||||||
// devices.add(new Par56Spot(deviceID++, 6, "Par56 Lampe 2"));
|
|
||||||
// devices.add(new Par56Spot(deviceID++, 11, "Par56 Lampe 3"));
|
|
||||||
// devices.add(new Par56Spot(deviceID++, 16, "Par56 Lampe 4"));
|
|
||||||
// devices.add(new Strobe1500(deviceID++, 21, "Stroboskop 1"));
|
|
||||||
// devices.add(new Par56Spot(deviceID, 508, "Par56 Lampe 5"));
|
|
||||||
// LOGGER.debug("added dummy devices in DAO");
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<BuntiDMXDevice> getAllDMXDevices() {
|
public List<BuntiDMXDevice> getAllDMXDevices() {
|
||||||
List<BuntiDMXDevice> list = new ArrayList<BuntiDMXDevice>();
|
return getHibernateTemplate().loadAll(BuntiDMXDevice.class);
|
||||||
for (BuntiDevice device : devices) {
|
|
||||||
if( device instanceof BuntiDMXDevice ) {
|
|
||||||
list.add((BuntiDMXDevice) device);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<BuntiDevice> getAllDevices() {
|
public List<BuntiDevice> getAllDevices() {
|
||||||
return Collections.unmodifiableCollection(devices);
|
return getHibernateTemplate().loadAll(BuntiDevice.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BuntiDevice getDeviceById(int deviceId) {
|
public BuntiDevice getDeviceById(int deviceId) {
|
||||||
for (BuntiDevice dev : devices) {
|
return getHibernateTemplate().get(BuntiDevice.class,deviceId);
|
||||||
if(dev.getId() == deviceId) {
|
|
||||||
return dev;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addDevice(BuntiDevice device) {
|
||||||
|
getHibernateTemplate().save(device);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeDevice(int deviceId) {
|
||||||
|
getHibernateTemplate().delete(getDeviceById(deviceId));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,16 +4,9 @@ import de.ctdo.bunti.model.Room;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author: lucas
|
|
||||||
* @date: 15.03.12 21:55
|
|
||||||
*/
|
|
||||||
public interface RoomsDAO {
|
public interface RoomsDAO {
|
||||||
|
|
||||||
List<Room> getRooms();
|
List<Room> getRooms();
|
||||||
Room getRoom(int id);
|
Room getRoom(int id);
|
||||||
Room addRoom(Room room);
|
Room addRoom(Room room);
|
||||||
void removeRoom(int id);
|
void removeRoom(int id);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,11 @@
|
||||||
package de.ctdo.bunti.dao;
|
package de.ctdo.bunti.dao;
|
||||||
|
|
||||||
import de.ctdo.bunti.model.Par56Spot;
|
|
||||||
import de.ctdo.bunti.model.Room;
|
import de.ctdo.bunti.model.Room;
|
||||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
public final class RoomsDAOImpl extends HibernateDaoSupport implements RoomsDAO {
|
public final class RoomsDAOImpl extends HibernateDaoSupport implements RoomsDAO {
|
||||||
|
|
||||||
public RoomsDAOImpl() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Room> getRooms() {
|
public List<Room> getRooms() {
|
||||||
return getHibernateTemplate().loadAll(Room.class);
|
return getHibernateTemplate().loadAll(Room.class);
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package de.ctdo.bunti.dmx;
|
package de.ctdo.bunti.dmx;
|
||||||
|
|
||||||
|
import de.ctdo.bunti.dmx.model.DMXChannel;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package de.ctdo.bunti.dmx;
|
package de.ctdo.bunti.dmx.model;
|
||||||
|
|
||||||
public class DMXChannel {
|
public class DMXChannel {
|
||||||
private int offset;
|
private int offset;
|
|
@ -1,13 +1,11 @@
|
||||||
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.DMXChannel;
|
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 javax.persistence.Column;
|
|
||||||
import javax.persistence.DiscriminatorValue;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.Transient;
|
import javax.persistence.Transient;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -113,6 +111,18 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
@Override
|
||||||
|
public final Map<String, Object> getOptions() {
|
||||||
|
Map<String, Object> options = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
for(DMXChannel channel: dmxChannels.getAllChannels()) {
|
||||||
|
options.put(channel.getName(), channel.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a channel to this DMX Device
|
* Add a channel to this DMX Device
|
||||||
* used internally by subclasses to define their structure
|
* used internally by subclasses to define their structure
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package de.ctdo.bunti.model;
|
package de.ctdo.bunti.model;
|
||||||
|
|
||||||
import javax.persistence.*;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -103,13 +101,8 @@ public abstract class BuntiDevice {
|
||||||
public abstract boolean setValuesFromOptions(Map<String, Object> options);
|
public abstract boolean setValuesFromOptions(Map<String, Object> options);
|
||||||
|
|
||||||
|
|
||||||
// @ManyToOne
|
@Transient
|
||||||
// @JoinColumn(name="ROOM_ID")
|
public abstract Map<String, Object> getOptions();
|
||||||
// public Room getRoom() {
|
|
||||||
// return room;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void setRoom(Room room) {
|
|
||||||
// this.room = room;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
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.DMXChannel;
|
import de.ctdo.bunti.dmx.model.DMXChannel;
|
||||||
|
import org.codehaus.jackson.annotate.JsonIgnore;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Transient;
|
import javax.persistence.Transient;
|
||||||
|
@ -41,16 +42,19 @@ public class Par56Spot extends BuntiDMXDevice {
|
||||||
setChannelValueByName(CHANNEL_BLUE, value);
|
setChannelValueByName(CHANNEL_BLUE, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
@Transient
|
@Transient
|
||||||
public final int getRed() {
|
public final int getRed() {
|
||||||
return getChannelValueByName(CHANNEL_RED);
|
return getChannelValueByName(CHANNEL_RED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
@Transient
|
@Transient
|
||||||
public final int getGreen() {
|
public final int getGreen() {
|
||||||
return getChannelValueByName(CHANNEL_GREEN);
|
return getChannelValueByName(CHANNEL_GREEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
@Transient
|
@Transient
|
||||||
public final int getBlue() {
|
public final int getBlue() {
|
||||||
return getChannelValueByName(CHANNEL_BLUE);
|
return getChannelValueByName(CHANNEL_BLUE);
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
package de.ctdo.bunti.model;
|
package de.ctdo.bunti.model;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.io.Serializable;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
@ -15,7 +13,7 @@ public final class Room {
|
||||||
private String floor;
|
private String floor;
|
||||||
private int xCord;
|
private int xCord;
|
||||||
private int yCord;
|
private int yCord;
|
||||||
private Set<BuntiDevice> devices = new HashSet<BuntiDevice>();
|
private List<BuntiDevice> devices = new ArrayList<BuntiDevice>();
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@ -67,38 +65,32 @@ public final class Room {
|
||||||
@JoinTable(name = "ROOM_BUNTIDEVICE",
|
@JoinTable(name = "ROOM_BUNTIDEVICE",
|
||||||
joinColumns = { @JoinColumn(name = "ROOM_ID") },
|
joinColumns = { @JoinColumn(name = "ROOM_ID") },
|
||||||
inverseJoinColumns = { @JoinColumn(name = "BUNTIDEVICE_ID") })
|
inverseJoinColumns = { @JoinColumn(name = "BUNTIDEVICE_ID") })
|
||||||
public Set<BuntiDevice> getDevices() {
|
public List<BuntiDevice> getDevices() {
|
||||||
return this.devices;
|
return Collections.unmodifiableList(this.devices);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDevices(Set<BuntiDevice> devices) {
|
public void setDevices(List<BuntiDevice> devices) {
|
||||||
this.devices = devices;
|
this.devices = devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// @Transient
|
@Transient
|
||||||
// public boolean addDevice(BuntiDevice device) {
|
public boolean addDevice(BuntiDevice device) {
|
||||||
// return getDevices().add(device);
|
return getDevices().add(device);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Transient
|
|
||||||
// public boolean removeDevice(BuntiDevice device) {
|
|
||||||
// return getDevices().remove(device);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Transient
|
|
||||||
// public BuntiDevice getDevice(int id) {
|
|
||||||
// for (BuntiDevice device: getDevices()) {
|
|
||||||
// if( device.getId() == id) {
|
|
||||||
// return device;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Transient
|
|
||||||
// public List<BuntiDevice> getDeviceList() {
|
|
||||||
// return Collections.unmodifiableList(getDevices());
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
public boolean removeDevice(BuntiDevice device) {
|
||||||
|
return getDevices().remove(device);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
public BuntiDevice getDevice(int id) {
|
||||||
|
for (BuntiDevice device: getDevices()) {
|
||||||
|
if( device.getId() == id) {
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
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.DMXChannel;
|
import de.ctdo.bunti.dmx.model.DMXChannel;
|
||||||
|
import org.codehaus.jackson.annotate.JsonIgnore;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Transient;
|
import javax.persistence.Transient;
|
||||||
|
@ -36,16 +37,19 @@ public class Strobe1500 extends BuntiDMXDevice {
|
||||||
return setChannelValueByName(CHANNEL_MODE, value);
|
return setChannelValueByName(CHANNEL_MODE, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
@Transient
|
@Transient
|
||||||
public final int getSpeed() {
|
public final int getSpeed() {
|
||||||
return getChannelValueByName(CHANNEL_SPEED);
|
return getChannelValueByName(CHANNEL_SPEED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
@Transient
|
@Transient
|
||||||
public final int getIntensity() {
|
public final int getIntensity() {
|
||||||
return getChannelValueByName(CHANNEL_INTENSITY);
|
return getChannelValueByName(CHANNEL_INTENSITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
@Transient
|
@Transient
|
||||||
public final int getMode() {
|
public final int getMode() {
|
||||||
return getChannelValueByName(CHANNEL_MODE);
|
return getChannelValueByName(CHANNEL_MODE);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
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.BuntiDevice;
|
|
||||||
import de.ctdo.bunti.webmodel.DeviceUpdate;
|
import de.ctdo.bunti.webmodel.DeviceUpdate;
|
||||||
import de.ctdo.bunti.webmodel.DeviceUpdates;
|
import de.ctdo.bunti.webmodel.DeviceUpdates;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -10,8 +9,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping(value = "/control")
|
@RequestMapping(value = "/control")
|
||||||
public class DeviceControlController {
|
public class DeviceControlController {
|
||||||
|
@ -23,29 +20,14 @@ public class DeviceControlController {
|
||||||
this.controller = controller;
|
this.controller = controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/devices", method = RequestMethod.GET)
|
|
||||||
public @ResponseBody Collection<BuntiDevice> getAll() {
|
|
||||||
LOGGER.info("handle GET /devices request");
|
|
||||||
return controller.getAllDevices();
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping(value = "/devices/{id}", method = RequestMethod.GET)
|
|
||||||
public @ResponseBody BuntiDevice getDeviceById(@PathVariable("id") int id) {
|
|
||||||
LOGGER.info("handle GET /devices/" + id + " request");
|
|
||||||
return controller.getDeviceById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping(value = "/devices", method = RequestMethod.POST)
|
@RequestMapping(value = "/devices", method = RequestMethod.POST)
|
||||||
public String setDevices(@RequestBody DeviceUpdates updates) {
|
public void setDevices(@RequestBody DeviceUpdates updates) {
|
||||||
LOGGER.info("handle PUT /devices" + " request update=" + updates.toString() );
|
LOGGER.info("handle PUT /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 "bla";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
package de.ctdo.bunti.web;
|
||||||
|
|
||||||
|
import de.ctdo.bunti.dao.BuntiDevicesDAO;
|
||||||
|
import de.ctdo.bunti.model.BuntiDevice;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping(value = "/devices")
|
||||||
|
public class DevicesController {
|
||||||
|
private BuntiDevicesDAO devicesDAO;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public void setDevicesDAO(BuntiDevicesDAO devicesDAO) {
|
||||||
|
this.devicesDAO = devicesDAO;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "", method = RequestMethod.GET)
|
||||||
|
public @ResponseBody Collection<BuntiDevice> getAll() {
|
||||||
|
return devicesDAO.getAllDevices();
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
||||||
|
public @ResponseBody BuntiDevice getDeviceById(@PathVariable("id") int id) {
|
||||||
|
return devicesDAO.getDeviceById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "", method = RequestMethod.POST)
|
||||||
|
public @ResponseBody BuntiDevice setDevices(@RequestBody BuntiDevice device) {
|
||||||
|
devicesDAO.addDevice(device);
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,47 +1,45 @@
|
||||||
package de.ctdo.bunti.web;
|
package de.ctdo.bunti.web;
|
||||||
|
|
||||||
import de.ctdo.bunti.control.BuntiController;
|
import de.ctdo.bunti.dao.RoomsDAO;
|
||||||
|
import de.ctdo.bunti.model.BuntiDevice;
|
||||||
import de.ctdo.bunti.model.Room;
|
import de.ctdo.bunti.model.Room;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping(value = "/rooms")
|
@RequestMapping(value = "/rooms")
|
||||||
public class RoomsController {
|
public class RoomsController {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(RoomsController.class);
|
private RoomsDAO roomsDAO;
|
||||||
private BuntiController controller;
|
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public final void setController(BuntiController controller) {
|
public void setRoomsDAO(RoomsDAO roomsDAO) {
|
||||||
this.controller = controller;
|
this.roomsDAO = roomsDAO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "", method = RequestMethod.GET)
|
@RequestMapping(value = "", method = RequestMethod.GET)
|
||||||
public @ResponseBody Collection<Room> getAll() {
|
public @ResponseBody Collection<Room> getAll() {
|
||||||
LOGGER.info("handle GET /rooms" + " request");
|
return roomsDAO.getRooms();
|
||||||
return controller.getAllRooms();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
||||||
public @ResponseBody Room getRoomById(@PathVariable("id") int id) {
|
public @ResponseBody Room getRoomById(@PathVariable("id") int id) {
|
||||||
LOGGER.info("handle GET /rooms/" + id + " request");
|
return roomsDAO.getRoom(id);
|
||||||
return controller.getRoomById(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/{id}/devices", method = RequestMethod.GET)
|
@RequestMapping(value = "/{id}/devices", method = RequestMethod.GET)
|
||||||
public @ResponseBody Room getDevicesFromRoom(@PathVariable("id") int id) {
|
public @ResponseBody
|
||||||
LOGGER.info("handle GET /rooms/id/devices " + id + " request");
|
List<BuntiDevice> getDevicesFromRoom(@PathVariable("id") int id) {
|
||||||
|
Room room = roomsDAO.getRoom(id);
|
||||||
|
|
||||||
Room r = controller.getRoomById(id);
|
if(room != null) {
|
||||||
|
return room.getDevices();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
return controller.getRoomById(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
package de.ctdo.bunti.webmodel;
|
package de.ctdo.bunti.webmodel;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Diese Klasse gibts nur, weil ich es nicht hinbekomme mit Jackson
|
||||||
|
* ein ArrayList<DeviceUpdate> als Parameter im Controller zu verarbeiten.
|
||||||
|
*/
|
||||||
public class DeviceUpdates {
|
public class DeviceUpdates {
|
||||||
|
|
||||||
private long timeStamp = 0;
|
private long timeStamp = 0;
|
||||||
|
|
||||||
private List<DeviceUpdate> updates = new ArrayList<DeviceUpdate>();
|
private List<DeviceUpdate> updates = new ArrayList<DeviceUpdate>();
|
||||||
|
|
||||||
|
|
||||||
public List<DeviceUpdate> getUpdates() {
|
public List<DeviceUpdate> getUpdates() {
|
||||||
return updates;
|
return updates;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,13 @@
|
||||||
<?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:tx="http://www.springframework.org/schema/tx"
|
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
|
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/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">
|
xmlns:jdbc="http://www.springframework.org/schema/jdbc">
|
||||||
|
|
||||||
<!--<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">-->
|
|
||||||
<!--<property name="location">-->
|
|
||||||
<!--<value>db.properties</value>-->
|
|
||||||
<!--</property>-->
|
|
||||||
<!--</bean>-->
|
|
||||||
|
|
||||||
<jdbc:embedded-database id="dataSource" type="H2">
|
<jdbc:embedded-database id="dataSource" type="H2">
|
||||||
<!--<jdbc:script location="classpath:init_data.sql" />-->
|
<jdbc:script location="classpath:init_schema.sql" />
|
||||||
|
<jdbc:script location="classpath:init_data.sql" />
|
||||||
</jdbc:embedded-database>
|
</jdbc:embedded-database>
|
||||||
|
|
||||||
<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
|
<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
|
||||||
|
@ -22,7 +16,7 @@
|
||||||
<props>
|
<props>
|
||||||
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
|
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
|
||||||
<prop key="hibernate.show_sql">true</prop>
|
<prop key="hibernate.show_sql">true</prop>
|
||||||
<prop key="hibernate.hbm2ddl.auto">create</prop>
|
<!--<prop key="hibernate.hbm2ddl.auto">create</prop>-->
|
||||||
</props>
|
</props>
|
||||||
</property>
|
</property>
|
||||||
<property name="dataSource" ref="dataSource" />
|
<property name="dataSource" ref="dataSource" />
|
||||||
|
@ -32,6 +26,10 @@
|
||||||
<property name="sessionFactory" ref="hibernateSessionFactory" />
|
<property name="sessionFactory" ref="hibernateSessionFactory" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<bean id="devicesDAO" class="de.ctdo.bunti.dao.BuntiDevicesDAOImpl">
|
||||||
|
<property name="sessionFactory" ref="hibernateSessionFactory" />
|
||||||
|
</bean>
|
||||||
|
|
||||||
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
|
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
|
||||||
|
|
||||||
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
|
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
|
||||||
|
|
|
@ -6,6 +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)
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package de.ctdo.bunti.control;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
//@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;
|
||||||
|
//
|
||||||
|
// @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 {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//}
|
|
@ -1,23 +0,0 @@
|
||||||
package de.ctdo.bunti.control;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
|
|
||||||
public class BuntiControllerTest {
|
|
||||||
|
|
||||||
BuntiControllerImpl dut;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
dut = new BuntiControllerImpl();
|
|
||||||
// dut.setDevicesDAO(daoMock);
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
// public void testSetDevice() throws Exception {
|
|
||||||
// Map<String,Object> options = new HashMap<String, Object>();
|
|
||||||
// options.put("optionA", "valueA");
|
|
||||||
// options.put("optionB", 42);
|
|
||||||
// assertTrue(dut.updateDeviceData(12, options));
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
package de.ctdo.bunti.dao;
|
||||||
|
|
||||||
|
import de.ctdo.bunti.model.BuntiDMXDevice;
|
||||||
|
import de.ctdo.bunti.model.BuntiDevice;
|
||||||
|
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.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
import static junit.framework.Assert.assertNull;
|
||||||
|
|
||||||
|
@ContextConfiguration(locations = { "classpath:/de/ctdo/bunti/hibernate-test-context.xml" })
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
public class BuntiDevicesDAOImplTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
BuntiDevicesDAO dut;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllDMXDevices() throws Exception {
|
||||||
|
List<BuntiDMXDevice> deviceList = dut.getAllDMXDevices();
|
||||||
|
assertEquals(4, deviceList.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllDevices() throws Exception {
|
||||||
|
List<BuntiDevice> deviceList = dut.getAllDevices();
|
||||||
|
assertEquals(4, deviceList.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetDeviceById() throws Exception {
|
||||||
|
BuntiDevice device = dut.getDeviceById(2);
|
||||||
|
|
||||||
|
assertEquals("Lampe2", device.getDeviceName());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
package de.ctdo.bunti.dao;
|
package de.ctdo.bunti.dao;
|
||||||
|
|
||||||
import de.ctdo.bunti.model.Room;
|
|
||||||
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;
|
||||||
|
@ -10,7 +9,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import static junit.framework.Assert.assertEquals;
|
import static junit.framework.Assert.assertEquals;
|
||||||
import static junit.framework.Assert.assertNull;
|
import static junit.framework.Assert.assertNull;
|
||||||
|
|
||||||
@ContextConfiguration()
|
@ContextConfiguration(locations = { "classpath:/de/ctdo/bunti/hibernate-test-context.xml" })
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
public class RoomsDAOImplTest {
|
public class RoomsDAOImplTest {
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package de.ctdo.bunti.dmx;
|
package de.ctdo.bunti.dmx;
|
||||||
|
|
||||||
|
import de.ctdo.bunti.dmx.model.DMXChannel;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package de.ctdo.bunti.dmx;
|
package de.ctdo.bunti.dmx;
|
||||||
|
|
||||||
|
import de.ctdo.bunti.dmx.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.model;
|
package de.ctdo.bunti.model;
|
||||||
|
|
||||||
import de.ctdo.bunti.dmx.DMXChannel;
|
import de.ctdo.bunti.dmx.model.DMXChannel;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
|
@ -26,13 +26,14 @@
|
||||||
<property name="sessionFactory" ref="hibernateSessionFactory" />
|
<property name="sessionFactory" ref="hibernateSessionFactory" />
|
||||||
</bean>
|
</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 />
|
<tx:annotation-driven />
|
||||||
|
|
||||||
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
|
|
||||||
<property name="sessionFactory" ref="hibernateSessionFactory"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</beans>
|
</beans>
|
Loading…
Reference in New Issue