Search in sources :

Example 1 with EventDto

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

the class ManagementService method findEvents.

// === FIND EVENTS ===
public EventMessageDataResponseDto findEvents(final DlmsConnectionManager conn, final DlmsDevice device, final FindEventsRequestList findEventsQueryMessageDataContainer, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    final List<EventDto> events = new ArrayList<>();
    log.info("findEvents setting up connection with meter {}", device.getDeviceIdentification());
    for (final FindEventsRequestDto findEventsQuery : findEventsQueryMessageDataContainer.getFindEventsQueryList()) {
        log.info("findEventsQuery.eventLogCategory: {}, findEventsQuery.from: {}, findEventsQuery.until: {}", findEventsQuery.getEventLogCategory().toString(), findEventsQuery.getFrom(), findEventsQuery.getUntil());
        events.addAll(this.findEventsCommandExecutor.execute(conn, device, findEventsQuery, messageMetadata));
    }
    return new EventMessageDataResponseDto(events);
}
Also used : FindEventsRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.FindEventsRequestDto) EventDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto) ArrayList(java.util.ArrayList) EventMessageDataResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventMessageDataResponseDto)

Example 2 with EventDto

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

the class EventService method enrichEvents.

public void enrichEvents(final MessageMetadata deviceMessageMetadata, final EventMessageDataResponseDto responseDto) throws FunctionalException {
    LOGGER.info("Enrich EventMessageDataResponse with EventTypes for device: {}", deviceMessageMetadata.getDeviceIdentification());
    final SmartMeter smartMeter = this.domainHelperService.findSmartMeter(deviceMessageMetadata.getDeviceIdentification());
    for (final EventDto eventDto : responseDto.getEvents()) {
        final String protocolName = smartMeter.getProtocolInfo() != null ? smartMeter.getProtocolInfo().getProtocol() : null;
        final EventTypeDto eventTypeDto = this.determineEventType(eventDto, protocolName);
        eventDto.setEventTypeDto(eventTypeDto);
    }
}
Also used : EventDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto) SmartMeter(org.opensmartgridplatform.domain.core.entities.SmartMeter) EventTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventTypeDto)

Example 3 with EventDto

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

the class EventServiceTest method testWrongEventCode.

@Test
void testWrongEventCode() {
    final FunctionalException functionalException = Assertions.assertThrows(FunctionalException.class, () -> {
        final ProtocolInfo protocolInfo = mock(ProtocolInfo.class);
        when(protocolInfo.getProtocol()).thenReturn("SMR");
        when(this.smartMeter.getProtocolInfo()).thenReturn(protocolInfo);
        final EventDto event = new EventDto(new DateTime(), 266, 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(functionalException.getExceptionType()).isEqualTo(FunctionalExceptionType.VALIDATION_ERROR);
}
Also used : EventDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto) ArrayList(java.util.ArrayList) ProtocolInfo(org.opensmartgridplatform.domain.core.entities.ProtocolInfo) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) EventMessageDataResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventMessageDataResponseDto) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with EventDto

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

the class EventsConverter method convertTo.

@Override
public Event convertTo(final EventDto source, final Type<Event> destinationType, final MappingContext context) {
    if (source == null) {
        return null;
    }
    final EventType eventType = EventType.valueOf(source.getEventTypeDto().name());
    final List<EventDetail> eventDetails = source.getEventDetails().stream().map(sourceDetail -> new EventDetail(sourceDetail.getName(), sourceDetail.getValue())).collect(Collectors.toList());
    return new Event(source.getTimestamp(), eventType, source.getEventCounter(), EventLogCategory.fromValue(source.getEventLogCategoryName()), eventDetails);
}
Also used : BidirectionalConverter(ma.glasnost.orika.converter.BidirectionalConverter) EventLogCategory(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventLogCategory) EventType(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventType) List(java.util.List) EventDetailDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDetailDto) Type(ma.glasnost.orika.metadata.Type) EventDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto) EventDetail(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventDetail) Event(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.Event) EventTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventTypeDto) Collectors(java.util.stream.Collectors) MappingContext(ma.glasnost.orika.MappingContext) EventType(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventType) Event(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.Event) EventDetail(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventDetail)

Example 5 with EventDto

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

the class FindEventsCommandExecutorTest method testRetrievalOfAuxiliaryLogEvents.

@Test
void testRetrievalOfAuxiliaryLogEvents() throws ProtocolAdapterException, IOException {
    // SETUP
    this.findEventsRequestDto = new FindEventsRequestDto(EventLogCategoryDto.AUXILIARY_EVENT_LOG, DateTime.now().minusDays(70), DateTime.now());
    when(this.getResult.getResultCode()).thenReturn(AccessResultCode.SUCCESS);
    when(this.getResult.getResultData()).thenReturn(this.resultData);
    when(this.resultData.getValue()).thenReturn(this.generateDataObjectsAuxiliary());
    // CALL
    final List<EventDto> events = this.executor.execute(this.conn, this.DLMS_DEVICE_5_1, this.findEventsRequestDto, this.messageMetadata);
    // VERIFY
    assertThat(events.size()).isEqualTo(34);
    int firstEventCode = 33664;
    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 : FindEventsRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.FindEventsRequestDto) 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