use of org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.UpdateDeviceResponse in project open-smart-grid-platform by OSGP.
the class DeviceManagementEndpoint method updateDevice.
@PayloadRoot(localPart = "UpdateDeviceRequest", namespace = DEVICE_MANAGEMENT_NAMESPACE)
@ResponsePayload
public UpdateDeviceResponse updateDevice(@OrganisationIdentification final String organisationIdentification, @RequestPayload final UpdateDeviceRequest request) throws OsgpException {
final String deviceToUpdateIdentification = request.getDeviceIdentification();
LOGGER.info("UpdateDeviceRequest received for device: {} for organisation: {}.", deviceToUpdateIdentification, organisationIdentification);
try {
final org.opensmartgridplatform.domain.core.entities.Ssld ssld = this.deviceManagementMapper.map(request.getUpdatedDevice(), org.opensmartgridplatform.domain.core.entities.Ssld.class);
this.deviceManagementService.updateDevice(organisationIdentification, deviceToUpdateIdentification, ssld);
} catch (final ConstraintViolationException e) {
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.WS_CORE, new ValidationException(e.getConstraintViolations()));
} catch (final Exception e) {
LOGGER.error(EXCEPTION_WHILE_UPDATING_DEVICE, e.getMessage(), deviceToUpdateIdentification, organisationIdentification, e);
this.handleException(e);
}
final UpdateDeviceResponse updateDeviceResponse = new UpdateDeviceResponse();
final String correlationUid = this.correlationIdProviderService.getCorrelationId(organisationIdentification, deviceToUpdateIdentification);
final AsyncResponse asyncResponse = new AsyncResponse();
asyncResponse.setCorrelationUid(correlationUid);
asyncResponse.setDeviceId(deviceToUpdateIdentification);
updateDeviceResponse.setAsyncResponse(asyncResponse);
try {
this.notificationService.sendNotification(organisationIdentification, deviceToUpdateIdentification, null, null, null, NotificationType.DEVICE_UPDATED);
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return updateDeviceResponse;
}
Aggregations