use of org.opensmartgridplatform.shared.exceptionhandling.NoDeviceResponseException in project open-smart-grid-platform by OSGP.
the class AdHocManagementService method handleGetStatusResponse.
public void handleGetStatusResponse(final DeviceStatusDto deviceStatusDto, final DomainType allowedDomainType, final CorrelationIds ids, final int messagePriority, final ResponseMessageResultType deviceResult, final OsgpException exception) {
ResponseMessageResultType result = deviceResult;
OsgpException osgpException = exception;
DeviceStatusMapped deviceStatusMapped = null;
if (deviceResult == ResponseMessageResultType.NOT_OK || exception != null) {
LOGGER.error("Device Response not ok.", osgpException);
} else {
final DeviceStatus status = this.domainCoreMapper.map(deviceStatusDto, DeviceStatus.class);
final Ssld ssld = this.ssldRepository.findByDeviceIdentification(ids.getDeviceIdentification());
final List<DeviceOutputSetting> deviceOutputSettings = ssld.getOutputSettings();
final Map<Integer, DeviceOutputSetting> dosMap = new HashMap<>();
for (final DeviceOutputSetting dos : deviceOutputSettings) {
dosMap.put(dos.getExternalId(), dos);
}
if (status != null) {
deviceStatusMapped = new DeviceStatusMapped(FilterLightAndTariffValuesHelper.filterTariffValues(status.getLightValues(), dosMap, allowedDomainType), FilterLightAndTariffValuesHelper.filterLightValues(status.getLightValues(), dosMap, allowedDomainType), status.getPreferredLinkType(), status.getActualLinkType(), status.getLightType(), status.getEventNotificationsMask());
this.updateDeviceRelayOverview(ssld, deviceStatusMapped);
} else {
result = ResponseMessageResultType.NOT_OK;
osgpException = new TechnicalException(ComponentType.DOMAIN_TARIFF_SWITCHING, "Device was not able to report status", new NoDeviceResponseException());
}
}
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withResult(result).withOsgpException(osgpException).withDataObject(deviceStatusMapped).withMessagePriority(messagePriority).build();
this.webServiceResponseMessageSender.send(responseMessage);
}
use of org.opensmartgridplatform.shared.exceptionhandling.NoDeviceResponseException in project open-smart-grid-platform by OSGP.
the class AdHocManagementService method handleSsld.
private void handleSsld(final String deviceIdentification, final DeviceStatus status, final DomainType allowedDomainType, final GetStatusResponse response) {
// Find device and output settings.
final Ssld ssld = this.ssldRepository.findByDeviceIdentification(deviceIdentification);
final List<DeviceOutputSetting> deviceOutputSettings = ssld.getOutputSettings();
// Create map with external relay number as key set.
final Map<Integer, DeviceOutputSetting> dosMap = new HashMap<>();
for (final DeviceOutputSetting dos : deviceOutputSettings) {
dosMap.put(dos.getExternalId(), dos);
}
if (status != null) {
// Map the DeviceStatus for SSLD.
final DeviceStatusMapped deviceStatusMapped = new DeviceStatusMapped(FilterLightAndTariffValuesHelper.filterTariffValues(status.getLightValues(), dosMap, allowedDomainType), FilterLightAndTariffValuesHelper.filterLightValues(status.getLightValues(), dosMap, allowedDomainType), status.getPreferredLinkType(), status.getActualLinkType(), status.getLightType(), status.getEventNotificationsMask());
// Update the relay overview with the relay information.
this.updateDeviceRelayStatusForGetStatus(ssld, deviceStatusMapped);
// Return mapped status using GetStatusResponse instance.
response.setDeviceStatusMapped(deviceStatusMapped);
} else {
// No status received, create bad response.
response.setDeviceStatusMapped(null);
response.setOsgpException(new TechnicalException(ComponentType.DOMAIN_PUBLIC_LIGHTING, "SSLD was not able to report relay status", new NoDeviceResponseException()));
response.setResult(ResponseMessageResultType.NOT_OK);
}
}
use of org.opensmartgridplatform.shared.exceptionhandling.NoDeviceResponseException in project open-smart-grid-platform by OSGP.
the class DeviceInstallationServiceTest method testHandleGetStatusResponseOkNotLMDStatusNull.
@Test
public void testHandleGetStatusResponseOkNotLMDStatusNull() throws FunctionalException {
when(this.domainCoreMapper.map(null, DeviceStatus.class)).thenReturn(null);
final Device mockedDevice = Mockito.mock(Device.class);
when(mockedDevice.getDeviceType()).thenReturn(null);
when(this.deviceDomainService.searchDevice(TEST_DEVICE)).thenReturn(mockedDevice);
when(this.ssldRepository.findByDeviceIdentification(TEST_DEVICE)).thenReturn(new Ssld());
this.deviceInstallationService.handleGetStatusResponse(null, CORRELATION_IDS, TEST_MESSAGE_TYPE, MESSAGE_PRIORITY, ResponseMessageResultType.OK, null);
verify(this.webServiceResponseMessageSender).send(this.argumentResponseMessage.capture());
assertThat(this.argumentResponseMessage.getValue()).usingRecursiveComparison().ignoringFields("dataObject").isEqualTo(this.createNewResponseMessage(ResponseMessageResultType.NOT_OK, new TechnicalException(ComponentType.DOMAIN_CORE, "SSLD was not able to report relay status", new NoDeviceResponseException()), null));
}
Aggregations