Search in sources :

Example 6 with PeriodicMeterReadsResponseItemDto

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

the class GetPeriodicMeterReadsCommandExecutorIntegrationTest method checkValues.

private void checkValues(final List<PeriodicMeterReadsResponseItemDto> periodicMeterReads, final PeriodTypeDto type) {
    final PeriodicMeterReadsResponseItemDto period1 = periodicMeterReads.get(0);
    final PeriodicMeterReadsResponseItemDto period2 = periodicMeterReads.get(1);
    if (type == PeriodTypeDto.MONTHLY || type == PeriodTypeDto.DAILY) {
        assertThat(period1.getActiveEnergyImportTariffOne().getValue().longValue()).isEqualTo(this.PERIOD_1_LONG_VALUE_1);
        assertThat(period1.getActiveEnergyImportTariffTwo().getValue().longValue()).isEqualTo(this.PERIOD_1_LONG_VALUE_2);
        assertThat(period1.getActiveEnergyExportTariffOne().getValue().longValue()).isEqualTo(this.PERIOD_1_LONG_VALUE_3);
        assertThat(period1.getActiveEnergyExportTariffTwo().getValue().longValue()).isEqualTo(this.PERIOD_1_LONG_VALUE_4);
        assertThat(period2.getActiveEnergyImportTariffOne().getValue().longValue()).isEqualTo(this.PERIOD_2_LONG_VALUE_1);
        assertThat(period2.getActiveEnergyImportTariffTwo().getValue().longValue()).isEqualTo(this.PERIOD_2_LONG_VALUE_2);
        assertThat(period2.getActiveEnergyExportTariffOne().getValue().longValue()).isEqualTo(this.PERIOD_2_LONG_VALUE_3);
        assertThat(period2.getActiveEnergyExportTariffTwo().getValue().longValue()).isEqualTo(this.PERIOD_2_LONG_VALUE_4);
    } else {
        // INTERVAL, only total values
        assertThat(period1.getActiveEnergyImport().getValue().longValue()).isEqualTo(this.PERIOD_1_LONG_VALUE_1);
        assertThat(period1.getActiveEnergyExport().getValue().longValue()).isEqualTo(this.PERIOD_1_LONG_VALUE_2);
        assertThat(period2.getActiveEnergyImport().getValue().longValue()).isEqualTo(this.PERIOD_2_LONG_VALUE_1);
        assertThat(period2.getActiveEnergyExport().getValue().longValue()).isEqualTo(this.PERIOD_2_LONG_VALUE_2);
    }
}
Also used : PeriodicMeterReadsResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsResponseItemDto)

Example 7 with PeriodicMeterReadsResponseItemDto

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

the class GetPeriodicMeterReadsCommandExecutor method execute.

@Override
public PeriodicMeterReadsResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final PeriodicMeterReadsRequestDto periodicMeterReadsQuery, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    if (periodicMeterReadsQuery == null) {
        throw new IllegalArgumentException("PeriodicMeterReadsQuery should contain PeriodType, BeginDate and EndDate.");
    }
    final PeriodTypeDto queryPeriodType = periodicMeterReadsQuery.getPeriodType();
    final DateTime from = new DateTime(periodicMeterReadsQuery.getBeginDate());
    final DateTime to = new DateTime(periodicMeterReadsQuery.getEndDate());
    final AttributeAddressForProfile profileBufferAddress = this.getProfileBufferAddress(queryPeriodType, from, to, device);
    final List<AttributeAddress> scalerUnitAddresses = this.getScalerUnitAddresses(profileBufferAddress);
    final Optional<ProfileCaptureTime> intervalTime = this.getProfileCaptureTime(device, this.dlmsObjectConfigService, Medium.ELECTRICITY);
    LOGGER.debug("Retrieving current billing period and profiles for period type: {}, from: {}, to: {}", queryPeriodType, from, to);
    // Get results one by one because getWithList does not work for all devices
    final List<GetResult> getResultList = new ArrayList<>();
    final List<AttributeAddress> allAttributeAddresses = new ArrayList<>();
    allAttributeAddresses.add(profileBufferAddress.getAttributeAddress());
    allAttributeAddresses.addAll(scalerUnitAddresses);
    for (final AttributeAddress address : allAttributeAddresses) {
        conn.getDlmsMessageListener().setDescription(String.format(FORMAT_DESCRIPTION, queryPeriodType, from, to, JdlmsObjectToStringUtil.describeAttributes(address)));
        getResultList.addAll(this.dlmsHelper.getAndCheck(conn, device, "retrieve periodic meter reads for " + queryPeriodType, address));
    }
    LOGGER.info("Received getResult: {} ", getResultList);
    final DataObject resultData = this.dlmsHelper.readDataObject(getResultList.get(0), PERIODIC_E_METER_READS);
    final List<DataObject> bufferedObjectsList = resultData.getValue();
    final List<PeriodicMeterReadsResponseItemDto> periodicMeterReads = new ArrayList<>();
    for (final DataObject bufferedObject : bufferedObjectsList) {
        final List<DataObject> bufferedObjectValue = bufferedObject.getValue();
        try {
            periodicMeterReads.add(this.convertToResponseItem(new ConversionContext(periodicMeterReadsQuery, bufferedObjectValue, getResultList, profileBufferAddress, scalerUnitAddresses, intervalTime), periodicMeterReads));
        } catch (final BufferedDateTimeValidationException e) {
            LOGGER.warn(e.getMessage(), e);
        }
    }
    return new PeriodicMeterReadsResponseDto(queryPeriodType, periodicMeterReads);
}
Also used : AttributeAddressForProfile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile) PeriodicMeterReadsResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsResponseItemDto) PeriodTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto) GetResult(org.openmuc.jdlms.GetResult) AttributeAddress(org.openmuc.jdlms.AttributeAddress) ArrayList(java.util.ArrayList) PeriodicMeterReadsResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsResponseDto) DateTime(org.joda.time.DateTime) BufferedDateTimeValidationException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.BufferedDateTimeValidationException) ProfileCaptureTime(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.ProfileCaptureTime) DataObject(org.openmuc.jdlms.datatypes.DataObject)

