Search in sources :

Example 1 with DeviceMessageStatus

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);
}
Also used : DeviceMessageStatus(com.alliander.osgp.webdevicesimulator.domain.entities.DeviceMessageStatus) Timer(java.util.Timer) TimerTask(java.util.TimerTask) ByteString(com.google.protobuf.ByteString) ParseException(java.text.ParseException) DeviceSimulatorException(com.alliander.osgp.webdevicesimulator.exceptions.DeviceSimulatorException) IOException(java.io.IOException)

Example 2 with DeviceMessageStatus

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;
    }
}
Also used : DeviceMessageStatus(com.alliander.osgp.webdevicesimulator.domain.entities.DeviceMessageStatus) Device(com.alliander.osgp.webdevicesimulator.domain.entities.Device) RegisterDevice(com.alliander.osgp.webdevicesimulator.service.RegisterDevice) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with DeviceMessageStatus

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();
    }
}
Also used : DeviceMessageStatus(com.alliander.osgp.webdevicesimulator.domain.entities.DeviceMessageStatus) EventNotificationToBeSent(com.alliander.osgp.webdevicesimulator.domain.valueobjects.EventNotificationToBeSent) ArrayList(java.util.ArrayList)

Example 4 with DeviceMessageStatus

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;
    }
}
Also used : DeviceMessageStatus(com.alliander.osgp.webdevicesimulator.domain.entities.DeviceMessageStatus) Device(com.alliander.osgp.webdevicesimulator.domain.entities.Device) RegisterDevice(com.alliander.osgp.webdevicesimulator.service.RegisterDevice) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with DeviceMessageStatus

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;
    }
}
Also used : DeviceMessageStatus(com.alliander.osgp.webdevicesimulator.domain.entities.DeviceMessageStatus) Device(com.alliander.osgp.webdevicesimulator.domain.entities.Device) RegisterDevice(com.alliander.osgp.webdevicesimulator.service.RegisterDevice) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

DeviceMessageStatus (com.alliander.osgp.webdevicesimulator.domain.entities.DeviceMessageStatus)5 Device (com.alliander.osgp.webdevicesimulator.domain.entities.Device)3 RegisterDevice (com.alliander.osgp.webdevicesimulator.service.RegisterDevice)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 EventNotificationToBeSent (com.alliander.osgp.webdevicesimulator.domain.valueobjects.EventNotificationToBeSent)1 DeviceSimulatorException (com.alliander.osgp.webdevicesimulator.exceptions.DeviceSimulatorException)1 ByteString (com.google.protobuf.ByteString)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1