Skip to content

Commit feadb3d

Browse files
authored
Change sheet type values and use OrderColumn (#5)
Signed-off-by: David BRAQUART <[email protected]>
1 parent d2b12d0 commit feadb3d

File tree

6 files changed

+70
-35
lines changed

6 files changed

+70
-35
lines changed

src/main/java/org/gridsuite/spreadsheetconfig/server/constants/SheetType.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,24 @@
99
/**
1010
* @author Achour BERRAHMA <achour.berrahma at rte-france.com>
1111
*/
12+
13+
// Must be in-sync with EQUIPMENT_TYPES in spreadsheet front component
1214
public enum SheetType {
13-
SUBSTATIONS,
14-
VOLTAGE_LEVELS,
15-
LINES,
16-
TWO_WINDINGS_TRANSFORMERS,
17-
THREE_WINDINGS_TRANSFORMERS,
18-
GENERATORS,
19-
LOADS,
20-
SHUNT_COMPENSATORS,
21-
STATIC_VAR_COMPENSATORS,
22-
BATTERIES,
23-
HVDC_LINES,
24-
LCC_CONVERTER_STATIONS,
25-
VSC_CONVERTER_STATIONS,
26-
DANGLING_LINES,
27-
BUSES,
28-
TIE_LINES
15+
SUBSTATION,
16+
VOLTAGE_LEVEL,
17+
LINE,
18+
TWO_WINDINGS_TRANSFORMER,
19+
THREE_WINDINGS_TRANSFORMER,
20+
GENERATOR,
21+
LOAD,
22+
SHUNT_COMPENSATOR,
23+
STATIC_VAR_COMPENSATOR,
24+
BATTERY,
25+
HVDC_LINE,
26+
LCC_CONVERTER_STATION,
27+
VSC_CONVERTER_STATION,
28+
DANGLING_LINE,
29+
BUS,
30+
TIE_LINE
2931
}
32+

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@ public class SpreadsheetConfigEntity {
3838
@ElementCollection
3939
@CollectionTable(
4040
name = "spreadsheet_custom_column",
41-
joinColumns = @JoinColumn(name = "spreadsheet_config_id")
41+
joinColumns = @JoinColumn(name = "spreadsheet_config_id"),
42+
uniqueConstraints = {
43+
@UniqueConstraint(name = "UK_config_id_name", columnNames = {"spreadsheet_config_id", "name"})
44+
}
4245
)
46+
@OrderColumn(name = "column_order")
4347
@Builder.Default
4448
private List<CustomColumnEmbeddable> customColumns = new ArrayList<>();
4549

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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="braquartdav (generated)" id="1729252344073-1">
4+
<dropPrimaryKey tableName="spreadsheet_custom_column"/>
5+
</changeSet>
6+
<changeSet author="braquartdav (generated)" id="1729252344073-3">
7+
<addColumn tableName="spreadsheet_custom_column">
8+
<column name="column_order" type="integer">
9+
<constraints nullable="false"/>
10+
</column>
11+
</addColumn>
12+
</changeSet>
13+
<changeSet author="braquartdav (generated)" id="1729252344073-4">
14+
<addUniqueConstraint columnNames="spreadsheet_config_id, name" constraintName="UK_config_id_name" tableName="spreadsheet_custom_column"/>
15+
</changeSet>
16+
<changeSet author="braquartdav (generated)" id="1729252344073-5">
17+
<createIndex indexName="IX_spreadsheet_custom_columnPK" tableName="spreadsheet_custom_column" unique="true">
18+
<column name="spreadsheet_config_id"/>
19+
<column name="column_order"/>
20+
</createIndex>
21+
</changeSet>
22+
<changeSet author="braquartdav (generated)" id="1729252344073-2">
23+
<addPrimaryKey columnNames="spreadsheet_config_id, column_order" constraintName="spreadsheet_custom_columnPK" tableName="spreadsheet_custom_column"/>
24+
</changeSet>
25+
</databaseChangeLog>
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
databaseChangeLog:
22
- include:
33
file: changesets/create-spreadsheet-config-table.xml
4-
relativeToChangelogFile: true
4+
relativeToChangelogFile: true
5+
- include:
6+
file: changesets/changelog_20241018T115212Z.xml
7+
relativeToChangelogFile: true

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void testConversionToDtoOfSpreadsheetConfig() {
3232
UUID id = UUID.randomUUID();
3333
SpreadsheetConfigEntity entity = SpreadsheetConfigEntity.builder()
3434
.id(id)
35-
.sheetType(SheetType.BATTERIES)
35+
.sheetType(SheetType.BATTERY)
3636
.customColumns(Arrays.asList(
3737
CustomColumnEmbeddable.builder().name("Column1").formula("A+B").build(),
3838
CustomColumnEmbeddable.builder().name("Column2").formula("C*D").build()
@@ -45,7 +45,7 @@ void testConversionToDtoOfSpreadsheetConfig() {
4545
.as("DTO conversion result")
4646
.satisfies(d -> {
4747
assertThat(d.id()).isEqualTo(id);
48-
assertThat(d.sheetType()).isEqualTo(SheetType.BATTERIES);
48+
assertThat(d.sheetType()).isEqualTo(SheetType.BATTERY);
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");
@@ -59,7 +59,7 @@ void testConversionToEntityOfSpreadsheetConfig() {
5959
UUID id = UUID.randomUUID();
6060
SpreadsheetConfigInfos dto = new SpreadsheetConfigInfos(
6161
id,
62-
SheetType.BUSES,
62+
SheetType.BUS,
6363
Arrays.asList(
6464
new CustomColumnInfos("Column1", "X+Y"),
6565
new CustomColumnInfos("Column2", "Z*W")
@@ -72,7 +72,7 @@ void testConversionToEntityOfSpreadsheetConfig() {
7272
.as("Entity conversion result")
7373
.satisfies(e -> {
7474
assertThat(e.getId()).isEqualTo(id);
75-
assertThat(e.getSheetType()).isEqualTo(SheetType.BUSES);
75+
assertThat(e.getSheetType()).isEqualTo(SheetType.BUS);
7676
assertThat(e.getCustomColumns()).hasSize(2);
7777
assertThat(e.getCustomColumns().get(0).getName()).isEqualTo("Column1");
7878
assertThat(e.getCustomColumns().get(0).getFormula()).isEqualTo("X+Y");

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void tearDown() {
6060

6161
@Test
6262
void testCreate() throws Exception {
63-
SpreadsheetConfigInfos configToCreate = new SpreadsheetConfigInfos(null, SheetType.BATTERIES, createCustomColumns());
63+
SpreadsheetConfigInfos configToCreate = new SpreadsheetConfigInfos(null, SheetType.BATTERY, createCustomColumns());
6464

6565
UUID configUuid = postSpreadsheetConfig(configToCreate);
6666
SpreadsheetConfigInfos createdConfig = getSpreadsheetConfig(configUuid);
@@ -86,7 +86,7 @@ void testCreateWithInvalidData() throws Exception {
8686

8787
@Test
8888
void testRead() throws Exception {
89-
SpreadsheetConfigInfos configToRead = new SpreadsheetConfigInfos(null, SheetType.BUSES, createCustomColumns());
89+
SpreadsheetConfigInfos configToRead = new SpreadsheetConfigInfos(null, SheetType.BUS, createCustomColumns());
9090

9191
UUID configUuid = saveAndReturnId(configToRead);
9292

@@ -101,15 +101,15 @@ void testRead() throws Exception {
101101

102102
@Test
103103
void testGetMetadata() throws Exception {
104-
SpreadsheetConfigInfos configToRead = new SpreadsheetConfigInfos(null, SheetType.BUSES, createCustomColumns());
104+
SpreadsheetConfigInfos configToRead = new SpreadsheetConfigInfos(null, SheetType.BUS, createCustomColumns());
105105

106106
UUID configUuid = saveAndReturnId(configToRead);
107107

108108
List<MetadataInfos> metadata = getMetadataInfos(configUuid);
109109

110110
assertThat(metadata).hasSize(1);
111111
assertThat(metadata.get(0).id()).isEqualTo(configUuid);
112-
assertThat(metadata.get(0).sheetType()).isEqualTo(SheetType.BUSES);
112+
assertThat(metadata.get(0).sheetType()).isEqualTo(SheetType.BUS);
113113

114114
}
115115

@@ -121,7 +121,7 @@ private List<MetadataInfos> getMetadataInfos(UUID configUuid) throws Exception {
121121

122122
return mapper.readValue(
123123
receivedMetadata.getResponse().getContentAsString(),
124-
new TypeReference<List<MetadataInfos>>() { });
124+
new TypeReference<>() { });
125125
}
126126

127127
@Test
@@ -134,7 +134,7 @@ void testReadNonExistent() throws Exception {
134134

135135
@Test
136136
void testUpdateWithInvalidData() throws Exception {
137-
SpreadsheetConfigInfos configToUpdate = new SpreadsheetConfigInfos(null, SheetType.BATTERIES, createCustomColumns());
137+
SpreadsheetConfigInfos configToUpdate = new SpreadsheetConfigInfos(null, SheetType.BATTERY, createCustomColumns());
138138

139139
UUID configUuid = saveAndReturnId(configToUpdate);
140140

@@ -150,11 +150,11 @@ void testUpdateWithInvalidData() throws Exception {
150150

151151
@Test
152152
void testUpdate() throws Exception {
153-
SpreadsheetConfigInfos configToUpdate = new SpreadsheetConfigInfos(null, SheetType.BATTERIES, createCustomColumns());
153+
SpreadsheetConfigInfos configToUpdate = new SpreadsheetConfigInfos(null, SheetType.BATTERY, createCustomColumns());
154154

155155
UUID configUuid = saveAndReturnId(configToUpdate);
156156

157-
SpreadsheetConfigInfos updatedConfig = new SpreadsheetConfigInfos(configUuid, SheetType.BUSES, createUpdatedCustomColumns());
157+
SpreadsheetConfigInfos updatedConfig = new SpreadsheetConfigInfos(configUuid, SheetType.BUS, createUpdatedCustomColumns());
158158

159159
String updatedConfigJson = mapper.writeValueAsString(updatedConfig);
160160

@@ -173,7 +173,7 @@ void testUpdate() throws Exception {
173173

174174
@Test
175175
void testDelete() throws Exception {
176-
SpreadsheetConfigInfos configToDelete = new SpreadsheetConfigInfos(null, SheetType.BATTERIES, createCustomColumns());
176+
SpreadsheetConfigInfos configToDelete = new SpreadsheetConfigInfos(null, SheetType.BATTERY, createCustomColumns());
177177

178178
UUID configUuid = saveAndReturnId(configToDelete);
179179

@@ -195,8 +195,8 @@ void testDeleteNonExistent() throws Exception {
195195

196196
@Test
197197
void testGetAll() throws Exception {
198-
SpreadsheetConfigInfos config1 = new SpreadsheetConfigInfos(null, SheetType.BATTERIES, createCustomColumns());
199-
SpreadsheetConfigInfos config2 = new SpreadsheetConfigInfos(null, SheetType.BUSES, createUpdatedCustomColumns());
198+
SpreadsheetConfigInfos config1 = new SpreadsheetConfigInfos(null, SheetType.BATTERY, createCustomColumns());
199+
SpreadsheetConfigInfos config2 = new SpreadsheetConfigInfos(null, SheetType.BUS, createUpdatedCustomColumns());
200200

201201
saveAndReturnId(config1);
202202
saveAndReturnId(config2);
@@ -208,7 +208,7 @@ void testGetAll() throws Exception {
208208

209209
@Test
210210
void testDuplicate() throws Exception {
211-
SpreadsheetConfigInfos configToCreate = new SpreadsheetConfigInfos(null, SheetType.BATTERIES, createCustomColumns());
211+
SpreadsheetConfigInfos configToCreate = new SpreadsheetConfigInfos(null, SheetType.BATTERY, createCustomColumns());
212212
UUID configUuid = postSpreadsheetConfig(configToCreate);
213213

214214
UUID duplicatedConfigUuid = duplicateSpreadsheetConfig(configUuid);
@@ -285,7 +285,7 @@ private List<SpreadsheetConfigInfos> getAllSpreadsheetConfigs() throws Exception
285285

286286
return mapper.readValue(
287287
mvcResult.getResponse().getContentAsString(),
288-
new TypeReference<List<SpreadsheetConfigInfos>>() { });
288+
new TypeReference<>() { });
289289
}
290290

291291
private UUID saveAndReturnId(SpreadsheetConfigInfos config) {

0 commit comments

Comments
 (0)