Example 8 with PeriodicMeterReadsResponseItemDto

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

the class GetPeriodicMeterReadsCommandExecutor method convertToResponseItem.

private PeriodicMeterReadsResponseItemDto convertToResponseItem(final ConversionContext ctx, final List<PeriodicMeterReadsResponseItemDto> periodicMeterReads) throws ProtocolAdapterException, BufferedDateTimeValidationException {
    LOGGER.info("Converting bufferObject with value: {} ", ctx.bufferedObjects);
    final Optional<Date> previousLogTime = this.getPreviousLogTime(periodicMeterReads);
    final Date logTime = this.readClock(ctx, previousLogTime, this.dlmsHelper);
    final AmrProfileStatusCodeDto status = this.readStatus(ctx.bufferedObjects, ctx.attributeAddressForProfile);
    if (ctx.periodicMeterReadsQuery.getPeriodType() == PeriodTypeDto.INTERVAL) {
        final DlmsMeterValueDto importValue = this.getScaledMeterValue(ctx.bufferedObjects, ctx.getResultList, ctx.attributeAddresses, ctx.attributeAddressForProfile, DlmsObjectType.ACTIVE_ENERGY_IMPORT, "positiveActiveEnergy");
        final DlmsMeterValueDto exportValue = this.getScaledMeterValue(ctx.bufferedObjects, ctx.getResultList, ctx.attributeAddresses, ctx.attributeAddressForProfile, DlmsObjectType.ACTIVE_ENERGY_EXPORT, "negativeActiveEnergy");
        LOGGER.info("Resulting values: LogTime: {}, status: {}, importValue {}, exportValue {} ", logTime, status, importValue, exportValue);
        return new PeriodicMeterReadsResponseItemDto(logTime, importValue, exportValue, status);
    } else {
        final DlmsMeterValueDto importValueRate1 = this.getScaledMeterValue(ctx.bufferedObjects, ctx.getResultList, ctx.attributeAddresses, ctx.attributeAddressForProfile, DlmsObjectType.ACTIVE_ENERGY_IMPORT_RATE_1, "positiveActiveEnergyTariff1");
        final DlmsMeterValueDto importValueRate2 = this.getScaledMeterValue(ctx.bufferedObjects, ctx.getResultList, ctx.attributeAddresses, ctx.attributeAddressForProfile, DlmsObjectType.ACTIVE_ENERGY_IMPORT_RATE_2, "positiveActiveEnergyTariff2");
        final DlmsMeterValueDto exportValueRate1 = this.getScaledMeterValue(ctx.bufferedObjects, ctx.getResultList, ctx.attributeAddresses, ctx.attributeAddressForProfile, DlmsObjectType.ACTIVE_ENERGY_EXPORT_RATE_1, "negativeActiveEnergyTariff1");
        final DlmsMeterValueDto exportValueRate2 = this.getScaledMeterValue(ctx.bufferedObjects, ctx.getResultList, ctx.attributeAddresses, ctx.attributeAddressForProfile, DlmsObjectType.ACTIVE_ENERGY_EXPORT_RATE_2, "negativeActiveEnergyTariff2");
        LOGGER.info("Resulting values: LogTime: {}, status: {}, importRate1Value {}, importRate2Value {}, " + "exportRate1Value {}, exportRate2Value {} ", logTime, status, importValueRate1, importValueRate2, exportValueRate1, exportValueRate2);
        return new PeriodicMeterReadsResponseItemDto(logTime, importValueRate1, importValueRate2, exportValueRate1, exportValueRate2, status);
    }
}
Also used : AmrProfileStatusCodeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeDto) PeriodicMeterReadsResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsResponseItemDto) Date(java.util.Date) DlmsMeterValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto)

Example 9 with PeriodicMeterReadsResponseItemDto

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

the class PeriodicMeterReadContainerMappingTest method testWithEmptyList.

