Search in sources :

Example 6 with DeviceMessageStatus

use of org.opensmartgridplatform.webdevicesimulator.domain.entities.DeviceMessageStatus in project open-smart-grid-platform by OSGP.

the class DeviceManagementController method sendRegisterDeviceCommand.

@PostMapping(value = COMMAND_REGISTER_URL)
@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(org.opensmartgridplatform.webdevicesimulator.domain.entities.DeviceMessageStatus) RegisterDevice(org.opensmartgridplatform.webdevicesimulator.service.RegisterDevice) Device(org.opensmartgridplatform.webdevicesimulator.domain.entities.Device) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

DeviceMessageStatus (org.opensmartgridplatform.webdevicesimulator.domain.entities.DeviceMessageStatus)6 Device (org.opensmartgridplatform.webdevicesimulator.domain.entities.Device)3 RegisterDevice (org.opensmartgridplatform.webdevicesimulator.service.RegisterDevice)3 PostMapping (org.springframework.web.bind.annotation.PostMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 ByteString (com.google.protobuf.ByteString)2 ExecutionException (java.util.concurrent.ExecutionException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 EventNotificationToBeSent (org.opensmartgridplatform.webdevicesimulator.domain.valueobjects.EventNotificationToBeSent)1 DeviceSimulatorException (org.opensmartgridplatform.webdevicesimulator.exceptions.DeviceSimulatorException)1