Search in sources :

Example 6 with DeviceStatusMapped

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

the class TariffSwitchingAdHocManagementEndpoint method getGetStatusResponse.

@PayloadRoot(localPart = "GetStatusAsyncRequest", namespace = NAMESPACE)
@ResponsePayload
public GetStatusResponse getGetStatusResponse(@OrganisationIdentification final String organisationIdentification, @RequestPayload final GetStatusAsyncRequest request) throws OsgpException {
    LOGGER.info("Get Status Response received from organisation: {} for correlationUid: {}.", organisationIdentification, request.getAsyncRequest().getCorrelationUid());
    final GetStatusResponse response = new GetStatusResponse();
    try {
        final ResponseMessage message = this.adHocManagementService.dequeueGetTariffStatusResponse(request.getAsyncRequest().getCorrelationUid());
        if (message != null) {
            response.setResult(OsgpResultType.fromValue(message.getResult().getValue()));
            final DeviceStatusMapped deviceStatus = (DeviceStatusMapped) message.getDataObject();
            if (deviceStatus != null) {
                response.setDeviceStatus(this.adHocManagementMapper.map(deviceStatus, org.opensmartgridplatform.adapter.ws.schema.tariffswitching.adhocmanagement.DeviceStatus.class));
            }
        }
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : GetStatusResponse(org.opensmartgridplatform.adapter.ws.schema.tariffswitching.adhocmanagement.GetStatusResponse) DeviceStatusMapped(org.opensmartgridplatform.domain.core.valueobjects.DeviceStatusMapped) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 7 with DeviceStatusMapped

use of org.opensmartgridplatform.domain.core.valueobjects.DeviceStatusMapped 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 8 with DeviceStatusMapped

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

Aggregations

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