Skip to content

Commit 880f5ad

Browse files
Add node aliases to the spreadsheet config collection (#35)
Signed-off-by: Franck LECUYER <[email protected]>
1 parent 9c6bb9f commit 880f5ad

File tree

7 files changed

+73
-26
lines changed

7 files changed

+73
-26
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public record SpreadsheetConfigCollectionInfos(
2121
UUID id,
2222

2323
@Schema(description = "List of spreadsheet configurations")
24-
List<SpreadsheetConfigInfos> spreadsheetConfigs
24+
List<SpreadsheetConfigInfos> spreadsheetConfigs,
25+
26+
@Schema(description = "List of node aliases")
27+
List<String> nodeAliases
2528
) {
2629
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,8 @@ public class SpreadsheetConfigCollectionEntity {
3535
@OrderColumn(name = "config_order")
3636
@Builder.Default
3737
private List<SpreadsheetConfigEntity> spreadsheetConfigs = new ArrayList<>();
38+
39+
@ElementCollection(fetch = FetchType.EAGER)
40+
@CollectionTable(name = "node_aliases", foreignKey = @ForeignKey(name = "fk_spreadsheet_config_collection_node_aliases"))
41+
private List<String> nodeAliases;
3842
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public UUID createSpreadsheetConfigCollection(SpreadsheetConfigCollectionInfos d
137137
entity.setSpreadsheetConfigs(dto.spreadsheetConfigs().stream()
138138
.map(SpreadsheetConfigMapper::toEntity)
139139
.toList());
140+
entity.setNodeAliases(dto.nodeAliases());
140141
return spreadsheetConfigCollectionRepository.save(entity).getId();
141142
}
142143

@@ -155,7 +156,7 @@ public SpreadsheetConfigCollectionInfos getSpreadsheetConfigCollection(UUID id)
155156
.orElseThrow(() -> new EntityNotFoundException(SPREADSHEET_CONFIG_COLLECTION_NOT_FOUND + id));
156157
return new SpreadsheetConfigCollectionInfos(entity.getId(), entity.getSpreadsheetConfigs().stream()
157158
.map(SpreadsheetConfigMapper::toDto)
158-
.toList());
159+
.toList(), entity.getNodeAliases());
159160
}
160161

161162
@Transactional
@@ -175,6 +176,7 @@ public void updateSpreadsheetConfigCollection(UUID id, SpreadsheetConfigCollecti
175176
entity.getSpreadsheetConfigs().addAll(dto.spreadsheetConfigs().stream()
176177
.map(SpreadsheetConfigMapper::toEntity)
177178
.toList());
179+
entity.setNodeAliases(dto.nodeAliases());
178180
}
179181

180182
@Transactional
@@ -202,6 +204,7 @@ public UUID duplicateSpreadsheetConfigCollection(UUID id) {
202204
return configDuplicate;
203205
})
204206
.toList());
207+
duplicate.setNodeAliases(new ArrayList<>(entity.getNodeAliases()));
205208
return spreadsheetConfigCollectionRepository.save(duplicate).getId();
206209
}
207210

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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="1742200048214-1">
4+
<createTable tableName="node_aliases">
5+
<column name="spreadsheet_config_collection_entity_id" type="UUID">
6+
<constraints nullable="false"/>
7+
</column>
8+
<column name="node_aliases" type="VARCHAR(255)"/>
9+
</createTable>
10+
</changeSet>
11+
<changeSet author="lecuyerfra (generated)" id="1742200048214-2">
12+
<addForeignKeyConstraint baseColumnNames="spreadsheet_config_collection_entity_id" baseTableName="node_aliases" constraintName="fk_spreadsheet_config_collection_node_aliases" deferrable="false" initiallyDeferred="false" referencedColumnNames="id" referencedTableName="spreadsheet_config_collection" validate="true"/>
13+
</changeSet>
14+
</databaseChangeLog>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ databaseChangeLog:
2929
- include:
3030
file: changesets/changelog_20250319T134629Z.xml
3131
relativeToChangelogFile: true
32+
- include:
33+
file: changesets/changelog_20250317T082711Z.xml
34+
relativeToChangelogFile: true

