use of com.alliander.osgp.webdevicesimulator.domain.entities.DeviceMessageStatus in project Protocol-Adapter-OSLP by OSGP.
the class OslpChannelHandler method sendDelayedDeviceRegistration.
private void sendDelayedDeviceRegistration(final Device device) {
if (device == null) {
return;
}
final String deviceIdentification = device.getDeviceIdentification();
if (StringUtils.isEmpty(deviceIdentification)) {
return;
}
new Timer().schedule(new TimerTask() {
@Override
public void run() {
try {
LOGGER.info("Sending DeviceRegistrationRequest for device: {}", deviceIdentification);
final DeviceMessageStatus deviceMessageStatus = OslpChannelHandler.this.registerDevice.sendRegisterDeviceCommand(device.getId(), true);
if (DeviceMessageStatus.OK.equals(deviceMessageStatus)) {
LOGGER.info("Sending ConfirmDeviceRegistrationRequest for device: {}", deviceIdentification);
OslpChannelHandler.this.registerDevice.sendConfirmDeviceRegistrationCommand(device.getId());
}
} catch (final Exception e) {
LOGGER.error("Caught exception during sendDelayedDeviceRegistration() for device : " + deviceIdentification, e);
}
}
}, 2000);
}
use of com.alliander.osgp.webdevicesimulator.domain.entities.DeviceMessageStatus in project Protocol-Adapter-OSLP by OSGP.
the class DeviceManagementController method sendConfirmDeviceRegistrationCommand.
@RequestMapping(value = COMMAND_REGISTER_CONFIRM_URL, method = RequestMethod.POST)
@ResponseBody
public String sendConfirmDeviceRegistrationCommand(@RequestBody final ConfirmDeviceRegistrationRequest request) {
// Find device
final Device device = this.deviceManagementService.findDevice(request.getDeviceId());
final DeviceMessageStatus status = this.registerDevice.sendConfirmDeviceRegistrationCommand(request.getDeviceId());
if (status == DeviceMessageStatus.OK) {
return this.getFeedbackMessage(FEEDBACK_MESSAGE_KEY_DEVICE_REGISTERED_CONFIRM, device.getDeviceIdentification());
} else if (status == DeviceMessageStatus.FAILURE) {
return this.getFeedbackMessage(FEEDBACK_MESSAGE_KEY_DEVICE_ERROR, device.getDeviceIdentification(), this.registerDevice.getErrorMessage());
} else {
return FAILURE_URL;
}
}
use of com.alliander.osgp.webdevicesimulator.domain.entities.DeviceMessageStatus in project Protocol-Adapter-OSLP by OSGP.
the class EventNotificationTransition method run.
@Override
public void run() {
if (this.deviceManagementService.getEventNotification()) {
// The original list with listofeventtobesent
final List<EventNotificationToBeSent> listeventNotificationToBeSent = this.deviceManagementService.getEventNotificationToBeSent();
// The local list of events
final List<EventNotificationToBeSent> listOfEvents = new ArrayList<>();
// add content of the original list into the local list of events
listOfEvents.addAll(listeventNotificationToBeSent);
// run through the list of events and send each
for (final EventNotificationToBeSent event : listOfEvents) {
DeviceMessageStatus status;
if (event.getLightOn()) {
// Send EventNotifications for Light Transition ON
LOGGER.info("Sending LIGHT_EVENTS_LIGHT_ON_VALUE event for device : {}: {} ", event.getdeviceId());
status = this.registerDevice.sendEventNotificationCommand(event.getdeviceId(), Oslp.Event.LIGHT_EVENTS_LIGHT_ON_VALUE, "LIGHT_EVENTS_LIGHT_ON_VALUE event occurred on Light Switching on ", null);
} else {
// Send EventNotifications for Light Transition OFF
LOGGER.info("Sending LIGHT_EVENTS_LIGHT_OFF_VALUE event for device : {}: {} ", event.getdeviceId());
status = this.registerDevice.sendEventNotificationCommand(event.getdeviceId(), Oslp.Event.LIGHT_EVENTS_LIGHT_OFF_VALUE, "LIGHT_EVENTS_LIGHT_OFF_VALUE event occurred on light Switching off ", null);
}
// device then this doesnt work.
if (status == DeviceMessageStatus.OK) {
listeventNotificationToBeSent.remove(event);
}
}
// The local list of events
listOfEvents.clear();
}
}
use of com.alliander.osgp.webdevicesimulator.domain.entities.DeviceMessageStatus in project Protocol-Adapter-OSLP by OSGP.
the class DeviceManagementController method sendEventNotificationCommandAll.
@RequestMapping(value = COMMAND_SENDNOTIFICATION_URL, method = RequestMethod.POST)
@ResponseBody
public String sendEventNotificationCommandAll(@RequestBody final SendEventNotificationRequest request) {
// Find device
final Device device = this.deviceManagementService.findDevice(request.getDeviceId());
final DeviceMessageStatus status = this.registerDevice.sendEventNotificationCommand(request.getDeviceId(), request.getEvent(), request.getDescription(), request.getIndex(), request.getHasTimestamp());
if (status == DeviceMessageStatus.OK) {
return this.getFeedbackMessage(FEEDBACK_MESSAGE_KEY_EVENTNOTIFICATION_SENT, device.getDeviceIdentification());
} else if (status == DeviceMessageStatus.FAILURE) {
return this.getFeedbackMessage(FEEDBACK_MESSAGE_KEY_DEVICE_ERROR, device.getDeviceIdentification(), this.registerDevice.getErrorMessage());
} else {
return FAILURE_URL;
}
}
use of com.alliander.osgp.webdevicesimulator.domain.entities.DeviceMessageStatus in project Protocol-Adapter-OSLP by OSGP.
the class DeviceManagementController method sendRegisterDeviceCommand.
@RequestMapping(value = COMMAND_REGISTER_URL, method = RequestMethod.POST)
@ResponseBody
public String sendRegisterDeviceCommand(@RequestBody final RegisterDeviceRequest request) {
// Find device
final Device device = this.deviceManagementService.findDevice(request.getDeviceId());
final DeviceMessageStatus status = this.registerDevice.sendRegisterDeviceCommand(request.getDeviceId(), request.getHasSchedule());
if (status == DeviceMessageStatus.OK) {
return this.getFeedbackMessage(FEEDBACK_MESSAGE_KEY_DEVICE_REGISTERED, device.getDeviceIdentification(), this.registerDevice.getCurrentTime());
} else if (status == DeviceMessageStatus.FAILURE) {
return this.getFeedbackMessage(FEEDBACK_MESSAGE_KEY_DEVICE_ERROR, device.getDeviceIdentification(), this.registerDevice.getErrorMessage());
} else {
return FAILURE_URL;
}
}
Aggregations