Search in sources :

Example 11 with EventDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto 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 EventDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto in project open-smart-grid-platform by OSGP.

the class EventsConverter method convertFrom.

@Override
public EventDto convertFrom(final Event source, final Type<EventDto> destinationType, final MappingContext context) {
    if (source == null) {
        return null;
    }
    final EventDto eventDto = new EventDto(source.getTimestamp(), source.getEventCode(), source.getEventCounter(), source.getEventLogCategory().name());
    eventDto.setEventTypeDto(EventTypeDto.valueOf(source.getEventType().name()));
    for (final EventDetail sourceEventDetail : source.getEventDetails()) {
        eventDto.addEventDetail(new EventDetailDto(sourceEventDetail.getName(), sourceEventDetail.getValue()));
    }
    return eventDto;
}
Also used : EventDetailDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDetailDto) EventDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto) EventDetail(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventDetail)

Example 13 with EventDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto in project open-smart-grid-platform by OSGP.

the class DataObjectToEventListConverter method convert.

public List<EventDto> convert(final DataObject source, final EventLogCategoryDto eventLogCategory) throws ProtocolAdapterException {
    final List<EventDto> eventList = new ArrayList<>();
    if (source == null) {
        throw new ProtocolAdapterException("DataObject should not be null");
    }
    final List<DataObject> listOfEvents = source.getValue();
    for (final DataObject eventDataObject : listOfEvents) {
        eventList.add(this.getEvent(eventDataObject, eventLogCategory));
    }
    return eventList;
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) EventDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto) ArrayList(java.util.ArrayList) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 14 with EventDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto in project open-smart-grid-platform by OSGP.

the class DataObjectToEventListConverter method getEvent.

private EventDto getEvent(final DataObject eventDataObject, final EventLogCategoryDto eventLogCategory) throws ProtocolAdapterException {
    final List<DataObject> eventData = eventDataObject.getValue();
    if (eventData == null) {
        throw new ProtocolAdapterException("eventData DataObject should not be null");
    }
    final int numberOfEventElements = eventLogCategory.getDetailsType().getNumberOfEventElements();
    if (eventData.size() != numberOfEventElements) {
        throw new ProtocolAdapterException("eventData size should be " + numberOfEventElements);
    }
    // extract values from List<DataObject> eventData.
    final DateTime dateTime = this.extractDateTime(eventData);
    final Integer code = this.extractCode(eventData);
    final Integer eventCounter = this.extractEventCounter(eventLogCategory, eventData);
    final String eventLogCategoryName = eventLogCategory.name();
    log.info("Event time is {}, event code is {}, event category is {} and event counter is {}", dateTime, code, eventLogCategoryName, eventCounter);
    // build a new EventDto with those values.
    final EventDto event = new EventDto(dateTime, code, eventCounter, eventLogCategoryName);
    // add details
    event.addEventDetails(this.extractEventDetails(eventLogCategory, eventData));
    return event;
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) EventDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) DateTime(org.joda.time.DateTime)

Example 15 with EventDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto in project open-smart-grid-platform by OSGP.

the class FindEventsCommandExecutorTest method testRetrievalOfPowerQualityEvents.

@Test
void testRetrievalOfPowerQualityEvents() throws ProtocolAdapterException, IOException {
    // SETUP
    when(this.getResult.getResultCode()).thenReturn(AccessResultCode.SUCCESS);
    when(this.getResult.getResultData()).thenReturn(this.resultData);
    when(this.resultData.getValue()).thenReturn(this.generateDataObjects());
    // CALL
    final List<EventDto> events = this.executor.execute(this.conn, this.DLMS_DEVICE_5_1, this.findEventsRequestDto, this.messageMetadata);
    // VERIFY
    assertThat(events.size()).isEqualTo(13);
    int firstEventCode = 77;
    for (final EventDto event : events) {
        assertThat(event.getEventCode()).isEqualTo(firstEventCode++);
    }
    verify(this.dlmsHelper, times(events.size())).convertDataObjectToDateTime(any(DataObject.class));
    verify(this.conn).getDlmsMessageListener();
    verify(this.conn).getConnection();
    verify(this.dlmsConnection).get(any(AttributeAddress.class));
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) EventDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto) AttributeAddress(org.openmuc.jdlms.AttributeAddress) Test(org.junit.jupiter.api.Test)

Aggregations

EventDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto)16 Test (org.junit.jupiter.api.Test)9 DataObject (org.openmuc.jdlms.datatypes.DataObject)8 DateTime (org.joda.time.DateTime)7 ArrayList (java.util.ArrayList)5 EventMessageDataResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventMessageDataResponseDto)5 EventDetailDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDetailDto)4 AttributeAddress (org.openmuc.jdlms.AttributeAddress)3 FindEventsRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.FindEventsRequestDto)3 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)2 ProtocolInfo (org.opensmartgridplatform.domain.core.entities.ProtocolInfo)2 EventDetail (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventDetail)2 EventMessagesResponse (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventMessagesResponse)2 EventTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventTypeDto)2 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 MappingContext (ma.glasnost.orika.MappingContext)1 BidirectionalConverter (ma.glasnost.orika.converter.BidirectionalConverter)1 Type (ma.glasnost.orika.metadata.Type)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1