powsybl / powsybl-open-rao

A toolbox based on powsybl framework dedicated to power systems coordinated capacity calculation and security analysis projects
Mozilla Public License 2.0
15 stars 6 forks source link

Make JSON CRAC import more robust #1098

Open pet-mit opened 2 months ago

pet-mit commented 2 months ago

Describe the current behavior

When an element in the json crac is wrong (for example a network action with one elementary action pointing to a network element that does not exist in the network), the json import fails and produces a null CRAC.

Describe the expected behavior

Do like other format importers: ignore the wrong elements and log the issue in the CracCreationContext. It may actually be hard because of the usage of the JsonParser that reads the file from top to bottom (meaning that when we face an issue, we should exit the current element "gracefully").

Describe the motivation

More robust importer

Extra Information

A basic test case : network action "complexNetworkActionId" should be ignored because one of its elementary actions is wrong

@Test crac-partial.json

void testPartialImport() {
    Network network = NetworkImportsUtil.createNetworkForJsonRetrocompatibilityTest();
    InputStream cracFile = getClass().getResourceAsStream("/crac-partial.json");
    CracCreationContext ccc = new JsonImport().importData(cracFile, CracCreationParameters.load(), network, null);

    assertNotNull(ccc);;
    assertTrue(ccc.isCreationSuccessful());

    Crac crac = ccc.getCrac();
    assertNotNull(crac);
}