Search in sources :

Example 1 with DeviceStatus

use of org.opensmartgridplatform.domain.core.valueobjects.DeviceStatus in project open-smart-grid-platform by OSGP.

the class AdHocManagementService method handleGetStatusResponse.

public void handleGetStatusResponse(final DeviceStatusDto deviceStatusDto, final CorrelationIds ids, final String messageType, final int messagePriority, final ResponseMessageResultType deviceResult, final OsgpException exception) {
    LOGGER.info("handleResponse for MessageType: {}", messageType);
    final GetStatusResponse response = new GetStatusResponse();
    response.setOsgpException(exception);
    response.setResult(deviceResult);
    if (deviceResult == ResponseMessageResultType.NOT_OK || exception != null) {
        LOGGER.error("Device Response not ok.", exception);
    } else {
        final DeviceStatus status = this.domainCoreMapper.map(deviceStatusDto, DeviceStatus.class);
        try {
            final Device dev = this.deviceDomainService.searchDevice(ids.getDeviceIdentification());
            if (LightMeasurementDevice.LMD_TYPE.equals(dev.getDeviceType())) {
                this.handleLmd(status, response);
            } else {
                this.handleSsld(ids.getDeviceIdentification(), status, DomainType.PUBLIC_LIGHTING, response);
            }
        } catch (final FunctionalException e) {
            LOGGER.error("Caught FunctionalException", e);
        }
    }
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withResult(response.getResult()).withOsgpException(response.getOsgpException()).withDataObject(response.getDeviceStatusMapped()).withMessagePriority(messagePriority).build();
    this.webServiceResponseMessageSender.send(responseMessage);
}
Also used : GetStatusResponse(org.opensmartgridplatform.adapter.domain.shared.GetStatusResponse) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) CdmaDevice(org.opensmartgridplatform.domain.core.valueobjects.CdmaDevice) RtuDevice(org.opensmartgridplatform.domain.core.entities.RtuDevice) Device(org.opensmartgridplatform.domain.core.entities.Device) DeviceStatus(org.opensmartgridplatform.domain.core.valueobjects.DeviceStatus) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage)

Example 2 with DeviceStatus

use of org.opensmartgridplatform.domain.core.valueobjects.DeviceStatus in project open-smart-grid-platform by OSGP.

the class StatusMappingTest method properlyMapsDeviceStatus.

@Test
void properlyMapsDeviceStatus() {
    final Status domainStatus = new DeviceStatus(LIGHT_VALUES, PREFERRED_LINK_TYPE, ACTUAL_LINK_TYPE, LIGHT_TYPE, EVENT_NOTIFICATIONS_MASK);
    final org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.Status wsStatus = this.adHocManagementMapper.map(domainStatus, org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.Status.class);
    final org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.DeviceStatus expected = expectedDeviceStatus();
    assertThat(wsStatus).isInstanceOf(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.DeviceStatus.class).usingRecursiveComparison().isEqualTo(expected);
}
Also used : Status(org.opensmartgridplatform.domain.core.valueobjects.Status) DeviceStatus(org.opensmartgridplatform.domain.core.valueobjects.DeviceStatus) LightSensorStatus(org.opensmartgridplatform.domain.core.valueobjects.LightSensorStatus) DeviceStatus(org.opensmartgridplatform.domain.core.valueobjects.DeviceStatus) Test(org.junit.jupiter.api.Test)

Example 3 with DeviceStatus

use of org.opensmartgridplatform.domain.core.valueobjects.DeviceStatus in project open-smart-grid-platform by OSGP.

the class DeviceInstallationService method handleGetStatusResponse.