src/main/resources/default-spreadsheet-config-collection.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1918,5 +1918,6 @@
19181918
}
19191919
]
19201920
}
1921-
]
1921+
],
1922+
"nodeAliases": []
19221923
}

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

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,40 +55,57 @@ void tearDown() {
5555

5656
@Test
5757
void testCreateCollection() throws Exception {
58-
SpreadsheetConfigCollectionInfos collectionToCreate = new SpreadsheetConfigCollectionInfos(null, createSpreadsheetConfigs());
58+
SpreadsheetConfigCollectionInfos collectionToCreate = new SpreadsheetConfigCollectionInfos(null, createSpreadsheetConfigs(), null);
5959

6060
UUID collectionUuid = postSpreadsheetConfigCollection(collectionToCreate);
6161
SpreadsheetConfigCollectionInfos createdCollection = getSpreadsheetConfigCollection(collectionUuid);
6262

6363
assertThat(createdCollection)
64-
.usingRecursiveComparison()
65-
.ignoringFields("spreadsheetConfigs.columns.uuid", "id", "spreadsheetConfigs.id")
66-
.isEqualTo(collectionToCreate);
64+
.usingRecursiveComparison()
65+
.ignoringFields("spreadsheetConfigs.columns.uuid", "id", "spreadsheetConfigs.id")
66+
.ignoringExpectedNullFields()
67+
.isEqualTo(collectionToCreate);
68+
assertThat(createdCollection.id()).isNotNull();
69+
}
70+
71+
@Test
72+
void testCreateCollectionWithAliases() throws Exception {
73+
SpreadsheetConfigCollectionInfos collectionToCreate = new SpreadsheetConfigCollectionInfos(null, createSpreadsheetConfigs(), List.of("alias1", "alias2", "alias3"));
74+
75+
UUID collectionUuid = postSpreadsheetConfigCollection(collectionToCreate);
76+
SpreadsheetConfigCollectionInfos createdCollection = getSpreadsheetConfigCollection(collectionUuid);
77+
78+
assertThat(createdCollection)
79+
.usingRecursiveComparison()
80+
.ignoringFields("spreadsheetConfigs.columns.uuid", "id", "spreadsheetConfigs.id")
81+
.ignoringExpectedNullFields()
82+
.isEqualTo(collectionToCreate);
6783
assertThat(createdCollection.id()).isNotNull();
6884
}
6985

7086
@Test
7187
void testReadCollection() throws Exception {
72-
SpreadsheetConfigCollectionInfos collectionToRead = new SpreadsheetConfigCollectionInfos(null, createSpreadsheetConfigs());
88+
SpreadsheetConfigCollectionInfos collectionToRead = new SpreadsheetConfigCollectionInfos(null, createSpreadsheetConfigs(), null);
7389

7490
UUID collectionUuid = saveAndReturnId(collectionToRead);
7591

7692
SpreadsheetConfigCollectionInfos receivedCollection = getSpreadsheetConfigCollection(collectionUuid);
7793

7894
assertThat(receivedCollection)
79-
.usingRecursiveComparison()
80-
.ignoringFields("spreadsheetConfigs.columns.uuid", "id", "spreadsheetConfigs.id")
81-
.isEqualTo(collectionToRead);
95+
.usingRecursiveComparison()
96+
.ignoringFields("spreadsheetConfigs.columns.uuid", "id", "spreadsheetConfigs.id")
97+
.ignoringExpectedNullFields()
98+
.isEqualTo(collectionToRead);
8299
assertThat(receivedCollection.id()).isEqualTo(collectionUuid);
83100
}
84101

85102
@Test
86103
void testUpdateCollection() throws Exception {
87-
SpreadsheetConfigCollectionInfos collectionToUpdate = new SpreadsheetConfigCollectionInfos(null, createSpreadsheetConfigs());
104+
SpreadsheetConfigCollectionInfos collectionToUpdate = new SpreadsheetConfigCollectionInfos(null, createSpreadsheetConfigs(), null);
88105

89106
UUID collectionUuid = saveAndReturnId(collectionToUpdate);
90107

91-
SpreadsheetConfigCollectionInfos updatedCollection = new SpreadsheetConfigCollectionInfos(collectionUuid, createUpdatedSpreadsheetConfigs());
108+
SpreadsheetConfigCollectionInfos updatedCollection = new SpreadsheetConfigCollectionInfos(collectionUuid, createUpdatedSpreadsheetConfigs(), null);
92109

93110
String updatedCollectionJson = mapper.writeValueAsString(updatedCollection);
94111

@@ -100,14 +117,15 @@ void testUpdateCollection() throws Exception {
100117
SpreadsheetConfigCollectionInfos retrievedCollection = getSpreadsheetConfigCollection(collectionUuid);
101118

102119
assertThat(retrievedCollection)
103-
.usingRecursiveComparison()
104-
.ignoringFields("spreadsheetConfigs.columns.uuid", "spreadsheetConfigs.id")
105-
.isEqualTo(updatedCollection);
120+
.usingRecursiveComparison()
121+
.ignoringFields("spreadsheetConfigs.columns.uuid", "spreadsheetConfigs.id")
122+
.ignoringExpectedNullFields()
123+
.isEqualTo(updatedCollection);
106124
}
107125

108126
@Test
109127
void testDeleteCollection() throws Exception {
110-
SpreadsheetConfigCollectionInfos collectionToDelete = new SpreadsheetConfigCollectionInfos(null, createSpreadsheetConfigs());
128+
SpreadsheetConfigCollectionInfos collectionToDelete = new SpreadsheetConfigCollectionInfos(null, createSpreadsheetConfigs(), null);
111129

112130
UUID collectionUuid = saveAndReturnId(collectionToDelete);
113131

@@ -120,23 +138,24 @@ void testDeleteCollection() throws Exception {
120138

121139
@Test
122140
void testDuplicateCollection() throws Exception {
123-
SpreadsheetConfigCollectionInfos collectionToCreate = new SpreadsheetConfigCollectionInfos(null, createSpreadsheetConfigs());
141+
SpreadsheetConfigCollectionInfos collectionToCreate = new SpreadsheetConfigCollectionInfos(null, createSpreadsheetConfigs(), null);
124142
UUID collectionUuid = postSpreadsheetConfigCollection(collectionToCreate);
125143

126144
UUID duplicatedCollectionUuid = duplicateSpreadsheetConfigCollection(collectionUuid);
127145

128146
SpreadsheetConfigCollectionInfos duplicatedCollection = getSpreadsheetConfigCollection(duplicatedCollectionUuid);
129147
assertThat(duplicatedCollection)
130-
.usingRecursiveComparison()
131-
.ignoringFields("spreadsheetConfigs.columns.uuid", "id", "spreadsheetConfigs.id")
132-
.isEqualTo(collectionToCreate);
148+
.usingRecursiveComparison()
149+
.ignoringFields("spreadsheetConfigs.columns.uuid", "id", "spreadsheetConfigs.id")
150+
.ignoringExpectedNullFields()
151+
.isEqualTo(collectionToCreate);
133152
assertThat(duplicatedCollection.id()).isNotEqualTo(collectionUuid);
134153
}
135154

136155
@Test
137156
void testMergeModelsIntoNewCollection() throws Exception {
138157
// create a first collection with 2 configs
139-
SpreadsheetConfigCollectionInfos collectionToCreate = new SpreadsheetConfigCollectionInfos(null, createSpreadsheetConfigs());
158+
SpreadsheetConfigCollectionInfos collectionToCreate = new SpreadsheetConfigCollectionInfos(null, createSpreadsheetConfigs(), null);
140159
UUID collectionUuid = postSpreadsheetConfigCollection(collectionToCreate);
141160
List<UUID> configIds = getSpreadsheetConfigCollection(collectionUuid).spreadsheetConfigs().stream().map(SpreadsheetConfigInfos::id).toList();
142161
assertThat(configIds).hasSize(2);
@@ -163,7 +182,7 @@ void testCreateDefaultCollection() throws Exception {
163182

164183
@Test
165184
void testAddSpreadsheetConfigToCollection() throws Exception {
166-
SpreadsheetConfigCollectionInfos initialCollection = new SpreadsheetConfigCollectionInfos(null, createSpreadsheetConfigs());
185+
SpreadsheetConfigCollectionInfos initialCollection = new SpreadsheetConfigCollectionInfos(null, createSpreadsheetConfigs(), null);
167186
UUID collectionUuid = postSpreadsheetConfigCollection(initialCollection);
168187

169188
List<ColumnInfos> columnInfos = Arrays.asList(
@@ -189,7 +208,7 @@ void testAddSpreadsheetConfigToCollection() throws Exception {
189208

190209
@Test
191210
void testRemoveSpreadsheetConfigFromCollection() throws Exception {
192-
SpreadsheetConfigCollectionInfos initialCollection = new SpreadsheetConfigCollectionInfos(null, createSpreadsheetConfigs());
211+
SpreadsheetConfigCollectionInfos initialCollection = new SpreadsheetConfigCollectionInfos(null, createSpreadsheetConfigs(), null);
193212
UUID collectionUuid = postSpreadsheetConfigCollection(initialCollection);
194213

195214
SpreadsheetConfigCollectionInfos createdCollection = getSpreadsheetConfigCollection(collectionUuid);
@@ -218,7 +237,7 @@ void testAddSpreadsheetConfigToNonExistentCollection() throws Exception {
218237

219238
@Test
220239
void testRemoveNonExistentSpreadsheetConfig() throws Exception {
221-
SpreadsheetConfigCollectionInfos collection = new SpreadsheetConfigCollectionInfos(null, createSpreadsheetConfigs());
240+
SpreadsheetConfigCollectionInfos collection = new SpreadsheetConfigCollectionInfos(null, createSpreadsheetConfigs(), null);
222241
UUID collectionUuid = postSpreadsheetConfigCollection(collection);
223242

224243
UUID nonExistentConfigId = UUID.randomUUID();
@@ -229,7 +248,7 @@ void testRemoveNonExistentSpreadsheetConfig() throws Exception {
229248
@Test
230249
void testReorderSpreadsheetConfigs() throws Exception {
231250
// Create a collection with multiple configs
232-
SpreadsheetConfigCollectionInfos collection = new SpreadsheetConfigCollectionInfos(null, createSpreadsheetConfigs());
251+
SpreadsheetConfigCollectionInfos collection = new SpreadsheetConfigCollectionInfos(null, createSpreadsheetConfigs(), null);
233252
UUID collectionId = postSpreadsheetConfigCollection(collection);
234253

235254
// Get the created collection to get the config IDs

0 commit comments

Comments
 (0)