Search in sources :

Example 1 with AmrProfileStatusCodeDto

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

the class PeriodicMeterReadContainerMappingTest method testWithNonEmptyList.

// Test if mapping with a non-empty List succeeds
@Test
public void testWithNonEmptyList() {
    // build test data
    final DlmsMeterValueDto activeEnergyImport = new DlmsMeterValueDto(new BigDecimal(1.0), DlmsUnitTypeDto.M3);
    final DlmsMeterValueDto activeEnergyExport = new DlmsMeterValueDto(new BigDecimal(1.0), DlmsUnitTypeDto.M3);
    final Set<AmrProfileStatusCodeFlagDto> amrProfileStatusCodeFlagSet = new TreeSet<>();
    amrProfileStatusCodeFlagSet.add(AmrProfileStatusCodeFlagDto.CRITICAL_ERROR);
    final AmrProfileStatusCodeDto amrProfileStatusCodeDto = new AmrProfileStatusCodeDto(amrProfileStatusCodeFlagSet);
    final PeriodicMeterReadsResponseItemDto periodicMeterReadsDto = new PeriodicMeterReadsResponseItemDto(new Date(), activeEnergyImport, activeEnergyExport, amrProfileStatusCodeDto);
    final List<PeriodicMeterReadsResponseItemDto> meterReads = new ArrayList<>();
    meterReads.add(periodicMeterReadsDto);
    final PeriodTypeDto periodType = PeriodTypeDto.DAILY;
    final PeriodicMeterReadsResponseDto periodicMeterReadsContainerDto = new PeriodicMeterReadsResponseDto(periodType, meterReads);
    // actual mapping
    final PeriodicMeterReadsContainer periodicMeterReadsContainer = this.monitoringMapper.map(periodicMeterReadsContainerDto, PeriodicMeterReadsContainer.class);
    // test mapping
    assertThat(periodicMeterReadsContainer).isNotNull();
    assertThat(periodicMeterReadsContainer.getPeriodType().name()).isEqualTo(periodicMeterReadsContainerDto.getPeriodType().name());
    assertThat(periodicMeterReadsContainer.getPeriodicMeterReads().size()).isEqualTo(periodicMeterReadsContainerDto.getPeriodicMeterReads().size());
    assertThat(periodicMeterReadsContainer.getPeriodicMeterReads().get(0).getLogTime()).isEqualTo(periodicMeterReadsContainerDto.getPeriodicMeterReads().get(0).getLogTime());
    assertThat(periodicMeterReadsContainer.getPeriodicMeterReads().get(0).getActiveEnergyImport().getValue()).isEqualTo(new BigDecimal("1.0"));
    assertThat(periodicMeterReadsContainer.getPeriodicMeterReads().get(0).getActiveEnergyImport().getOsgpUnit()).isEqualTo(OsgpUnit.M3);
    assertThat(periodicMeterReadsContainer.getPeriodicMeterReads().get(0).getActiveEnergyExport().getValue()).isEqualTo(new BigDecimal("1.0"));
    assertThat(periodicMeterReadsContainer.getPeriodicMeterReads().get(0).getActiveEnergyExport().getOsgpUnit()).isEqualTo(OsgpUnit.M3);
    assertThat(periodicMeterReadsContainer.getPeriodicMeterReads().get(0).getAmrProfileStatusCode().getAmrProfileStatusCodeFlags().size()).isEqualTo(periodicMeterReadsContainerDto.getPeriodicMeterReads().get(0).getAmrProfileStatusCode().getAmrProfileStatusCodeFlags().size());
    assertThat(periodicMeterReadsContainer.getPeriodicMeterReads().get(0).getAmrProfileStatusCode().getAmrProfileStatusCodeFlags().contains(AmrProfileStatusCodeFlag.CRITICAL_ERROR)).isTrue();
}
Also used : AmrProfileStatusCodeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeDto) PeriodicMeterReadsResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsResponseItemDto) PeriodTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto) AmrProfileStatusCodeFlagDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeFlagDto) ArrayList(java.util.ArrayList) PeriodicMeterReadsResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsResponseDto) BigDecimal(java.math.BigDecimal) Date(java.util.Date) TreeSet(java.util.TreeSet) PeriodicMeterReadsContainer(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PeriodicMeterReadsContainer) DlmsMeterValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto) Test(org.junit.jupiter.api.Test)