public void handleGetStatusResponse(final DeviceStatusDto deviceStatusDto, final CorrelationIds ids, final String messageType, final int messagePriority, final ResponseMessageResultType deviceResult, final OsgpException exception) {
    LOGGER.info("handleResponse for MessageType: {}", messageType);
    final GetStatusResponse response = new GetStatusResponse();
    response.setOsgpException(exception);
    response.setResult(deviceResult);
    if (deviceResult == ResponseMessageResultType.NOT_OK || exception != null) {
        LOGGER.error("Device Response not ok.", exception);
    } else {
        final DeviceStatus status = this.domainCoreMapper.map(deviceStatusDto, DeviceStatus.class);
        try {
            final Device dev = this.deviceDomainService.searchDevice(ids.getDeviceIdentification());
            if (LightMeasurementDevice.LMD_TYPE.equals(dev.getDeviceType())) {
                this.handleLmd(status, response);
            } else {
                this.handleSsld(ids.getDeviceIdentification(), status, response);
            }
        } catch (final FunctionalException e) {
            LOGGER.error("Caught FunctionalException", e);
        }
    }
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withResult(response.getResult()).withOsgpException(response.getOsgpException()).withDataObject(response.getDeviceStatusMapped()).withMessagePriority(messagePriority).withMessageType(MessageType.GET_STATUS.name()).build();
    this.webServiceResponseMessageSender.send(responseMessage);
}
Also used : GetStatusResponse(org.opensmartgridplatform.adapter.domain.shared.GetStatusResponse) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) Device(org.opensmartgridplatform.domain.core.entities.Device) DeviceStatus(org.opensmartgridplatform.domain.core.valueobjects.DeviceStatus) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage)

Example 4 with DeviceStatus

use of org.opensmartgridplatform.domain.core.valueobjects.DeviceStatus 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);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) NoDeviceResponseException(org.opensmartgridplatform.shared.exceptionhandling.NoDeviceResponseException) HashMap(java.util.HashMap) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) DeviceStatusMapped(org.opensmartgridplatform.domain.core.valueobjects.DeviceStatusMapped) DeviceStatus(org.opensmartgridplatform.domain.core.valueobjects.DeviceStatus) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Example 5 with DeviceStatus

use of org.opensmartgridplatform.domain.core.valueobjects.DeviceStatus in project open-smart-grid-platform by OSGP.

the class DeviceInstallationServiceTest method testHandleGetStatusResponseOkNotLmdStatusNotNull.

@Test
public void testHandleGetStatusResponseOkNotLmdStatusNotNull() throws FunctionalException {
    final DeviceStatus mockedStatus = Mockito.mock(DeviceStatus.class);
    when(mockedStatus.getLightValues()).thenReturn(Collections.emptyList());
    when(this.domainCoreMapper.map(null, DeviceStatus.class)).thenReturn(mockedStatus);
    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.OK, null, null));
}
Also used : LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) Device(org.opensmartgridplatform.domain.core.entities.Device) DeviceStatus(org.opensmartgridplatform.domain.core.valueobjects.DeviceStatus) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld) Test(org.junit.jupiter.api.Test)

Aggregations

DeviceStatus (org.opensmartgridplatform.domain.core.valueobjects.DeviceStatus)6 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)4 Device (org.opensmartgridplatform.domain.core.entities.Device)3 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)3 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)3 Test (org.junit.jupiter.api.Test)2 GetStatusResponse (org.opensmartgridplatform.adapter.domain.shared.GetStatusResponse)2 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)2 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)2 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)2 HashMap (java.util.HashMap)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1 GetStatusResponse (org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.GetStatusResponse)1 DeviceOutputSetting (org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting)1 RtuDevice (org.opensmartgridplatform.domain.core.entities.RtuDevice)1 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)1 CdmaDevice (org.opensmartgridplatform.domain.core.valueobjects.CdmaDevice)1 DeviceStatusMapped (org.opensmartgridplatform.domain.core.valueobjects.DeviceStatusMapped)1 LightSensorStatus (org.opensmartgridplatform.domain.core.valueobjects.LightSensorStatus)1 Status (org.opensmartgridplatform.domain.core.valueobjects.Status)1