Search in sources :

Example 21 with RequestMessage

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

the class DlmsChannelHandlerServer method processPushedSms.

private void processPushedSms(final DlmsPushNotification message, final String correlationId, final String deviceIdentification, final String ipAddress) {
    this.logMessage(message);
    final PushNotificationSmsDto pushNotificationSms = new PushNotificationSmsDto(deviceIdentification, ipAddress);
    final RequestMessage requestMessage = new RequestMessage(correlationId, "no-organisation", deviceIdentification, ipAddress, null, null, pushNotificationSms);
    log.info("Sending push notification sms wakeup to GXF with correlation ID: {}", correlationId);
    this.osgpRequestMessageSender.send(requestMessage, MessageType.PUSH_NOTIFICATION_SMS.name(), null);
}
Also used : RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) PushNotificationSmsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PushNotificationSmsDto)

Example 22 with RequestMessage

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

the class DomainRequestMessageSender method sendMessage.

private static void sendMessage(final RequestMessage requestMessage, final String messageType, final JmsTemplate jmsTemplate) {
    LOGGER.info("Sending request message to incoming domain requests queue, messageType: {} organisationIdentification: {} deviceIdentification: {}", messageType, requestMessage.getOrganisationIdentification(), requestMessage.getDeviceIdentification());
    jmsTemplate.send(new MessageCreator() {

        @Override
        public Message createMessage(final Session session) throws JMSException {
            final ObjectMessage objectMessage = session.createObjectMessage(requestMessage);
            objectMessage.setJMSCorrelationID(requestMessage.getCorrelationUid());
            objectMessage.setJMSType(messageType);
            objectMessage.setStringProperty(Constants.ORGANISATION_IDENTIFICATION, requestMessage.getOrganisationIdentification());
            objectMessage.setStringProperty(Constants.DEVICE_IDENTIFICATION, requestMessage.getDeviceIdentification());
            return objectMessage;
        }
    });
}
Also used : ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) MessageCreator(org.springframework.jms.core.MessageCreator) Session(javax.jms.Session)

Example 23 with RequestMessage

use of org.opensmartgridplatform.shared.infra.jms.RequestMessage 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)

Example 24 with RequestMessage

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

the class PushNotificationSmsMessageProcessor 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());
    final RequestMessage requestMessage = (RequestMessage) message.getObject();
    final Object dataObject = requestMessage.getRequest();
    try {
        final Device device = this.getDevice(metadata.getDeviceIdentification());
        final PushNotificationSmsDto pushNotificationSms = (PushNotificationSmsDto) dataObject;
        this.storeSmsAsEvent(pushNotificationSms);
        if (pushNotificationSms.getIpAddress() != null && !"".equals(pushNotificationSms.getIpAddress())) {
            LOGGER.info("Updating device {} IP address from {} to {}", metadata.getDeviceIdentification(), requestMessage.getIpAddress(), pushNotificationSms.getIpAddress());
            // Convert the IP address from String to InetAddress.
            final InetAddress address = InetAddress.getByName(pushNotificationSms.getIpAddress());
            device.updateRegistrationData(address, device.getDeviceType());
            device.updateConnectionDetailsToSuccess();
            this.deviceRepository.save(device);
        } else {
            LOGGER.warn("Sms notification request for device = {} has no new IP address. Discard request.", metadata.getDeviceIdentification());
        }
    } catch (final UnknownHostException | FunctionalException e) {
        final String errorMessage = String.format("%s occurred, reason: %s", e.getClass().getName(), e.getMessage());
        LOGGER.error(errorMessage, e);
        throw new JMSException(errorMessage);
    }
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) UnknownHostException(java.net.UnknownHostException) Device(org.opensmartgridplatform.domain.core.entities.Device) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) JMSException(javax.jms.JMSException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) InetAddress(java.net.InetAddress) PushNotificationSmsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PushNotificationSmsDto)

Example 25 with RequestMessage

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

the class PushNotificationAlarmMessageProcessorTest method init.

