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);
}
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;
}
}
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;
}
}
Aggregations