Search in sources :

Example 21 with ResponseMessageResultType

use of org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType in project open-smart-grid-platform by OSGP.

the class ConfigurationService method handleGetFirmwareVersionResponse.

/**
 * Maps the firmware Dto's to value objects and sends it back to the ws-adapter layer
 *
 * @param messageMetadata contains the message meta data
 * @param deviceResult indicates whether the execution was successful
 * @param exception contains the exception if one was thrown
 * @param firmwareVersionList contains the firmware result list
 */
public void handleGetFirmwareVersionResponse(final MessageMetadata messageMetadata, final ResponseMessageResultType deviceResult, final OsgpException exception, final List<FirmwareVersionDto> firmwareVersionList) {
    log.info("handleGetFirmwareVersionResponse for MessageType: {}", messageMetadata.getMessageType());
    ResponseMessageResultType result = deviceResult;
    if (exception != null) {
        log.error("Get firmware version response not ok. Unexpected Exception", exception);
        result = ResponseMessageResultType.NOT_OK;
    }
    final List<FirmwareVersion> firmwareVersions = this.configurationMapper.mapAsList(firmwareVersionList, FirmwareVersion.class);
    final FirmwareVersionResponse firmwareVersionResponse = new FirmwareVersionResponse(firmwareVersions);
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withMessageMetadata(messageMetadata).withResult(result).withOsgpException(exception).withDataObject(firmwareVersionResponse).build();
    this.webServiceResponseMessageSender.send(responseMessage, messageMetadata.getMessageType());
    this.firmwareService.saveFirmwareVersionsReturnedFromDevice(messageMetadata.getDeviceIdentification(), firmwareVersions);
}
Also used : FirmwareVersionResponse(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.FirmwareVersionResponse) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)

Example 22 with ResponseMessageResultType

use of org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType in project open-smart-grid-platform by OSGP.

the class DefaultDeviceResponseService method handleDefaultDeviceResponse.

public void handleDefaultDeviceResponse(final CorrelationIds ids, final String messageType, final int messagePriority, final ResponseMessageResultType deviceResult, final OsgpException exception) {
    LOGGER.info("handleDefaultDeviceResponse for MessageType: {}", messageType);
    ResponseMessageResultType result = deviceResult;
    OsgpException osgpException = exception;
    if (deviceResult == ResponseMessageResultType.NOT_OK && exception == null) {
        LOGGER.error("Incorrect response received, exception should not be null when result is not ok");
        osgpException = new TechnicalException(ComponentType.DOMAIN_TARIFF_SWITCHING, "An unknown error occurred");
    }
    if (deviceResult == ResponseMessageResultType.OK && exception != null) {
        LOGGER.error("Incorrect response received, result should be set to not ok when exception is not null");
        result = ResponseMessageResultType.NOT_OK;
    }
    final MessageMetadata metaData = new MessageMetadata.Builder().withCorrelationUid(ids.getCorrelationUid()).withDeviceIdentification(ids.getDeviceIdentification()).withOrganisationIdentification(ids.getOrganisationIdentification()).withMessageType(messageType).build();
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withMessageMetadata(metaData).withResult(result).withOsgpException(osgpException).withMessagePriority(messagePriority).build();
    this.webServiceResponseMessageSender.send(responseMessage);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)

Example 23 with ResponseMessageResultType

use of org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType in project open-smart-grid-platform by OSGP.

the class DeviceCommunicationInformationService method updateDeviceConnectionInformation.

/**
 * Update the device record with information about the device connection. Based on the response
 * message, set the time stamps and counter for the device.
 *
 * @param message The {@link ProtocolResponseMessage} containing the response message.
 */
@Transactional
public void updateDeviceConnectionInformation(final ProtocolResponseMessage message) {
    final String deviceIdentification = message.getDeviceIdentification();
    Device device = this.deviceRepository.findByDeviceIdentification(deviceIdentification);
    if (device == null) {
        LOGGER.info("No device {} found to update connection information for with {} {} response with correlation UID {}." + " This may be appropriate as the device could be expected to be unknown to GXF.", deviceIdentification, message.getMessageType(), message.getResult(), message.getCorrelationUid());
        return;
    }
    final ResponseMessageResultType result = message.getResult();
    if (ResponseMessageResultType.OK == result) {
        device.updateConnectionDetailsToSuccess();
    } else if (ResponseMessageResultType.NOT_OK == result) {
        device.updateConnectionDetailsToFailure();
    } else {
        LOGGER.warn("Unexpected result type: {}, connection information not updated for device: {}", result, deviceIdentification);
        return;
    }
    device = this.deviceRepository.save(device);
    LOGGER.info("Updated connection information for device: {}, last successful connection timestamp: {}, last failed connection timestamp: {}, connection failure count: {} based on result type: {}", deviceIdentification, device.getLastSuccessfulConnectionTimestamp(), device.getLastFailedConnectionTimestamp(), device.getFailedConnectionCount(), result.name());
}
Also used : Device(org.opensmartgridplatform.domain.core.entities.Device) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with ResponseMessageResultType