@BeforeEach
public void init() throws JMSException, UnknownEntityException {
    final String correlationUid = "corr-uid-1";
    final String organisationIdentification = "test-org";
    final String ipAddress = "127.0.0.1";
    final RequestMessage requestMessage = new RequestMessage(correlationUid, organisationIdentification, DEVICE_IDENTIFICATION, ipAddress, null, null, this.pushNotificationAlarm);
    this.message = new ObjectMessageBuilder().withCorrelationUid(correlationUid).withMessageType(MessageType.PUSH_NOTIFICATION_ALARM.name()).withDeviceIdentification(DEVICE_IDENTIFICATION).withObject(requestMessage).build();
    this.device = new Device(DEVICE_IDENTIFICATION);
    when(this.deviceRepository.findByDeviceIdentification(DEVICE_IDENTIFICATION)).thenReturn(this.device);
    when(this.deviceRepository.save(this.device)).thenAnswer((Answer<Void>) invocationOnMock -> null);
    doNothing().when(this.eventNotificationMessageService).handleEvent(any(String.class), any(Date.class), any(EventType.class), any(String.class), any(Integer.class));
    when(this.deviceAuthorizationRepository.findByDeviceAndFunctionGroup(this.device, DeviceFunctionGroup.OWNER)).thenReturn(Collections.singletonList(this.deviceAuthorization));
    when(this.deviceAuthorization.getOrganisation()).thenReturn(this.organisation);
    when(this.organisation.getOrganisationIdentification()).thenReturn(requestMessage.getOrganisationIdentification());
    when(this.domainInfoRepository.findAll()).thenReturn(Collections.singletonList(this.domainInfo));
    when(this.domainInfo.getDomain()).thenReturn("SMART_METERING");
    when(this.domainInfo.getDomainVersion()).thenReturn("1.0");
    doNothing().when(this.domainRequestService).send(any(RequestMessage.class), any(String.class), any(DomainInfo.class));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Strictness(org.mockito.quality.Strictness) BeforeEach(org.junit.jupiter.api.BeforeEach) DeviceAuthorizationRepository(org.opensmartgridplatform.domain.core.repositories.DeviceAuthorizationRepository) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) DeviceAuthorization(org.opensmartgridplatform.domain.core.entities.DeviceAuthorization) Date(java.util.Date) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EventType(org.opensmartgridplatform.domain.core.valueobjects.EventType) ObjectMessage(javax.jms.ObjectMessage) MessageType(org.opensmartgridplatform.shared.infra.jms.MessageType) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) Answer(org.mockito.stubbing.Answer) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) InjectMocks(org.mockito.InjectMocks) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) DomainRequestService(org.opensmartgridplatform.core.domain.model.domain.DomainRequestService) DomainInfo(org.opensmartgridplatform.domain.core.entities.DomainInfo) DeviceRepository(org.opensmartgridplatform.domain.core.repositories.DeviceRepository) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) JMSException(javax.jms.JMSException) EventNotificationMessageService(org.opensmartgridplatform.core.application.services.EventNotificationMessageService) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) UnknownEntityException(org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException) PushNotificationAlarmDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PushNotificationAlarmDto) Device(org.opensmartgridplatform.domain.core.entities.Device) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) DomainInfoRepository(org.opensmartgridplatform.domain.core.repositories.DomainInfoRepository) DeviceFunctionGroup(org.opensmartgridplatform.domain.core.valueobjects.DeviceFunctionGroup) Collections(java.util.Collections) EventType(org.opensmartgridplatform.domain.core.valueobjects.EventType) Device(org.opensmartgridplatform.domain.core.entities.Device) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) DomainInfo(org.opensmartgridplatform.domain.core.entities.DomainInfo) Date(java.util.Date) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

RequestMessage (org.opensmartgridplatform.shared.infra.jms.RequestMessage)79 Device (org.opensmartgridplatform.domain.core.entities.Device)33 JMSException (javax.jms.JMSException)18 ObjectMessage (javax.jms.ObjectMessage)13 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)11 Test (org.junit.jupiter.api.Test)9 DomainInfo (org.opensmartgridplatform.domain.core.entities.DomainInfo)7 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)6 Message (javax.jms.Message)5 Session (javax.jms.Session)5 RtuDevice (org.opensmartgridplatform.domain.core.entities.RtuDevice)5 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)5 UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)4 MessageCreator (org.springframework.jms.core.MessageCreator)4 Transactional (org.springframework.transaction.annotation.Transactional)4 BeforeEach (org.junit.jupiter.api.BeforeEach)3 CdmaDevice (org.opensmartgridplatform.domain.core.valueobjects.CdmaDevice)3 EventNotificationDto (org.opensmartgridplatform.dto.valueobjects.EventNotificationDto)3 SystemEventDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SystemEventDto)3 ObjectMessageBuilder (org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder)3