Search in sources :

Example 1 with ResponseMessage

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

the class CommonDefaultResponseMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing common default 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;
    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();
    } 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);
        final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
        this.defaultDeviceResponseService.handleDefaultDeviceResponse(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) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException)

Example 2 with ResponseMessage

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

the class DeviceManagementService method setDeviceLifecycleStatus.

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

Example 3 with ResponseMessage

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

the class MonitoringService method handleGetPQValuesResponse.

public void handleGetPQValuesResponse(final GetPQValuesResponseDto getPQValuesResponseDto, final CorrelationIds ids, final String messageType, final ResponseMessageResultType responseMessageResultType, final OsgpException osgpException) {
    LOGGER.info("handleResponse for MessageType: {}", messageType);
    final String deviceIdentification = ids.getDeviceIdentification();
    final String organisationIdentification = ids.getOrganisationIdentification();
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    GetPQValuesResponse getPQValuesResponse = 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);
        getPQValuesResponse = this.mapper.map(getPQValuesResponseDto, GetPQValuesResponse.class);
    } catch (final Exception e) {
        LOGGER.error("Unexpected Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        exception = this.ensureOsgpException(e, "Exception occurred while getting PQ Values Response Data");
    }
    // Support for Push messages, generate correlationUid
    String actualCorrelationUid = ids.getCorrelationUid();
    if ("no-correlationUid".equals(actualCorrelationUid)) {
        actualCorrelationUid = getCorrelationId("DeviceGenerated", deviceIdentification);
    }
    final CorrelationIds actualIds = new CorrelationIds(organisationIdentification, deviceIdentification, actualCorrelationUid);
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(actualIds).withResult(result).withOsgpException(exception).withDataObject(getPQValuesResponse).build();
    this.responseMessageRouter.send(responseMessage, messageType);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) GetPQValuesResponse(org.opensmartgridplatform.domain.da.valueobjects.GetPQValuesResponse) 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) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds)

Example 4 with ResponseMessage

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

the class AdminUpdateKeyResponseMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing admin update key response message");
    String correlationUid = null;
    String messageType = null;
    String organisationIdentification = null;
    String deviceIdentification = null;
    ResponseMessage responseMessage = null;
    ResponseMessageResultType responseMessageResultType = null;
    OsgpException osgpException = null;
    try {
        correlationUid = message.getJMSCorrelationID();
        messageType = message.getJMSType();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        responseMessage = (ResponseMessage) message.getObject();
        responseMessageResultType = responseMessage.getResult();
        osgpException = responseMessage.getOsgpException();
    } 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("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);
        this.deviceManagementService.handleUpdateKeyResponse(deviceIdentification, organisationIdentification, correlationUid, messageType, responseMessageResultType, osgpException);
    } catch (final Exception e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, messageType, MessagePriorityEnum.DEFAULT.getPriority());
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException)

Example 5 with ResponseMessage

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

the class DeviceManagementService method handleUpdateKeyResponse.

public void handleUpdateKeyResponse(final String deviceIdentification, final String organisationIdentification, final String correlationUid, final String messageType, final ResponseMessageResultType deviceResult, final OsgpException exception) {
    LOGGER.info("MessageType: {}. Handle update key response for device: {} for organisation: {}", messageType, deviceIdentification, organisationIdentification);
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    OsgpException osgpException = exception;
    try {
        if (deviceResult == ResponseMessageResultType.NOT_OK || osgpException != null) {
            LOGGER.error("Device Response not ok.", osgpException);
            throw osgpException;
        }
        Ssld device = this.ssldRepository.findByDeviceIdentification(deviceIdentification);
        if (device == null) {
            // Device not found, create new device
            LOGGER.debug("Device [{}] does not exist, creating new device", deviceIdentification);
            device = new Ssld(deviceIdentification);
        }
        device.setPublicKeyPresent(true);
        this.ssldRepository.save(device);
        LOGGER.info("publicKey has been set for device: {} for organisation: {}", deviceIdentification, organisationIdentification);
    } catch (final Exception e) {
        LOGGER.error("Unexpected Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while updating key", e);
    }
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withCorrelationUid(correlationUid).withOrganisationIdentification(organisationIdentification).withDeviceIdentification(deviceIdentification).withResult(result).withOsgpException(osgpException).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) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) UnknownEntityException(org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException) PlatformException(org.opensmartgridplatform.domain.core.exceptions.PlatformException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

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