Search in sources :

Example 6 with MeasurementReportDto

use of org.opensmartgridplatform.dto.da.measurements.MeasurementReportDto in project open-smart-grid-platform by OSGP.

the class MeasurementAsduHandler method handleAsdu.

@Override
public void handleAsdu(final ASdu asdu, final ResponseMetadata responseMetadata) {
    LOGGER.debug("Received measurement of type {}.", asdu.getTypeIdentification());
    final MeasurementReportDto measurementReportDto = this.converter.convert(asdu);
    this.deviceResponseServiceRegistry.forDeviceType(responseMetadata.getDeviceType()).process(measurementReportDto, responseMetadata);
}
Also used : MeasurementReportDto(org.opensmartgridplatform.dto.da.measurements.MeasurementReportDto)

Example 7 with MeasurementReportDto

use of org.opensmartgridplatform.dto.da.measurements.MeasurementReportDto in project open-smart-grid-platform by OSGP.

the class SinglePointInformationWithTimeTagAsduHandler method handleAsdu.

@Override
public void handleAsdu(final ASdu asdu, final ResponseMetadata responseMetadata) {
    LOGGER.debug("Received asdu {} for device {}.", asdu, responseMetadata.getDeviceIdentification());
    final MeasurementReportDto measurementReportDto = this.converter.convert(asdu);
    final DeviceResponseService deviceResponseService = this.deviceResponseServiceRegistry.forDeviceType(responseMetadata.getDeviceType());
    if (CauseOfTransmission.SPONTANEOUS == asdu.getCauseOfTransmission()) {
        deviceResponseService.processEvent(measurementReportDto, responseMetadata);
    } else {
        deviceResponseService.process(measurementReportDto, responseMetadata);
    }
}
Also used : DeviceResponseService(org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.DeviceResponseService) MeasurementReportDto(org.opensmartgridplatform.dto.da.measurements.MeasurementReportDto)

Example 8 with MeasurementReportDto

use of org.opensmartgridplatform.dto.da.measurements.MeasurementReportDto in project open-smart-grid-platform by OSGP.

the class GetMeasurementReportResponseMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing Measurement Report message");
    String correlationUid = null;
    String messageType = null;
    String organisationIdentification = null;
    String deviceIdentification = null;
    ResponseMessage responseMessage = null;
    ResponseMessageResultType responseMessageResultType = null;
    OsgpException osgpException = null;
    Object dataObject = null;
    try {
        correlationUid = message.getJMSCorrelationID();
        messageType = message.getJMSType();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        responseMessage = (ResponseMessage) message.getObject();
        responseMessageResultType = responseMessage.getResult();
        osgpException = responseMessage.getOsgpException();
        dataObject = responseMessage.getDataObject();
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        LOGGER.debug("correlationUid: {}", correlationUid);
        LOGGER.debug("messageType: {}", messageType);
        LOGGER.debug("organisationIdentification: {}", organisationIdentification);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("responseMessageResultType: {}", responseMessageResultType);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("osgpException", osgpException);
        return;
    }
    try {
        LOGGER.info("Calling application service function to handle response: {}", messageType);
        final MeasurementReportDto dataResponse = (MeasurementReportDto) dataObject;
        final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
        this.monitoringService.handleGetMeasurementReportResponse(dataResponse, ids, messageType, responseMessageResultType, osgpException);
    } catch (final Exception e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, messageType);
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) MeasurementReportDto(org.opensmartgridplatform.dto.da.measurements.MeasurementReportDto) JMSException(javax.jms.JMSException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException)

Example 9 with MeasurementReportDto

use of org.opensmartgridplatform.dto.da.measurements.MeasurementReportDto in project open-smart-grid-platform by OSGP.

the class DomainDistributionAutomationMapperTest method testMeasurementReportMapping.

