Search in sources :

Example 86 with MessageMetadata

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

the class OsgpCoreResponseSteps method protocolResponseMessage.

private ProtocolResponseMessage protocolResponseMessage(final Map<String, String> map) {
    final String deviceIdentification = map.get("device_identification");
    final Iec60870Device device = this.deviceSteps.getDevice(deviceIdentification).orElse(null);
    final DomainInfo domainInfo = DomainInfoFactory.forDeviceType(device.getDeviceType());
    final MessageMetadata deviceMessageMetadata = new MessageMetadata.Builder().withDeviceIdentification(deviceIdentification).withMessageType(MessageType.GET_LIGHT_SENSOR_STATUS.name()).withDomain(domainInfo.getDomain()).withDomainVersion(domainInfo.getDomainVersion()).build();
    return ProtocolResponseMessage.newBuilder().messageMetadata(deviceMessageMetadata).dataObject(new LightSensorStatusDto(LightSensorStatusTypeDto.valueOf(map.get("status")))).result(ResponseMessageResultType.OK).build();
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) DomainInfo(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DomainInfo) Iec60870Device(org.opensmartgridplatform.adapter.protocol.iec60870.domain.entities.Iec60870Device) LightSensorStatusDto(org.opensmartgridplatform.dto.valueobjects.LightSensorStatusDto)

Example 87 with MessageMetadata

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

the class OsgpCoreResponseSteps method connectResponseMessage.

private ProtocolResponseMessage connectResponseMessage(final Map<String, String> map) {
    final String deviceIdentification = map.get("device_identification");
    final Iec60870Device device = this.deviceSteps.getDevice(deviceIdentification).orElse(null);
    final DomainInfo domainInfo = DomainInfoFactory.forDeviceType(device.getDeviceType());
    final MessageMetadata deviceMessageMetadata = new MessageMetadata.Builder().withDeviceIdentification(deviceIdentification).withMessageType(MessageType.CONNECT.name()).withDomain(domainInfo.getDomain()).withDomainVersion(domainInfo.getDomainVersion()).build();
    return ProtocolResponseMessage.newBuilder().messageMetadata(deviceMessageMetadata).result(ResponseMessageResultType.OK).build();
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) DomainInfo(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DomainInfo) Iec60870Device(org.opensmartgridplatform.adapter.protocol.iec60870.domain.entities.Iec60870Device)

Example 88 with MessageMetadata

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

the class AbstractMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) {
    LOGGER.info("Processing message.");
    MessageMetadata messageMetadata = null;
    try {
        messageMetadata = MessageMetadata.fromMessage(message);
        final RequestMetadata requestMetadata = RequestMetadata.newBuilder().messageMetadata(messageMetadata).build();
        final ClientConnection deviceConnection = this.iec60870DeviceConnectionService.getConnection(requestMetadata);
        this.process(deviceConnection, requestMetadata);
    } catch (final ProtocolAdapterException e) {
        this.handleError(messageMetadata, e);
    } catch (final Exception e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
    }
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ClientConnection(org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.ClientConnection) ProtocolAdapterException(org.opensmartgridplatform.shared.exceptionhandling.ProtocolAdapterException) ProtocolAdapterException(org.opensmartgridplatform.shared.exceptionhandling.ProtocolAdapterException) JMSException(javax.jms.JMSException) RequestMetadata(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.RequestMetadata)

Example 89 with MessageMetadata

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

the class DeviceManagementService method handleSetSchedule.

public void handleSetSchedule(final String deviceUid) throws TechnicalException {
    final List<PendingSetScheduleRequest> pendingSetScheduleRequestList = this.pendingSetScheduleRequestService.getAllByDeviceUidNotExpired(deviceUid);
    if (pendingSetScheduleRequestList.isEmpty()) {
        // schedule with astronomical offsets
        return;
    }
    if (pendingSetScheduleRequestList.size() > 1) {
        throw new TechnicalException(String.format("Currently there are %d pending set schedule requests for device %s. Only one is allowed.", pendingSetScheduleRequestList.size(), deviceUid));
    }
    final PendingSetScheduleRequest pendingSetScheduleRequest = pendingSetScheduleRequestList.get(0);
    final ScheduleMessageDataContainerDto dto = pendingSetScheduleRequest.getScheduleMessageDataContainerDto();
    ScheduleMessageDataContainerDto.Builder builder = new ScheduleMessageDataContainerDto.Builder(dto.getSchedule());
    builder = builder.withScheduleMessageType(ScheduleMessageTypeDto.SET_SCHEDULE);
    final ScheduleMessageDataContainerDto scheduleMessageDataContainer = builder.build();
    final DeviceRequest deviceRequest = pendingSetScheduleRequest.getDeviceRequest();
    final MessageMetadata messageMetadata = this.getMessageMetadataFromDeviceRequest(deviceRequest);
    final SetScheduleDeviceRequest newDeviceRequest = new SetScheduleDeviceRequest(DeviceRequest.newBuilder().messageMetaData(messageMetadata), scheduleMessageDataContainer, RelayTypeDto.LIGHT);
    this.deviceService.setSchedule(newDeviceRequest);
    this.pendingSetScheduleRequestService.remove(pendingSetScheduleRequest);
}
Also used : PendingSetScheduleRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.PendingSetScheduleRequest) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ScheduleMessageDataContainerDto(org.opensmartgridplatform.dto.valueobjects.ScheduleMessageDataContainerDto) SetScheduleDeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest) SetScheduleDeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest) DeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceRequest)

Example 90 with MessageMetadata

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

the class CommonSetEventNotificationsRequestMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) {
    LOGGER.debug("Processing common set event notifications request message");
    MessageMetadata messageMetadata;
    EventNotificationMessageDataContainerDto eventNotificationMessageDataContainer;
    try {
        messageMetadata = MessageMetadata.fromMessage(message);
        eventNotificationMessageDataContainer = (EventNotificationMessageDataContainerDto) 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 SetEventNotificationsDeviceRequest deviceRequest = new SetEventNotificationsDeviceRequest(DeviceRequest.newBuilder().messageMetaData(messageMetadata), eventNotificationMessageDataContainer);
        this.deviceService.setEventNotifications(deviceRequest);
    } catch (final RuntimeException e) {
        this.handleError(e, messageMetadata);
    }
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) SetEventNotificationsDeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetEventNotificationsDeviceRequest) JMSException(javax.jms.JMSException) EventNotificationMessageDataContainerDto(org.opensmartgridplatform.dto.valueobjects.EventNotificationMessageDataContainerDto)

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