Search in sources :

Example 81 with ResponseMessage

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

the class DeviceManagementService method updateDeviceCdmaSettings.

public void updateDeviceCdmaSettings(final String organisationIdentification, final String deviceIdentification, final String correlationUid, final CdmaSettings cdmaSettings) throws FunctionalException {
    LOGGER.debug("UpdateDeviceCdmaSettings called with organisation {}, deviceIdentification {}, and {}", organisationIdentification, deviceIdentification, cdmaSettings);
    this.findOrganisation(organisationIdentification);
    this.transactionalDeviceService.updateDeviceCdmaSettings(deviceIdentification, cdmaSettings);
    final ResponseMessageResultType result = ResponseMessageResultType.OK;
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withCorrelationUid(correlationUid).withOrganisationIdentification(organisationIdentification).withDeviceIdentification(deviceIdentification).withResult(result).withMessageType(MessageType.UPDATE_DEVICE_CDMA_SETTINGS.name()).build();
    this.webServiceResponseMessageSender.send(responseMessage);
}
Also used : ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)

Example 82 with ResponseMessage

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

the class FirmwareManagementService method handleGetFirmwareVersionResponse.

public void handleGetFirmwareVersionResponse(final List<FirmwareVersionDto> firmwareVersionsDto, final CorrelationIds ids, final String messageType, final int messagePriority, final ResponseMessageResultType deviceResult, final OsgpException exception) {
    LOGGER.info("handleResponse for MessageType: {}", messageType);
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    OsgpException osgpException = exception;
    try {
        if (deviceResult == ResponseMessageResultType.NOT_OK || osgpException != null) {
            LOGGER.error("Device Response not ok.", osgpException);
            throw osgpException;
        }
    } catch (final Exception e) {
        LOGGER.error("Unexpected Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while getting device firmware version", e);
    }
    final List<FirmwareVersion> firmwareVersions = this.domainCoreMapper.mapAsList(firmwareVersionsDto, FirmwareVersion.class);
    this.checkFirmwareHistory(ids.getDeviceIdentification(), firmwareVersions);
    final boolean hasPendingFirmwareUpdate = this.checkSsldPendingFirmwareUpdate(ids, firmwareVersions);
    if (!hasPendingFirmwareUpdate) {
        final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withResult(result).withOsgpException(osgpException).withDataObject((Serializable) firmwareVersions).withMessagePriority(messagePriority).withMessageType(MessageType.GET_FIRMWARE_VERSION.name()).build();
        this.webServiceResponseMessageSender.send(responseMessage);
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) Serializable(java.io.Serializable) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)

Example 83 with ResponseMessage

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

the class CommonGetFirmwareResponseMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing common get firmware version response message");
    String correlationUid = null;
    String messageType = null;
    int messagePriority = MessagePriorityEnum.DEFAULT.getPriority();
    String organisationIdentification = null;
    String deviceIdentification = null;
    ResponseMessage responseMessage;
    ResponseMessageResultType responseMessageResultType = null;
    OsgpException osgpException = null;
    Object dataObject;
    try {
        correlationUid = message.getJMSCorrelationID();
        messageType = message.getJMSType();
        messagePriority = message.getJMSPriority();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        responseMessage = (ResponseMessage) message.getObject();
        responseMessageResultType = responseMessage.getResult();
        osgpException = responseMessage.getOsgpException();
        dataObject = responseMessage.getDataObject();
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        LOGGER.debug("correlationUid: {}", correlationUid);
        LOGGER.debug("messageType: {}", messageType);
        LOGGER.debug("messagePriority: {}", messagePriority);
        LOGGER.debug("organisationIdentification: {}", organisationIdentification);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("responseMessageResultType: {}", responseMessageResultType);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("osgpException", osgpException);
        return;
    }
    try {
        LOGGER.info("Calling application service function to handle response: {}", messageType);
        @SuppressWarnings("unchecked") final List<FirmwareVersionDto> firmwareVersions = (List<FirmwareVersionDto>) dataObject;
        final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
        this.firmwareManagementService.handleGetFirmwareVersionResponse(firmwareVersions, ids, messageType, messagePriority, responseMessageResultType, osgpException);
    } catch (final Exception e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, messageType, messagePriority);
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException) List(java.util.List) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds)

Example 84 with ResponseMessage

use of org.opensmartgridplatform.shared.infra.jms.ResponseMessage 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 85 with ResponseMessage

use of org.opensmartgridplatform.shared.infra.jms.ResponseMessage 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_CORE, "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 ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withResult(result).withOsgpException(osgpException).withMessagePriority(messagePriority).withMessageType(messageType).build();
    this.webServiceResponseMessageSender.send(responseMessage);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)

Aggregations

ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)144 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)78 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)66 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)33 JMSException (javax.jms.JMSException)29 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)23 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)20 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)20 ConstraintViolationException (javax.validation.ConstraintViolationException)19 Test (org.junit.jupiter.api.Test)19 CorrelationIds (org.opensmartgridplatform.shared.infra.jms.CorrelationIds)18 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)16 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)12 ObjectMessage (javax.jms.ObjectMessage)9 ProtocolResponseMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)8 Transactional (org.springframework.transaction.annotation.Transactional)5 ArrayList (java.util.ArrayList)4 Device (org.opensmartgridplatform.domain.core.entities.Device)4 UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)4 FirmwareVersion (org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)4