Search in sources :

Example 1 with FindEventsRequestDto

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

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

Example 3 with FindEventsRequestDto

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

the class FindEventsCommandExecutorTest method before.

@BeforeEach
public void before() throws ProtocolAdapterException, IOException {
    final DataObject fromDate = mock(DataObject.class);
    final DataObject toDate = mock(DataObject.class);
    this.messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
    this.findEventsRequestDto = new FindEventsRequestDto(EventLogCategoryDto.POWER_QUALITY_EVENT_LOG, DateTime.now().minusDays(70), DateTime.now());
    final DataObjectToEventListConverter dataObjectToEventListConverter = new DataObjectToEventListConverter(this.dlmsHelper);
    final DlmsObjectConfigService dlmsObjectConfigService = new DlmsObjectConfigService(this.dlmsHelper, new DlmsObjectConfigConfiguration().getDlmsObjectConfigs());
    this.executor = new FindEventsCommandExecutor(this.dlmsHelper, dataObjectToEventListConverter, dlmsObjectConfigService);
    when(this.dlmsHelper.asDataObject(this.findEventsRequestDto.getFrom())).thenReturn(fromDate);
    when(this.dlmsHelper.asDataObject(this.findEventsRequestDto.getUntil())).thenReturn(toDate);
    when(this.dlmsHelper.convertDataObjectToDateTime(any(DataObject.class))).thenReturn(new CosemDateTimeDto());
    when(this.conn.getDlmsMessageListener()).thenReturn(this.dlmsMessageListener);
    when(this.conn.getConnection()).thenReturn(this.dlmsConnection);
    when(this.dlmsConnection.get(any(AttributeAddress.class))).thenReturn(this.getResult);
}
Also used : DlmsObjectConfigConfiguration(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectConfigConfiguration) FindEventsRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.FindEventsRequestDto) DlmsObjectConfigService(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectConfigService) DataObject(org.openmuc.jdlms.datatypes.DataObject) DataObjectToEventListConverter(org.opensmartgridplatform.adapter.protocol.dlms.application.mapping.DataObjectToEventListConverter) AttributeAddress(org.openmuc.jdlms.AttributeAddress) CosemDateTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with FindEventsRequestDto

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

the class BundleServiceTest method testConnectionException.

/**
 * Tests the retry mechanism works in the adapter-protocol. In the first run a ConnectionException
 * is thrown while executing the {@link FindEventsRequestDto}. In the second attempt (when the
 * connection is restored again) the rest of the actions are executed.
 *
 * @throws ProtocolAdapterException is not thrown in this test
 */
@Test
public void testConnectionException() throws ProtocolAdapterException {
    final List<ActionDto> actionDtoList = this.makeActions();
    final BundleMessagesRequestDto dto = new BundleMessagesRequestDto(actionDtoList);
    // Set the point where to throw the ConnectionException
    this.getStub(FindEventsRequestDto.class).failWithRuntimeException(new ConnectionException("Connection Exception thrown!"));
    try {
        // Execute all the actions
        this.callExecutors(dto, this.messageMetadata);
        fail("A ConnectionException should be thrown");
    } catch (final ConnectionException connectionException) {
        // The execution is stopped. The number of responses is equal to the
        // actions performed before the point the exception is thrown. See
        // also the order of the ArrayList in method 'makeActions'.
        assertThat(dto.getAllResponses().size()).isEqualTo(9);
    }
    // Reset the point where the exception was thrown.
    this.getStub(FindEventsRequestDto.class).failWithRuntimeException(null);
    try {
        // Execute the remaining actions
        this.callExecutors(dto, this.messageMetadata);
        assertThat(actionDtoList.size()).isEqualTo(dto.getAllResponses().size());
    } catch (final ConnectionException connectionException) {
        fail("A ConnectionException should not have been thrown.");
    }
}
Also used : BundleMessagesRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto) FindEventsRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.FindEventsRequestDto) ActionDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionDto) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException) Test(org.junit.jupiter.api.Test)

Example 5 with FindEventsRequestDto

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

the class FindEventsCommandExecutorTest method testRetrievalOfEventsFromPowerQualityExtendedEventLogThrowsExceptionWhenNotSupportedByDevice.

@Test
void testRetrievalOfEventsFromPowerQualityExtendedEventLogThrowsExceptionWhenNotSupportedByDevice() throws ProtocolAdapterException, IOException {
    this.findEventsRequestDto = new FindEventsRequestDto(EventLogCategoryDto.POWER_QUALITY_EXTENDED_EVENT_LOG, DateTime.now().minusDays(70), DateTime.now());
    assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> {
        this.executor.execute(this.conn, this.DLMS_DEVICE_5_0, this.findEventsRequestDto, this.messageMetadata);
    });
}
Also used : FindEventsRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.FindEventsRequestDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) Test(org.junit.jupiter.api.Test)

Aggregations

FindEventsRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.FindEventsRequestDto)7 Test (org.junit.jupiter.api.Test)5 AttributeAddress (org.openmuc.jdlms.AttributeAddress)3 DataObject (org.openmuc.jdlms.datatypes.DataObject)3 EventDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto)3 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)2 ArrayList (java.util.ArrayList)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 DataObjectToEventListConverter (org.opensmartgridplatform.adapter.protocol.dlms.application.mapping.DataObjectToEventListConverter)1 DlmsObjectConfigConfiguration (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectConfigConfiguration)1 DlmsObjectConfigService (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectConfigService)1 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)1 ActionDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionDto)1 BundleMessagesRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto)1 CosemDateTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)1 EventMessageDataResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventMessageDataResponseDto)1