-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
get Composite Modification endpoint #541
Conversation
Signed-off-by: Mathieu DEHARBE <[email protected]>
Signed-off-by: Mathieu DEHARBE <[email protected]>
Signed-off-by: Mathieu DEHARBE <[email protected]>
Signed-off-by: Mathieu DEHARBE <[email protected]>
Signed-off-by: Mathieu DEHARBE <[email protected]>
Signed-off-by: Mathieu DEHARBE <[email protected]>
Signed-off-by: Mathieu DEHARBE <[email protected]>
@GetMapping(value = "/network-composite-modification/{id}", produces = MediaType.APPLICATION_JSON_VALUE) | ||
@Operation(summary = "Get the content of a composite modification via its id") | ||
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Content of the composite modification"), | ||
@ApiResponse(responseCode = "404", description = "This composite modification does not exist")} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
404 code is for not found response
for readability reasons I suggest
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Content of the composite modification"), @ApiResponse(responseCode = "404", description = "Composite modification not found") })
If the id is not found in the database, an exception should be thrown by networkModificationService
Currently, it returns 200 OK even if the id doesn’t exist !...
fix it (with try-catch or another solution)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Message changed. Remobved that 404.
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Content of the composite modification"), | ||
@ApiResponse(responseCode = "404", description = "This composite modification does not exist")} | ||
) | ||
public ResponseEntity<List<ModificationInfos>> getCompositeModificationContent(@PathVariable("id") UUID compositeModificationId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PathVariable(value = "id", required = true) UUID compositeModificationId
to ensure that the id is mandatory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For PathVariable boolean required() default true
If I add a true, intellij calls it a redundant parameter.
@@ -220,6 +220,18 @@ public ResponseEntity<UUID> createNetworkCompositeModification(@RequestBody List | |||
return ResponseEntity.ok().body(networkModificationService.createNetworkCompositeModification(modificationUuids)); | |||
} | |||
|
|||
@GetMapping(value = "/network-composite-modification/{id}", produces = MediaType.APPLICATION_JSON_VALUE) | |||
@Operation(summary = "Get the content of a composite modification via its id") | |||
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Content of the composite modification"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Content is not clear enough and it is generic description
maybe "The modifications list of the composite"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kind of updated all of this to be closer to @GetMapping(value = "/groups/{groupUuid}/network-modifications", produces = MediaType.APPLICATION_JSON_VALUE)
I think it was clearer that my previous endpoint.
public ResponseEntity<List<ModificationInfos>> getCompositeModificationContent(@PathVariable("id") UUID compositeModificationId) { | ||
return ResponseEntity.ok() | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.body(networkModificationService.getCompositeModificationContentMetadata(compositeModificationId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metadata ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed getNetworkModificationsFromComposite
I am still not very satisfied of it, but still better than metadata indeed.
@Transactional(readOnly = true) | ||
public List<ModificationInfos> getCompositeModificationsInfos(@NonNull List<UUID> uuids) { | ||
public List<ModificationInfos> getCompositeModificationsContentInfos(@NonNull List<UUID> uuids, boolean onlyCommonData) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't need to rename this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok but I don't think this is a good name : it sounds like we are getting the infos of the composite modifications but we are not. We get the infos of the network modifications that are inside the composite modifications and don't get those of the composite modifications themselves.
It sent me in the wrong direction when I was looking at functions.
@@ -394,15 +394,28 @@ public List<ModificationInfos> getModificationsInfos(@NonNull List<UUID> uuids) | |||
return uuids.stream().map(entities::get).filter(Objects::nonNull).map(this::getModificationInfos).toList(); | |||
} | |||
|
|||
/** | |||
* @param onlyCommonData if true, only returns the basic data common to all the modifications. If false, returns complete modifications |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain the basic of the data and what do you mean by onlyCommonData?
It doesn't make sense to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the network modifications use the ModificationInfos
. The data inside this class is the common data to all the network modifications.
But they also have specific data extending this data like BatteryModificationInfos
or LineCreationInfos
.
.stream() | ||
.map(this::getModificationInfo) | ||
.toList(); | ||
List<UUID> networkModificationsUuids = modificationRepository.findModificationIdsByCompositeModificationId(uuid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
foundEntities
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean renaming networkModificationsUuids
? But those are not entities.
List<UUID> networkModificationsUuids = modificationRepository.findModificationIdsByCompositeModificationId(uuid); | ||
List<ModificationInfos> orderedModifications; | ||
if (onlyCommonData) { | ||
List<ModificationEntity> networkModifications = modificationRepository.findBaseDataByIdIn(networkModificationsUuids); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
networkModificationsEntities
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK.
.stream() | ||
.map(this::getModificationInfo) | ||
.toList(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (uuids.isEmpty()) {
return Collections.emptyList();
}
and we can do better by fetching all modification uuids in one go like
.collect(Collectors.toMap(
uuid -> uuid,
modificationRepository::findModificationIdsByCompositeModificationId));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand, but I completely changed this funciton anyway so I don't think this is still needed.
.stream() | ||
.map(this::getModificationInfo) | ||
.toList(); | ||
} | ||
entities.addAll(orderedModifications); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (UUID uuid : uuids) {
List<UUID> networkModificationsUuids = networkModificationsMap.get(uuid);
if (onlyMetadata) {
List<ModificationEntity> networkModifications = modificationRepository.findBaseDataByIdIn(networkModificationsUuids);
entities.addAll(networkModifications.stream()
.map(this::getModificationInfos)
.toList());
} else {
entities.addAll(networkModificationsUuids.stream()
.map(this::getModificationInfo)
.toList());
}
}
return Collections.unmodifiableList(entities);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same answer than the previous comment.
@@ -220,6 +220,18 @@ public ResponseEntity<UUID> createNetworkCompositeModification(@RequestBody List | |||
return ResponseEntity.ok().body(networkModificationService.createNetworkCompositeModification(modificationUuids)); | |||
} | |||
|
|||
@GetMapping(value = "/network-composite-modification/{id}", produces = MediaType.APPLICATION_JSON_VALUE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GetMapping(value = "/network-composite-modification/{id}", produces = MediaType.APPLICATION_JSON_VALUE) | |
@GetMapping(value = "/network-composite-modification/{uuid}", produces = MediaType.APPLICATION_JSON_VALUE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK done and updated with a /network-modifications
. I think this is clearer.
@Transactional(readOnly = true) | ||
public List<ModificationInfos> getCompositeModificationsInfos(@NonNull List<UUID> uuids) { | ||
public List<ModificationInfos> getCompositeModificationsContentInfos(@NonNull List<UUID> uuids, boolean onlyCommonData) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this method should return wether a list of modification base infos or a modification full infos. You could rather implement 2 two methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it gets too confusing. I separated them.
Signed-off-by: Mathieu DEHARBE <[email protected]>
Signed-off-by: Mathieu DEHARBE <[email protected]>
src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Mathieu DEHARBE <[email protected]>
Quality Gate passedIssues Measures |
No description provided.