diff --git a/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/BranchCreationEntity.java b/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/BranchCreationEntity.java index 9d8cf0b7e..84038b1a9 100644 --- a/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/BranchCreationEntity.java +++ b/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/BranchCreationEntity.java @@ -71,7 +71,7 @@ public class BranchCreationEntity extends EquipmentCreationEntity { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinTable( joinColumns = @JoinColumn(name = "branch_id"), foreignKey = @ForeignKey(name = "branch_id_fk"), - inverseJoinColumns = @JoinColumn(name = "operational_limits_groups_id"), inverseForeignKey = @ForeignKey(name = "operational_limits_groups_id_fk")) + inverseJoinColumns = @JoinColumn(name = "operational_limits_groups_id"), inverseForeignKey = @ForeignKey(name = "operational_limits_groups_creation_id_fk")) @OrderColumn(name = "pos_operationalLimitsGroups") private List operationalLimitsGroups; diff --git a/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/VscCreationEntity.java b/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/VscCreationEntity.java index e2caddaee..95b09e054 100644 --- a/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/VscCreationEntity.java +++ b/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/VscCreationEntity.java @@ -60,7 +60,7 @@ public class VscCreationEntity extends EquipmentCreationEntity { name = "converter_station_1_id", referencedColumnName = "id", foreignKey = @ForeignKey( - name = "converter_station_1_id_fk" + name = "converter_station_creation_1_id_fk" )) private ConverterStationCreationEntity converterStation1; @@ -69,7 +69,7 @@ public class VscCreationEntity extends EquipmentCreationEntity { name = "converter_station_2_id", referencedColumnName = "id", foreignKey = @ForeignKey( - name = "converter_station_2_id_fk" + name = "converter_station_creation_2_id_fk" )) private ConverterStationCreationEntity converterStation2; diff --git a/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/BranchModificationEntity.java b/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/BranchModificationEntity.java index fd97592d1..2c159d809 100644 --- a/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/BranchModificationEntity.java +++ b/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/BranchModificationEntity.java @@ -41,7 +41,7 @@ public class BranchModificationEntity extends BasicEquipmentModificationEntity { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinTable( joinColumns = @JoinColumn(name = "branch_id"), foreignKey = @ForeignKey(name = "branch_modification_id_fk"), - inverseJoinColumns = @JoinColumn(name = "operational_limits_groups_id"), inverseForeignKey = @ForeignKey(name = "operational_limits_groups_id_fk")) + inverseJoinColumns = @JoinColumn(name = "operational_limits_groups_id"), inverseForeignKey = @ForeignKey(name = "operational_limits_groups_modification_id_fk")) @OrderColumn(name = "pos_operationalLimitsGroups") private List operationalLimitsGroups; diff --git a/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/EquipmentModificationEntity.java b/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/EquipmentModificationEntity.java index 050d0be72..46533b504 100644 --- a/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/EquipmentModificationEntity.java +++ b/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/EquipmentModificationEntity.java @@ -13,6 +13,7 @@ import org.gridsuite.modification.dto.ModificationInfos; import org.gridsuite.modification.server.entities.ModificationEntity; +import java.util.ArrayList; import java.util.List; /** @@ -25,10 +26,9 @@ public class EquipmentModificationEntity extends ModificationEntity { @Column(name = "equipmentId") private String equipmentId; - @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "equipment_modification_id") + @OneToMany(mappedBy = "modification", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) @OrderColumn(name = "insert_position") - private List properties; + private List properties = new ArrayList<>(); protected EquipmentModificationEntity(EquipmentModificationInfos equipmentModificationInfos) { super(equipmentModificationInfos); @@ -45,8 +45,11 @@ private void assignAttributes(EquipmentModificationInfos equipmentModificationIn equipmentId = equipmentModificationInfos.getEquipmentId(); List newProperties = equipmentModificationInfos.getProperties() == null ? null : equipmentModificationInfos.getProperties().stream() - .map(FreePropertyEntity::new) - .toList(); + .map(info -> { + FreePropertyEntity entity = new FreePropertyEntity(info); + entity.setModification(this); + return entity; + }).toList(); if (this.properties != null) { // update using the same reference with clear/add (to avoid JPA exception) this.properties.clear(); @@ -54,7 +57,7 @@ private void assignAttributes(EquipmentModificationInfos equipmentModificationIn this.properties.addAll(newProperties); } } else { - this.properties = newProperties; + this.properties = (newProperties != null) ? new ArrayList<>(newProperties) : new ArrayList<>(); } } } diff --git a/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/FreePropertyEntity.java b/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/FreePropertyEntity.java index bbc2e2698..c11ff58a3 100644 --- a/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/FreePropertyEntity.java +++ b/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/FreePropertyEntity.java @@ -11,15 +11,18 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; import lombok.experimental.SuperBuilder; +import org.gridsuite.modification.dto.FreePropertyInfos; +import org.gridsuite.modification.server.entities.ModificationEntity; import java.util.UUID; -import org.gridsuite.modification.dto.FreePropertyInfos; /** * @author Joris Mancini */ @Getter +@Setter @NoArgsConstructor @AllArgsConstructor @SuperBuilder @@ -46,6 +49,10 @@ public class FreePropertyEntity { @Column(name = "previous_value") private String previousValue; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "equipment_modification_id", referencedColumnName = "id", foreignKey = @ForeignKey(name = "free_property_modification_id_fk_constraint")) + private ModificationEntity modification; + public FreePropertyInfos toInfos() { return FreePropertyInfos.builder() .name(name) @@ -57,6 +64,7 @@ public FreePropertyInfos toInfos() { } public FreePropertyEntity(FreePropertyInfos freePropertyInfos) { - this(null, freePropertyInfos.getName(), freePropertyInfos.getValue(), freePropertyInfos.isDeletionMark(), freePropertyInfos.isAdded(), freePropertyInfos.getPreviousValue()); + this(null, freePropertyInfos.getName(), freePropertyInfos.getValue(), freePropertyInfos.isDeletionMark(), + freePropertyInfos.isAdded(), freePropertyInfos.getPreviousValue(), null); } } diff --git a/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/VscModificationEntity.java b/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/VscModificationEntity.java index 87c5e4e4f..c026baee7 100644 --- a/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/VscModificationEntity.java +++ b/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/VscModificationEntity.java @@ -104,7 +104,7 @@ public class VscModificationEntity extends BasicEquipmentModificationEntity { name = "converter_station_1_id", referencedColumnName = "id", foreignKey = @ForeignKey( - name = "converter_station_1_id_fk" + name = "converter_station_modification_1_id_fk" )) private ConverterStationModificationEntity converterStation1; @@ -113,7 +113,7 @@ public class VscModificationEntity extends BasicEquipmentModificationEntity { name = "converter_station_2_id", referencedColumnName = "id", foreignKey = @ForeignKey( - name = "converter_station_2_id_fk" + name = "converter_station_modification_2_id_fk" )) private ConverterStationModificationEntity converterStation2; diff --git a/src/main/resources/db/changelog/changesets/changelog_20251021T145023Z.xml b/src/main/resources/db/changelog/changesets/changelog_20251021T145023Z.xml new file mode 100644 index 000000000..22187e9cb --- /dev/null +++ b/src/main/resources/db/changelog/changesets/changelog_20251021T145023Z.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/db/changelog/db.changelog-master.yaml b/src/main/resources/db/changelog/db.changelog-master.yaml index d4ebfc89d..b5c23af9b 100644 --- a/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/src/main/resources/db/changelog/db.changelog-master.yaml @@ -435,3 +435,6 @@ databaseChangeLog: - include: file: changesets/changelog_20251104T150402Z.xml relativeToChangelogFile: true + - include: + file: changesets/changelog_20251021T145023Z.xml + relativeToChangelogFile: true diff --git a/src/test/java/org/gridsuite/modification/server/service/ModificationRepositoryTest.java b/src/test/java/org/gridsuite/modification/server/service/ModificationRepositoryTest.java index efca3a6e7..b2cce1733 100644 --- a/src/test/java/org/gridsuite/modification/server/service/ModificationRepositoryTest.java +++ b/src/test/java/org/gridsuite/modification/server/service/ModificationRepositoryTest.java @@ -768,7 +768,7 @@ void testSubstationCreation() { SQLStatementCountValidator.reset(); networkModificationRepository.deleteModificationGroup(TEST_GROUP_ID, true); - assertRequestsCount(5, 0, 2, 4); + assertRequestsCount(5, 0, 1, 4); assertThrows(NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, false, true), new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage());