Search in sources :

Example 36 with MessageMetadata

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

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

the class DaRtuDeviceRequestMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing distribution automation request message");
    final MessageMetadata messageMetadata;
    final Serializable request;
    try {
        messageMetadata = MessageMetadata.fromMessage(message);
        request = message.getObject();
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        return;
    }
    final RequestMessageData requestMessageData = RequestMessageData.newBuilder().messageMetadata(messageMetadata).build();
    this.printDomainInfo(requestMessageData);
    final Iec61850DeviceResponseHandler iec61850DeviceResponseHandler = this.createIec61850DeviceResponseHandler(requestMessageData, message);
    final DeviceRequest.Builder deviceRequestBuilder = DeviceRequest.newBuilder().messageMetaData(messageMetadata);
    this.deviceService.getData(new DaDeviceRequest(deviceRequestBuilder, request), iec61850DeviceResponseHandler, this);
}
Also used : Iec61850DeviceResponseHandler(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.Iec61850DeviceResponseHandler) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Serializable(java.io.Serializable) DaDeviceRequest(org.opensmartgridplatform.adapter.protocol.iec61850.device.da.rtu.DaDeviceRequest) JMSException(javax.jms.JMSException) DeviceRequest(org.opensmartgridplatform.adapter.protocol.iec61850.device.DeviceRequest) DaDeviceRequest(org.opensmartgridplatform.adapter.protocol.iec61850.device.da.rtu.DaDeviceRequest) RequestMessageData(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.RequestMessageData)

Example 38 with MessageMetadata

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

the class PublicLightingResumeScheduleRequestMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) {
    LOGGER.debug("Processing public lighting resume schedule request message");
    MessageMetadata messageMetadata;
    ResumeScheduleMessageDataContainerDto resumeScheduleMessageDataContainer;
    try {
        messageMetadata = MessageMetadata.fromMessage(message);
        resumeScheduleMessageDataContainer = (ResumeScheduleMessageDataContainerDto) message.getObject();
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        return;
    }
    try {
        this.printDomainInfo(messageMetadata.getMessageType(), messageMetadata.getDomain(), messageMetadata.getDomainVersion());
        final ResumeScheduleDeviceRequest deviceRequest = new ResumeScheduleDeviceRequest(DeviceRequest.newBuilder().messageMetaData(messageMetadata), resumeScheduleMessageDataContainer);
        this.deviceService.resumeSchedule(deviceRequest);
    } catch (final RuntimeException e) {
        this.handleError(e, messageMetadata);
    }
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) JMSException(javax.jms.JMSException) ResumeScheduleMessageDataContainerDto(org.opensmartgridplatform.dto.valueobjects.ResumeScheduleMessageDataContainerDto) ResumeScheduleDeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.ResumeScheduleDeviceRequest)

Example 39 with MessageMetadata

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

the class PublicLightingSetScheduleRequestMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) {
    LOGGER.debug("Processing public lighting set schedule request message");
    final MessageMetadata messageMetadata;
    final ScheduleDto schedule;
    try {
        messageMetadata = MessageMetadata.fromMessage(message);
        schedule = (ScheduleDto) message.getObject();
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        return;
    }
    try {
        this.pendingSetScheduleRequestService.removeExpiredPendingSetScheduleRequestRecords(messageMetadata.getDeviceIdentification());
        final List<PendingSetScheduleRequest> pendingSetScheduleRequestList = this.pendingSetScheduleRequestService.getAllByDeviceIdentificationNotExpired(messageMetadata.getDeviceIdentification());
        if (!pendingSetScheduleRequestList.isEmpty()) {
            throw new FunctionalException(FunctionalExceptionType.SET_SCHEDULE_WITH_ASTRONOMICAL_OFFSETS_IN_PROGRESS, ComponentType.PROTOCOL_OSLP, new Throwable(String.format("A set schedule with astronomical offsets is already in progress for device %s", messageMetadata.getDeviceIdentification())));
        }
        ScheduleMessageDataContainerDto.Builder builder = new ScheduleMessageDataContainerDto.Builder(schedule);
        if (schedule.getAstronomicalSunriseOffset() != null || schedule.getAstronomicalSunsetOffset() != null) {
            LOGGER.info("Set a schedule for a device with astronomical offsets");
            builder = builder.withScheduleMessageType(ScheduleMessageTypeDto.RETRIEVE_CONFIGURATION);
        }
        final ScheduleMessageDataContainerDto scheduleMessageDataContainer = builder.build();
        this.printDomainInfo(messageMetadata.getMessageType(), messageMetadata.getDomain(), messageMetadata.getDomainVersion());
        final SetScheduleDeviceRequest deviceRequest = new SetScheduleDeviceRequest(DeviceRequest.newBuilder().messageMetaData(messageMetadata), scheduleMessageDataContainer, RelayTypeDto.LIGHT);
        this.deviceService.setSchedule(deviceRequest);
    } catch (final RuntimeException e) {
        this.handleError(e, messageMetadata);
    } catch (final FunctionalException e) {
        this.handleFunctionalException(e, messageMetadata);
    }
}
Also used : PendingSetScheduleRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.PendingSetScheduleRequest) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ScheduleMessageDataContainerDto(org.opensmartgridplatform.dto.valueobjects.ScheduleMessageDataContainerDto) SetScheduleDeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest) JMSException(javax.jms.JMSException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ScheduleDto(org.opensmartgridplatform.dto.valueobjects.ScheduleDto)

Example 40 with MessageMetadata

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

the class TariffSwitchingGetStatusRequestMessageProcessor method handleGetStatusDeviceResponse.

private void handleGetStatusDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final String domain, final String domainVersion, final String messageType, final int retryCount) {
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    OsgpException osgpException = null;
    DeviceStatusDto status = null;
    try {
        final GetStatusDeviceResponse response = (GetStatusDeviceResponse) deviceResponse;
        status = response.getDeviceStatus();
    } catch (final Exception e) {
        LOGGER.error("Device Response Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while getting device status", e);
    }
    final MessageMetadata messageMetadata = MessageMetadataFactory.from(deviceResponse, messageType).builder().withDomain(domain).withDomainVersion(domainVersion).withRetryCount(retryCount).build();
    final ProtocolResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(messageMetadata).result(result).osgpException(osgpException).dataObject(status).build();
    responseMessageSender.send(responseMessage);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) GetStatusDeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetStatusDeviceResponse) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) DeviceStatusDto(org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) IOException(java.io.IOException) JMSException(javax.jms.JMSException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)

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