diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/RestClientImpl.java b/network-store-client/src/main/java/com/powsybl/network/store/client/RestClientImpl.java index 7a0eda37b..3a22c4537 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/RestClientImpl.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/RestClientImpl.java @@ -113,6 +113,19 @@ private > Optional getOneDocument(St } } + @Override + public Optional getOneExtensionAttributes(String url, Object... uriVariables) { + ResponseEntity response = restTemplate.exchange(url, HttpMethod.GET, null, new ParameterizedTypeReference<>() { }, uriVariables); + if (response.getStatusCode() == HttpStatus.OK) { + ExtensionAttributes body = response.getBody(); + return Optional.of(body); + } else if (response.getStatusCode() == HttpStatus.NOT_FOUND) { + return Optional.empty(); + } else { + throw createHttpException(url, "get", response.getStatusCode()); + } + } + @Override public List> getAll(String target, String url, Object... uriVariables) { ResponseEntity> response = getDocument(url, new ParameterizedTypeReference<>() { diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java b/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java index c94cdebf8..a0c68d986 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java @@ -899,7 +899,7 @@ public Optional getExtensionAttributes(UUID networkUuid, in @Override public Map getAllExtensionsAttributesByResourceTypeAndExtensionName(UUID networkUuid, int variantNum, ResourceType resourceType, String extensionName) { - return getExtensionAttributesMap("/networks/{networkUuid}/{variantNum}/identifiables/types/{type}/extensions/{extensionName}", networkUuid, variantNum, resourceType, extensionName); + return getExtensionAttributesMap("/networks/{networkUuid}/{variantNum}/types/{type}/extensions/{extensionName}", networkUuid, variantNum, resourceType, extensionName); } @Override @@ -909,7 +909,7 @@ public Map getAllExtensionsAttributesByIdentifiable @Override public Map> getAllExtensionsAttributesByResourceType(UUID networkUuid, int variantNum, ResourceType resourceType) { - return getExtensionAttributesNestedMap("/networks/{networkUuid}/{variantNum}/identifiables/types/{resourceType}/extensions", networkUuid, variantNum, resourceType); + return getExtensionAttributesNestedMap("/networks/{networkUuid}/{variantNum}/types/{resourceType}/extensions", networkUuid, variantNum, resourceType); } @Override diff --git a/network-store-client/src/test/java/com/powsybl/network/store/client/PreloadingNetworkStoreClientTest.java b/network-store-client/src/test/java/com/powsybl/network/store/client/PreloadingNetworkStoreClientTest.java index c80c5a01d..f0c981ec4 100644 --- a/network-store-client/src/test/java/com/powsybl/network/store/client/PreloadingNetworkStoreClientTest.java +++ b/network-store-client/src/test/java/com/powsybl/network/store/client/PreloadingNetworkStoreClientTest.java @@ -831,7 +831,7 @@ public void testGetExtensionCache() throws IOException { String extensionAttributes = objectMapper.writerFor(new TypeReference>() { }).writeValueAsString(Map.of(identifiableId1, apc1, identifiableId2, apc2)); - server.expect(ExpectedCount.once(), requestTo("/networks/" + networkUuid + "/" + Resource.INITIAL_VARIANT_NUM + "/identifiables/types/" + ResourceType.GENERATOR + "/extensions/activepowercontrol")) + server.expect(ExpectedCount.once(), requestTo("/networks/" + networkUuid + "/" + Resource.INITIAL_VARIANT_NUM + "/types/" + ResourceType.GENERATOR + "/extensions/activepowercontrol")) .andExpect(method(GET)) .andRespond(withSuccess(extensionAttributes, MediaType.APPLICATION_JSON)); @@ -855,7 +855,7 @@ public void testGetExtensionEmptyExtensionAttributesCache() throws IOException { String identifiableId1 = "GEN"; String extensionAttributes = objectMapper.writerFor(new TypeReference>() { }).writeValueAsString(Map.of()); - server.expect(ExpectedCount.once(), requestTo("/networks/" + networkUuid + "/" + Resource.INITIAL_VARIANT_NUM + "/identifiables/types/" + ResourceType.GENERATOR + "/extensions/activepowercontrol")) + server.expect(ExpectedCount.once(), requestTo("/networks/" + networkUuid + "/" + Resource.INITIAL_VARIANT_NUM + "/types/" + ResourceType.GENERATOR + "/extensions/activepowercontrol")) .andExpect(method(GET)) .andRespond(withSuccess(extensionAttributes, MediaType.APPLICATION_JSON)); @@ -898,7 +898,7 @@ public void testGetExtensionsCache() throws IOException { String multipleExtensionAttributes = objectMapper.writerFor(new TypeReference>>() { }).writeValueAsString(Map.of(identifiableId1, Map.of(ActivePowerControl.NAME, apc1, GeneratorStartup.NAME, gs1), identifiableId2, Map.of(ActivePowerControl.NAME, apc2))); - server.expect(ExpectedCount.once(), requestTo("/networks/" + networkUuid + "/" + Resource.INITIAL_VARIANT_NUM + "/identifiables/types/" + ResourceType.GENERATOR + "/extensions")) + server.expect(ExpectedCount.once(), requestTo("/networks/" + networkUuid + "/" + Resource.INITIAL_VARIANT_NUM + "/types/" + ResourceType.GENERATOR + "/extensions")) .andExpect(method(GET)) .andRespond(withSuccess(multipleExtensionAttributes, MediaType.APPLICATION_JSON)); @@ -925,7 +925,7 @@ public void testGetExtensionsEmptyExtensionAttributesCache() throws IOException // Two successive ExtensionAttributes retrieval, only the first should send a REST request, the second uses the cache String multipleExtensionAttributes = objectMapper.writerFor(new TypeReference>>() { }).writeValueAsString(Map.of()); - server.expect(ExpectedCount.once(), requestTo("/networks/" + networkUuid + "/" + Resource.INITIAL_VARIANT_NUM + "/identifiables/types/" + ResourceType.GENERATOR + "/extensions")) + server.expect(ExpectedCount.once(), requestTo("/networks/" + networkUuid + "/" + Resource.INITIAL_VARIANT_NUM + "/types/" + ResourceType.GENERATOR + "/extensions")) .andExpect(method(GET)) .andRespond(withSuccess(multipleExtensionAttributes, MediaType.APPLICATION_JSON));