use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class DeviceRequestMessageListener method sendNotSupportedException.
private void sendNotSupportedException(final ObjectMessage objectMessage, final MessageMetadata messageMetadata) {
try {
final Exception exception = new NotSupportedException(ComponentType.PROTOCOL_IEC60870, messageMetadata.getMessageType());
final FunctionalException osgpException = new FunctionalException(FunctionalExceptionType.UNSUPPORTED_DEVICE_ACTION, ComponentType.PROTOCOL_IEC60870, exception);
final ProtocolResponseMessage protocolResponseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(messageMetadata.builder().withScheduled(false).build()).result(ResponseMessageResultType.NOT_OK).osgpException(osgpException).dataObject(objectMessage.getObject()).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 EventServiceTest method testWrongEventCode.
@Test
void testWrongEventCode() {
final FunctionalException functionalException = Assertions.assertThrows(FunctionalException.class, () -> {
final ProtocolInfo protocolInfo = mock(ProtocolInfo.class);
when(protocolInfo.getProtocol()).thenReturn("SMR");
when(this.smartMeter.getProtocolInfo()).thenReturn(protocolInfo);
final EventDto event = new EventDto(new DateTime(), 266, 2, "STANDARD_EVENT_LOG");
final ArrayList<EventDto> events = new ArrayList<>();
events.add(event);
final EventMessageDataResponseDto responseDto = new EventMessageDataResponseDto(events);
this.eventService.enrichEvents(this.deviceMessageMetadata, responseDto);
});
assertThat(functionalException.getExceptionType()).isEqualTo(FunctionalExceptionType.VALIDATION_ERROR);
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class SmartMeteringManagementEndpoint method getDevices.
@PayloadRoot(localPart = "GetDevicesRequest", namespace = NAMESPACE)
@ResponsePayload
public GetDevicesResponse getDevices(@OrganisationIdentification final String organisationIdentification, @RequestPayload final GetDevicesRequest request) throws OsgpException {
log.info("Get Devices Request received from organisation: {}.", organisationIdentification);
GetDevicesResponse response = null;
try {
response = new GetDevicesResponse();
final Page<Device> page = this.managementService.findAllDevices(organisationIdentification, request.getPage());
final DevicePage devicePage = new DevicePage();
devicePage.setTotalPages(page.getTotalPages());
devicePage.getDevices().addAll(this.managementMapper.mapAsList(page.getContent(), org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.Device.class));
response.setDevicePage(devicePage);
} catch (final ConstraintViolationException e) {
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, COMPONENT_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 SmartMeteringManagementEndpoint method getDisableDebuggingResponse.
@PayloadRoot(localPart = "DisableDebuggingAsyncRequest", namespace = NAMESPACE)
@ResponsePayload
public DisableDebuggingResponse getDisableDebuggingResponse(@OrganisationIdentification final String organisationIdentification, @RequestPayload final DisableDebuggingAsyncRequest request) throws OsgpException {
log.info("DisableDebugging response for organisation: {} and device: {}.", organisationIdentification, request.getDeviceIdentification());
DisableDebuggingResponse response = null;
try {
response = new DisableDebuggingResponse();
final ResponseData responseData = this.responseDataService.get(request.getCorrelationUid(), ComponentType.WS_SMART_METERING);
this.throwExceptionIfResultNotOk(responseData, "Disable 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 SmartMeteringManagementEndpoint method clearMBusStatusOnAllChannelsResponse.
@PayloadRoot(localPart = "ClearMBusStatusOnAllChannelsAsyncRequest", namespace = NAMESPACE)
@ResponsePayload
public ClearMBusStatusOnAllChannelsResponse clearMBusStatusOnAllChannelsResponse(@OrganisationIdentification final String organisationIdentification, @RequestPayload final ClearMBusStatusOnAllChannelsAsyncRequest request) throws OsgpException {
log.info("Clear M-Bus Status On All Channels response for organisation: {} and device: {}.", organisationIdentification, request.getDeviceIdentification());
ClearMBusStatusOnAllChannelsResponse response = null;
try {
response = new ClearMBusStatusOnAllChannelsResponse();
final ResponseData responseData = this.responseDataService.get(request.getCorrelationUid(), ComponentType.WS_SMART_METERING);
this.throwExceptionIfResultNotOk(responseData, "Clear M-Bus Status On All Channels");
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;
}
Aggregations