Example 2 with AmrProfileStatusCodeDto

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

the class PeriodicMeterReadsContainerGasMappingTest method testWithNonEmptyList.

// Test if mapping with a non-empty List succeeds
@Test
public void testWithNonEmptyList() {
    // build test data
    final DlmsMeterValueDto consumption = new DlmsMeterValueDto(new BigDecimal(1.0), DlmsUnitTypeDto.M3);
    final Set<AmrProfileStatusCodeFlagDto> amrProfileStatusCodeFlagSet = new TreeSet<>();
    amrProfileStatusCodeFlagSet.add(AmrProfileStatusCodeFlagDto.CRITICAL_ERROR);
    final AmrProfileStatusCodeDto amrProfileStatusCodeDto = new AmrProfileStatusCodeDto(amrProfileStatusCodeFlagSet);
    final PeriodicMeterReadsGasResponseItemDto periodicMeterReadsGasDto = new PeriodicMeterReadsGasResponseItemDto(new Date(), consumption, new Date(), amrProfileStatusCodeDto);
    final List<PeriodicMeterReadsGasResponseItemDto> meterReads = new ArrayList<>();
    meterReads.add(periodicMeterReadsGasDto);
    final PeriodTypeDto periodType = PeriodTypeDto.DAILY;
    final PeriodicMeterReadGasResponseDto periodicMeterReadsContainerDto = new PeriodicMeterReadGasResponseDto(periodType, meterReads);
    // actual mapping
    final PeriodicMeterReadsContainerGas periodicMeterReadsContainerGas = this.monitoringMapper.map(periodicMeterReadsContainerDto, PeriodicMeterReadsContainerGas.class);
    // test mapping
    assertThat(periodicMeterReadsContainerGas).withFailMessage("Mapping must take place. So the result cannot be null.").isNotNull();
    assertThat(periodicMeterReadsContainerGas.getPeriodType().name()).withFailMessage("After the mapping the name of the period must be the same.").isEqualTo(periodicMeterReadsContainerDto.getPeriodType().name());
    assertThat(periodicMeterReadsContainerGas.getPeriodicMeterReadsGas().size()).withFailMessage("The number of periodic meter reads before and after the mapping must be equal.").isEqualTo(periodicMeterReadsContainerDto.getPeriodicMeterReadsGas().size());
    assertThat(periodicMeterReadsContainerGas.getPeriodicMeterReadsGas().get(0).getLogTime()).withFailMessage("After the mapping the log time of the first entry must be the same.").isEqualTo(periodicMeterReadsContainerDto.getPeriodicMeterReadsGas().get(0).getLogTime());
    assertThat(periodicMeterReadsContainerGas.getPeriodicMeterReadsGas().get(0).getCaptureTime()).withFailMessage("After the mapping the capture time of the first entry must be the same.").isEqualTo(periodicMeterReadsContainerDto.getPeriodicMeterReadsGas().get(0).getCaptureTime());
    assertThat(periodicMeterReadsContainerGas.getPeriodicMeterReadsGas().get(0).getConsumption().getValue()).withFailMessage("After the mapping the consumption must be equal.").isEqualTo(new BigDecimal("1.0"));
    assertThat(periodicMeterReadsContainerGas.getPeriodicMeterReadsGas().get(0).getConsumption().getOsgpUnit()).withFailMessage("After the mapping the osgp unit value must be the same.").isEqualTo(OsgpUnit.M3);
    assertThat(periodicMeterReadsContainerGas.getPeriodicMeterReadsGas().get(0).getAmrProfileStatusCode().getAmrProfileStatusCodeFlags().size()).withFailMessage("After the mapping the size of the arm profile status code flags must be the same.").isEqualTo(periodicMeterReadsContainerDto.getPeriodicMeterReadsGas().get(0).getAmrProfileStatusCode().getAmrProfileStatusCodeFlags().size());
    assertThat(periodicMeterReadsContainerGas.getPeriodicMeterReadsGas().get(0).getAmrProfileStatusCode().getAmrProfileStatusCodeFlags().contains(AmrProfileStatusCodeFlag.CRITICAL_ERROR)).withFailMessage("After the mapping the amr profile status code flags must contain the CRITICAL_ERROR flag.").isTrue();
}
Also used : AmrProfileStatusCodeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeDto) PeriodTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto) PeriodicMeterReadsGasResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsGasResponseItemDto) AmrProfileStatusCodeFlagDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeFlagDto) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) Date(java.util.Date) TreeSet(java.util.TreeSet) PeriodicMeterReadGasResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadGasResponseDto) PeriodicMeterReadsContainerGas(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PeriodicMeterReadsContainerGas) DlmsMeterValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto) Test(org.junit.jupiter.api.Test)

