Skip to content

Commit

Permalink
Add endpoint to get spreadsheetConfig
Browse files Browse the repository at this point in the history
Signed-off-by: Ayoub LABIDI <ayoub.labidi@protonmail.com>
  • Loading branch information
ayolab committed Oct 22, 2024
1 parent 4e25195 commit 49f965f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,13 @@ public ResponseEntity<Void> duplicateSpreadsheetConfig(@RequestParam("duplicateF
return ResponseEntity.status(HttpStatus.CREATED).build();
}

@GetMapping(value = "/explore/spreadsheet-configs/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get a spreadsheet configuration")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Spreadsheet config retrieved")})
public ResponseEntity<String> getSpreadsheetConfig(@PathVariable UUID id) {
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(exploreService.getSpreadsheetConfig(id));
}

@PostMapping(value = "/explore/composite-modifications")
@Operation(summary = "create composite modification element from existing network modifications")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Modifications have been created and composite modification element created in the directory")})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ public void duplicateSpreadsheetConfig(UUID sourceId, UUID targetDirectoryId, St
directoryService.duplicateElement(sourceId, newSpreadsheetConfigUuid, targetDirectoryId, userId);
}

public String getSpreadsheetConfig(UUID configUuid) {
return spreadsheetConfigService.getSpreadsheetConfig(configUuid);
}

public void createCompositeModifications(List<UUID> modificationUuids, String userId, String name,
String description, UUID parentDirectoryUuid) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ public UUID createSpreadsheetConfig(String config) {
return restTemplate.exchange(spreadsheetConfigServerBaseUri + path, HttpMethod.POST, httpEntity, UUID.class).getBody();
}

public String getSpreadsheetConfig(UUID configUuid) {
Objects.requireNonNull(configUuid);

var path = UriComponentsBuilder
.fromPath(SPREADSHEET_CONFIG_SERVER_ROOT_PATH + DELIMITER + configUuid)
.buildAndExpand()
.toUriString();

return restTemplate.exchange(spreadsheetConfigServerBaseUri + path, HttpMethod.GET, null, String.class).getBody();
}

public UUID duplicateSpreadsheetConfig(UUID configUuid) {
Objects.requireNonNull(configUuid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ public MockResponse dispatch(RecordedRequest request) {
.setResponseCode(200)
.setHeader("Content-Type", "application/json")
.setBody(objectMapper.writeValueAsString(responseList));
} else if (path.matches(SPREADSHEET_CONFIG_SERVER_BASE_URL + "/" + CONFIG_UUID) && "GET".equals(request.getMethod())) {
Map<String, Object> response = new HashMap<>();
response.put("sheetType", "GENERATOR");

return new MockResponse()
.setResponseCode(200)
.setHeader("Content-Type", "application/json")
.setBody(objectMapper.writeValueAsString(response));
} else if (path.matches("/v1/elements\\?ids=.*")) {
ElementAttributes elementAttributes = new ElementAttributes(
CONFIG_UUID,
Expand Down Expand Up @@ -248,4 +256,12 @@ void testGetSpreadsheetConfigMetadata() throws Exception {
.andExpect(jsonPath("$[0].specificMetadata.id").value(CONFIG_UUID.toString()))
.andExpect(jsonPath("$[0].specificMetadata.sheetType").value("GENERATORS"));
}

@Test
void testGetSpreadsheetConfig() throws Exception {
mockMvc.perform(get(BASE_URL + "/{id}", CONFIG_UUID))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.sheetType").value("GENERATOR"));
}
}

0 comments on commit 49f965f

Please sign in to comment.