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;
import de.ctdo.bunti.model.BuntiDevice;
import java.util.Collection;
import java.util.Map;
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;
import java.util.Collection;
import java.util.Map;
import org.slf4j.Logger;
@ -9,14 +10,13 @@ import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;
import net.sf.json.JSONObject;
import de.ctdo.bunti.DeviceChangedEvent;
import de.ctdo.bunti.dao.BuntiDevicesDAO;
import de.ctdo.bunti.model.*;
@Component
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 BuntiDevicesDAO devicesDAO;
@ -25,42 +25,30 @@ public class BuntiControllerImpl implements BuntiController, ApplicationEventPub
this.devicesDAO = devicesDAO;
}
public final void performJSONString(String json) {
@Override
public Collection<BuntiDevice> getAllDevices() {
return devicesDAO.getAllDevices();
}
JSONObject jsonobj = JSONObject.fromObject(json);
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) {
BuntiDevice device = devicesDAO.getDeviceById(deviceId);
if (device != null) {
this.applicationEventPublisher.publishEvent(new DeviceChangedEvent(this, device, options));
logger.debug("publishEvent in BuntiController");
return true;
}
return false;
}
@Override
@Override
public BuntiDevice getDeviceById(int deviceId) {
return devicesDAO.getDeviceById(deviceId);
}
@Override
public final void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
this.applicationEventPublisher = publisher;
}