Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<sonar.organization>gridsuite</sonar.organization>
<sonar.projectKey>org.gridsuite:network-modification-server</sonar.projectKey>
<!-- TODO network-modification.version remove when included in gridsuite-dependencies -->
<network-modification.version>0.72.0</network-modification.version>
<network-modification.version>0.73.0-SNAPSHOT</network-modification.version>
<!-- TODO network-store.version remove when included in powsybl-ws-dependencies -->
<network-store-client.version>1.39.0</network-store-client.version>
<!-- FIXME to remove when powsybl-ws-dependencies upgrades to springboot 3.5.9 -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.gridsuite.modification.dto.LineCreationInfos;
import org.gridsuite.modification.dto.LineSegmentInfos;
import org.gridsuite.modification.dto.ModificationInfos;

import jakarta.persistence.*;
import org.gridsuite.modification.server.entities.equipment.modification.FreePropertyEntity;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
* @author Sylvain Bouzols <sylvain.bouzols at rte-france.com>
*/
Expand All @@ -37,6 +41,13 @@ public class LineCreationEntity extends BranchCreationEntity {
@Column(name = "b2")
private Double b2;

@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinTable(
joinColumns = @JoinColumn(name = "line_id"), foreignKey = @ForeignKey(name = "line_id_fk"),
inverseJoinColumns = @JoinColumn(name = "line_segments_id"), inverseForeignKey = @ForeignKey(name = "line_segments_id_fk"),
uniqueConstraints = @UniqueConstraint(name = "line_creation_line_segments_uk", columnNames = {"line_segments_id"}))
private List<LineSegmentEntity> lineSegments;

public LineCreationEntity(LineCreationInfos lineCreationInfos) {
super(lineCreationInfos);
assignAttributes(lineCreationInfos);
Expand All @@ -54,6 +65,19 @@ private void assignAttributes(LineCreationInfos lineCreationInfos) {
b1 = lineCreationInfos.getB1();
g2 = lineCreationInfos.getG2();
b2 = lineCreationInfos.getB2();
lineSegments = assignLineSegments(lineCreationInfos.getLineSegments());
}

private List<LineSegmentEntity> assignLineSegments(List<LineSegmentInfos> lineSegmentInfos) {
List<LineSegmentEntity> updatedLineSegments = lineSegments;

if (updatedLineSegments == null) {
updatedLineSegments = new ArrayList<>();
} else {
updatedLineSegments.clear();
}
updatedLineSegments.addAll(LineSegmentEntity.toLineSegmentEntities(lineSegmentInfos));
return updatedLineSegments;
}

@Override
Expand All @@ -62,7 +86,7 @@ public LineCreationInfos toModificationInfos() {
}

private LineCreationInfos.LineCreationInfosBuilder<?, ?> toLineCreationInfosBuilder() {
LineCreationInfos.LineCreationInfosBuilder<?, ?> builder = LineCreationInfos
return LineCreationInfos
.builder()
.uuid(getId())
.date(getDate())
Expand Down Expand Up @@ -98,9 +122,8 @@ public LineCreationInfos toModificationInfos() {
getProperties().stream()
.map(FreePropertyEntity::toInfos)
.toList())
.operationalLimitsGroups(OperationalLimitsGroupEntity.fromOperationalLimitsGroupsEntities(getOperationalLimitsGroups()));

return builder;
.operationalLimitsGroups(OperationalLimitsGroupEntity.fromOperationalLimitsGroupsEntities(getOperationalLimitsGroups()))
.lineSegments(LineSegmentEntity.fromLineSegmentsEntity(getLineSegments()));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org.gridsuite.modification.server.entities.equipment.creation;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.gridsuite.modification.dto.LineSegmentInfos;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
* @author El Cheikh Bassel <bassel.el-cheikh_externe at rte-france.com>
*/

@NoArgsConstructor
@Getter
@Entity
@Table(name = "line_segments")
@AllArgsConstructor
public class LineSegmentEntity {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "uuid")
private UUID uuid;

@Column(name = "segment_type_id")
private String segmentTypeId;

@Column(name = "segment_distance_value")
private Integer segmentDistanceValue;

@Column(name = "area")
private String area;

@Column(name = "temperature")
private String temperature;

@Column(name = "shape_factor")
private Integer shapeFactor;

public static List<LineSegmentEntity> toLineSegmentEntities(List<LineSegmentInfos> lineSegmentInfos) {
List<LineSegmentEntity> lineSegments = new ArrayList<>();
if (CollectionUtils.isEmpty(lineSegmentInfos)) {
return lineSegments;
}
for (LineSegmentInfos segment : lineSegmentInfos) {
lineSegments.add(new LineSegmentEntity(null,
segment.segmentTypeId(),
segment.segmentDistanceValue(),
segment.area(),
segment.temperature(),
segment.shapeFactor()));
}
return lineSegments;
}

public static List<LineSegmentInfos> fromLineSegmentsEntity(List<LineSegmentEntity> lineSegmentEntities) {
List<LineSegmentInfos> lineSegments = new ArrayList<>();
if (CollectionUtils.isEmpty(lineSegmentEntities)) {
return lineSegments;
}
for (LineSegmentEntity entity : lineSegmentEntities) {
lineSegments.add(
new LineSegmentInfos(entity.segmentTypeId,
entity.segmentDistanceValue,
entity.area, entity.temperature,
entity.shapeFactor));
}
return lineSegments;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
<changeSet author="elcheikhbas (generated)" id="1774347058503-15">
<createTable tableName="line_creation_line_segments">
<column name="line_id" type="UUID">
<constraints nullable="false"/>
</column>
<column name="line_segments_id" type="UUID">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet author="elcheikhbas (generated)" id="1774347058503-16">
<createTable tableName="line_segments">
<column name="uuid" type="UUID">
<constraints nullable="false" primaryKey="true" primaryKeyName="line_segmentsPK"/>
</column>
<column name="area" type="VARCHAR(255)"/>
<column name="segment_distance_value" type="INT"/>
<column name="segment_type_id" type="VARCHAR(255)"/>
<column name="shape_factor" type="INT"/>
<column name="temperature" type="VARCHAR(255)"/>
</createTable>
</changeSet>
<changeSet author="elcheikhbas (generated)" id="1774347058503-17">
<addUniqueConstraint columnNames="line_segments_id" constraintName="line_creation_line_segments_uk" tableName="line_creation_line_segments"/>
</changeSet>
<changeSet author="elcheikhbas (generated)" id="1774347058503-18">
<addForeignKeyConstraint baseColumnNames="line_id" baseTableName="line_creation_line_segments" constraintName="line_id_fk" deferrable="false" initiallyDeferred="false" referencedColumnNames="id" referencedTableName="line_creation" validate="true"/>
</changeSet>
<changeSet author="elcheikhbas (generated)" id="1774347058503-19">
<addForeignKeyConstraint baseColumnNames="line_segments_id" baseTableName="line_creation_line_segments" constraintName="line_segments_id_fk" deferrable="false" initiallyDeferred="false" referencedColumnNames="uuid" referencedTableName="line_segments" validate="true"/>
</changeSet>
</databaseChangeLog>
4 changes: 3 additions & 1 deletion src/main/resources/db/changelog/db.changelog-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -462,4 +462,6 @@ databaseChangeLog:
- include:
file: changesets/changelog_20260304T143540Z.xml
relativeToChangelogFile: true

- include:
file: changesets/changelog_20260324T101024Z.xml
relativeToChangelogFile: true
Loading