Search in sources :

Example 21 with Device

use of com.alliander.osgp.webdevicesimulator.domain.entities.Device in project Protocol-Adapter-OSLP by OSGP.

the class DeviceManagementController method createDevice.

@RequestMapping(value = DEVICE_CREATE_URL, method = RequestMethod.POST)
public String createDevice(@ModelAttribute(MODEL_ATTRIBUTE_DEVICE) final Device created, final BindingResult bindingResult, final RedirectAttributes attributes) {
    if (bindingResult.hasErrors()) {
        return DEVICE_CREATE_VIEW;
    }
    created.setDeviceUid(this.createRandomDeviceUid());
    Device device = null;
    try {
        // Store device
        device = this.deviceManagementService.addDevice(created);
        this.addFeedbackMessage(attributes, FEEDBACK_MESSAGE_KEY_DEVICE_CREATED, device.getDeviceIdentification());
    } catch (final Exception e) {
        LOGGER.error("Error creating device: {}", e);
        this.setErrorFeedbackMessage(created, attributes);
    }
    return this.createRedirectViewPath(DEVICES_URL);
}
Also used : Device(com.alliander.osgp.webdevicesimulator.domain.entities.Device) RegisterDevice(com.alliander.osgp.webdevicesimulator.service.RegisterDevice) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with Device

use of com.alliander.osgp.webdevicesimulator.domain.entities.Device 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)

Example 23 with Device

use of com.alliander.osgp.webdevicesimulator.domain.entities.Device in project Protocol-Adapter-OSLP by OSGP.

the class DeviceManagementController method setSequenceNumber.

@RequestMapping(value = COMMAND_SET_SEQUENCE_NUMBER_URL, method = RequestMethod.POST)
@ResponseBody
public Integer setSequenceNumber(@RequestBody final SetSequenceNumberRequest setSequenceNumberRequest) {
    final Long deviceId = setSequenceNumberRequest.getDeviceId();
    final Integer sequenceNumber = setSequenceNumberRequest.getSequenceNumber();
    Device device = this.deviceManagementService.findDevice(deviceId);
    if (device != null) {
        device.setSequenceNumber(sequenceNumber);
        device = this.deviceManagementService.updateDevice(device);
        return device.getSequenceNumber();
    } else {
        return -1;
    }
}
Also used : 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

Device (com.alliander.osgp.webdevicesimulator.domain.entities.Device)23 RegisterDevice (com.alliander.osgp.webdevicesimulator.service.RegisterDevice)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)5 DeviceSimulatorException (com.alliander.osgp.webdevicesimulator.exceptions.DeviceSimulatorException)4 OslpEnvelope (com.alliander.osgp.oslp.OslpEnvelope)3 DeviceMessageStatus (com.alliander.osgp.webdevicesimulator.domain.entities.DeviceMessageStatus)3 IOException (java.io.IOException)3 UnknownHostException (java.net.UnknownHostException)3 Oslp (com.alliander.osgp.oslp.Oslp)2 ByteString (com.google.protobuf.ByteString)2 Message (com.alliander.osgp.oslp.Oslp.Message)1 OutOfSequenceEvent (com.alliander.osgp.webdevicesimulator.service.OslpChannelHandler.OutOfSequenceEvent)1