Skip to content

Commit

Permalink
get all modification of a group (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamal-khey committed Oct 6, 2023
1 parent fb83b68 commit 3880047
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ public ResponseEntity<ModificationInfos> getNetworkModification(
return ResponseEntity.ok().body(networkModificationService.getNetworkModification(networkModificationUuid));
}

@GetMapping(value = "/network-modifications", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get all network modification")
@ApiResponse(responseCode = "200", description = "The network modifications were returned")
public ResponseEntity<List<ModificationInfos>> getAllNetworkModification(
@Parameter(description = "Group UUID") @RequestParam("groupUuid") UUID groupUuid,
@Parameter(description = "delete only stashed modifications") @RequestParam(name = "onlyStashed", required = false, defaultValue = "false") Boolean onlyStashed){
if(!onlyStashed)
return ResponseEntity.ok().body(networkModificationService.getAllNetworkModifications(groupUuid));
else
return ResponseEntity.ok().body(networkModificationService.getAllStashedModifications(groupUuid));
}

@DeleteMapping(value = "/network-modifications", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Delete network modifications")
@ApiResponse(responseCode = "200", description = "The network modifications were deleted")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,25 @@ public ModificationInfos getModificationInfo(UUID modificationUuid) {
.toModificationInfos();
}

//get all modifications infos
@Transactional(readOnly = true)
public List<ModificationInfos> getAllModificationInfo(UUID groupUuid) {
ModificationGroupEntity groupEntity = getModificationGroup(groupUuid);
return groupEntity.getModifications().stream()
.map(ModificationEntity::toModificationInfos)
.collect(Collectors.toList());
}

//find all stashed modifications
@Transactional(readOnly = true)
public List<ModificationInfos> getAllStashedModificationsInfo(UUID groupUuid) {
ModificationGroupEntity groupEntity = getModificationGroup(groupUuid);
return groupEntity.getModifications().stream()
.filter(ModificationEntity::getStashed)
.map(ModificationEntity::toModificationInfos)
.collect(Collectors.toList());
}

@Transactional // To have the 2 delete in the same transaction (atomic)
public void deleteModificationGroup(UUID groupUuid, boolean errorOnGroupNotFound) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ public ModificationInfos getNetworkModification(UUID networkModificationUuid) {
return networkModificationRepository.getModificationInfo(networkModificationUuid);
}

//get all network modifications
@Transactional(readOnly = true)
public List<ModificationInfos> getAllNetworkModifications(UUID groupUuid) {
return networkModificationRepository.getAllModificationInfo(groupUuid);
}

@Transactional(readOnly = true)
public List<ModificationInfos> getAllStashedModifications(UUID groupUuid) {
return networkModificationRepository.getAllStashedModificationsInfo(groupUuid);
}

public void deleteModificationGroup(UUID groupUuid, boolean errorOnGroupNotFound) {
networkModificationRepository.deleteModificationGroup(groupUuid, errorOnGroupNotFound);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,43 @@ private List<ModificationInfos> createSomeSwitchModifications(UUID groupId, int
return modificationList;
}

@Test
public void testGetNetworkModification() throws Exception {
// create 3 modifications
List<ModificationInfos> modificationList = createSomeSwitchModifications(TEST_GROUP_ID, 3);
List<UUID> modificationUuidList = modificationList.stream().map(ModificationInfos::getUuid).collect(Collectors.toList());

// get all modifications
{
MvcResult mvcResult = mockMvc.perform(get("/v1/network-modifications?groupUuid=" + TEST_GROUP_ID))
.andExpect(status().isOk()).andReturn();
var modificationListResult = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<List<ModificationInfos>>() {});
var newModificationList = modificationRepository.getAllModificationInfo(TEST_GROUP_ID);
assertEquals(modificationUuidList, newModificationList.stream().map(ModificationInfos::getUuid).collect(Collectors.toList()));
assertEquals(modificationListResult.size(), modificationUuidList.size());
}

{
MvcResult mvcResultStashed = mockMvc.perform(get("/v1/network-modifications?groupUuid=" + TEST_GROUP_ID+ "&onlyStashed=true"))
.andExpect(status().isOk()).andReturn();
var stashedModificationListResult = mapper.readValue(mvcResultStashed.getResponse().getContentAsString(), new TypeReference<List<ModificationInfos>>() {});
assertEquals(0, stashedModificationListResult.size());
}

{ // stash one modification and get stashed modification only
UUID modificationUuid = modificationUuidList.get(0);
mockMvc.perform(post("/v1/network-modifications/stash?groupUuid=" + TEST_GROUP_ID + "&uuids=" + modificationUuid))
.andExpect(status().isOk());
MvcResult mvcResultStashed = mockMvc.perform(get("/v1/network-modifications?groupUuid=" + TEST_GROUP_ID+ "&onlyStashed=true"))
.andExpect(status().isOk()).andReturn();
var stashedModificationListResult = mapper.readValue(mvcResultStashed.getResponse().getContentAsString(), new TypeReference<List<ModificationInfos>>() {});
assertEquals(1, stashedModificationListResult.size());
assertEquals(modificationUuid, stashedModificationListResult.get(0).getUuid());
}

}


@Test
public void testDuplicateModification() throws Exception {
// create 3 modifications
Expand Down

0 comments on commit 3880047

Please sign in to comment.