use of org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType in project open-smart-grid-platform by OSGP.

the class AdHocManagementService method handleGetDataResponse.

public void handleGetDataResponse(final GetDataResponseDto dataResponseDto, final CorrelationIds ids, final String messageType, final ResponseMessageResultType responseMessageResultType, final OsgpException osgpException) {
    LOGGER.info("handleResponse for MessageType: {}", messageType);
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    GetDataResponse dataResponse = null;
    OsgpException exception = null;
    try {
        if (responseMessageResultType == ResponseMessageResultType.NOT_OK || osgpException != null) {
            LOGGER.error("Device Response not ok.", osgpException);
            throw osgpException;
        }
        this.handleResponseMessageReceived(ids.getDeviceIdentification());
        dataResponse = this.mapper.map(dataResponseDto, GetDataResponse.class);
    } catch (final Exception e) {
        LOGGER.error("Unexpected Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        exception = this.ensureOsgpException(e, "Exception occurred while getting data");
    }
    // Support for Push messages, generate correlationUid
    String actualCorrelationUid = ids.getCorrelationUid();
    if ("no-correlationUid".equals(actualCorrelationUid)) {
        actualCorrelationUid = this.correlationIdProviderUUIDService.getCorrelationId("DeviceGenerated", ids.getDeviceIdentification());
    }
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withCorrelationUid(actualCorrelationUid).withMessageType(messageType).withResult(result).withOsgpException(exception).withDataObject(dataResponse).build();
    this.webServiceResponseMessageSender.send(responseMessage, messageType);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) GetDataResponse(org.opensmartgridplatform.domain.microgrids.valueobjects.GetDataResponse) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OptimisticLockException(javax.persistence.OptimisticLockException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) UnknownEntityException(org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)

Example 25 with ResponseMessageResultType

use of org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType in project open-smart-grid-platform by OSGP.

the class AdHocManagementService method handleSetDataResponse.

public void handleSetDataResponse(final EmptyResponseDto emptyResponseDto, final CorrelationIds ids, final String messageType, final ResponseMessageResultType responseMessageResultType, final OsgpException osgpException) {
    LOGGER.info("handleResponse for MessageType: {}", messageType);
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    EmptyResponse emptyResponse = null;
    OsgpException exception = null;
    try {
        if (responseMessageResultType == ResponseMessageResultType.NOT_OK || osgpException != null) {
            LOGGER.error("Device Response not ok.", osgpException);
            throw osgpException;
        }
        this.handleResponseMessageReceived(ids.getDeviceIdentification());
        emptyResponse = this.mapper.map(emptyResponseDto, EmptyResponse.class);
    } catch (final Exception e) {
        LOGGER.error("Unexpected Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        exception = this.ensureOsgpException(e, "Exception occurred while setting data");
    }
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withResult(result).withOsgpException(exception).withDataObject(emptyResponse).build();
    this.webServiceResponseMessageSender.send(responseMessage, messageType);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) EmptyResponse(org.opensmartgridplatform.domain.microgrids.valueobjects.EmptyResponse) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OptimisticLockException(javax.persistence.OptimisticLockException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) UnknownEntityException(org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)

Aggregations

ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)102 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)78 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)52 JMSException (javax.jms.JMSException)39 CorrelationIds (org.opensmartgridplatform.shared.infra.jms.CorrelationIds)24 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)20 ProtocolResponseMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)17 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)15 Serializable (java.io.Serializable)12 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)12 Test (org.junit.jupiter.api.Test)6 DeviceStatusDto (org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto)6 IOException (java.io.IOException)5 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)4 UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)4 FirmwareVersion (org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)4 GetStatusDeviceResponse (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetStatusDeviceResponse)3 Device (org.opensmartgridplatform.domain.core.entities.Device)3 FirmwareVersionDto (org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto)3 Calendar (java.util.Calendar)2