From dda37950e763678e8e02d70a31a9d2a760bfbfdb Mon Sep 17 00:00:00 2001 From: David Kleiven Date: Sun, 19 Nov 2023 15:15:58 +0100 Subject: [PATCH] Add default security analysis parameters --- src/main/ApiUtil.kt | 13 +++++++++++++ src/test/AppTest.kt | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/main/ApiUtil.kt b/src/main/ApiUtil.kt index db0b65e..47f9873 100644 --- a/src/main/ApiUtil.kt +++ b/src/main/ApiUtil.kt @@ -3,6 +3,8 @@ package com.github.statnett.loadflowservice import com.fasterxml.jackson.databind.ObjectMapper import com.powsybl.iidm.network.Network import com.powsybl.nad.NetworkAreaDiagram +import com.powsybl.security.SecurityAnalysisParameters +import com.powsybl.security.json.SecurityAnalysisJsonModule import com.powsybl.sensitivity.SensitivityAnalysisParameters import com.powsybl.sensitivity.json.SensitivityJsonModule import com.powsybl.sld.SingleLineDiagram @@ -116,11 +118,18 @@ fun defaultSensitivityAnalysisParameters(): String { return mapper.writeValueAsString(SensitivityAnalysisParameters()) } +fun defaultSecurityAnalysisParameters(): String { + val mapper = ObjectMapper() + mapper.registerModule(SecurityAnalysisJsonModule()) + return mapper.writeValueAsString(SecurityAnalysisParameters()) +} + class UnknownRouteException(message: String) : Exception(message) fun defaultParameterSet(name: String): String { val loadParams = "load-params" val sensitivityAnalysisParams = "sensitivity-analysis-params" + val securityAnalysisParams = "security-analysis-params" return when (name) { loadParams -> { defaultLoadFlowParameters() @@ -130,6 +139,10 @@ fun defaultParameterSet(name: String): String { defaultSensitivityAnalysisParameters() } + securityAnalysisParams -> { + defaultSecurityAnalysisParameters() + } + else -> { val allowed = listOf(loadParams, sensitivityAnalysisParams) throw UnknownRouteException("Unknown parameters set $name. Must be one of $allowed") diff --git a/src/test/AppTest.kt b/src/test/AppTest.kt index 3484760..d012fad 100644 --- a/src/test/AppTest.kt +++ b/src/test/AppTest.kt @@ -354,6 +354,18 @@ class ApplicationTest { } } + @Test + fun `test default security analysis parameters`() { + testApplication { + val response = client.get("default-values/security-analysis-params") + assertEquals(HttpStatusCode.OK, response.status) + val body = response.bodyAsText() + assertTrue(body.startsWith("{")) + assertTrue(body.endsWith("}")) + } + + } + }