2012-03-03 01:29:06 +00:00
|
|
|
package de.ctdo.bunti.control;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
2012-03-26 21:21:44 +00:00
|
|
|
import de.ctdo.bunti.model.*;
|
2012-03-03 01:29:06 +00:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2012-03-03 12:00:53 +00:00
|
|
|
import org.springframework.context.ApplicationEventPublisher;
|
|
|
|
import org.springframework.context.ApplicationEventPublisherAware;
|
2012-03-03 01:29:06 +00:00
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
import de.ctdo.bunti.dao.BuntiDevicesDAO;
|
|
|
|
|
|
|
|
@Component
|
2012-03-21 22:43:00 +00:00
|
|
|
public class BuntiControllerImpl implements BuntiController, ApplicationEventPublisherAware {
|
2012-03-08 00:22:31 +00:00
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(BuntiControllerImpl.class);
|
2012-03-03 12:00:53 +00:00
|
|
|
private ApplicationEventPublisher applicationEventPublisher = null;
|
2012-03-03 01:29:06 +00:00
|
|
|
|
2012-05-25 23:56:44 +00:00
|
|
|
@Autowired
|
|
|
|
private BuntiDevicesDAO devicesDAO;
|
2012-03-03 01:29:06 +00:00
|
|
|
|
2012-03-20 17:01:54 +00:00
|
|
|
@Autowired
|
2012-05-25 23:56:44 +00:00
|
|
|
private DeviceValueCache deviceCache;
|
2012-03-20 17:01:54 +00:00
|
|
|
|
2012-03-07 18:19:21 +00:00
|
|
|
@Override
|
2012-03-09 22:37:26 +00:00
|
|
|
public final void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
|
|
|
|
this.applicationEventPublisher = publisher;
|
2012-03-07 18:19:21 +00:00
|
|
|
}
|
2012-03-03 01:29:06 +00:00
|
|
|
|
2012-03-07 18:19:21 +00:00
|
|
|
@Override
|
2012-03-09 22:37:26 +00:00
|
|
|
public final boolean updateDeviceData(int deviceId, Map<String, Object> options) {
|
2012-03-03 01:29:06 +00:00
|
|
|
BuntiDevice device = devicesDAO.getDeviceById(deviceId);
|
|
|
|
|
|
|
|
if (device != null) {
|
2012-03-08 00:22:31 +00:00
|
|
|
LOGGER.debug("publishEvent in BuntiController");
|
2012-03-12 00:17:52 +00:00
|
|
|
|
2012-05-25 23:56:44 +00:00
|
|
|
deviceCache.updateData(deviceId, options);
|
2012-05-25 13:52:42 +00:00
|
|
|
|
|
|
|
device.setValuesFromOptions(options) ;
|
|
|
|
|
2012-03-12 00:17:52 +00:00
|
|
|
this.applicationEventPublisher.publishEvent(new DeviceChangedEvent(this, device, options));
|
|
|
|
|
2012-03-03 01:29:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-25 13:52:42 +00:00
|
|
|
@Override
|
|
|
|
public DeviceUpdate getDeviceValues(int deviceId) {
|
2012-05-25 23:56:44 +00:00
|
|
|
return deviceCache.getData(deviceId);
|
2012-03-09 22:37:26 +00:00
|
|
|
}
|
2012-03-03 12:00:53 +00:00
|
|
|
|
2012-03-03 01:29:06 +00:00
|
|
|
}
|