Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… into generic-topleveldocument
  • Loading branch information
antoinebhs committed Sep 24, 2024
2 parents fc6b55f + 6a31f41 commit b82b5ec
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ private <T, D extends AbstractTopLevelDocument<T>> Optional<T> getOneDocument(St
}
}

@Override
public Optional<ExtensionAttributes> getOneExtensionAttributes(String url, Object... uriVariables) {
ResponseEntity<ExtensionAttributes> 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 <T extends IdentifiableAttributes> List<Resource<T>> getAll(String target, String url, Object... uriVariables) {
ResponseEntity<TopLevelDocument<T>> response = getDocument(url, new ParameterizedTypeReference<>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ public Optional<ExtensionAttributes> getExtensionAttributes(UUID networkUuid, in

@Override
public Map<String, ExtensionAttributes> 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
Expand All @@ -909,7 +909,7 @@ public Map<String, ExtensionAttributes> getAllExtensionsAttributesByIdentifiable

@Override
public Map<String, Map<String, ExtensionAttributes>> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ public void testGetExtensionCache() throws IOException {

String extensionAttributes = objectMapper.writerFor(new TypeReference<Map<String, ExtensionAttributes>>() {
}).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));

Expand All @@ -855,7 +855,7 @@ public void testGetExtensionEmptyExtensionAttributesCache() throws IOException {
String identifiableId1 = "GEN";
String extensionAttributes = objectMapper.writerFor(new TypeReference<Map<String, ExtensionAttributes>>() {
}).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));

Expand Down Expand Up @@ -898,7 +898,7 @@ public void testGetExtensionsCache() throws IOException {

String multipleExtensionAttributes = objectMapper.writerFor(new TypeReference<Map<String, Map<String, ExtensionAttributes>>>() {
}).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));

Expand All @@ -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<Map<String, Map<String, ExtensionAttributes>>>() {
}).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));

Expand Down

0 comments on commit b82b5ec

Please sign in to comment.