Skip to content

feat: Issue #97 - Standardize relatedLinks Infrastructure with Composition Pattern#99

Merged
dfcoffin merged 3 commits intomainfrom
feature/issue-97-standardize-related-links
Feb 1, 2026
Merged

feat: Issue #97 - Standardize relatedLinks Infrastructure with Composition Pattern#99
dfcoffin merged 3 commits intomainfrom
feature/issue-97-standardize-related-links

Conversation

@dfcoffin
Copy link
Contributor

@dfcoffin dfcoffin commented Feb 1, 2026

Summary

  • Standardizes relatedLinks infrastructure across all 13 ESPI entities using @AssociationOverride
  • Refactors EndDevice/Meter hierarchy from inheritance to composition pattern using Asset + EndDeviceFields @embeddable
  • Resolves Hibernate conflict where MeterEntity couldn't override relatedLinks from parent EndDeviceEntity

Key Technical Changes

Architecture Refactoring:

  • Converted Asset from @MappedSuperclass to @embeddable for composition
  • Created EndDeviceFields @embeddable for 4 EndDevice-specific fields (isVirtual, isPan, installCode, amrSystem)
  • Both EndDeviceEntity and MeterEntity now extend IdentifiedObject directly and embed Asset + EndDeviceFields
  • Used Lombok @DeleGate for transparent field access to embedded objects

Entity Updates (13 entities):

  • Usage Domain: ApplicationInformationEntity, AuthorizationEntity, ElectricPowerQualitySummaryEntity, ReadingTypeEntity
  • Customer Domain: CustomerEntity, CustomerAccountEntity, CustomerAgreementEntity, EndDeviceEntity, MeterEntity, ProgramDateIdMappingsEntity, ServiceLocationEntity, ServiceSupplierEntity, StatementEntity
  • All entities now have explicit @AssociationOverride for separate relatedLinks tables

Mapper Updates:

  • EndDeviceMapper: Updated to map from nested embedded objects (asset., endDeviceFields.)
  • MeterMapper: Updated to map from nested embedded objects (asset., endDeviceFields.)
  • Required because MapStruct annotation processing runs before Lombok @DeleGate

Database Migrations:

  • V1: Added relatedLinks tables for 4 usage domain entities
  • V3: Added relatedLinks tables for 9 customer domain entities, expanded meters table with all IdentifiedObject + Asset + EndDeviceFields columns

Test Plan

  • All 760 unit tests passing
  • H2 in-memory database integration tests: 3 tests passing
  • MySQL TestContainers integration tests: 2 tests passing
  • PostgreSQL TestContainers integration tests: 59 tests passing
  • EndDeviceRepositoryTest: 13 tests passing (CRUD + Asset fields + EndDevice fields)
  • MeterRepositoryTest: 16 tests passing (CRUD + Asset fields + EndDevice fields + Meter fields)
  • All customer domain repository tests: 152 tests passing
  • Flyway migrations verified on all databases (H2, MySQL, PostgreSQL)
  • MapStruct compilation successful with nested property mappings
  • Lombok @DeleGate working correctly for transparent field access

Total: 824+ tests passing across all database platforms

Files Changed

19 files changed (542 insertions, 335 deletions):

  • 11 entity files (Asset, EndDeviceFields, EndDevice, Meter, + 7 customer domain entities)
  • 4 usage domain entities
  • 2 mapper files
  • 2 Flyway migration scripts

Related Issues

Closes #97

🤖 Generated with Claude Code

dfcoffin and others added 3 commits January 31, 2026 15:47
Extended Phase A0 (PREREQUISITE) to include bidirectional Atom links for
EndDevice and Meter entities in addition to the original 4 entities:

Previous (4 entities):
- CustomerAgreement
- ProgramDateIdMappings
- ServiceLocation
- ServiceSupplier

Added (2 additional entities):
- EndDevice
- Meter (inherits from EndDevice)

Investigation confirmed:
- All 6 related_links database tables exist in V3 migration
- All 6 entities lack @ElementCollection mappings for relatedLinks
- Bidirectional relationships required:
  - ServiceLocation ↔ EndDevice
  - ServiceLocation ↔ Meter
  - CustomerAgreement ↔ ProgramDateIdMappings
  - CustomerAgreement ↔ ServiceLocation
  - CustomerAgreement ↔ ServiceSupplier

Per NAESB ESPI 4.0 standard, these relationships are implemented via
Atom <link rel="related"> elements, not via customer.xsd definitions.

Related to #28 (Phase 17: ProgramDateIdMappings)
…ition Pattern

Implements Issue #97 to standardize relatedLinks infrastructure across all ESPI entities
using @AssociationOverride and composition pattern with Lombok @DeleGate.

Key Changes:
- Converted Asset from @MappedSuperclass to @embeddable for composition
- Created EndDeviceFields @embeddable for 4 EndDevice-specific fields
- Refactored EndDeviceEntity and MeterEntity to use composition instead of inheritance
- Both entities now embed Asset + EndDeviceFields with @DeleGate for transparent access
- Added @AssociationOverride to 13 entities (4 usage domain + 9 customer domain)

Entity Changes:
- Usage Domain: ApplicationInformationEntity, AuthorizationEntity,
  ElectricPowerQualitySummaryEntity, ReadingTypeEntity
- Customer Domain: CustomerEntity, CustomerAccountEntity, CustomerAgreementEntity,
  EndDeviceEntity, MeterEntity, ProgramDateIdMappingsEntity, ServiceLocationEntity,
  ServiceSupplierEntity, StatementEntity

Mapper Updates:
- EndDeviceMapper: Updated to map from nested embedded objects (asset.*, endDeviceFields.*)
- MeterMapper: Updated to map from nested embedded objects (asset.*, endDeviceFields.*)
- Required because MapStruct runs before Lombok @DeleGate generates delegation methods

Database Migrations:
- V1__Create_Base_Tables.sql: Added relatedLinks tables for usage domain entities
- V3__Create_additiional_Base_Tables.sql: Added relatedLinks tables for customer domain,
  expanded meters table with all IdentifiedObject, Asset, and EndDeviceFields columns

Technical Details:
- Resolved Hibernate inheritance conflict where MeterEntity couldn't override relatedLinks
- Used composition (HAS-A) instead of inheritance (IS-A) per NAESB ESPI 4.0 customer.xsd
- Lombok @DeleGate provides transparent access to embedded fields for service layer
- Each entity now has separate relatedLinks join table via @AssociationOverride

Test Results:
- All 760 unit tests passing
- H2 in-memory database integration: 3 tests passing
- MySQL TestContainers integration: 2 tests passing
- PostgreSQL TestContainers integration: 59 tests passing
- Total: 824+ tests passing across all database platforms

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Added JPA mapping guideline for entity toString() method sequencing to ensure
consistency with database schema definitions.

Guideline enforces that toString() methods must follow exact database field
sequence from Flyway migration scripts:
- Standard sequence: id, description, created, updated, published, upLink,
  selfLink, [type-specific fields in database column order], relatedLinks
- Ensures toString() output matches CREATE TABLE statement column order
- Improves debugging and log readability by maintaining schema alignment

This guideline supports Issue #97 relatedLinks standardization work where
consistent field ordering across entities is critical.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@dfcoffin dfcoffin merged commit fe77497 into main Feb 1, 2026
5 checks passed
@dfcoffin dfcoffin deleted the feature/issue-97-standardize-related-links branch February 1, 2026 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Standardize relatedLinks Infrastructure Across All Entities

1 participant