Skip to content
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

Merged
merged 15 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,16 @@ public ResponseEntity<UUID> createNetworkCompositeModification(@RequestBody List
return ResponseEntity.ok().body(networkModificationService.createNetworkCompositeModification(modificationUuids));
}

@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) {
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_JSON)
.body(networkModificationService.getNetworkModificationsFromComposite(compositeModificationUuid)
);
}

@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")})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public interface ModificationRepository extends JpaRepository<ModificationEntity
@Query(value = "SELECT new ModificationEntity(m.id, m.type) FROM ModificationEntity m WHERE m.id IN (?1)")
List<ModificationEntity> findMetadataIn(List<UUID> uuids);

/**
* @return base data of the network modifications (the data from the main common table, not those specific to each modification)
*/
@Query(value = "SELECT new ModificationEntity(m.id, m.type, m.date, m.stashed, m.activated, m.messageType, m.messageValues) FROM ModificationEntity m WHERE m.id IN (?1) order by m.modificationsOrder")
List<ModificationEntity> findBaseDataByIdIn(List<UUID> uuids);

@Query(value = "SELECT m FROM ModificationEntity m WHERE m.id IN (?1) ORDER BY m.modificationsOrder")
List<ModificationEntity> findAllByIdIn(List<UUID> uuids);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,20 @@ public List<ModificationInfos> getModificationsInfos(@NonNull List<UUID> uuids)
return uuids.stream().map(entities::get).filter(Objects::nonNull).map(this::getModificationInfos).toList();
}

/**
* returns the data from all the network modifications contained in the composite modification sent as parameter
* but only returns the basic data common to all the modifications form the ModificationInfos, not from the extended classes
*/
@Transactional(readOnly = true)
public List<ModificationInfos> getBasicNetworkModificationsFromComposite(@NonNull UUID uuid) {
List<UUID> networkModificationsUuids = modificationRepository.findModificationIdsByCompositeModificationId(uuid);
List<ModificationEntity> networkModificationsEntities = modificationRepository.findBaseDataByIdIn(networkModificationsUuids);
return networkModificationsEntities
.stream()
.map(this::getModificationInfos)
.toList();
}

@Transactional(readOnly = true)
public List<ModificationInfos> getCompositeModificationsInfos(@NonNull List<UUID> uuids) {
List<ModificationInfos> entities = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public List<ModificationInfos> getNetworkModifications(UUID groupUuid, boolean o
return getNetworkModifications(groupUuid, onlyMetadata, errorOnGroupNotFound, false);
}

@Transactional(readOnly = true)
public List<ModificationInfos> getNetworkModificationsFromComposite(UUID compositeModificationUuid) {
return networkModificationRepository.getBasicNetworkModificationsFromComposite(compositeModificationUuid);
}

@Transactional(readOnly = true)
public ModificationInfos getNetworkModification(UUID networkModificationUuid) {
return networkModificationRepository.getModificationInfo(networkModificationUuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class ModificationControllerTest {

private static final String URI_NETWORK_MODIF_BASE = "/v1/network-modifications";
private static final String URI_COMPOSITE_NETWORK_MODIF_BASE = "/v1/network-composite-modifications";
private static final String URI_GET_COMPOSITE_NETWORK_MODIF_CONTENT = "/v1/network-composite-modification/";
private static final String URI_NETWORK_MODIF_PARAMS = "&groupUuid=" + TEST_GROUP_ID + "&reportUuid=" + TEST_REPORT_ID + "&reporterId=" + UUID.randomUUID();
private static final String URI_NETWORK_MODIF = URI_NETWORK_MODIF_BASE + "?networkUuid=" + TEST_NETWORK_ID + URI_NETWORK_MODIF_PARAMS;
private static final String URI_NETWORK_MODIF_BUS_BREAKER = URI_NETWORK_MODIF_BASE + "?networkUuid=" + TEST_NETWORK_BUS_BREAKER_ID + URI_NETWORK_MODIF_PARAMS;
Expand Down Expand Up @@ -695,9 +696,10 @@ void testMoveModificationInSameGroup() throws Exception {

@Test
void testNetworkCompositeModification() throws Exception {
// Insert a switch modification in the group
List<ModificationInfos> modificationList = createSomeSwitchModifications(TEST_GROUP_ID, 1);
assertEquals(1, modificationRepository.getModifications(TEST_GROUP_ID, true, true).size());
// Insert some switch modifications in the group
int modificationsNumber = 2;
List<ModificationInfos> modificationList = createSomeSwitchModifications(TEST_GROUP_ID, modificationsNumber);
assertEquals(modificationsNumber, modificationRepository.getModifications(TEST_GROUP_ID, true, true).size());

// Create a composite modification with the switch modification
List<UUID> modificationUuids = modificationList.stream().map(ModificationInfos::getUuid).toList();
Expand All @@ -710,7 +712,13 @@ void testNetworkCompositeModification() throws Exception {
.build();
UUID compositeModificationUuid = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { });
assertThat(modificationRepository.getModificationInfo(compositeModificationUuid)).recursivelyEquals(compositeModificationInfos);
assertEquals(1, modificationRepository.getModifications(TEST_GROUP_ID, true, true).size());
assertEquals(modificationsNumber, modificationRepository.getModifications(TEST_GROUP_ID, true, true).size());

// get the composite modification metadata
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());

// Insert the composite modification in the group
mvcResult = mockMvc.perform(
Expand All @@ -725,10 +733,10 @@ void testNetworkCompositeModification() throws Exception {
assertApplicationStatusOK(mvcResult);

List<ModificationInfos> newModificationList = modificationRepository.getModifications(TEST_GROUP_ID, false, true);
assertEquals(2, newModificationList.size());
assertEquals(modificationsNumber * 2, newModificationList.size());
List<UUID> newModificationUuidList = newModificationList.stream().map(ModificationInfos::getUuid).toList();
assertEquals(modificationUuids.get(0), newModificationUuidList.get(0));
assertThat(modificationList.get(0)).recursivelyEquals(newModificationList.get(1));
assertThat(modificationList.get(0)).recursivelyEquals(newModificationList.get(modificationsNumber));
}

@Test
Expand Down
Loading