Skip to content

Commit 2cd5baf

Browse files
committed
Code improvements
Signed-off-by: BOUHOURS Antoine <[email protected]>
1 parent 26dea58 commit 2cd5baf

File tree

9 files changed

+23
-69
lines changed

9 files changed

+23
-69
lines changed

network-store-client/src/main/java/com/powsybl/network/store/client/PreloadingNetworkStoreClient.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -874,13 +874,13 @@ public void removeConfiguredBuses(UUID networkUuid, int variantNum, List<String>
874874

875875
@Override
876876
public Optional<ExtensionAttributes> getExtensionAttributes(UUID networkUuid, int variantNum, ResourceType resourceType, String identifiableId, String extensionName) {
877-
delegate.loadAllExtensionsAttributesByResourceTypeAndExtensionName(networkUuid, variantNum, resourceType, extensionName);
877+
((CachedNetworkStoreClient) delegate).loadAllExtensionsAttributesByResourceTypeAndExtensionName(networkUuid, variantNum, resourceType, extensionName);
878878
return delegate.getExtensionAttributes(networkUuid, variantNum, resourceType, identifiableId, extensionName);
879879
}
880880

881881
@Override
882882
public Map<String, ExtensionAttributes> getAllExtensionsAttributesByIdentifiableId(UUID networkUuid, int variantNum, ResourceType resourceType, String id) {
883-
delegate.loadAllExtensionsAttributesByResourceType(networkUuid, variantNum, resourceType);
883+
((CachedNetworkStoreClient) delegate).loadAllExtensionsAttributesByResourceType(networkUuid, variantNum, resourceType);
884884
return delegate.getAllExtensionsAttributesByIdentifiableId(networkUuid, variantNum, resourceType, id);
885885
}
886886
}

network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java

-10
Original file line numberDiff line numberDiff line change
@@ -902,11 +902,6 @@ public Map<String, ExtensionAttributes> getAllExtensionsAttributesByResourceType
902902
return getExtensionAttributesMap("/networks/{networkUuid}/{variantNum}/identifiables/types/{type}/extensions/{extensionName}", networkUuid, variantNum, resourceType, extensionName);
903903
}
904904

905-
@Override
906-
public void loadAllExtensionsAttributesByResourceTypeAndExtensionName(UUID networkUuid, int variantNum, ResourceType resourceType, String extensionName) {
907-
// nothing to do
908-
}
909-
910905
@Override
911906
public Map<String, ExtensionAttributes> getAllExtensionsAttributesByIdentifiableId(UUID networkUuid, int variantNum, ResourceType resourceType, String identifiableId) {
912907
return getExtensionAttributesMap("/networks/{networkUuid}/{variantNum}/identifiables/{identifiableId}/extensions", networkUuid, variantNum, identifiableId);
@@ -917,11 +912,6 @@ public Map<String, Map<String, ExtensionAttributes>> getAllExtensionsAttributesB
917912
return getExtensionAttributesNestedMap("/networks/{networkUuid}/{variantNum}/identifiables/types/{resourceType}/extensions", networkUuid, variantNum, resourceType);
918913
}
919914

