use of org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadGasResponseDto in project open-smart-grid-platform by OSGP.
the class PeriodicMeterReadsContainerGasMappingTest method testWithNullList.
// the List is not allowed to be null because of the way the constructor is
// defined
@Test
public void testWithNullList() {
final List<PeriodicMeterReadsGasResponseItemDto> meterReads = null;
final PeriodTypeDto periodType = PeriodTypeDto.DAILY;
assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> {
new PeriodicMeterReadGasResponseDto(periodType, meterReads);
});
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadGasResponseDto in project open-smart-grid-platform by OSGP.
the class PeriodicMeterReadsContainerGasMappingTest method testWithEmptyList.
// Test if mapping with an empty List succeeds
@Test
public void testWithEmptyList() {
final List<PeriodicMeterReadsGasResponseItemDto> meterReads = new ArrayList<>();
final PeriodTypeDto periodType = PeriodTypeDto.DAILY;
final PeriodicMeterReadGasResponseDto periodicMeterReadsContainerGasDto = new PeriodicMeterReadGasResponseDto(periodType, meterReads);
final PeriodicMeterReadsContainerGas periodicMeterReadContainerGas = this.monitoringMapper.map(periodicMeterReadsContainerGasDto, PeriodicMeterReadsContainerGas.class);
assertThat(periodicMeterReadContainerGas).isNotNull();
assertThat(periodicMeterReadContainerGas.getPeriodicMeterReadsGas()).isEmpty();
assertThat(periodicMeterReadContainerGas.getPeriodType().name()).isEqualTo(periodicMeterReadsContainerGasDto.getPeriodType().name());
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadGasResponseDto 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.PeriodicMeterReadGasResponseDto in project open-smart-grid-platform by OSGP.
the class GetPeriodicMeterReadsGasCommandExecutor method execute.
@Override
public PeriodicMeterReadGasResponseDto 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, periodicMeterReadsQuery.getChannel(), from, to, device);
final List<AttributeAddress> scalerUnitAddresses = this.getScalerUnitAddresses(periodicMeterReadsQuery.getChannel(), profileBufferAddress);
final Optional<ProfileCaptureTime> intervalTime = this.getProfileCaptureTime(device, this.dlmsObjectConfigService, Medium.GAS);
LOGGER.info("Retrieving current billing period and profiles for gas for period type: {}, from: " + "{}, to: {}", queryPeriodType, from, to);
/*
* workaround for a problem when using with_list and retrieving a profile
* buffer, this will be returned erroneously.
*/
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, periodicMeterReadsQuery.getChannel(), queryPeriodType, from, to, JdlmsObjectToStringUtil.describeAttributes(address)));
getResultList.addAll(this.dlmsHelper.getAndCheck(conn, device, "retrieve periodic meter reads for " + queryPeriodType + ", channel " + periodicMeterReadsQuery.getChannel(), address));
}
LOGGER.info("Received getResult: {} ", getResultList);
final DataObject resultData = this.dlmsHelper.readDataObject(getResultList.get(0), PERIODIC_G_METER_READS);
final List<DataObject> bufferedObjectsList = resultData.getValue();
final List<PeriodicMeterReadsGasResponseItemDto> 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);
}
}
LOGGER.info("Resulting periodicMeterReads: {} ", periodicMeterReads);
return new PeriodicMeterReadGasResponseDto(queryPeriodType, periodicMeterReads);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadGasResponseDto in project open-smart-grid-platform by OSGP.
the class PeriodicMeterReadsresponseMessageProcessor method handleMessage.
@Override
protected void handleMessage(final MessageMetadata deviceMessageMetadata, final ResponseMessage responseMessage, final OsgpException osgpException) {
if (responseMessage.getDataObject() instanceof PeriodicMeterReadsResponseDto) {
final PeriodicMeterReadsResponseDto periodicMeterReadsContainer = (PeriodicMeterReadsResponseDto) responseMessage.getDataObject();
this.monitoringService.handlePeriodicMeterReadsresponse(deviceMessageMetadata, responseMessage.getResult(), osgpException, periodicMeterReadsContainer);
} else if (responseMessage.getDataObject() instanceof PeriodicMeterReadGasResponseDto) {
final PeriodicMeterReadGasResponseDto periodicMeterReadsContainerGas = (PeriodicMeterReadGasResponseDto) responseMessage.getDataObject();
this.monitoringService.handlePeriodicMeterReadsresponse(deviceMessageMetadata, responseMessage.getResult(), osgpException, periodicMeterReadsContainerGas);
}
}
Aggregations