Search in sources :

Example 31 with MessageMetadata

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

the class GetFirmwareFileResponseMessageProcessor method handleMessage.

@Override
protected Serializable handleMessage(final DlmsConnectionManager conn, final DlmsDevice device, final Serializable response) throws OsgpException {
    if (!(response instanceof ResponseMessage)) {
        throw new ProtocolAdapterException("Invalid response type, expected ResponseMessage object.");
    }
    final ResponseMessage responseMessage = (ResponseMessage) response;
    if (ResponseMessageResultType.OK.equals(responseMessage.getResult())) {
        final FirmwareFileDto firmwareFileDto = (FirmwareFileDto) responseMessage.getDataObject();
        final MessageMetadata messageMetadata = this.messageMetadataFromResponseMessage(responseMessage);
        return this.firmwareService.updateFirmware(conn, device, firmwareFileDto, messageMetadata);
    } else {
        throw new ProtocolAdapterException("Get Firmware File failed.", responseMessage.getOsgpException());
    }
}
Also used : FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 32 with MessageMetadata

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

the class DomainHelperServiceTest method setsIpAddressFromMessageMetadataIfIpAddressIsStatic.

@Test
void setsIpAddressFromMessageMetadataIfIpAddressIsStatic() throws Exception {
    final String ipAddress = IP_ADDRESS;
    final DlmsDevice dlmsDevice = new DlmsDeviceBuilder().withIpAddress(null).withIpAddressStatic(true).build();
    final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withIpAddress(ipAddress).build();
    this.domainHelperService.setIpAddressFromMessageMetadataOrSessionProvider(dlmsDevice, messageMetadata);
    assertThat(dlmsDevice.getIpAddress()).isEqualTo(ipAddress);
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) Test(org.junit.jupiter.api.Test)

Example 33 with MessageMetadata

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

the class DlmsChannelHandlerServer method processPushedAlarm.

private void processPushedAlarm(final DlmsPushNotification message, final String correlationId, final String deviceIdentification, final String ipAddress) {
    this.logMessage(message);
    final PushNotificationAlarmDto pushNotificationAlarm = new PushNotificationAlarmDto(deviceIdentification, message.getAlarms(), message.toByteArray());
    final RequestMessage requestMessage = new RequestMessage(correlationId, "no-organisation", deviceIdentification, ipAddress, null, null, pushNotificationAlarm);
    final MessageMetadata messageMetadata = new Builder().withMessagePriority(MessagePriorityEnum.HIGH.getPriority()).build();
    log.info("Sending push notification alarm to GXF with correlation ID: {}", correlationId);
    this.osgpRequestMessageSender.send(requestMessage, MessageType.PUSH_NOTIFICATION_ALARM.name(), messageMetadata);
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) PushNotificationAlarmDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PushNotificationAlarmDto) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) Builder(org.opensmartgridplatform.shared.infra.jms.MessageMetadata.Builder)

Example 34 with MessageMetadata

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

the class DeviceRegistrationCompletedMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    final MessageMetadata metadata = MessageMetadata.fromMessage(message);
    LOGGER.info("Received message of messageType: {} organisationIdentification: {} deviceIdentification: {}", this.messageType, metadata.getOrganisationIdentification(), metadata.getDeviceIdentification());
    this.deviceRegistrationMessageService.sendRequestMessageToDomainCore(metadata.getDeviceIdentification(), metadata.getOrganisationIdentification(), metadata.getCorrelationUid(), MessageType.DEVICE_REGISTRATION_COMPLETED);
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata)

Example 35 with MessageMetadata

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

the class GetFirmwareFileMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    MessageMetadata metadata = null;
    Device device = null;
    String firmwareFileIdentification = StringUtils.EMPTY;
    try {
        metadata = MessageMetadata.fromMessage(message);
        LOGGER.info("[{}] - Received message of messageType: {}, organisationIdentification: {}, deviceIdentification: {}", metadata.getCorrelationUid(), metadata.getMessageType(), metadata.getOrganisationIdentification(), metadata.getDeviceIdentification());
        device = this.deviceRepository.findByDeviceIdentification(metadata.getDeviceIdentification());
        final RequestMessage requestMessage = (RequestMessage) message.getObject();
        final UpdateFirmwareRequestDto updateFirmwareRequestDto = (UpdateFirmwareRequestDto) requestMessage.getRequest();
        firmwareFileIdentification = updateFirmwareRequestDto.getFirmwareIdentification();
        final FirmwareFile firmwareFile = this.firmwareFileRepository.findByIdentificationOnly(firmwareFileIdentification);
        final FirmwareFileDto firmwareFileDto = new FirmwareFileDto(firmwareFileIdentification, updateFirmwareRequestDto.getDeviceIdentification(), firmwareFile.getFile(), firmwareFile.getImageIdentifier());
        this.sendSuccesResponse(metadata, device.getProtocolInfo(), firmwareFileDto);
    } catch (final Exception e) {
        LOGGER.error("Exception while retrieving firmware file: {}", firmwareFileIdentification);
        final OsgpException osgpException = new OsgpException(ComponentType.OSGP_CORE, "Exception while retrieving firmware file.", e);
        this.sendFailureResponse(metadata, device.getProtocolInfo(), osgpException);
    }
}
Also used : UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Device(org.opensmartgridplatform.domain.core.entities.Device) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) FirmwareFile(org.opensmartgridplatform.domain.core.entities.FirmwareFile) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException)

Aggregations

MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)147 JMSException (javax.jms.JMSException)65 Device (org.opensmartgridplatform.domain.core.entities.Device)29 Test (org.junit.jupiter.api.Test)25 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)23 ProtocolResponseMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)22 DeviceRequest (org.opensmartgridplatform.adapter.protocol.iec61850.device.DeviceRequest)20 RequestMessageData (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.RequestMessageData)20 Iec61850DeviceResponseHandler (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.Iec61850DeviceResponseHandler)20 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)19 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)18 CommonRequestMessage (org.opensmartgridplatform.adapter.ws.core.infra.jms.CommonRequestMessage)15 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)14 RequestMessage (org.opensmartgridplatform.shared.infra.jms.RequestMessage)14 ObjectMessage (javax.jms.ObjectMessage)13 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)13 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)13 Serializable (java.io.Serializable)12 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)12 UpdateFirmwareRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto)10