920-
@Override
921-
public void loadAllExtensionsAttributesByResourceType(UUID networkUuid, int variantNum, ResourceType resourceType) {
922-
// nothing to do
923-
}
924-
925915
@Override
926916
public void removeExtensionAttributes(UUID networkUuid, int variantNum, ResourceType resourceType, String identifiableId, String extensionName) {
927917
restClient.delete("/networks/{networkUuid}/{variantNum}/identifiables/{identifiableId}/extensions/{extensionName}", networkUuid, variantNum, identifiableId, extensionName);

network-store-client/src/test/java/com/powsybl/network/store/client/PreloadingNetworkStoreClientTest.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ public void testGetExtensionsCacheWithClonedNetwork() throws IOException {
997997
server.expect(ExpectedCount.once(), requestTo("/networks/" + networkUuid + "/" + Resource.INITIAL_VARIANT_NUM + "/identifiables/types/" + ResourceType.GENERATOR + "/extensions"))
998998
.andExpect(method(GET))
999999
.andRespond(withSuccess(multipleExtensionAttributes, MediaType.APPLICATION_JSON));
1000-
cachedClient.getAllExtensionsAttributesByResourceType(networkUuid, Resource.INITIAL_VARIANT_NUM, ResourceType.GENERATOR);
1000+
cachedClient.getAllExtensionsAttributesByIdentifiableId(networkUuid, Resource.INITIAL_VARIANT_NUM, ResourceType.GENERATOR, identifiableId1);
10011001
server.verify();
10021002
server.reset();
10031003

@@ -1008,9 +1008,8 @@ public void testGetExtensionsCacheWithClonedNetwork() throws IOException {
10081008
cachedClient.cloneNetwork(networkUuid, Resource.INITIAL_VARIANT_NUM, targetVariantNum, targetVariantId);
10091009

10101010
// Verify that the cache is copied and there is no new fetch
1011-
cachedClient.getAllExtensionsAttributesByResourceType(networkUuid, targetVariantNum, ResourceType.GENERATOR);
1012-
Map<String, ExtensionAttributes> extensionAttributesByExtensionNameMap = cachedClient.getAllExtensionsAttributesByIdentifiableId(networkUuid, targetVariantNum, ResourceType.GENERATOR, identifiableId1);
1013-
assertEquals(2, extensionAttributesByExtensionNameMap.size());
1011+
Map<String, ExtensionAttributes> extensionAttributesByIdentifiableId = cachedClient.getAllExtensionsAttributesByIdentifiableId(networkUuid, targetVariantNum, ResourceType.GENERATOR, identifiableId1);
1012+
assertEquals(2, extensionAttributesByIdentifiableId.size());
10141013
server.verify();
10151014
server.reset();
10161015
}

network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CachedNetworkStoreClient.java

-2
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,6 @@ public Optional<ExtensionAttributes> getExtensionAttributes(UUID networkUuid, in
10761076
return getCache(resourceType).getCollection(networkUuid, variantNum).getExtensionAttributes(networkUuid, variantNum, resourceType, identifiableId, extensionName);
10771077
}
10781078

1079-
@Override
10801079
public void loadAllExtensionsAttributesByResourceTypeAndExtensionName(UUID networkUuid, int variantNum, ResourceType resourceType, String extensionName) {
10811080
getCache(resourceType).getCollection(networkUuid, variantNum).loadAllExtensionsAttributesByResourceTypeAndExtensionName(networkUuid, variantNum, resourceType, extensionName);
10821081
}
@@ -1086,7 +1085,6 @@ public Map<String, ExtensionAttributes> getAllExtensionsAttributesByIdentifiable
10861085
return getCache(resourceType).getCollection(networkUuid, variantNum).getAllExtensionsAttributesByIdentifiableId(networkUuid, variantNum, resourceType, identifiableId);
10871086
}
10881087

1089-
@Override
10901088
public void loadAllExtensionsAttributesByResourceType(UUID networkUuid, int variantNum, ResourceType resourceType) {
10911089
getCache(resourceType).getCollection(networkUuid, variantNum).loadAllExtensionsAttributesByResourceType(networkUuid, variantNum, resourceType);
10921090
}

network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CollectionCache.java

+4-18
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,9 @@ private void addExtensionAttributesToCache(String identifiableId, String extensi
395395
}
396396

397397
/**
398-
* Get the extensions attributes with specified extension name for all the identifiables of the collection in the cache.
398+
* Load all the extensions attributes with specified extension name for all the identifiables of the collection in the cache.
399399
*/
400-
public Map<String, ExtensionAttributes> getAllExtensionsAttributesByResourceTypeAndExtensionName(UUID networkUuid, int variantNum, ResourceType type, String extensionName) {
400+
public void loadAllExtensionsAttributesByResourceTypeAndExtensionName(UUID networkUuid, int variantNum, ResourceType type, String extensionName) {
401401
if (!isFullyLoadedExtension(extensionName)) {
402402
// if collection has not yet been fully loaded we load it from the server
403403
Map<String, ExtensionAttributes> extensionAttributesMap = delegate.getAllExtensionsAttributesByResourceTypeAndExtensionName(networkUuid, variantNum, type, extensionName);
@@ -406,13 +406,6 @@ public Map<String, ExtensionAttributes> getAllExtensionsAttributesByResourceType
406406
extensionAttributesMap.forEach((identifiableId, extensionAttributes) -> addExtensionAttributesToCache(identifiableId, extensionName, extensionAttributes));
407407
fullyLoadedExtensionsByExtensionName.add(extensionName);
408408
}
409-
//TODO This method is only used to load extension attributes in the collection cache when using preloading collection.
410-
// The return is never used by the client as the call to getAllExtensionsAttributesByResourceTypeAndExtensionName() is always followed
411-
// by a call to getExtensionAttributes(). The latter returns something meaningful for the client
412-
// and it's used in the identifiable.getExtension() method. The map extensionAttributesMap can't be stored in the cache to be returned
413-
// as we can't ensure synchronization with the resources map (if extensions or identifiables are updated/removed).
414-
// We should refactor this method to return void.
415-
return null;
416409
}
417410

418411
/**
@@ -454,9 +447,9 @@ private void addAllExtensionAttributesToCache(String id, Map<String, ExtensionAt
454447
}
455448

456449
/**
457-
* Get all the extensions attributes for all the identifiables with specified resource type in the cache
450+
* Load all the extensions attributes for all the identifiables with specified resource type in the cache
458451
*/
459-
public Map<String, Map<String, ExtensionAttributes>> getAllExtensionsAttributesByResourceType(UUID networkUuid, int variantNum, ResourceType type) {
452+
public void loadAllExtensionsAttributesByResourceType(UUID networkUuid, int variantNum, ResourceType type) {
460453
if (!fullyLoadedExtensions) {
461454
// if collection has not yet been fully loaded we load it from the server
462455
Map<String, Map<String, ExtensionAttributes>> extensionAttributesMap = delegate.getAllExtensionsAttributesByResourceType(networkUuid, variantNum, type);
@@ -465,13 +458,6 @@ public Map<String, Map<String, ExtensionAttributes>> getAllExtensionsAttributesB
465458
extensionAttributesMap.forEach(this::addAllExtensionAttributesToCache);
466459
fullyLoadedExtensions = true;
467460
}
468-
//TODO This method is only used to load extension attributes in the collection cache when using preloading collection.
469-
// The return is never used by the client as the call to getAllExtensionsAttributesByResourceType() is always followed
470-
// by a call to getAllExtensionsAttributesByIdentifiableId(). The latter returns something meaningful for the client
471-
// and it's used in the identifiable.getExtensions() method. The map extensionAttributesMap can't be stored in the cache to be returned
472-
// as we can't ensure synchronization with the resources map (if extensions or identifiables are updated/removed).
473-
// We should refactor this method to return void.
474-
return null;
475461
}
476462

477463
public void removeExtensionAttributesByExtensionName(String identifiableId, String extensionName) {

network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkStoreClient.java

-4
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,6 @@ public interface NetworkStoreClient {
318318
*/
319319
Map<String, ExtensionAttributes> getAllExtensionsAttributesByResourceTypeAndExtensionName(UUID networkUuid, int variantNum, ResourceType resourceType, String extensionName);
320320

321-
void loadAllExtensionsAttributesByResourceTypeAndExtensionName(UUID networkUuid, int variantNum, ResourceType resourceType, String extensionName);
322-
323321
/**
324322
* For one identifiable with a specific identifiable id, retrieves all extension attributes of this identifiable.
325323
* @return A {@link Map} where keys are extension names and values are {@link ExtensionAttributes}.
@@ -333,8 +331,6 @@ public interface NetworkStoreClient {
333331
*/
334332
Map<String, Map<String, ExtensionAttributes>> getAllExtensionsAttributesByResourceType(UUID networkUuid, int variantNum, ResourceType resourceType);
335333

336-
void loadAllExtensionsAttributesByResourceType(UUID networkUuid, int variantNum, ResourceType resourceType);
337-
338334
void removeExtensionAttributes(UUID networkUuid, int variantNum, ResourceType resourceType, String identifiableId, String extensionName);
339335

340336
Optional<Resource<IdentifiableAttributes>> getIdentifiable(UUID networkUuid, int variantNum, String id);

network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/OfflineNetworkStoreClient.java

-10
Original file line numberDiff line numberDiff line change
@@ -616,11 +616,6 @@ public Map<String, ExtensionAttributes> getAllExtensionsAttributesByResourceType
616616
return Map.of();
617617
}
618618

619-
@Override
620-
public void loadAllExtensionsAttributesByResourceTypeAndExtensionName(UUID networkUuid, int variantNum, ResourceType resourceType, String extensionName) {
621-
// nothing to do
622-
}
623-
624619
@Override
625620
public Map<String, ExtensionAttributes> getAllExtensionsAttributesByIdentifiableId(UUID networkUuid, int variantNum, ResourceType resourceType, String identifiableId) {
626621
return Map.of();
@@ -631,11 +626,6 @@ public Map<String, Map<String, ExtensionAttributes>> getAllExtensionsAttributesB
631626
return Map.of();
632627
}
633628

634-
@Override
635-
public void loadAllExtensionsAttributesByResourceType(UUID networkUuid, int variantNum, ResourceType resourceType) {
636-
// nothing to do
637-
}
638-
639629
@Override
640630
public void removeExtensionAttributes(UUID uuid, int workingVariantNum, ResourceType resourceType, String identifiableId, String extensionName) {
641631
// nothing to do

0 commit comments

Comments
 (0)