Skip to content

Commit ed57206

Browse files
Add column id and column dependencies (#20)
* feat: persist column dependencies * Add column id Signed-off-by: Franck LECUYER <[email protected]> Co-authored-by: Joris Mancini <[email protected]>
1 parent 50b34cd commit ed57206

File tree

10 files changed

+81
-23
lines changed

10 files changed

+81
-23
lines changed

src/main/java/org/gridsuite/studyconfig/server/dto/CustomColumnInfos.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,11 @@ public record CustomColumnInfos(
2020
String name,
2121

2222
@Schema(description = "Column formula")
23-
String formula
23+
String formula,
24+
25+
@Schema(description = "Column dependencies")
26+
String dependencies,
27+
28+
@Schema(description = "Column id")
29+
String id
2430
) { }

src/main/java/org/gridsuite/studyconfig/server/entities/CustomColumnEmbeddable.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ public class CustomColumnEmbeddable {
2626
@Column(name = "formula", columnDefinition = "CLOB")
2727
private String formula;
2828

29+
@Column(name = "dependencies", columnDefinition = "CLOB")
30+
private String dependencies;
31+
32+
@Column(name = "columnId", nullable = false, columnDefinition = "varchar(255)")
33+
private String id;
2934
}

src/main/java/org/gridsuite/studyconfig/server/entities/SpreadsheetConfigEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class SpreadsheetConfigEntity {
4040
name = "spreadsheet_custom_column",
4141
joinColumns = @JoinColumn(name = "spreadsheet_config_id"),
4242
uniqueConstraints = {
43-
@UniqueConstraint(name = "UK_config_id_name", columnNames = {"spreadsheet_config_id", "name"})
43+
@UniqueConstraint(name = "UK_config_id_column_id", columnNames = {"spreadsheet_config_id", "column_id"})
4444
}
4545
)
4646
@OrderColumn(name = "column_order")

src/main/java/org/gridsuite/studyconfig/server/mapper/SpreadsheetConfigMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ public static SpreadsheetConfigEntity toEntity(SpreadsheetConfigInfos dto) {
4949
}
5050

5151
public static CustomColumnInfos toCustomColumnDto(CustomColumnEmbeddable entity) {
52-
return new CustomColumnInfos(entity.getName(), entity.getFormula());
52+
return new CustomColumnInfos(entity.getName(), entity.getFormula(), entity.getDependencies(), entity.getId());
5353
}
5454

5555
public static CustomColumnEmbeddable toCustomColumnEmbeddable(CustomColumnInfos dto) {
56-
return new CustomColumnEmbeddable(dto.name(), dto.formula());
56+
return new CustomColumnEmbeddable(dto.name(), dto.formula(), dto.dependencies(), dto.id());
5757
}
5858
}

