Search in sources :

Example 1 with PeriodicMeterReadsGasResponseItemDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsGasResponseItemDto 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);
    });
}
Also used : PeriodTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto) PeriodicMeterReadsGasResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsGasResponseItemDto) PeriodicMeterReadGasResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadGasResponseDto) Test(org.junit.jupiter.api.Test)

Example 2 with PeriodicMeterReadsGasResponseItemDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsGasResponseItemDto 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());
}
Also used : PeriodTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto) PeriodicMeterReadsGasResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsGasResponseItemDto) ArrayList(java.util.ArrayList) PeriodicMeterReadGasResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadGasResponseDto) PeriodicMeterReadsContainerGas(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PeriodicMeterReadsContainerGas) Test(org.junit.jupiter.api.Test)

Example 3 with PeriodicMeterReadsGasResponseItemDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsGasResponseItemDto 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 4 with PeriodicMeterReadsGasResponseItemDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsGasResponseItemDto 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);
}
Also used : AttributeAddressForProfile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile) PeriodTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto) GetResult(org.openmuc.jdlms.GetResult) PeriodicMeterReadsGasResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsGasResponseItemDto) AttributeAddress(org.openmuc.jdlms.AttributeAddress) ArrayList(java.util.ArrayList) 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) PeriodicMeterReadGasResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadGasResponseDto)

Example 5 with PeriodicMeterReadsGasResponseItemDto

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

Aggregations

PeriodicMeterReadsGasResponseItemDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsGasResponseItemDto)10 PeriodTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto)6 PeriodicMeterReadGasResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadGasResponseDto)6 Test (org.junit.jupiter.api.Test)5 DataObject (org.openmuc.jdlms.datatypes.DataObject)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 DateTime (org.joda.time.DateTime)3 AttributeAddress (org.openmuc.jdlms.AttributeAddress)3 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 PeriodicMeterReadsContainerGas (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PeriodicMeterReadsContainerGas)2 ChannelDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelDto)2 PeriodicMeterReadsRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsRequestDto)2 BigDecimal (java.math.BigDecimal)1 Arrays (java.util.Arrays)1 Calendar (java.util.Calendar)1 Collections (java.util.Collections)1 GregorianCalendar (java.util.GregorianCalendar)1