Skip to content

Commit

Permalink
Add optional parameter to get complete data of modifications in a com…
Browse files Browse the repository at this point in the history
…posite modification. (#567)

* Add optional parameter to get complete data of modifications in a composite modification.

Signed-off-by: Franck LECUYER <[email protected]>
  • Loading branch information
FranckLecuyer authored Dec 2, 2024
1 parent 18c55ab commit e67f5e9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,11 @@ public ResponseEntity<UUID> createNetworkCompositeModification(@RequestBody List
@GetMapping(value = "/network-composite-modification/{uuid}/network-modifications", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get the list of the network modifications inside a composite modification")
@ApiResponse(responseCode = "200", description = "List of the modifications inside the composite modification")
public ResponseEntity<List<ModificationInfos>> getNetworkModificationsFromComposite(@PathVariable("uuid") UUID compositeModificationUuid) {
public ResponseEntity<List<ModificationInfos>> getNetworkModificationsFromComposite(@PathVariable("uuid") UUID compositeModificationUuid,
@Parameter(description = "Only metadata") @RequestParam(name = "onlyMetadata", required = false, defaultValue = "true") Boolean onlyMetadata) {
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_JSON)
.body(networkModificationService.getNetworkModificationsFromComposite(compositeModificationUuid)
.body(networkModificationService.getNetworkModificationsFromComposite(compositeModificationUuid, onlyMetadata)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ public List<ModificationInfos> getNetworkModifications(UUID groupUuid, boolean o
}

@Transactional(readOnly = true)
public List<ModificationInfos> getNetworkModificationsFromComposite(UUID compositeModificationUuid) {
return networkModificationRepository.getBasicNetworkModificationsFromComposite(compositeModificationUuid);
public List<ModificationInfos> getNetworkModificationsFromComposite(UUID compositeModificationUuid, boolean onlyMetadata) {
if (onlyMetadata) {
return networkModificationRepository.getBasicNetworkModificationsFromComposite(compositeModificationUuid);
} else {
return networkModificationRepository.getCompositeModificationsInfos(List.of(compositeModificationUuid));
}
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,11 +717,26 @@ void testNetworkCompositeModification() throws Exception {
assertThat(modificationRepository.getModificationInfo(compositeModificationUuid)).recursivelyEquals(compositeModificationInfos);
assertEquals(modificationsNumber, modificationRepository.getModifications(TEST_GROUP_ID, true, true).size());

// get the composite modification metadata
// get the composite modification (metadata only)
mvcResult = mockMvc.perform(get(URI_GET_COMPOSITE_NETWORK_MODIF_CONTENT + compositeModificationUuid + "/network-modifications"))
.andExpect(status().isOk()).andReturn();
List<ModificationInfos> compositeModificationContent = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { });
assertEquals(modificationsNumber, compositeModificationContent.size());
assertNotNull(compositeModificationContent.get(0).getMessageType());
assertNotNull(compositeModificationContent.get(0).getMessageValues());
assertNull(((EquipmentAttributeModificationInfos) compositeModificationContent.get(0)).getEquipmentAttributeName());
assertNull(((EquipmentAttributeModificationInfos) compositeModificationContent.get(0)).getEquipmentAttributeValue());
assertNull(((EquipmentAttributeModificationInfos) compositeModificationContent.get(0)).getEquipmentType());
assertNull(((EquipmentAttributeModificationInfos) compositeModificationContent.get(0)).getEquipmentId());

// get the composite modification (complete data)
mvcResult = mockMvc.perform(get(URI_GET_COMPOSITE_NETWORK_MODIF_CONTENT + compositeModificationUuid + "/network-modifications?onlyMetadata=false"))
.andExpect(status().isOk()).andReturn();
compositeModificationContent = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { });
assertEquals("open", ((EquipmentAttributeModificationInfos) compositeModificationContent.get(0)).getEquipmentAttributeName());
assertEquals(Boolean.TRUE, ((EquipmentAttributeModificationInfos) compositeModificationContent.get(0)).getEquipmentAttributeValue());
assertEquals(IdentifiableType.SWITCH, ((EquipmentAttributeModificationInfos) compositeModificationContent.get(0)).getEquipmentType());
assertEquals("v1b1", ((EquipmentAttributeModificationInfos) compositeModificationContent.get(0)).getEquipmentId());

// Insert the composite modification in the group
mvcResult = mockMvc.perform(
Expand Down

0 comments on commit e67f5e9

Please sign in to comment.