use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class SmartMeteringInstallationEndpoint method addDevice.
@PayloadRoot(localPart = "AddDeviceRequest", namespace = SMARTMETER_INSTALLATION_NAMESPACE)
@ResponsePayload
public AddDeviceAsyncResponse addDevice(@OrganisationIdentification final String organisationIdentification, @RequestPayload final AddDeviceRequest request, @MessagePriority final String messagePriority, @ScheduleTime final String scheduleTime, @ResponseUrl final String responseUrl, @BypassRetry final String bypassRetry) throws OsgpException {
log.info("Incoming AddDeviceRequest for meter: {}.", request.getDevice().getDeviceIdentification());
AsyncResponse asyncResponse = null;
try {
final SmartMeteringDevice device = this.installationMapper.map(request.getDevice(), SmartMeteringDevice.class);
final DeviceModel deviceModel = new DeviceModel(request.getDeviceModel().getManufacturer(), request.getDeviceModel().getModelCode(), "");
final AddSmartMeterRequest addSmartMeterRequest = new AddSmartMeterRequest(device, deviceModel);
final RequestMessageMetadata requestMessageMetadata = RequestMessageMetadata.newBuilder().withOrganisationIdentification(organisationIdentification).withDeviceIdentification(device.getDeviceIdentification()).withDeviceFunction(null).withMessageType(MessageType.ADD_METER).withMessagePriority(messagePriority).withScheduleTime(scheduleTime).withBypassRetry(bypassRetry).build();
asyncResponse = this.requestService.enqueueAndSendRequest(requestMessageMetadata, addSmartMeterRequest);
this.saveResponseUrlIfNeeded(asyncResponse.getCorrelationUid(), responseUrl);
} catch (final ConstraintViolationException e) {
log.error("Exception: {} while adding device: {} for organisation {}.", e.getMessage(), request.getDevice().getDeviceIdentification(), organisationIdentification, e);
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.WS_CORE, new ValidationException(e.getConstraintViolations()));
} catch (final Exception e) {
log.error("Exception: {} while adding device: {} for organisation {}.", e.getMessage(), request.getDevice().getDeviceIdentification(), organisationIdentification, e);
this.handleException(e);
}
return this.installationMapper.map(asyncResponse, AddDeviceAsyncResponse.class);
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class SmartMeteringMonitoringEndpoint method getRetrievePushNotificationAlarmResponse.
@PayloadRoot(localPart = "RetrievePushNotificationAlarmRequest", namespace = SMARTMETER_MONITORING_NAMESPACE)
@ResponsePayload
public RetrievePushNotificationAlarmResponse getRetrievePushNotificationAlarmResponse(@OrganisationIdentification final String organisationIdentification, @RequestPayload final RetrievePushNotificationAlarmRequest request) throws OsgpException {
log.info("Incoming RetrievePushNotificationAlarmRequest for correlation UID: {}", request.getCorrelationUid());
RetrievePushNotificationAlarmResponse response = null;
try {
final ResponseData responseData = this.responseDataService.get(request.getCorrelationUid(), PushNotificationAlarm.class, ComponentType.WS_SMART_METERING);
this.throwExceptionIfResultNotOk(responseData, "retrieving the push notification alarm");
response = this.monitoringMapper.map(responseData.getMessageData(), RetrievePushNotificationAlarmResponse.class);
} catch (final FunctionalException e) {
throw e;
} catch (final Exception e) {
log.error("Exception: {} while sending RetrievePushNotificationAlarmRequest for correlation UID: {} for organisation {}.", e.getMessage(), request.getCorrelationUid(), organisationIdentification);
this.handleException(e);
}
return response;
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class SmartMeteringManagementEndpoint method getEnableDebuggingResponse.
@PayloadRoot(localPart = "EnableDebuggingAsyncRequest", namespace = NAMESPACE)
@ResponsePayload
public EnableDebuggingResponse getEnableDebuggingResponse(@OrganisationIdentification final String organisationIdentification, @RequestPayload final EnableDebuggingAsyncRequest request) throws OsgpException {
log.info("EnableDebugging response for organisation: {} and device: {}.", organisationIdentification, request.getDeviceIdentification());
EnableDebuggingResponse response = null;
try {
response = new EnableDebuggingResponse();
final ResponseData responseData = this.responseDataService.get(request.getCorrelationUid(), ComponentType.WS_SMART_METERING);
this.throwExceptionIfResultNotOk(responseData, "Enable Debugging");
response.setResult(OsgpResultType.fromValue(responseData.getResultType().getValue()));
if (responseData.getMessageData() instanceof String) {
response.setDescription((String) responseData.getMessageData());
}
} catch (final ConstraintViolationException e) {
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.WS_SMART_METERING, new ValidationException(e.getConstraintViolations()));
} catch (final Exception e) {
this.handleException(e);
}
return response;
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class DeviceRequestMessageListener method sendException.
private void sendException(final ObjectMessage objectMessage, final Exception exception) {
try {
final ResponseMessageResultType result = ResponseMessageResultType.NOT_OK;
final FunctionalException osgpException = new FunctionalException(FunctionalExceptionType.UNSUPPORTED_DEVICE_ACTION, ComponentType.PROTOCOL_IEC61850, exception);
final Serializable dataObject = objectMessage.getObject();
final MessageMetadata messageMetadata = MessageMetadata.fromMessage(objectMessage);
final ProtocolResponseMessage protocolResponseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(messageMetadata.builder().withScheduled(false).build()).result(result).osgpException(osgpException).dataObject(dataObject).build();
this.deviceResponseMessageSender.send(protocolResponseMessage);
} catch (final Exception e) {
LOGGER.error("Unexpected error during sendException(ObjectMessage, Exception)", e);
}
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class ConfigurationService method setEncryptionKeyExchangeOnGMeter.
public void setEncryptionKeyExchangeOnGMeter(final MessageMetadata messageMetadata) throws FunctionalException {
log.info("set Encryption Key Exchange On G-Meter for organisationIdentification: {} for deviceIdentification: " + "{}", messageMetadata.getOrganisationIdentification(), messageMetadata.getDeviceIdentification());
final SmartMeter gasDevice = this.domainHelperService.findSmartMeter(messageMetadata.getDeviceIdentification());
final Device gatewayDevice = gasDevice.getGatewayDevice();
if (gatewayDevice == null) {
/*
* For now throw a FunctionalException, based on the same reasoning
* as with the channel a couple of lines up. As soon as we have
* scenario's with direct communication with gas meters this will
* have to be changed.
*/
throw new FunctionalException(FunctionalExceptionType.GATEWAY_DEVICE_NOT_SET_FOR_MBUS_DEVICE, ComponentType.DOMAIN_SMART_METERING, new GatewayDeviceNotSetForMbusDeviceException());
}
final GMeterInfoDto requestDto = new GMeterInfoDto(gasDevice.getChannel(), gasDevice.getDeviceIdentification());
this.osgpCoreRequestMessageSender.send(requestDto, messageMetadata.builder().withDeviceIdentification(gatewayDevice.getDeviceIdentification()).withIpAddress(gatewayDevice.getIpAddress()).withNetworkSegmentIds(gatewayDevice.getBtsId(), gatewayDevice.getCellId()).build());
}
Aggregations