Search in sources :

Example 11 with ProtocolInfo

use of org.opensmartgridplatform.domain.core.entities.ProtocolInfo in project open-smart-grid-platform by OSGP.

the class EventServiceTest method assertEventType.

private void assertEventType(final int eventCode, final String protocol, final EventTypeDto expectedEventTypeDto) throws FunctionalException {
    final ProtocolInfo protocolInfo = mock(ProtocolInfo.class);
    when(protocolInfo.getProtocol()).thenReturn(protocol);
    when(this.smartMeter.getProtocolInfo()).thenReturn(protocolInfo);
    final EventDto event = new EventDto(new DateTime(), eventCode, 2, "STANDARD_EVENT_LOG");
    final ArrayList<EventDto> events = new ArrayList<>();
    events.add(event);
    final EventMessageDataResponseDto responseDto = new EventMessageDataResponseDto(events);
    this.eventService.enrichEvents(this.deviceMessageMetadata, responseDto);
    assertThat(responseDto.getEvents().size()).isOne();
    final EventDto eventDto = responseDto.getEvents().get(0);
    assertThat(eventDto.getEventTypeDto()).isEqualTo(expectedEventTypeDto);
    assertThat(eventDto.getEventCode()).isEqualTo(eventCode);
    final List<EventDetailDto> eventDetails = eventDto.getEventDetails();
    assertThat(eventDetails.size()).isZero();
}
Also used : EventDetailDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDetailDto) EventDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto) ArrayList(java.util.ArrayList) ProtocolInfo(org.opensmartgridplatform.domain.core.entities.ProtocolInfo) EventMessageDataResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventMessageDataResponseDto) DateTime(org.joda.time.DateTime)

Example 12 with ProtocolInfo

use of org.opensmartgridplatform.domain.core.entities.ProtocolInfo in project open-smart-grid-platform by OSGP.

the class ProtocolResponseMessageJmsTemplateFactory method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws SSLException {
    for (final ProtocolInfo protocolInfo : this.protocolInfos) {
        LOGGER.info("Initializing ProtocolResponseMessageJmsTemplate {}", protocolInfo.getKey());
        this.init(protocolInfo);
    }
}
Also used : ProtocolInfo(org.opensmartgridplatform.domain.core.entities.ProtocolInfo)

Example 13 with ProtocolInfo

use of org.opensmartgridplatform.domain.core.entities.ProtocolInfo in project open-smart-grid-platform by OSGP.

the class ProtocolRequestMessageListenerContainerFactory method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws SSLException {
    for (final ProtocolInfo protocolInfo : this.protocolInfos) {
        LOGGER.info("Initializing ProtocolRequestMessageListenerContainer {}", protocolInfo.getKey());
        this.init(protocolInfo);
    }
}
Also used : ProtocolInfo(org.opensmartgridplatform.domain.core.entities.ProtocolInfo)

Example 14 with ProtocolInfo

use of org.opensmartgridplatform.domain.core.entities.ProtocolInfo in project open-smart-grid-platform by OSGP.

the class DomainResponseMessageListener method onMessage.

@Override
public void onMessage(final Message message) {
    try {
        final ObjectMessage objectMessage = (ObjectMessage) message;
        final String messageType = objectMessage.getJMSType();
        final Object dataObject = objectMessage.getObject();
        LOGGER.info("Received domain incoming response message of type [{}]", messageType);
        ProtocolInfo protocolInfo = null;
        for (final ProtocolInfo pi : this.protocolInfos) {
            if ("OSLP".equals(pi.getProtocol()) && "1.0".equals(pi.getProtocolVersion())) {
                protocolInfo = pi;
            }
        }
        if (protocolInfo == null) {
            throw new OsgpCoreException("No protocol info!");
        }
        if ("REGISTER_DEVICE".equals(messageType)) {
            final ResponseMessage responseMessage = (ResponseMessage) dataObject;
            this.protocolResponseService.send(responseMessage, messageType, protocolInfo, MessageMetadata.fromMessage(message));
        } else {
            throw new OsgpCoreException("Unknown JMSType: " + messageType);
        }
    } catch (final JMSException e) {
        LOGGER.error("Exception: {}, StackTrace: {}", e.getMessage(), e.getStackTrace(), e);
    } catch (final OsgpCoreException e) {
        LOGGER.error("OsgpCoreException", e);
    }
}
Also used : OsgpCoreException(org.opensmartgridplatform.domain.core.exceptions.OsgpCoreException) ObjectMessage(javax.jms.ObjectMessage) ProtocolInfo(org.opensmartgridplatform.domain.core.entities.ProtocolInfo) JMSException(javax.jms.JMSException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage)

