Skip to content

Commit c43883c

Browse files
authored
Merge pull request #1080 from OSGP/feature/SMHE-1613_Get_scaler_from_object_config
SMHE-1613 Get scaler from object config
2 parents 55cef85 + 6953b70 commit c43883c

File tree

64 files changed

+4732
-806
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+4732
-806
lines changed

integration-tests/cucumber-tests-platform-smartmetering/src/test/resources/features/osgp-adapter-ws-smartmetering/monitoring/GetPeriodicMeterReads.feature

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ Feature: SmartMetering Monitoring - Get Periodic Meter Reads
6161
| INTERVAL | 2015-09-01T00:00:00.000Z | 2015-10-01T00:00:00.000Z | TESTG102400000001 | TEST1024000000001 | DSMR | 4.2.2 |
6262
| MONTHLY | 2016-01-01T00:00:00.000Z | 2016-09-01T00:00:00.000Z | TESTG102400000001 | TEST1024000000001 | DSMR | 4.2.2 |
6363
| DAILY | 2022-05-02T00:00:00.000Z | 2022-05-02T00:00:00.000Z | TESTG102400000001 | TEST1024000000001 | DSMR | 4.2.2 |
64+
| INTERVAL | 2015-09-01T00:00:00.000Z | 2015-10-01T00:00:00.000Z | TESTG103100000001 | TEST1031000000001 | SMR | 4.3 |
65+
| MONTHLY | 2016-01-01T00:00:00.000Z | 2016-09-01T00:00:00.000Z | TESTG103100000001 | TEST1031000000001 | SMR | 4.3 |
66+
| DAILY | 2022-05-02T00:00:00.000Z | 2022-05-02T00:00:00.000Z | TESTG103100000001 | TEST1031000000001 | SMR | 4.3 |
6467
| INTERVAL | 2015-09-01T00:00:00.000Z | 2015-10-01T00:00:00.000Z | TESTG102700000001 | TEST1027000000001 | SMR | 5.0.0 |
6568
| MONTHLY | 2016-01-01T00:00:00.000Z | 2016-09-01T00:00:00.000Z | TESTG102700000001 | TEST1027000000001 | SMR | 5.0.0 |
66-
| DAILY | 2022-05-02T00:00:00.000Z | 2022-05-02T00:00:00.000Z | TESTG102700000001 | TEST1027000000001 | SMR | 5.0.0 |
69+
| DAILY | 2022-05-02T00:00:00.000Z | 2022-05-02T00:00:00.000Z | TESTG102700000001 | TEST1027000000001 | SMR | 5.0.0 |
70+
| INTERVAL | 2015-09-01T00:00:00.000Z | 2015-10-01T00:00:00.000Z | TESTG102800000001 | TEST1028000000001 | SMR | 5.1 |
71+
| MONTHLY | 2016-01-01T00:00:00.000Z | 2016-09-01T00:00:00.000Z | TESTG102800000001 | TEST1028000000001 | SMR | 5.1 |
72+
| DAILY | 2022-05-02T00:00:00.000Z | 2022-05-02T00:00:00.000Z | TESTG102800000001 | TEST1028000000001 | SMR | 5.1 |
73+
| INTERVAL | 2015-09-01T00:00:00.000Z | 2015-10-01T00:00:00.000Z | TESTG102900000001 | TEST1029000000001 | SMR | 5.2 |
74+
| MONTHLY | 2016-01-01T00:00:00.000Z | 2016-09-01T00:00:00.000Z | TESTG102900000001 | TEST1029000000001 | SMR | 5.2 |
75+
| DAILY | 2022-05-02T00:00:00.000Z | 2022-05-02T00:00:00.000Z | TESTG102900000001 | TEST1029000000001 | SMR | 5.2 |
76+
| INTERVAL | 2015-09-01T00:00:00.000Z | 2015-10-01T00:00:00.000Z | TESTG103000000001 | TEST1030000000001 | SMR | 5.5 |
77+
| MONTHLY | 2016-01-01T00:00:00.000Z | 2016-09-01T00:00:00.000Z | TESTG103000000001 | TEST1030000000001 | SMR | 5.5 |
78+
| DAILY | 2022-05-02T00:00:00.000Z | 2022-05-02T00:00:00.000Z | TESTG103000000001 | TEST1030000000001 | SMR | 5.5 |

osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/application/services/BundleService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
package org.opensmartgridplatform.adapter.domain.smartmetering.application.services;
66

7+
import static org.opensmartgridplatform.adapter.domain.smartmetering.application.services.util.DeviceModelCodeUtil.createDeviceModelCodes;
8+
79
import java.util.Arrays;
810
import java.util.List;
911
import org.opensmartgridplatform.adapter.domain.smartmetering.application.mapping.ConfigurationMapper;
@@ -81,6 +83,9 @@ public void handleBundle(
8183
final SmartMeter smartMeter =
8284
this.domainHelperService.findSmartMeter(messageMetadata.getDeviceIdentification());
8385

86+
final List<SmartMeter> smartMeters = this.domainHelperService.searchMBusDevicesFor(smartMeter);
87+
final String deviceModelCodes = createDeviceModelCodes(smartMeter, smartMeters);
88+
8489
final BundleMessagesRequestDto requestDto =
8590
this.actionMapperService.mapAllActions(bundleMessageRequest, smartMeter);
8691

@@ -92,6 +97,7 @@ public void handleBundle(
9297
.builder()
9398
.withNetworkAddress(smartMeter.getNetworkAddress())
9499
.withNetworkSegmentIds(smartMeter.getBtsId(), smartMeter.getCellId())
100+
.withDeviceModelCode(deviceModelCodes)
95101
.build());
96102
}
97103

osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/application/services/DomainHelperService.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package org.opensmartgridplatform.adapter.domain.smartmetering.application.services;
66

7+
import java.util.List;
78
import org.opensmartgridplatform.domain.core.entities.SmartMeter;
89
import org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException;
910
import org.opensmartgridplatform.domain.core.services.SmartMeterDomainService;
@@ -56,4 +57,16 @@ public void ensureFunctionalExceptionForUnknownDevice(final String deviceIdentif
5657
*/
5758
this.findSmartMeter(deviceIdentification);
5859
}
60+
61+
/**
62+
* Search the MBus Devices coupled on this SmartMeter.
63+
*
64+
* @param smartMeter
65+
* @return the active device for the given identification
66+
* @throws FunctionalException when the device is not in the database or is not in use
67+
*/
68+
public List<SmartMeter> searchMBusDevicesFor(final SmartMeter smartMeter) {
69+
70+
return this.smartMeteringDeviceDomainService.searchMBusDevicesFor(smartMeter);
71+
}
5972
}

osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/application/services/MonitoringService.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
package org.opensmartgridplatform.adapter.domain.smartmetering.application.services;
66