@Test
public void testMeasurementReportMapping() {
    // Arrange
    final int commonAddress = 55;
    final String groupIdentification = "137";
    final float[] gasFlowMeasurements = { 78.733f, 21.000f };
    // Arrange domain
    final MeasurementGroup expectedGroup = DomainMeasurementsFactory.gasFlowMeasurementGroup(groupIdentification, gasFlowMeasurements);
    final List<MeasurementGroup> expectedGroups = new ArrayList<>();
    expectedGroups.add(expectedGroup);
    final MeasurementReport expected = new MeasurementReport(DomainMeasurementsFactory.spontaneousReportHeader(commonAddress), expectedGroups);
    // Arrange DTO
    final MeasurementReportHeaderDto dtoHeader = DtoMeasurementsFactory.spontaneousReportHeader(commonAddress);
    final MeasurementGroupDto dtoGroup = DtoMeasurementsFactory.gasFlowMeasurementGroup(groupIdentification, gasFlowMeasurements);
    final List<MeasurementGroupDto> dtoGroups = new ArrayList<>();
    dtoGroups.add(dtoGroup);
    final MeasurementReportDto dtoReport = new MeasurementReportDto(dtoHeader, dtoGroups);
    // Act
    final MeasurementReport actual = this.mapper.map(dtoReport, MeasurementReport.class);
    // Assert
    assertThat(actual).isEqualTo(expected);
}
Also used : MeasurementReportDto(org.opensmartgridplatform.dto.da.measurements.MeasurementReportDto) ArrayList(java.util.ArrayList) MeasurementGroupDto(org.opensmartgridplatform.dto.da.measurements.MeasurementGroupDto) MeasurementReport(org.opensmartgridplatform.domain.da.measurements.MeasurementReport) MeasurementGroup(org.opensmartgridplatform.domain.da.measurements.MeasurementGroup) MeasurementReportHeaderDto(org.opensmartgridplatform.dto.da.measurements.MeasurementReportHeaderDto) Test(org.junit.jupiter.api.Test)

Example 10 with MeasurementReportDto

use of org.opensmartgridplatform.dto.da.measurements.MeasurementReportDto in project open-smart-grid-platform by OSGP.

the class SinglePointWithQualityAsduHandlerTest method testHandleAsduShouldSendMeasurementReport.

/**
 * Test method for {@link
 * org.opensmartgridplatform.adapter.protocol.iec60870.domain.lightmeasurement.asduhandlers.SinglePointWithQualityAsduHandler#handleAsdu(org.openmuc.j60870.ASdu,
 * org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata)}.
 *
 * @throws Exception
 */
@Test
void testHandleAsduShouldSendMeasurementReport() throws Exception {
    // Arrange
    when(this.deviceResponseServiceMap.forDeviceType(DeviceType.LIGHT_MEASUREMENT_RTU)).thenReturn(this.deviceResponseService);
    final ASdu asdu = this.createAsdu();
    final ResponseMetadata responseMetadata = this.createResponseMetadata();
    final MeasurementReportDto measurementReport = this.createMeasurementReportDto();
    when(this.converterService.convert(asdu)).thenReturn(measurementReport);
    when(this.deviceResponseServiceMap.forDeviceType(GATEWAY_DEVICE_TYPE)).thenReturn(this.deviceResponseService);
    // Act
    this.asduHandler.handleAsdu(asdu, responseMetadata);
    // Assert
    verify(this.deviceResponseService).process(any(MeasurementReportDto.class), eq(responseMetadata));
}
Also used : MeasurementReportDto(org.opensmartgridplatform.dto.da.measurements.MeasurementReportDto) ASdu(org.openmuc.j60870.ASdu) ResponseMetadata(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata) Test(org.junit.jupiter.api.Test)

Aggregations

MeasurementReportDto (org.opensmartgridplatform.dto.da.measurements.MeasurementReportDto)11 Test (org.junit.jupiter.api.Test)6 ResponseMetadata (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata)4 ASdu (org.openmuc.j60870.ASdu)3 MeasurementGroupDto (org.opensmartgridplatform.dto.da.measurements.MeasurementGroupDto)3 MeasurementReportHeaderDto (org.opensmartgridplatform.dto.da.measurements.MeasurementReportHeaderDto)3 Iec60870Device (org.opensmartgridplatform.adapter.protocol.iec60870.domain.entities.Iec60870Device)2 ArrayList (java.util.ArrayList)1 JMSException (javax.jms.JMSException)1 DeviceResponseService (org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.DeviceResponseService)1 MeasurementGroup (org.opensmartgridplatform.domain.da.measurements.MeasurementGroup)1 MeasurementReport (org.opensmartgridplatform.domain.da.measurements.MeasurementReport)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1 CorrelationIds (org.opensmartgridplatform.shared.infra.jms.CorrelationIds)1 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)1 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)1