Skip to content

Commit c2a7949

Browse files
authored
Add endpoint to replace all spreadsheet configs in a collection (#136)
Signed-off-by: Ayoub LABIDI <[email protected]>
1 parent 7c750cd commit c2a7949

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

src/main/java/org/gridsuite/explore/server/ExploreController.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,19 @@ public ResponseEntity<Void> updateSpreadsheetConfigCollection(@PathVariable UUID
445445
return ResponseEntity.noContent().build();
446446
}
447447

448+
@PutMapping(value = "/explore/spreadsheet-config-collections/{id}/spreadsheet-configs/replace-all", consumes = MediaType.APPLICATION_JSON_VALUE)
449+
@Operation(summary = "Replace all spreadsheet configurations in a collection")
450+
@ApiResponses(value = {@ApiResponse(responseCode = "204", description = "Spreadsheet config collection has been successfully modified")})
451+
@PreAuthorize("@authorizationService.isAuthorized(#userId, #id, null, T(org.gridsuite.explore.server.dto.PermissionType).WRITE)")
452+
public ResponseEntity<Void> replaceAllSpreadsheetConfigsInCollection(@PathVariable UUID id,
453+
@RequestBody List<UUID> configUuids,
454+
@RequestHeader(QUERY_PARAM_USER_ID) String userId,
455+
@RequestParam(QUERY_PARAM_NAME) String name,
456+
@RequestParam(QUERY_PARAM_DESCRIPTION) String description) {
457+
exploreService.replaceAllSpreadsheetConfigsInCollection(id, configUuids, userId, name, description);
458+
return ResponseEntity.noContent().build();
459+
}
460+
448461
@PostMapping(value = "/explore/spreadsheet-configs", params = "duplicateFrom")
449462
@Operation(summary = "Duplicate a spreadsheet configuration")
450463
@ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Spreadsheet config has been successfully duplicated")})

src/main/java/org/gridsuite/explore/server/services/ExploreService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ public void updateSpreadsheetConfigCollection(UUID id, String spreadsheetConfigC
327327
updateElementNameAndDescription(id, name, description, userId);
328328
}
329329

330+
public void replaceAllSpreadsheetConfigsInCollection(UUID id, List<UUID> configIds, String userId, String name, String description) {
331+
spreadsheetConfigCollectionService.replaceAllSpreadsheetConfigsInCollection(id, configIds);
332+
updateElementNameAndDescription(id, name, description, userId);
333+
}
334+
330335
public void duplicateSpreadsheetConfig(UUID sourceId, UUID targetDirectoryId, String userId) {
331336
UUID newSpreadsheetConfigUuid = spreadsheetConfigService.duplicateSpreadsheetConfig(sourceId);
332337
directoryService.duplicateElement(sourceId, newSpreadsheetConfigUuid, targetDirectoryId, userId);

src/main/java/org/gridsuite/explore/server/services/SpreadsheetConfigCollectionService.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,23 @@ public void updateSpreadsheetConfigCollection(UUID collectionId, String collecti
108108
restTemplate.exchange(spreadsheetConfigServerBaseUri + path, HttpMethod.PUT, httpEntity, Void.class);
109109
}
110110

111+
public void replaceAllSpreadsheetConfigsInCollection(UUID collectionId, List<UUID> configIds) {
112+
Objects.requireNonNull(collectionId);
113+
Objects.requireNonNull(configIds);
114+
115+
var path = UriComponentsBuilder
116+
.fromPath(SPREADSHEET_CONFIG_COLLECTIONS_PATH + DELIMITER + collectionId + "/spreadsheet-configs/replace-all")
117+
.buildAndExpand()
118+
.toUriString();
119+
120+
HttpHeaders headers = new HttpHeaders();
121+
headers.setContentType(MediaType.APPLICATION_JSON);
122+
123+
HttpEntity<List<UUID>> httpEntity = new HttpEntity<>(configIds, headers);
124+
125+
restTemplate.exchange(spreadsheetConfigServerBaseUri + path, HttpMethod.PUT, httpEntity, Void.class);
126+
}
127+
111128
@Override
112129
public void delete(UUID configUuid, String userId) {
113130
Objects.requireNonNull(configUuid);

src/test/java/org/gridsuite/explore/server/SpreadsheetConfigCollectionTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ public MockResponse dispatch(RecordedRequest request) {
9090
return new MockResponse(201, Headers.of("Content-Type", "application/json"), objectMapper.writeValueAsString(COLLECTION_UUID));
9191
} else if (path.matches(SPREADSHEET_CONFIG_COLLECTION_SERVER_BASE_URL + "/" + COLLECTION_UUID)) {
9292
return new MockResponse(204);
93+
} else if (path.matches(SPREADSHEET_CONFIG_COLLECTION_SERVER_BASE_URL + "/" + COLLECTION_UUID + "/spreadsheet-configs/replace-all")) {
94+
return new MockResponse(204);
9395
} else if (path.matches(SPREADSHEET_CONFIG_COLLECTION_SERVER_BASE_URL + "\\?duplicateFrom=" + COLLECTION_UUID) && "POST".equals(request.getMethod())) {
9496
return new MockResponse(201, Headers.of("Content-Type", "application/json"), objectMapper.writeValueAsString(UUID.randomUUID()));
9597
} else if (path.matches("/v1/directories/.*/elements\\?allowNewName=.*") && "POST".equals(request.getMethod()) || path.matches("/v1/elements/" + COLLECTION_UUID)) {
@@ -137,6 +139,18 @@ void testCreateSpreadsheetConfigCollectionWithMerge() throws Exception {
137139
perform.andExpect(status().isCreated());
138140
}
139141

142+
@Test
143+
void testReplaceAllSpreadsheetConfigsInCollection() throws Exception {
144+
String configIds = "[\"" + UUID.randomUUID() + "\", \"" + UUID.randomUUID() + "\"]";
145+
ResultActions perform = mockMvc.perform(put(BASE_URL + "/{id}/spreadsheet-configs/replace-all", COLLECTION_UUID)
146+
.contentType(MediaType.APPLICATION_JSON)
147+
.content(configIds)
148+
.param("name", COLLECTION_NAME)
149+
.param("description", "Test Description")
150+
.header("userId", USER_ID));
151+
perform.andExpect(status().isNoContent());
152+
}
153+
140154
@Test
141155
void testUpdateSpreadsheetConfigCollection() throws Exception {
142156
mockMvc.perform(put(BASE_URL + "/{id}", COLLECTION_UUID)

0 commit comments

Comments
 (0)