Skip to content

Commit

Permalink
metadata instead of complete ModificationInfos
Browse files Browse the repository at this point in the history
Signed-off-by: Mathieu DEHARBE <[email protected]>
  • Loading branch information
Mathieu-Deharbe committed Oct 9, 2024
1 parent 190e807 commit 94c049d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,10 @@ public ResponseEntity<UUID> createNetworkCompositeModification(@RequestBody List
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Content of the composite modification"),
@ApiResponse(responseCode = "404", description = "This composite modification does not exist")}
)
// TODO : renvoyer plutôt des métadonnées plutôt que des modifications complètes ?? (List<ModificationMetadata>) ?? => bof pas de name dedans !
public ResponseEntity<List<ModificationInfos>> getCompositeModificationContent(@PathVariable("id") UUID compositeModificationId) {
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_JSON)
.body(networkModificationService.getCompositeModificationContentInfos(compositeModificationId)
.body(networkModificationService.getCompositeModificationContentMetadata(compositeModificationId)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public List<ModificationInfos> getModifications(UUID groupUuid, boolean onlyMeta
return getModifications(groupUuid, onlyMetadata, errorOnGroupNotFound, false);
}

// TODO : regarder cette récup de métadata plutôt que la mienne
@Transactional(readOnly = true)
public List<ModificationInfos> getModifications(UUID groupUuid, boolean onlyMetadata, boolean errorOnGroupNotFound, boolean onlyStashed) {
try {
Expand Down Expand Up @@ -315,6 +316,15 @@ public ModificationInfos getModificationInfo(UUID modificationUuid) {
return getModificationInfos(optionalModificationEntity.get());
}

@Transactional(readOnly = true)
public ModificationInfos getMetadata(UUID modificationUuid) {
Optional<ModificationEntity> optionalModificationEntity = modificationRepository.findById(modificationUuid);
if (!optionalModificationEntity.isPresent()) {
throw new NetworkModificationException(MODIFICATION_NOT_FOUND, modificationUuid.toString());
}
return ModificationInfos.fromEntity(optionalModificationEntity.get());
}

@Transactional // To have the 2 delete in the same transaction (atomic)
public void deleteModificationGroup(UUID groupUuid, boolean errorOnGroupNotFound) {
try {
Expand Down Expand Up @@ -388,16 +398,17 @@ public List<ModificationInfos> getModificationsInfos(@NonNull List<UUID> uuids)
}

/**
* @param onlyMetadata if true, only returns the basic data common to all the modificaions
* @return the data from all the network modification contained in the composite modification sent as parameters
*/
@Transactional(readOnly = true)
public List<ModificationInfos> getCompositeModificationsContentInfos(@NonNull List<UUID> uuids) {
public List<ModificationInfos> getCompositeModificationsContentInfos(@NonNull List<UUID> uuids, boolean onlyMetadata) {
List<ModificationInfos> entities = new ArrayList<>();
uuids.forEach(uuid -> {
List<UUID> foundEntities = modificationRepository.findModificationIdsByCompositeModificationId(uuid);
List<ModificationInfos> orderedModifications = foundEntities
.stream()
.map(this::getModificationInfo)
.map(onlyMetadata ? this::getMetadata : this::getModificationInfo)
.toList();
entities.addAll(orderedModifications);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public List<ModificationInfos> getNetworkModifications(UUID groupUuid, boolean o

@Transactional(readOnly = true)
// Need a transaction for collections lazy loading ==> TODO : this is copy pasted, is this true here ?
public List<ModificationInfos> getCompositeModificationContentInfos(UUID compositeModificationUuid) {
return networkModificationRepository.getCompositeModificationsContentInfos(List.of(compositeModificationUuid));
public List<ModificationInfos> getCompositeModificationContentMetadata(UUID compositeModificationUuid) {
return networkModificationRepository.getCompositeModificationsContentInfos(List.of(compositeModificationUuid), true);
}

@Transactional(readOnly = true)
Expand Down Expand Up @@ -291,7 +291,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.getCompositeModificationsContentInfos(modificationsUuids);
List<ModificationInfos> modificationInfos = networkModificationRepository.getCompositeModificationsContentInfos(modificationsUuids, false);
networkModificationRepository.saveModificationInfos(targetGroupUuid, modificationInfos);
return applyModifications(networkUuid, variantId, reportInfos, modificationInfos);
}
Expand Down Expand Up @@ -334,7 +334,7 @@ public Optional<NetworkModificationResult> applyModificationsFromUuids(UUID netw
String variantId,
ReportInfos reportInfos,
List<UUID> modificationsUuids) {
List<ModificationInfos> modificationInfos = networkModificationRepository.getCompositeModificationsContentInfos(modificationsUuids);
List<ModificationInfos> modificationInfos = networkModificationRepository.getCompositeModificationsContentInfos(modificationsUuids, false);
return applyModifications(networkUuid, variantId, reportInfos, modificationInfos);
}
}

0 comments on commit 94c049d

Please sign in to comment.