cleanup and extension

This commit is contained in:
Lucas Pleß 2012-03-07 19:19:21 +01:00
parent 2535e98e41
commit 019c235ea5
2 changed files with 21 additions and 27 deletions

View File

@ -1,9 +1,15 @@
package de.ctdo.bunti.control; package de.ctdo.bunti.control;
import de.ctdo.bunti.model.BuntiDevice;
import java.util.Collection;
import java.util.Map; import java.util.Map;
public interface BuntiController { public interface BuntiController {
boolean setDevice(int deviceID, Map<String, Object> options); Collection<BuntiDevice> getAllDevices();
BuntiDevice getDeviceById(int deviceId);
boolean setDevice(int deviceId, Map<String, Object> options);
} }

View File

@ -1,5 +1,6 @@
package de.ctdo.bunti.control; package de.ctdo.bunti.control;
import java.util.Collection;
import java.util.Map; import java.util.Map;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -9,14 +10,13 @@ import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware; import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import net.sf.json.JSONObject;
import de.ctdo.bunti.DeviceChangedEvent; import de.ctdo.bunti.DeviceChangedEvent;
import de.ctdo.bunti.dao.BuntiDevicesDAO; import de.ctdo.bunti.dao.BuntiDevicesDAO;
import de.ctdo.bunti.model.*; import de.ctdo.bunti.model.*;
@Component @Component
public class BuntiControllerImpl implements BuntiController, ApplicationEventPublisherAware { public class BuntiControllerImpl implements BuntiController, ApplicationEventPublisherAware {
private Logger logger = LoggerFactory.getLogger(getClass()); private static final Logger logger = LoggerFactory.getLogger(BuntiControllerImpl.class);
private ApplicationEventPublisher applicationEventPublisher = null; private ApplicationEventPublisher applicationEventPublisher = null;
private BuntiDevicesDAO devicesDAO; private BuntiDevicesDAO devicesDAO;
@ -25,41 +25,29 @@ public class BuntiControllerImpl implements BuntiController, ApplicationEventPub
this.devicesDAO = devicesDAO; this.devicesDAO = devicesDAO;
} }
public final void performJSONString(String json) { @Override
public Collection<BuntiDevice> getAllDevices() {
JSONObject jsonobj = JSONObject.fromObject(json); return devicesDAO.getAllDevices();
if (jsonobj.containsKey("command")) {
String command = jsonobj.get("command").toString();
if (command.equals("setdmxchannels")) {
} else if (command.equals("switchdevice")) {
}
}
} }
@Override @Override
public final boolean setDevice(int deviceId, Map<String, Object> options) { public final boolean setDevice(int deviceId, Map<String, Object> options) {
BuntiDevice device = devicesDAO.getDeviceById(deviceId); BuntiDevice device = devicesDAO.getDeviceById(deviceId);
if (device != null) { if (device != null) {
this.applicationEventPublisher.publishEvent(new DeviceChangedEvent(this, device, options)); this.applicationEventPublisher.publishEvent(new DeviceChangedEvent(this, device, options));
logger.debug("publishEvent in BuntiController"); logger.debug("publishEvent in BuntiController");
return true; return true;
} }
return false; return false;
} }
@Override
public BuntiDevice getDeviceById(int deviceId) {
return devicesDAO.getDeviceById(deviceId);
}
@Override @Override
public final void setApplicationEventPublisher(ApplicationEventPublisher publisher) { public final void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
this.applicationEventPublisher = publisher; this.applicationEventPublisher = publisher;