Search in sources :

Example 96 with ResponseMessageResultType

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

the class MonitoringService method handleGetMeasurementReportResponse.

public void handleGetMeasurementReportResponse(final MeasurementReportDto measurementReportDto, final CorrelationIds ids, final String messageType, final ResponseMessageResultType responseMessageResultType, final OsgpException osgpException) {
    LOGGER.info("handleResponse for MessageType: {}", messageType);
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    MeasurementReport measurementReport = null;
    OsgpException exception = osgpException;
    try {
        if (responseMessageResultType == ResponseMessageResultType.NOT_OK || osgpException != null) {
            LOGGER.error("Device Response not ok.", osgpException);
            throw osgpException;
        }
        this.rtuResponseService.handleResponseMessageReceived(LOGGER, ids.getDeviceIdentification(), true);
        measurementReport = this.mapper.map(measurementReportDto, MeasurementReport.class);
    } catch (final Exception e) {
        LOGGER.error("Unexpected Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        exception = this.ensureOsgpException(e, "Exception occurred while receiving Measurement Report");
    }
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withResult(result).withOsgpException(exception).withDataObject(measurementReport).build();
    this.responseMessageRouter.send(responseMessage, messageType);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) MeasurementReport(org.opensmartgridplatform.domain.da.measurements.MeasurementReport) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException)

Example 97 with ResponseMessageResultType

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

the class AdHocManagementService method handleGetDeviceModelResponse.

public void handleGetDeviceModelResponse(final GetDeviceModelResponseDto getDeviceModelResponseDto, final CorrelationIds correlationIds, final String messageType, final ResponseMessageResultType responseMessageResultType, final OsgpException osgpException) {
    LOGGER.info("handleResponse for MessageType: {}", messageType);
    final String deviceIdentification = correlationIds.getDeviceIdentification();
    final String organisationIdentification = correlationIds.getOrganisationIdentification();
    final String correlationUid = correlationIds.getCorrelationUid();
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    GetDeviceModelResponse getDeviceModelResponse = null;
    OsgpException exception = osgpException;
    try {
        if (responseMessageResultType == ResponseMessageResultType.NOT_OK || osgpException != null) {
            LOGGER.error("Device Response not ok.", osgpException);
            throw osgpException;
        }
        this.rtuResponseService.handleResponseMessageReceived(LOGGER, deviceIdentification, true);
        getDeviceModelResponse = this.mapper.map(getDeviceModelResponseDto, GetDeviceModelResponse.class);
    } catch (final Exception e) {
        LOGGER.error("Unexpected Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        exception = this.ensureOsgpException(e, "Exception occurred while getting Device Model Response Data");
    }
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withCorrelationUid(correlationUid).withOrganisationIdentification(organisationIdentification).withDeviceIdentification(deviceIdentification).withResult(result).withOsgpException(exception).withDataObject(getDeviceModelResponse).build();
    this.responseMessageRouter.send(responseMessage, messageType);
}
Also used : GetDeviceModelResponse(org.opensmartgridplatform.domain.da.valueobjects.GetDeviceModelResponse) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException)

Example 98 with ResponseMessageResultType

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