// Test if mapping with an empty List succeeds
@Test
public void testWithEmptyList() {
    final List<PeriodicMeterReadsResponseItemDto> meterReads = new ArrayList<>();
    final PeriodTypeDto periodType = PeriodTypeDto.DAILY;
    final PeriodicMeterReadsResponseDto periodicMeterReadsContainerDto = new PeriodicMeterReadsResponseDto(periodType, meterReads);
    final PeriodicMeterReadsContainer periodicMeterReadContainer = this.monitoringMapper.map(periodicMeterReadsContainerDto, PeriodicMeterReadsContainer.class);
    assertThat(periodicMeterReadContainer).isNotNull();
    assertThat(periodicMeterReadContainer.getPeriodicMeterReads()).isEmpty();
    assertThat(periodicMeterReadContainer.getPeriodType().name()).isEqualTo(periodicMeterReadsContainerDto.getPeriodType().name());
}
Also used : PeriodicMeterReadsResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsResponseItemDto) PeriodTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto) PeriodicMeterReadsContainer(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PeriodicMeterReadsContainer) ArrayList(java.util.ArrayList) PeriodicMeterReadsResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsResponseDto) Test(org.junit.jupiter.api.Test)

Example 10 with PeriodicMeterReadsResponseItemDto

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

the class PeriodicMeterReadContainerMappingTest method mapsPeriodicMeterReadsResponseItemDto.

@Test
public void mapsPeriodicMeterReadsResponseItemDto() {
    final Date logTime = new Date();
    final ActiveEnergyValuesDto valuesDto = new ActiveEnergyValuesDto(new DlmsMeterValueDto(new BigDecimal("12.34"), DlmsUnitTypeDto.M3), new DlmsMeterValueDto(new BigDecimal("12.35"), DlmsUnitTypeDto.M3), new DlmsMeterValueDto(new BigDecimal("12.36"), DlmsUnitTypeDto.M3), new DlmsMeterValueDto(new BigDecimal("12.37"), DlmsUnitTypeDto.M3), new DlmsMeterValueDto(new BigDecimal("12.38"), DlmsUnitTypeDto.M3), new DlmsMeterValueDto(new BigDecimal("12.39"), DlmsUnitTypeDto.M3));
    final AmrProfileStatusCodeDto amrProfileStatusCodeDto = new AmrProfileStatusCodeDto(new HashSet<>(asList(AmrProfileStatusCodeFlagDto.CRITICAL_ERROR, AmrProfileStatusCodeFlagDto.CLOCK_ADJUSTED)));
    final PeriodicMeterReadsResponseItemDto source = new PeriodicMeterReadsResponseItemDto(logTime, valuesDto, amrProfileStatusCodeDto);
    final PeriodicMeterReads readsResult = this.monitoringMapper.map(source, PeriodicMeterReads.class);
    final ActiveEnergyValues expectedValues = new ActiveEnergyValues(new OsgpMeterValue(new BigDecimal("12.340"), OsgpUnit.M3), new OsgpMeterValue(new BigDecimal("12.350"), OsgpUnit.M3), new OsgpMeterValue(new BigDecimal("12.360"), OsgpUnit.M3), new OsgpMeterValue(new BigDecimal("12.370"), OsgpUnit.M3), new OsgpMeterValue(new BigDecimal("12.380"), OsgpUnit.M3), new OsgpMeterValue(new BigDecimal("12.390"), OsgpUnit.M3));
    final AmrProfileStatusCode amrProfileStatusCode = new AmrProfileStatusCode(new HashSet<>(asList(AmrProfileStatusCodeFlag.CRITICAL_ERROR, AmrProfileStatusCodeFlag.CLOCK_ADJUSTED)));
    final PeriodicMeterReads expectedReads = new PeriodicMeterReads(logTime, expectedValues, amrProfileStatusCode);
    assertThat(readsResult).usingRecursiveComparison().isEqualTo(expectedReads);
}
Also used : AmrProfileStatusCodeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeDto) PeriodicMeterReadsResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsResponseItemDto) AmrProfileStatusCode(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AmrProfileStatusCode) PeriodicMeterReads(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PeriodicMeterReads) ActiveEnergyValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActiveEnergyValuesDto) ActiveEnergyValues(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ActiveEnergyValues) Date(java.util.Date) BigDecimal(java.math.BigDecimal) OsgpMeterValue(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.OsgpMeterValue) DlmsMeterValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto) Test(org.junit.jupiter.api.Test)

Aggregations

PeriodicMeterReadsResponseItemDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsResponseItemDto)10 Test (org.junit.jupiter.api.Test)6 PeriodTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto)6 PeriodicMeterReadsResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsResponseDto)6 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 DateTime (org.joda.time.DateTime)3 AttributeAddress (org.openmuc.jdlms.AttributeAddress)3 DataObject (org.openmuc.jdlms.datatypes.DataObject)3 BigDecimal (java.math.BigDecimal)2 GetResult (org.openmuc.jdlms.GetResult)2 AttributeAddressForProfile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile)2 Protocol (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol)2 AmrProfileStatusCodeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeDto)2 DlmsMeterValueDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto)2 PeriodicMeterReadsRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsRequestDto)2 Arrays (java.util.Arrays)1 Calendar (java.util.Calendar)1 Collections (java.util.Collections)1 GregorianCalendar (java.util.GregorianCalendar)1