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