src/main/java/org/gridsuite/studyconfig/server/service/SpreadsheetConfigService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public UUID duplicateSpreadsheetConfig(UUID id) {
5454
.map(column -> CustomColumnEmbeddable.builder()
5555
.name(column.getName())
5656
.formula(column.getFormula())
57+
.dependencies(column.getDependencies())
58+
.id(column.getId())
5759
.build())
5860
.toList();
5961

@@ -166,6 +168,8 @@ public UUID duplicateSpreadsheetConfigCollection(UUID id) {
166168
.map(column -> CustomColumnEmbeddable.builder()
167169
.name(column.getName())
168170
.formula(column.getFormula())
171+
.dependencies(column.getDependencies())
172+
.id(column.getId())
169173
.build())
170174
.toList());
171175
return configDuplicate;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
2+
<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">
3+
<changeSet author="lecuyerfra (generated)" id="1737731735521-1">
4+
<sql dbms="postgresql">
5+
TRUNCATE TABLE spreadsheet_config CASCADE;
6+
</sql>
7+
</changeSet>
8+
<changeSet author="lecuyerfra (generated)" id="1737731735521-2">
9+
<sql dbms="postgresql">
10+
TRUNCATE TABLE spreadsheet_config_collection CASCADE;
11+
</sql>
12+
</changeSet>
13+
<changeSet author="lecuyerfra (generated)" id="1737731735521-3">
14+
<addColumn tableName="spreadsheet_custom_column">
15+
<column name="column_id" type="varchar(255)">
16+
<constraints nullable="false"/>
17+
</column>
18+
</addColumn>
19+
</changeSet>
20+
<changeSet author="lecuyerfra (generated)" id="1737731735521-4">
21+
<addUniqueConstraint columnNames="spreadsheet_config_id, column_id" constraintName="UK_config_id_column_id" tableName="spreadsheet_custom_column"/>
22+
</changeSet>
23+
<changeSet author="lecuyerfra (generated)" id="1737731735521-5">
24+
<dropUniqueConstraint constraintName="UK_config_id_name" tableName="spreadsheet_custom_column"/>
25+
</changeSet>
26+
<changeSet author="mancinijor (generated)" id="1737731735521-6">
27+
<addColumn tableName="spreadsheet_custom_column">
28+
<column name="dependencies" type="CLOB"/>
29+
</addColumn>
30+
</changeSet>
31+
</databaseChangeLog>

src/main/resources/db/changelog/db.changelog-master.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ databaseChangeLog:
1111
- include:
1212
file: changesets/changelog_20241211T160640Z.xml
1313
relativeToChangelogFile: true
14+
- include:
15+
file: changesets/changelog_20250124T151522Z.xml
16+
relativeToChangelogFile: true

src/test/java/org/gridsuite/studyconfig/server/DtoConverterTest.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ void testConversionToDtoOfSpreadsheetConfig() {
3434
.id(id)
3535
.sheetType(SheetType.BATTERY)
3636
.customColumns(Arrays.asList(
37-
CustomColumnEmbeddable.builder().name("Column1").formula("A+B").build(),
38-
CustomColumnEmbeddable.builder().name("Column2").formula("C*D").build()
37+
CustomColumnEmbeddable.builder().name("Column1").formula("A+B").id("id1").build(),
38+
CustomColumnEmbeddable.builder().name("Column2").formula("C*D").id("id2").build()
3939
))
4040
.build();
4141

@@ -49,8 +49,10 @@ void testConversionToDtoOfSpreadsheetConfig() {
4949
assertThat(d.customColumns()).hasSize(2);
5050
assertThat(d.customColumns().get(0).name()).isEqualTo("Column1");
5151
assertThat(d.customColumns().get(0).formula()).isEqualTo("A+B");
52+
assertThat(d.customColumns().get(0).id()).isEqualTo("id1");
5253
assertThat(d.customColumns().get(1).name()).isEqualTo("Column2");
5354
assertThat(d.customColumns().get(1).formula()).isEqualTo("C*D");
55+
assertThat(d.customColumns().get(1).id()).isEqualTo("id2");
5456
});
5557
}
5658

@@ -61,8 +63,8 @@ void testConversionToEntityOfSpreadsheetConfig() {
6163
id,
6264
SheetType.BUS,
6365
Arrays.asList(
64-
new CustomColumnInfos("Column1", "X+Y"),
65-
new CustomColumnInfos("Column2", "Z*W")
66+
new CustomColumnInfos("Column1", "X+Y", "[\"col1\", \"col2\"]", "id1"),
67+
new CustomColumnInfos("Column2", "Z*W", "[\"col1\"]", "id2")
6668
)
6769
);
6870

@@ -75,8 +77,12 @@ void testConversionToEntityOfSpreadsheetConfig() {
7577
assertThat(e.getCustomColumns()).hasSize(2);
7678
assertThat(e.getCustomColumns().get(0).getName()).isEqualTo("Column1");
7779
assertThat(e.getCustomColumns().get(0).getFormula()).isEqualTo("X+Y");
80+
assertThat(e.getCustomColumns().get(0).getId()).isEqualTo("id1");
81+
assertThat(e.getCustomColumns().get(0).getDependencies()).isEqualTo("[\"col1\", \"col2\"]");
7882
assertThat(e.getCustomColumns().get(1).getName()).isEqualTo("Column2");
7983
assertThat(e.getCustomColumns().get(1).getFormula()).isEqualTo("Z*W");
84+
assertThat(e.getCustomColumns().get(1).getId()).isEqualTo("id2");
85+
assertThat(e.getCustomColumns().get(1).getDependencies()).isEqualTo("[\"col1\"]");
8086
});
8187
}
8288
}
@@ -88,6 +94,7 @@ void testConversionToDtoOfCustomColumn() {
8894
CustomColumnEmbeddable entity = CustomColumnEmbeddable.builder()
8995
.name("TestColumn")
9096
.formula("A+B+C")
97+
.id("idTest")
9198
.build();
9299

93100
CustomColumnInfos dto = SpreadsheetConfigMapper.toCustomColumnDto(entity);
@@ -97,20 +104,22 @@ void testConversionToDtoOfCustomColumn() {
97104
.satisfies(d -> {
98105
assertThat(d.name()).isEqualTo("TestColumn");
99106
assertThat(d.formula()).isEqualTo("A+B+C");
107+
assertThat(d.id()).isEqualTo("idTest");
100108
});
101109
}
102110

103111
@Test
104112
void testConversionToEmbeddableOfCustomColumn() {
105-
CustomColumnInfos dto = new CustomColumnInfos("TestColumn", "X*Y*Z");
106-
113+
CustomColumnInfos dto = new CustomColumnInfos("TestColumn", "X*Y*Z", "[\"col1\", \"col2\"]", "idTest");
107114
CustomColumnEmbeddable customColumnEmbeddable = SpreadsheetConfigMapper.toCustomColumnEmbeddable(dto);
108115

109116
assertThat(customColumnEmbeddable)
110117
.as("Entity conversion result")
111118
.satisfies(e -> {
112119
assertThat(e.getName()).isEqualTo("TestColumn");
113120
assertThat(e.getFormula()).isEqualTo("X*Y*Z");
121+
assertThat(e.getDependencies()).isEqualTo("[\"col1\", \"col2\"]");
122+
assertThat(e.getId()).isEqualTo("idTest");
114123
});
115124
}
116125
}