Example 3 with AmrProfileStatusCodeDto

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

the class AbstractPeriodicMeterReadsCommandExecutor method readStatus.

AmrProfileStatusCodeDto readStatus(final List<DataObject> bufferedObjects, final AttributeAddressForProfile attributeAddressForProfile) throws ProtocolAdapterException {
    final Integer statusIndex = attributeAddressForProfile.getIndex(DlmsObjectType.AMR_STATUS, null);
    AmrProfileStatusCodeDto amrProfileStatusCode = null;
    if (statusIndex != null) {
        amrProfileStatusCode = this.readAmrProfileStatusCode(bufferedObjects.get(statusIndex));
    }
    return amrProfileStatusCode;
}
Also used : AmrProfileStatusCodeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeDto)

Example 4 with AmrProfileStatusCodeDto

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

the class GetPeriodicMeterReadsGasCommandExecutor method convertToResponseItem.

private PeriodicMeterReadsGasResponseItemDto convertToResponseItem(final ConversionContext ctx, final List<PeriodicMeterReadsGasResponseItemDto> periodicMeterReads) throws ProtocolAdapterException, BufferedDateTimeValidationException {
    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);
    final DataObject gasValue = this.readValue(ctx.bufferedObjects, ctx.attributeAddressForProfile);
    final DataObject scalerUnit = this.readScalerUnit(ctx.getResultList, ctx.attributeAddresses, ctx.attributeAddressForProfile, ctx.periodicMeterReadsQuery.getChannel().getChannelNumber());
    final Optional<Date> previousCaptureTime = this.getPreviousCaptureTime(periodicMeterReads);
    final Date captureTime = this.readCaptureTime(ctx, previousCaptureTime);
    LOGGER.info("Converting bufferObject with value: {} ", ctx.bufferedObjects);
    LOGGER.info("Resulting values: LogTime: {}, status: {}, gasValue {}, scalerUnit: {}, captureTime {} ", logTime, status, gasValue, scalerUnit, captureTime);
    return new PeriodicMeterReadsGasResponseItemDto(logTime, this.dlmsHelper.getScaledMeterValue(gasValue, scalerUnit, GAS_VALUE), captureTime, status);
}
Also used : AmrProfileStatusCodeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeDto) DataObject(org.openmuc.jdlms.datatypes.DataObject) PeriodicMeterReadsGasResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsGasResponseItemDto) Date(java.util.Date)

Example 5 with AmrProfileStatusCodeDto

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

Aggregations

AmrProfileStatusCodeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeDto)6 Date (java.util.Date)5 DlmsMeterValueDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto)4 BigDecimal (java.math.BigDecimal)3 Test (org.junit.jupiter.api.Test)3 PeriodicMeterReadsResponseItemDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsResponseItemDto)3 ArrayList (java.util.ArrayList)2 TreeSet (java.util.TreeSet)2 AmrProfileStatusCodeFlagDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeFlagDto)2 PeriodTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto)2 PeriodicMeterReadsGasResponseItemDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsGasResponseItemDto)2 DataObject (org.openmuc.jdlms.datatypes.DataObject)1 ActiveEnergyValues (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ActiveEnergyValues)1 AmrProfileStatusCode (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AmrProfileStatusCode)1 OsgpMeterValue (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.OsgpMeterValue)1 PeriodicMeterReads (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PeriodicMeterReads)1 PeriodicMeterReadsContainer (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PeriodicMeterReadsContainer)1 PeriodicMeterReadsContainerGas (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PeriodicMeterReadsContainerGas)1 ActiveEnergyValuesDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ActiveEnergyValuesDto)1 PeriodicMeterReadGasResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadGasResponseDto)1