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();
}
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();
}
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;
}
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);
}
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);
}
}
Aggregations