src/test/java/org/gridsuite/studyconfig/server/SpreadsheetConfigCollectionIntegrationTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ void testDuplicateCollection() throws Exception {
136136

137137
private List<SpreadsheetConfigInfos> createSpreadsheetConfigs() {
138138
List<CustomColumnInfos> customColumnInfos = Arrays.asList(
139-
new CustomColumnInfos("cust_a", "cust_b + cust_c"),
140-
new CustomColumnInfos("cust_b", "var_minP + 1")
139+
new CustomColumnInfos("cust_a", "cust_b + cust_c", "[\"cust_b\", \"cust_c\"]", "idA"),
140+
new CustomColumnInfos("cust_b", "var_minP + 1", null, "idB")
141141
);
142142

143143
return List.of(
@@ -148,10 +148,10 @@ private List<SpreadsheetConfigInfos> createSpreadsheetConfigs() {
148148

149149
private List<SpreadsheetConfigInfos> createUpdatedSpreadsheetConfigs() {
150150
List<CustomColumnInfos> customColumnInfos = Arrays.asList(
151-
new CustomColumnInfos("cust_a", "cust_b + cust_c"),
152-
new CustomColumnInfos("cust_b", "var_minP + 2"),
153-
new CustomColumnInfos("cust_c", "cust_b + 2"),
154-
new CustomColumnInfos("cust_d", "5 + 1")
151+
new CustomColumnInfos("cust_a", "cust_b + cust_c", "[\"cust_b\", \"cust_c\"]", "idA"),
152+
new CustomColumnInfos("cust_b", "var_minP + 2", null, "idB"),
153+
new CustomColumnInfos("cust_c", "cust_b + 2", "[\"cust_b\"]", "idC"),
154+
new CustomColumnInfos("cust_d", "5 + 1", null, "idD")
155155
);
156156

157157
return List.of(

src/test/java/org/gridsuite/studyconfig/server/SpreadsheetConfigIntegrationTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,18 +232,18 @@ void testDuplicateNonExistent() throws Exception {
232232

233233
private List<CustomColumnInfos> createCustomColumns() {
234234
return Arrays.asList(
235-
new CustomColumnInfos("cust_a", "cust_b + cust_c"),
236-
new CustomColumnInfos("cust_b", "var_minP + 1"),
237-
new CustomColumnInfos("cust_c", "cust_b + 1"),
238-
new CustomColumnInfos("cust_d", "5 + 2")
235+
new CustomColumnInfos("cust_a", "cust_b + cust_c", "[\"cust_b\", \"cust_c\"]", "idA"),
236+
new CustomColumnInfos("cust_b", "var_minP + 1", null, "idB"),
237+
new CustomColumnInfos("cust_c", "cust_b + 1", "[\"cust_b\"]", "idC"),
238+
new CustomColumnInfos("cust_d", "5 + 2", null, "idD")
239239
);
240240
}
241241

242242
private List<CustomColumnInfos> createUpdatedCustomColumns() {
243243
return Arrays.asList(
244-
new CustomColumnInfos("cust_x", "cust_y * 2"),
245-
new CustomColumnInfos("cust_y", "var_maxP - 1"),
246-
new CustomColumnInfos("cust_z", "cust_x / 2")
244+
new CustomColumnInfos("cust_x", "cust_y * 2", "[\"cust_y\"]", "idX"),
245+
new CustomColumnInfos("cust_y", "var_maxP - 1", null, "idY"),
246+
new CustomColumnInfos("cust_z", "cust_x / 2", "[\"cust_x\"]", "idZ")
247247
);
248248
}
249249

0 commit comments

Comments
 (0)