Skip to content

Commit 8ecad71

Browse files
authored
refactor: Phase 2 - ReadingType ESPI 4.0 schema compliance (field order)
Reordered ReadingType entity, DTO, and migration fields to match ESPI 4.0 XSD element sequence. Changes: - ReadingTypeEntity: Reordered fields 13-18 to match XSD sequence - ReadingTypeDto: Updated @XmlType propOrder and record components - V1__Create_Base_Tables.sql: Reordered reading_types table columns - All 550 tests passing Part of #28 (Phase 2 of 26) 🤖 Generated with Claude Code
1 parent 701d407 commit 8ecad71

File tree

3 files changed

+68
-70
lines changed

3 files changed

+68
-70
lines changed

openespi-common/src/main/java/org/greenbuttonalliance/espi/common/domain/usage/ReadingTypeEntity.java

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ public class ReadingTypeEntity extends IdentifiedObject {
132132
@Column(name = "time_attribute", length = 50)
133133
private String timeAttribute;
134134

135+
/**
136+
* Time-of-use indicator.
137+
* Used for time-based pricing structures.
138+
*/
139+
@Column(name = "tou", length = 50)
140+
private String tou;
141+
135142
/**
136143
* Unit of measure for the readings.
137144
* Values: WH (watt-hours), W (watts), V (volts), A (amperes), etc.
@@ -146,20 +153,24 @@ public class ReadingTypeEntity extends IdentifiedObject {
146153
@Column(name = "cpp", length = 50)
147154
private String cpp;
148155

156+
/**
157+
* Interharmonic information for power quality measurements.
158+
* Contains details about harmonic distortion.
159+
*/
160+
@Embedded
161+
@AttributeOverrides({
162+
@AttributeOverride(name = "numerator", column = @Column(name = "interharmonic_numerator")),
163+
@AttributeOverride(name = "denominator", column = @Column(name = "interharmonic_denominator"))
164+
})
165+
private ReadingInterharmonic interharmonic;
166+
149167
/**
150168
* Measuring period for the readings.
151169
* Describes the measurement timing characteristics.
152170
*/
153171
@Column(name = "measuring_period", length = 50)
154172
private String measuringPeriod;
155173

156-
/**
157-
* Time-of-use indicator.
158-
* Used for time-based pricing structures.
159-
*/
160-
@Column(name = "tou", length = 50)
161-
private String tou;
162-
163174
/**
164175
* Rational number argument for complex calculations.
165176
* Used for mathematical transformations of readings.
@@ -171,17 +182,6 @@ public class ReadingTypeEntity extends IdentifiedObject {
171182
})
172183
private RationalNumber argument;
173184

174-
/**
175-
* Interharmonic information for power quality measurements.
176-
* Contains details about harmonic distortion.
177-
*/
178-
@Embedded
179-
@AttributeOverrides({
180-
@AttributeOverride(name = "numerator", column = @Column(name = "interharmonic_numerator")),
181-
@AttributeOverride(name = "denominator", column = @Column(name = "interharmonic_denominator"))
182-
})
183-
private ReadingInterharmonic interharmonic;
184-
185185
/**
186186
* Meter readings that use this reading type.
187187
* One-to-many relationship with eager loading for performance.
@@ -253,7 +253,7 @@ public void merge(ReadingTypeEntity other) {
253253
if (other != null) {
254254
super.merge(other);
255255

256-
// Update all reading type characteristics
256+
// Update all reading type characteristics (in XSD sequence order)
257257
this.accumulationBehaviour = other.accumulationBehaviour;
258258
this.commodity = other.commodity;
259259
this.consumptionTier = other.consumptionTier;
@@ -266,14 +266,12 @@ public void merge(ReadingTypeEntity other) {
266266
this.phase = other.phase;
267267
this.powerOfTenMultiplier = other.powerOfTenMultiplier;
268268
this.timeAttribute = other.timeAttribute;
269+
this.tou = other.tou;
269270
this.uom = other.uom;
270271
this.cpp = other.cpp;
272+
this.interharmonic = other.interharmonic;
271273
this.measuringPeriod = other.measuringPeriod;
272-
this.tou = other.tou;
273-
274-
// Update embedded values
275274
this.argument = other.argument;
276-
this.interharmonic = other.interharmonic;
277275

278276
// Note: meterReadings collection is not merged to preserve existing relationships
279277
}
@@ -437,12 +435,12 @@ public String toString() {
437435
"phase = " + getPhase() + ", " +
438436
"powerOfTenMultiplier = " + getPowerOfTenMultiplier() + ", " +
439437
"timeAttribute = " + getTimeAttribute() + ", " +
438+
"tou = " + getTou() + ", " +
440439
"uom = " + getUom() + ", " +
441440
"cpp = " + getCpp() + ", " +
441+
"interharmonic = " + getInterharmonic() + ", " +
442442
"measuringPeriod = " + getMeasuringPeriod() + ", " +
443-
"tou = " + getTou() + ", " +
444443
"argument = " + getArgument() + ", " +
445-
"interharmonic = " + getInterharmonic() + ", " +
446444
"description = " + getDescription() + ", " +
447445
"created = " + getCreated() + ", " +
448446
"updated = " + getUpdated() + ", " +

openespi-common/src/main/java/org/greenbuttonalliance/espi/common/dto/usage/ReadingTypeDto.java

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
@XmlRootElement(name = "ReadingType", namespace = "http://naesb.org/espi")
3838
@XmlAccessorType(XmlAccessType.FIELD)
3939
@XmlType(name = "ReadingType", namespace = "http://naesb.org/espi", propOrder = {
40-
"description", "accumulationBehaviour", "commodity", "consumptionTier", "currency",
41-
"dataQualifier", "defaultQuality", "flowDirection", "intervalLength", "kind",
42-
"phase", "powerOfTenMultiplier", "timeAttribute", "uom", "cpp", "measuringPeriod",
43-
"tou", "argument", "interharmonic"
40+
"accumulationBehaviour", "commodity", "consumptionTier", "currency", "dataQualifier",
41+
"defaultQuality", "flowDirection", "intervalLength", "kind", "phase",
42+
"powerOfTenMultiplier", "timeAttribute", "tou", "uom", "cpp", "interharmonic",
43+
"measuringPeriod", "argument"
4444
})
4545
public record ReadingTypeDto(
4646

@@ -205,7 +205,7 @@ public record ReadingTypeDto(
205205

206206
/**
207207
* Time attribute describing the time period of interest.
208-
*
208+
*
209209
* ESPI values:
210210
* - NONE: No specific time context
211211
* - BILLING_PERIOD: Within billing cycle
@@ -218,10 +218,23 @@ public record ReadingTypeDto(
218218
*/
219219
@XmlElement(name = "timeAttribute")
220220
String timeAttribute,
221-
221+
222+
/**
223+
* Time-of-use indicator.
224+
* Used for time-based pricing structures and rate schedules.
225+
*
226+
* Typical utility TOU periods:
227+
* - 1: Peak hours (highest rates)
228+
* - 2: Partial-peak hours (medium rates)
229+
* - 3: Off-peak hours (lowest rates)
230+
* - 0: No TOU pricing
231+
*/
232+
@XmlElement(name = "tou")
233+
String tou,
234+
222235
/**
223236
* Unit of measure for the readings.
224-
*
237+
*
225238
* ESPI electrical units:
226239
* - WH: Watt-hours (energy)
227240
* - W: Watts (power)
@@ -240,23 +253,36 @@ public record ReadingTypeDto(
240253
*/
241254
@XmlElement(name = "uom")
242255
String uom,
243-
256+
244257
/**
245258
* Critical peak pricing indicator.
246259
* Used for demand response programs and peak pricing events.
247-
*
260+
*
248261
* Values typically:
249262
* - 0: Normal pricing
250263
* - 1: Critical peak pricing active
251264
* - 2: Peak pricing warning
252265
*/
253266
@XmlElement(name = "cpp")
254267
String cpp,
255-
268+
269+
/**
270+
* Interharmonic information for power quality measurements.
271+
* Contains details about harmonic distortion and frequency analysis.
272+
*
273+
* Used for:
274+
* - Total harmonic distortion (THD) measurements
275+
* - Individual harmonic analysis
276+
* - Power quality monitoring
277+
* - Frequency domain analysis
278+
*/
279+
@XmlElement(name = "interharmonic")
280+
ReadingInterharmonicDto interharmonic,
281+
256282
/**
257283
* Measuring period for the readings.
258284
* Describes the measurement timing characteristics and sampling.
259-
*
285+
*
260286
* Values describe how measurements are taken:
261287
* - CONTINUOUS: Continuous monitoring
262288
* - INTERVAL: Fixed interval sampling
@@ -265,44 +291,18 @@ public record ReadingTypeDto(
265291
*/
266292
@XmlElement(name = "measuringPeriod")
267293
String measuringPeriod,
268-
269-
/**
270-
* Time-of-use indicator.
271-
* Used for time-based pricing structures and rate schedules.
272-
*
273-
* Typical utility TOU periods:
274-
* - 1: Peak hours (highest rates)
275-
* - 2: Partial-peak hours (medium rates)
276-
* - 3: Off-peak hours (lowest rates)
277-
* - 0: No TOU pricing
278-
*/
279-
@XmlElement(name = "tou")
280-
String tou,
281-
294+
282295
/**
283296
* Rational number argument for complex calculations.
284297
* Used for mathematical transformations and scaling of readings.
285-
*
298+
*
286299
* Common uses:
287300
* - CT/PT ratio transformations
288301
* - Unit conversions
289302
* - Scaling factors for display
290303
*/
291304
@XmlElement(name = "argument")
292-
RationalNumberDto argument,
293-
294-
/**
295-
* Interharmonic information for power quality measurements.
296-
* Contains details about harmonic distortion and frequency analysis.
297-
*
298-
* Used for:
299-
* - Total harmonic distortion (THD) measurements
300-
* - Individual harmonic analysis
301-
* - Power quality monitoring
302-
* - Frequency domain analysis
303-
*/
304-
@XmlElement(name = "interharmonic")
305-
ReadingInterharmonicDto interharmonic
305+
RationalNumberDto argument
306306

307307
) {
308308

openespi-common/src/main/resources/db/migration/V1__Create_Base_Tables.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ CREATE TABLE reading_types
256256
self_link_href VARCHAR(1024),
257257
self_link_type VARCHAR(255),
258258

259-
-- Reading type specific fields
259+
-- Reading type specific fields (in ESPI 4.0 XSD sequence order)
260260
accumulation_behaviour VARCHAR(50),
261261
commodity VARCHAR(50),
262262
consumption_tier VARCHAR(50),
@@ -269,14 +269,14 @@ CREATE TABLE reading_types
269269
phase VARCHAR(50),
270270
power_of_ten_multiplier VARCHAR(50),
271271
time_attribute VARCHAR(50),
272+
tou VARCHAR(50),
272273
uom VARCHAR(50),
273274
cpp VARCHAR(50),
275+
interharmonic_numerator BIGINT,
276+
interharmonic_denominator BIGINT,
274277
measuring_period VARCHAR(50),
275-
tou VARCHAR(50),
276278
argument_numerator DECIMAL(38,0),
277-
argument_denominator DECIMAL(38,0),
278-
interharmonic_numerator BIGINT,
279-
interharmonic_denominator BIGINT
279+
argument_denominator DECIMAL(38,0)
280280
);
281281

282282
CREATE INDEX idx_reading_type_kind ON reading_types (kind);

0 commit comments

Comments
 (0)