7+
import static org.opensmartgridplatform.adapter.domain.smartmetering.application.services.util.DeviceModelCodeUtil.createDeviceModelCodes;
8+
9+
import java.util.List;
710
import org.opensmartgridplatform.adapter.domain.smartmetering.application.mapping.MonitoringMapper;
811
import org.opensmartgridplatform.adapter.domain.smartmetering.infra.jms.core.JmsMessageSender;
912
import org.opensmartgridplatform.adapter.domain.smartmetering.infra.jms.ws.WebServiceResponseMessageSender;
@@ -123,15 +126,26 @@ public void requestPeriodicMeterReads(
123126
new AssertionError(
124127
"Meter for gas reads should have an energy meter as gateway device."));
125128
}
129+
130+
final SmartMeter gatewaySmartMeter =
131+
this.domainHelperService.findSmartMeter(gatewayDevice.getDeviceIdentification());
132+
final List<SmartMeter> smartMeters =
133+
this.domainHelperService.searchMBusDevicesFor(gatewaySmartMeter);
134+
final String deviceModelCodes = createDeviceModelCodes(gatewaySmartMeter, smartMeters);
135+
126136
this.osgpCoreRequestMessageSender.send(
127137
requestDto,
128138
messageMetadata
129139
.builder()
130140
.withDeviceIdentification(gatewayDevice.getDeviceIdentification())
131141
.withNetworkAddress(gatewayDevice.getNetworkAddress())
132142
.withNetworkSegmentIds(gatewayDevice.getBtsId(), gatewayDevice.getCellId())
143+
.withDeviceModelCode(deviceModelCodes)
133144
.build());
134145
} else {
146+
final List<SmartMeter> smartMeters =
147+
this.domainHelperService.searchMBusDevicesFor(smartMeter);
148+
final String deviceModelCodes = createDeviceModelCodes(smartMeter, smartMeters);
135149

136150
final PeriodicMeterReadsRequestDto requestDto =
137151
this.monitoringMapper.map(
@@ -142,6 +156,7 @@ public void requestPeriodicMeterReads(
142156
.builder()
143157
.withNetworkAddress(smartMeter.getNetworkAddress())
144158
.withNetworkSegmentIds(smartMeter.getBtsId(), smartMeter.getCellId())
159+
.withDeviceModelCode(deviceModelCodes)
145160
.build());
146161
}
147162
}
@@ -211,7 +226,6 @@ public void requestActualMeterReads(
211226

212227
final SmartMeter smartMeter =
213228
this.domainHelperService.findSmartMeter(messageMetadata.getDeviceIdentification());
214-
215229
if (actualMeterReadsQuery.isMbusDevice()) {
216230

217231
if (smartMeter.getChannel() == null) {
@@ -240,6 +254,13 @@ public void requestActualMeterReads(
240254
new AssertionError(
241255
"Meter for gas reads should have an energy meter as gateway device."));
242256
}
257+
258+
final SmartMeter gatewaySmartMeter =
259+
this.domainHelperService.findSmartMeter(gatewayDevice.getDeviceIdentification());
260+
final List<SmartMeter> smartMeters =
261+
this.domainHelperService.searchMBusDevicesFor(gatewaySmartMeter);
262+
final String deviceModelCodes = createDeviceModelCodes(gatewaySmartMeter, smartMeters);
263+
243264
final ActualMeterReadsQueryDto requestDto =
244265
new ActualMeterReadsQueryDto(ChannelDto.fromNumber(smartMeter.getChannel()));
245266
this.osgpCoreRequestMessageSender.send(
@@ -249,14 +270,21 @@ public void requestActualMeterReads(
249270
.withDeviceIdentification(gatewayDevice.getDeviceIdentification())
250271
.withNetworkAddress(gatewayDevice.getNetworkAddress())
251272
.withNetworkSegmentIds(gatewayDevice.getBtsId(), gatewayDevice.getCellId())
273+
.withDeviceModelCode(deviceModelCodes)
252274
.build());
253275
} else {
276+
277+
final List<SmartMeter> smartMeters =
278+
this.domainHelperService.searchMBusDevicesFor(smartMeter);
279+
final String deviceModelCodes = createDeviceModelCodes(smartMeter, smartMeters);
280+
254281
this.osgpCoreRequestMessageSender.send(
255282
new ActualMeterReadsQueryDto(),
256283
messageMetadata
257284
.builder()
258285
.withNetworkAddress(smartMeter.getNetworkAddress())
259286
.withNetworkSegmentIds(smartMeter.getBtsId(), smartMeter.getCellId())
287+
.withDeviceModelCode(deviceModelCodes)
260288
.build());
261289
}
262290
}
@@ -323,6 +351,9 @@ public void requestActualPowerQuality(
323351
final SmartMeter smartMeter =
324352
this.domainHelperService.findSmartMeter(messageMetadata.getDeviceIdentification());
325353

354+
final List<SmartMeter> smartMeters = this.domainHelperService.searchMBusDevicesFor(smartMeter);
355+
final String deviceModelCodes = createDeviceModelCodes(smartMeter, smartMeters);
356+
326357
final ActualPowerQualityRequestDto requestDto =
327358
this.monitoringMapper.map(request, ActualPowerQualityRequestDto.class);
328359

@@ -332,6 +363,7 @@ public void requestActualPowerQuality(
332363
.builder()
333364
.withNetworkAddress(smartMeter.getNetworkAddress())
334365
.withNetworkSegmentIds(smartMeter.getBtsId(), smartMeter.getCellId())
366+
.withDeviceModelCode(deviceModelCodes)
335367
.build());
336368
}
337369

@@ -430,6 +462,9 @@ public void requestPowerQualityProfile(
430462
final SmartMeter smartMeter =
431463
this.domainHelperService.findSmartMeter(messageMetadata.getDeviceIdentification());
432464

465+
final List<SmartMeter> smartMeters = this.domainHelperService.searchMBusDevicesFor(smartMeter);
466+
final String deviceModelCodes = createDeviceModelCodes(smartMeter, smartMeters);
467+
433468
final ConfigureDefinableLoadProfileRequestDto requestDto =
434469
this.monitoringMapper.map(request, ConfigureDefinableLoadProfileRequestDto.class);
435470

@@ -439,6 +474,7 @@ public void requestPowerQualityProfile(
439474
.builder()
440475
.withNetworkAddress(smartMeter.getNetworkAddress())
441476
.withNetworkSegmentIds(smartMeter.getBtsId(), smartMeter.getCellId())
477+
.withDeviceModelCode(deviceModelCodes)
442478
.build());
443479
}
444480

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// SPDX-FileCopyrightText: Copyright Contributors to the GXF project
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
package org.opensmartgridplatform.adapter.domain.smartmetering.application.services.util;
5+
6+
import java.util.List;
7+
import org.opensmartgridplatform.domain.core.entities.SmartMeter;
8+
9+
public class DeviceModelCodeUtil {
10+
private DeviceModelCodeUtil() {
11+
/// static class
12+
}
13+
14+
public static String createDeviceModelCodes(
15+
final SmartMeter gatewayDevice, final List<SmartMeter> mbusDevices) {
16+
17+
final String emetercode =
18+
gatewayDevice.getDeviceModel() != null ? gatewayDevice.getDeviceModel().getModelCode() : "";
19+
final String mbus1code = getAndMapMbusChannelSmartMeter(mbusDevices, 1);
20+
final String mbus2code = getAndMapMbusChannelSmartMeter(mbusDevices, 2);
21+
final String mbus3code = getAndMapMbusChannelSmartMeter(mbusDevices, 3);
22+
final String mbus4code = getAndMapMbusChannelSmartMeter(mbusDevices, 4);
23+
24+
return String.format("%s,%s,%s,%s,%s", emetercode, mbus1code, mbus2code, mbus3code, mbus4code);
25+
}
26+
27+
private static String getAndMapMbusChannelSmartMeter(
28+
final List<SmartMeter> mbusDevices, final int channel) {
29+
return mbusDevices.stream()
30+
.filter(m -> m.getChannel() != null && m.getChannel() == channel)
31+
.map(m -> m.getDeviceModel() != null ? m.getDeviceModel().getModelCode() : "")
32+
.map(s -> s.replace(",", "")) // no comma's signs
33+
.findAny()
34+
.orElse("");
35+
}
36+
}

osgp/platform/osgp-adapter-domain-smartmetering/src/test/java/org/opensmartgridplatform/adapter/domain/smartmetering/application/services/MeterReadsGasMappingTest.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
import org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsUnitTypeDto;
1818
import org.opensmartgridplatform.dto.valueobjects.smartmetering.MeterReadsGasResponseDto;
1919

20-
public class MeterReadsGasMappingTest {
20+
class MeterReadsGasMappingTest {
2121

2222
private final MonitoringMapper monitoringMapper = new MonitoringMapper();
2323

2424
// Test the mapping of a complete MeterReadsGasDto object
2525
@Test
26-
public void testMeterReadsGasMappingTest() {
26+
void testMeterReadsGasMappingTest() {
2727
// build test data
2828
final DlmsMeterValueDto consumption =
29-
new DlmsMeterValueDto(new BigDecimal(1.0), DlmsUnitTypeDto.M3);
29+
new DlmsMeterValueDto(new BigDecimal("1.0"), DlmsUnitTypeDto.M3);
3030
final MeterReadsGasResponseDto meterReadsGasDto =
3131
new MeterReadsGasResponseDto(new Date(), consumption, new Date());
3232
// actual mapping
@@ -39,13 +39,35 @@ public void testMeterReadsGasMappingTest() {
3939

4040
final BigDecimal bigDecimal1 = consumption.getValue();
4141
final BigDecimal bigDecimal2 = meterReadsGas.getConsumption().getValue();
42-
assertThat(bigDecimal1.compareTo(bigDecimal2) == 0).isTrue();
42+
assertThat(bigDecimal1).isEqualByComparingTo(bigDecimal2);
43+
assertThat(meterReadsGas.getConsumption().getOsgpUnit()).isEqualTo(OsgpUnit.M3);
44+
}
45+
46+
// Test the mapping of a complete MeterReadsGasDto object without a capture time
47+
@Test
48+
void testMeterReadsGasMappingWithoutCaptureTimeTest() {
49+
// build test data
50+
final DlmsMeterValueDto consumption =
51+
new DlmsMeterValueDto(new BigDecimal("1.0"), DlmsUnitTypeDto.M3);
52+
final MeterReadsGasResponseDto meterReadsGasDto =
53+
new MeterReadsGasResponseDto(new Date(), consumption, null);
54+
// actual mapping
55+
final MeterReadsGas meterReadsGas =
56+
this.monitoringMapper.map(meterReadsGasDto, MeterReadsGas.class);
57+
// test mapping
58+
assertThat(meterReadsGas).isNotNull();
59+
assertThat(meterReadsGas.getLogTime()).isEqualTo(meterReadsGasDto.getLogTime());
60+
assertThat(meterReadsGas.getCaptureTime()).isNull();
61+
62+
final BigDecimal bigDecimal1 = consumption.getValue();
63+
final BigDecimal bigDecimal2 = meterReadsGas.getConsumption().getValue();
64+
assertThat(bigDecimal1).isEqualByComparingTo(bigDecimal2);
4365
assertThat(meterReadsGas.getConsumption().getOsgpUnit()).isEqualTo(OsgpUnit.M3);
4466
}
4567

4668
// Test mapping when DlmsMeterValue is null;
4769
@Test
48-
public void testWithNullDlmsMeterValueDto() {
70+
void testWithNullDlmsMeterValueDto() {
4971
// build test data
5072
final DlmsMeterValueDto consumption = null;
5173
final MeterReadsGasResponseDto meterReadsGasDto =
@@ -63,7 +85,7 @@ public void testWithNullDlmsMeterValueDto() {
6385
// Dates can never be null, because of the way the constructor for a
6486
// MeterReadsGasDto is defined.
6587
@Test
66-
public void testWithNullDates() {
88+
void testWithNullDates() {
6789
final DlmsMeterValueDto consumption =
6890
new DlmsMeterValueDto(new BigDecimal(1.0), DlmsUnitTypeDto.M3);
6991
assertThatExceptionOfType(NullPointerException.class)

0 commit comments

Comments
 (0)