the class DomainResponseMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) {
    log.debug("Processing response message");
    String correlationUid = null;
    String actualMessageType = null;
    String organisationIdentification = null;
    String deviceIdentification = null;
    final String notificationMessage;
    final NotificationType notificationType;
    final ResponseMessageResultType resultType;
    final String resultDescription;
    final Serializable dataObject;
    try {
        correlationUid = message.getJMSCorrelationID();
        actualMessageType = message.getJMSType();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        resultType = ResponseMessageResultType.valueOf(message.getStringProperty(Constants.RESULT));
        resultDescription = message.getStringProperty(Constants.DESCRIPTION);
        notificationMessage = message.getStringProperty(Constants.DESCRIPTION);
        notificationType = NotificationType.valueOf(actualMessageType);
        dataObject = message.getObject();
    } catch (final JMSException e) {
        log.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        log.debug("correlationUid: {}", correlationUid);
        log.debug("messageType: {}", actualMessageType);
        log.debug("organisationIdentification: {}", organisationIdentification);
        log.debug("deviceIdentification: {}", deviceIdentification);
        return;
    }
    log.info("Calling application service function to handle response: {} with correlationUid: {}", actualMessageType, correlationUid);
    final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
    this.handleMessage(ids, actualMessageType, resultType, resultDescription, dataObject);
    try {
        log.info("Send notification for correlationUid: {}", correlationUid);
        // Send notification indicating data is available.
        this.notificationService.sendNotification(new ApplicationDataLookupKey(organisationIdentification, this.webserviceNotificationApplicationName), new GenericNotification(notificationMessage, resultType.name(), deviceIdentification, correlationUid, String.valueOf(notificationType)));
        log.info("Notification sent for correlationUid: {}", correlationUid);
    } catch (final Exception e) {
        // Logging is enough, sending the notification will be done
        // automatically by the resend notification job
        log.warn("Delivering notification with correlationUid: {} and notification type: {} did not complete successfully.", correlationUid, notificationType, e);
    }
}
Also used : Serializable(java.io.Serializable) GenericNotification(org.opensmartgridplatform.adapter.ws.schema.shared.notification.GenericNotification) ApplicationDataLookupKey(org.opensmartgridplatform.adapter.ws.domain.entities.ApplicationDataLookupKey) NotificationType(org.opensmartgridplatform.adapter.ws.schema.core.notification.NotificationType) JMSException(javax.jms.JMSException) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) JMSException(javax.jms.JMSException)

Example 99 with ResponseMessageResultType

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

the class MicrogridsGetDataRequestMessageProcessor method handleGetDataDeviceResponse.

private void handleGetDataDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final DomainInformation domainInformation, final String messageType, final int retryCount, final boolean isScheduled) {
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    OsgpException osgpException = null;
    GetDataResponseDto dataResponse = null;
    try {
        final GetDataDeviceResponse response = (GetDataDeviceResponse) deviceResponse;
        dataResponse = response.getDataResponse();
    } catch (final Exception e) {
        LOGGER.error("Device Response Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        osgpException = new TechnicalException(ComponentType.PROTOCOL_IEC61850, "Unexpected exception while retrieving response message", e);
    }
    final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withDeviceIdentification(deviceResponse.getDeviceIdentification()).withOrganisationIdentification(deviceResponse.getOrganisationIdentification()).withCorrelationUid(deviceResponse.getCorrelationUid()).withMessageType(messageType).withDomain(domainInformation.getDomain()).withDomainVersion(domainInformation.getDomainVersion()).withMessagePriority(deviceResponse.getMessagePriority()).withScheduled(isScheduled).withRetryCount(retryCount).build();
    final ProtocolResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(messageMetadata).result(result).osgpException(osgpException).dataObject(dataResponse).build();
    responseMessageSender.send(responseMessage);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) GetDataDeviceResponse(org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.responses.GetDataDeviceResponse) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) GetDataResponseDto(org.opensmartgridplatform.dto.valueobjects.microgrids.GetDataResponseDto) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)

Example 100 with ResponseMessageResultType

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

the class CommonGetFirmwareRequestMessageProcessor method handleGetFirmwareVersionDeviceResponse.

private void handleGetFirmwareVersionDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final DomainInformation domainInformation, final String messageType, final int retryCount, final boolean isScheduled) {
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    OsgpException osgpException = null;
    List<FirmwareVersionDto> firmwareVersions = null;
    try {
        firmwareVersions = ((GetFirmwareVersionDeviceResponse) deviceResponse).getFirmwareVersions();
    } catch (final Exception e) {
        LOGGER.error("Device Response Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        osgpException = new TechnicalException(ComponentType.UNKNOWN, "Unexpected exception while retrieving response message", e);
    }
    final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withDeviceIdentification(deviceResponse.getDeviceIdentification()).withOrganisationIdentification(deviceResponse.getOrganisationIdentification()).withCorrelationUid(deviceResponse.getCorrelationUid()).withMessageType(messageType).withDomain(domainInformation.getDomain()).withDomainVersion(domainInformation.getDomainVersion()).withMessagePriority(deviceResponse.getMessagePriority()).withScheduled(isScheduled).withRetryCount(retryCount).build();
    final ProtocolResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(messageMetadata).result(result).osgpException(osgpException).dataObject((Serializable) firmwareVersions).build();
    responseMessageSender.send(responseMessage);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Serializable(java.io.Serializable) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)

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