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 content endpoint #102

Merged
merged 14 commits into from
Nov 13, 2024
Merged
21 changes: 21 additions & 0 deletions src/main/java/org/gridsuite/explore/server/ExploreController.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,15 @@ public ResponseEntity<List<ElementAttributes>> getElementsMetadata(@RequestParam
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(directoryService.getElementsMetadata(ids, elementTypes, equipmentTypes));
}

@GetMapping(value = "/explore/composite-modification/{id}/network-modifications", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "get the basic information of the network modifications contained in a composite modification")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Basic infos from all the contained network modifications")})
public ResponseEntity<List<Object>> getCompositeModificationContent(@PathVariable("id") UUID compositeModificationId) {
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_JSON)
.body(exploreService.getCompositeModificationContent(compositeModificationId));
}

@PutMapping(value = "/explore/filters/{id}", consumes = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Modify a filter")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The filter has been successfully modified")})
Expand All @@ -271,6 +280,18 @@ public ResponseEntity<Void> updateContingencyList(
return ResponseEntity.ok().build();
}

@PutMapping(value = "/explore/composite-modification/{id}", consumes = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Modify a composite modification")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The composite modification has been modified successfully")})
public ResponseEntity<Void> updateCompositeModification(
@PathVariable UUID id,
@RequestParam(name = "name") String name,
@RequestHeader(QUERY_PARAM_USER_ID) String userId) {

exploreService.updateCompositeModification(id, userId, name);
return ResponseEntity.ok().build();
}

@PostMapping(value = "/explore/parameters", consumes = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "create parameters")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "parameters creation request delegated to corresponding server")})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ public void updateContingencyList(UUID id, String content, String userId, String
updateElementName(id, name, userId);
}

public void updateCompositeModification(UUID id, String userId, String name) {
updateElementName(id, name, userId);
}

public List<Object> getCompositeModificationContent(UUID compositeModificationId) {
return networkModificationService.getCompositeModificationContent(compositeModificationId);
}

private void updateElementName(UUID id, String name, String userId) {
// if the name is empty, no need to call directory-server
if (StringUtils.isNotBlank(name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,19 @@ public List<Map<String, Object>> getMetadata(List<UUID> modificationUuids) {
new ParameterizedTypeReference<List<Map<String, Object>>>() {
}).getBody();
}

public List<Object> getCompositeModificationContent(UUID compositeModificationId) {
String path = UriComponentsBuilder
.fromPath(DELIMITER +
NETWORK_MODIFICATION_API_VERSION +
DELIMITER +
"/network-composite-modification/" +
compositeModificationId +
"/network-modifications")
.buildAndExpand()
.toUriString();
return restTemplate.exchange(networkModificationServerBaseUri + path, HttpMethod.GET, null,
new ParameterizedTypeReference<List<Object>>() {
}).getBody();
}
}
48 changes: 47 additions & 1 deletion src/test/java/org/gridsuite/explore/server/ExploreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class ExploreTest {
private static final UUID INVALID_ELEMENT_UUID = UUID.randomUUID();
private static final UUID PARAMETERS_UUID = UUID.randomUUID();
private static final UUID MODIFICATION_UUID = UUID.randomUUID();
private static final UUID MODIFICATION2_UUID = UUID.randomUUID();
private static final UUID COMPOSITE_MODIFICATION_UUID = UUID.randomUUID();
private static final UUID STUDY_COPY_UUID = UUID.randomUUID();
private static final UUID CASE_COPY_UUID = UUID.randomUUID();
private static final UUID CONTINGENCY_LIST_COPY_UUID = UUID.randomUUID();
Expand All @@ -97,6 +99,20 @@ class ExploreTest {
private final Map<String, Object> specificMetadata2 = Map.of("equipmentType", "LINE", "id", FILTER_UUID_2);
private final Map<String, Object> caseSpecificMetadata = Map.of("uuid", CASE_UUID, "name", TEST_FILE, "format", "XIIDM");
private final Map<String, Object> modificationSpecificMetadata = Map.of("id", MODIFICATION_UUID, "type", "LOAD_MODIFICATION");
private final List<Map<String, Object>> compositeModificationMetadata = List.of(
Map.of(
"uuid", MODIFICATION_UUID,
"type", "LOAD_MODIFICATION",
"messageType", "LOAD_MODIFICATION",
"messageValues", "{\"equipmentId\":\"equipmentId1\"}",
"activated", true),
Map.of(
"uuid", MODIFICATION2_UUID,
"type", "SHUNT_COMPENSATOR_MODIFICATION",
"messageType", "SHUNT_COMPENSATOR_MODIFICATION",
"messageValues", "{\"equipmentId\":\"equipmentId2\"}",
"activated", true)
);

private static final UUID SCRIPT_ID_BASE_FORM_CONTINGENCY_LIST_UUID = UUID.randomUUID();
private static final UUID ELEMENT_UUID = UUID.randomUUID();
Expand Down Expand Up @@ -291,7 +307,15 @@ public MockResponse dispatch(RecordedRequest request) {
} else if (path.matches("/v1/cases/metadata[?]ids=" + CASE_UUID)) {
return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), caseInfosAttributesAsString);
} else if (path.matches("/v1/network-modifications/metadata[?]ids=" + MODIFICATION_UUID)) {
return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), modificationInfosAttributesAsString);
return new MockResponse(200,
Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE),
modificationInfosAttributesAsString);
} else if (path.matches("/v1/network-composite-modification/" + COMPOSITE_MODIFICATION_UUID + "/network-modifications")) {
return new MockResponse(200,
Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE),
mapper.writeValueAsString(compositeModificationMetadata));
} else if (path.matches("/v1/network-composite-modification/.*") && "PUT".equals(request.getMethod())) {
return new MockResponse(200);
} else if (path.matches("/v1/studies/metadata[?]ids=" + PRIVATE_STUDY_UUID)) {
return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), listOfPrivateStudyAttributesAsString.replace("elementUuid", "id"));
} else if (path.matches("/v1/users/" + USER_WITH_CASE_LIMIT_EXCEEDED + "/profile/max-cases")) {
Expand Down Expand Up @@ -754,6 +778,17 @@ void testCreateNetworkCompositeModifications() throws Exception {
).andExpect(status().isOk());
}

@Test
void testModifyCompositeModifications(final MockWebServer server) throws Exception {
final String name = "script name";
mockMvc.perform(
put("/v1/explore/composite-modification/{id}", COMPOSITE_MODIFICATION_UUID)
.contentType(APPLICATION_JSON)
.param("name", name)
.header("userId", USER1)
).andExpect(status().isOk());
}

@Test
void testGetModificationMetadata() throws Exception {
final String expectedResult = mapper.writeValueAsString(new ElementAttributes(MODIFICATION_UUID, "one modif", "MODIFICATION", USER1, 0L, null, modificationSpecificMetadata));
Expand All @@ -767,6 +802,17 @@ void testGetModificationMetadata() throws Exception {
assertEquals(mapper.writeValueAsString(elementsMetadata.get(0)), expectedResult);
}

@Test
void testGetCompositeModificationContent() throws Exception {
MvcResult result = mockMvc.perform(get("/v1/explore/composite-modification/" + COMPOSITE_MODIFICATION_UUID + "/network-modifications")
.header("userId", USER1)
).andExpect(status().isOk())
.andReturn();
String response = result.getResponse().getContentAsString();
List<Map<String, Object>> metadata = mapper.readValue(response, new TypeReference<>() { });
assertEquals(2, metadata.size());
}

@Test
void testMaxCaseCreationExceeded() throws Exception {
//test create a study with a user that already exceeded his cases limit
Expand Down
Loading