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

add list of ids to contingency info export endpoint #102

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ public ResponseEntity<List<ContingencyInfos>> exportContingencyInfosList(@PathVa
return ResponseEntity.ok().body(service.exportContingencyInfosList(id, networkUuid, variantId));
}

@GetMapping(value = "/contingency-lists/contingency-infos/export", produces = MediaType.APPLICATION_JSON_VALUE)
antoinebhs marked this conversation as resolved.
Show resolved Hide resolved
@Operation(summary = "Evaluate and export a contingency infos list to JSON format")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The contingency list in JSON format"),
@ApiResponse(responseCode = "404", description = "The contingency list does not exists")})
antoinebhs marked this conversation as resolved.
Show resolved Hide resolved
public ResponseEntity<List<ContingencyInfos>> exportContingencyInfosList(@RequestParam(value = "networkUuid", required = false) UUID networkUuid,
antoinebhs marked this conversation as resolved.
Show resolved Hide resolved
@RequestParam(value = "variantId", required = false) String variantId,
@RequestParam(value = "ids", required = true) List<UUID> ids) {
antoinebhs marked this conversation as resolved.
Show resolved Hide resolved
return ResponseEntity.ok().body(service.exportContingencyInfosList(ids, networkUuid, variantId));
}

@PostMapping(value = "/script-contingency-lists", consumes = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Create a script contingency list")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The script contingency list have been created successfully")})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ public List<ContingencyInfos> exportContingencyInfosList(UUID id, UUID networkUu
return evaluateContingencyList(findContingencyList(id, network), network);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove previous exportContingencyInfosList definition

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@Transactional(readOnly = true)
public List<ContingencyInfos> exportContingencyInfosList(List<UUID> ids, UUID networkUuid, String variantId) {
Network network = getNetworkFromUuid(networkUuid, variantId);
return ids.stream().map(id -> evaluateContingencyList(findContingencyList(id, network), network)).flatMap(Collection::stream).toList();
}

private PersistentContingencyList findContingencyList(UUID id, Network network) {
Objects.requireNonNull(id);
return getAnyContingencyList(id, network)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.powsybl.contingency.Contingency;
import com.powsybl.contingency.GeneratorContingency;
import com.powsybl.contingency.LineContingency;
import com.powsybl.contingency.contingency.list.IdentifierContingencyList;
import com.powsybl.iidm.network.Terminal;
Expand Down Expand Up @@ -788,6 +789,45 @@ private void testExportContingencies(String content, String expectedContent, UUI
.andExpect(status().isOk());
}

@Test
public void testExportMultiContingenciesInfo() throws Exception {
Set<String> noCountries = Collections.emptySet();
String lineForm = genFormContingencyList(EquipmentType.LINE, -1., EQUALITY, noCountries);
String genForm = genFormContingencyList(EquipmentType.GENERATOR, 100., LESS_THAN, noCountries);

List<UUID> contingencies = new ArrayList<>();
contingencies.add(addNewFormContingencyList(lineForm));
contingencies.add(addNewFormContingencyList(genForm));

StringBuilder urlBuilder = new StringBuilder();
urlBuilder.append("/").append(VERSION).append("/contingency-lists/contingency-infos/export");
urlBuilder.append("?networkUuid=").append(NETWORK_UUID);
urlBuilder.append("&variantId=").append(VARIANT_ID_1);

contingencies.forEach(id -> urlBuilder.append("&").append("ids").append("=").append(id));

ContingencyInfos expectedContingency1 = new ContingencyInfos("NHV1_NHV2_1", new Contingency("NHV1_NHV2_1", null, List.of(new LineContingency("NHV1_NHV2_1"))), null, Set.of());
ContingencyInfos expectedContingency2 = new ContingencyInfos("NHV1_NHV2_2", new Contingency("NHV1_NHV2_2", null, List.of(new LineContingency("NHV1_NHV2_2"))), null, Set.of());
ContingencyInfos expectedContingency3 = new ContingencyInfos("GEN", new Contingency("GEN", null, List.of(new GeneratorContingency("GEN"))), null, Set.of());

mvc.perform(get(urlBuilder.toString())
.contentType(APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON))
.andExpect(content().json(objectMapper.writeValueAsString(List.of(expectedContingency1, expectedContingency2, expectedContingency3))));
// delete data
contingencies.forEach(id -> {
try {
mvc.perform(delete("/" + VERSION + "/contingency-lists/" + id.toString()))
.andExpect(status().isOk());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
);

}

@Test
public void testExportContingenciesInfos() throws Exception {
ScriptContingencyList scriptContingencyList = new ScriptContingencyList("contingency('NHV1_NHV2_1') {\n" +
Expand Down
Loading