Example 15 with ProtocolInfo

use of org.opensmartgridplatform.domain.core.entities.ProtocolInfo in project open-smart-grid-platform by OSGP.

the class DeviceRequestMessageService method processMessage.

public void processMessage(final ProtocolRequestMessage message) throws FunctionalException {
    try {
        final Device device = this.domainHelperService.findDevice(message.getDeviceIdentification());
        final ProtocolInfo protocolInfo;
        if (device.getGatewayDevice() == null) {
            protocolInfo = device.getProtocolInfo();
        } else {
            protocolInfo = device.getGatewayDevice().getProtocolInfo();
        }
        if (protocolInfo == null || !this.protocolRequestService.isSupported(protocolInfo)) {
            if (protocolInfo == null) {
                LOGGER.error("Protocol unknown for device [{}]", device.getDeviceIdentification());
            } else {
                LOGGER.error("Protocol [{}] with version [{}] unknown for device [{}], needs to be reloaded.", protocolInfo.getProtocol(), protocolInfo.getProtocolVersion(), device.getDeviceIdentification());
            }
            throw new FunctionalException(FunctionalExceptionType.PROTOCOL_UNKNOWN_FOR_DEVICE, ComponentType.OSGP_CORE);
        }
        LOGGER.info("Device is using protocol [{}] with version [{}]", protocolInfo.getProtocol(), protocolInfo.getProtocolVersion());
        final Organisation organisation = this.domainHelperService.findOrganisation(message.getOrganisationIdentification());
        this.domainHelperService.isAllowed(organisation, device, Enum.valueOf(DeviceFunction.class, message.getMessageType()));
        this.protocolRequestService.send(message, protocolInfo);
    } catch (final FunctionalException e) {
        this.domainResponseMessageSender.send(message, e);
        throw e;
    }
}
Also used : Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) DeviceFunction(org.opensmartgridplatform.domain.core.valueobjects.DeviceFunction) Device(org.opensmartgridplatform.domain.core.entities.Device) ProtocolInfo(org.opensmartgridplatform.domain.core.entities.ProtocolInfo) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

Aggregations

ProtocolInfo (org.opensmartgridplatform.domain.core.entities.ProtocolInfo)15 Device (org.opensmartgridplatform.domain.core.entities.Device)4 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)3 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)3 ArrayList (java.util.ArrayList)2 DateTime (org.joda.time.DateTime)2 Test (org.junit.jupiter.api.Test)2 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)2 DlmsDeviceBuilder (org.opensmartgridplatform.cucumber.platform.smartmetering.builders.entities.DlmsDeviceBuilder)2 SmartMeter (org.opensmartgridplatform.domain.core.entities.SmartMeter)2 EventDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto)2 EventMessageDataResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventMessageDataResponseDto)2 InetAddress (java.net.InetAddress)1 Date (java.util.Date)1 JMSException (javax.jms.JMSException)1 ObjectMessage (javax.jms.ObjectMessage)1 EntityNotFoundException (javax.persistence.EntityNotFoundException)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)1 DeviceBuilder (org.opensmartgridplatform.cucumber.platform.smartmetering.builders.entities.DeviceBuilder)1