Search in sources :

Example 1 with MeasurementReport

use of org.opensmartgridplatform.domain.da.measurements.MeasurementReport 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 2 with MeasurementReport

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

the class MonitoringService method handleGetMeasurementReportResponse.

public void handleGetMeasurementReportResponse(final MeasurementReportDto measurementReportDto, final CorrelationIds ids, final String messageType, final ResponseMessageResultType responseMessageResultType, final OsgpException osgpException) {
    LOGGER.info("handleResponse for MessageType: {}", messageType);
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    MeasurementReport measurementReport = null;
    OsgpException exception = osgpException;
    try {
        if (responseMessageResultType == ResponseMessageResultType.NOT_OK || osgpException != null) {
            LOGGER.error("Device Response not ok.", osgpException);
            throw osgpException;
        }
        this.rtuResponseService.handleResponseMessageReceived(LOGGER, ids.getDeviceIdentification(), true);
        measurementReport = this.mapper.map(measurementReportDto, MeasurementReport.class);
    } catch (final Exception e) {
        LOGGER.error("Unexpected Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        exception = this.ensureOsgpException(e, "Exception occurred while receiving Measurement Report");
    }
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withResult(result).withOsgpException(exception).withDataObject(measurementReport).build();
    this.responseMessageRouter.send(responseMessage, messageType);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) MeasurementReport(org.opensmartgridplatform.domain.da.measurements.MeasurementReport) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException)

Aggregations

MeasurementReport (org.opensmartgridplatform.domain.da.measurements.MeasurementReport)2 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1 MeasurementGroup (org.opensmartgridplatform.domain.da.measurements.MeasurementGroup)1 MeasurementGroupDto (org.opensmartgridplatform.dto.da.measurements.MeasurementGroupDto)1 MeasurementReportDto (org.opensmartgridplatform.dto.da.measurements.MeasurementReportDto)1 MeasurementReportHeaderDto (org.opensmartgridplatform.dto.da.measurements.MeasurementReportHeaderDto)1 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)1 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)1