-
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
Changes from 10 commits
190e807
94c049d
0dcc187
b4fe982
04d95b4
959bfd4
659dfb2
b001a7f
6886fb4
d890755
002e663
6277098
8dbf573
5443632
4d88cac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Content is not clear enough and it is generic description There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I kind of updated all of this to be closer to I think it was clearer that my previous endpoint. |
||
@ApiResponse(responseCode = "404", description = "This composite modification does not exist")} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 404 code is for not found response If the id is not found in the database, an exception should be thrown by networkModificationService There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Message changed. Remobved that 404. |
||
) | ||
public ResponseEntity<List<ModificationInfos>> getCompositeModificationContent(@PathVariable("id") UUID compositeModificationId) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. For PathVariable If I add a true, intellij calls it a redundant parameter. |
||
return ResponseEntity.ok() | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.body(networkModificationService.getCompositeModificationContentMetadata(compositeModificationId) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Renamed I am still not very satisfied of it, but still better than metadata indeed. |
||
); | ||
} | ||
|
||
@PostMapping(value = "/network-modifications", consumes = MediaType.APPLICATION_JSON_VALUE) | ||
@Operation(summary = "Duplicate some modifications without group ownership") | ||
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The duplicated modifications uuids mapped with their source uuid")}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the network modifications use the But they also have specific data extending this data like |
||
* @return the data from all the network modification contained in the composite modification sent as parameters | ||
*/ | ||
@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 commentThe 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 commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it gets too confusing. I separated them. |
||
List<ModificationInfos> entities = new ArrayList<>(); | ||
uuids.forEach(uuid -> { | ||
List<UUID> foundEntities = modificationRepository.findModificationIdsByCompositeModificationId(uuid); | ||
List<ModificationInfos> orderedModifications = foundEntities | ||
.stream() | ||
.map(this::getModificationInfo) | ||
.toList(); | ||
List<UUID> networkModificationsUuids = modificationRepository.findModificationIdsByCompositeModificationId(uuid); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean renaming |
||
List<ModificationInfos> orderedModifications; | ||
if (onlyCommonData) { | ||
List<ModificationEntity> networkModifications = modificationRepository.findBaseDataByIdIn(networkModificationsUuids); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. OK. |
||
orderedModifications = networkModifications | ||
.stream() | ||
.map(this::getModificationInfos) | ||
.toList(); | ||
} else { | ||
orderedModifications = networkModificationsUuids | ||
.stream() | ||
.map(this::getModificationInfo) | ||
.toList(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
and we can do better by fetching all modification uuids in one go like
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
entities.addAll(orderedModifications); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same answer than the previous comment. |
||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,12 @@ public List<ModificationInfos> getNetworkModifications(UUID groupUuid, boolean o | |
return getNetworkModifications(groupUuid, onlyMetadata, errorOnGroupNotFound, false); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
// Need a transaction for collections lazy loading | ||
Mathieu-Deharbe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public List<ModificationInfos> getCompositeModificationContentMetadata(UUID compositeModificationUuid) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ContentMetadata ? can be implied, you might shorten it to getCompositeModificationMetadata There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed, removed all references to Metadata. |
||
return networkModificationRepository.getCompositeModificationsContentInfos(List.of(compositeModificationUuid), true); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public ModificationInfos getNetworkModification(UUID networkModificationUuid) { | ||
return networkModificationRepository.getModificationInfo(networkModificationUuid); | ||
|
@@ -289,7 +295,7 @@ public Optional<NetworkModificationResult> duplicateModifications(UUID targetGro | |
public Optional<NetworkModificationResult> insertCompositeModifications(UUID targetGroupUuid, | ||
UUID networkUuid, String variantId, | ||
ReportInfos reportInfos, List<UUID> modificationsUuids) { | ||
List<ModificationInfos> modificationInfos = networkModificationRepository.getCompositeModificationsInfos(modificationsUuids); | ||
List<ModificationInfos> modificationInfos = networkModificationRepository.getCompositeModificationsContentInfos(modificationsUuids, false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ContentInfos ? (content or infos have the same meaning) you could keep only Infos There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed. |
||
networkModificationRepository.saveModificationInfos(targetGroupUuid, modificationInfos); | ||
return applyModifications(networkUuid, variantId, reportInfos, modificationInfos); | ||
} | ||
|
@@ -332,7 +338,7 @@ public Optional<NetworkModificationResult> applyModificationsFromUuids(UUID netw | |
String variantId, | ||
ReportInfos reportInfos, | ||
List<UUID> modificationsUuids) { | ||
List<ModificationInfos> modificationInfos = networkModificationRepository.getCompositeModificationsInfos(modificationsUuids); | ||
List<ModificationInfos> modificationInfos = networkModificationRepository.getCompositeModificationsContentInfos(modificationsUuids, false); | ||
return applyModifications(networkUuid, variantId, reportInfos, modificationInfos); | ||
} | ||
} |
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.
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.