From 879fca6b49cccaa05a84cf90863ba111ccc87160 Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Wed, 24 Apr 2024 19:38:09 +0200 Subject: [PATCH 01/25] Dynamic Simulation - Using gridsuite filter library for mapping --- pom.xml | 24 +++ .../ds/server/DynamicSimulationException.java | 1 + .../RestResponseEntityExceptionHandler.java | 1 + .../dto/dynamicmapping/InputMapping.java | 27 +++ .../ds/server/dto/dynamicmapping/Rule.java | 36 ++++ .../ds/server/dto/dynamicmapping/Script.java | 2 - .../dynamicmapping/automata/Automaton.java | 25 +++ .../automata/BasicProperty.java | 17 ++ .../DynamicSimulationWorkerService.java | 25 ++- .../dynamicmapping/DynamicMappingClient.java | 4 + .../impl/DynamicMappingClientImpl.java | 27 ++- .../contexts/DynamicSimulationRunContext.java | 8 +- .../service/parameters/ParametersService.java | 5 + .../impl/ParametersServiceImpl.java | 73 +++++++- ...DynamicSimulationControllerIEEE14Test.java | 15 +- .../DynamicSimulationControllerTest.java | 4 +- .../DynamicMappingClientTest.java | 12 +- .../data/ieee14/_01/input/mapping.json | 157 ++++++++++++++++++ 18 files changed, 427 insertions(+), 36 deletions(-) create mode 100644 src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/InputMapping.java create mode 100644 src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Rule.java create mode 100644 src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/Automaton.java create mode 100644 src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/BasicProperty.java create mode 100644 src/test/resources/data/ieee14/_01/input/mapping.json diff --git a/pom.xml b/pom.xml index 676cdd0e..0ce849d1 100644 --- a/pom.xml +++ b/pom.xml @@ -140,10 +140,22 @@ com.powsybl powsybl-dynawaltz + 2.4.0-SNAPSHOT com.powsybl powsybl-dynawaltz-dsl + 2.4.0-SNAPSHOT + + + com.rte-france.powsybl + powsybl-dynawaltz-rte + 4.4.0-SNAPSHOT + + + com.rte-france.powsybl + powsybl-dynawaltz-dsl-rte + 4.4.0-SNAPSHOT com.powsybl @@ -251,5 +263,17 @@ wiremock test + + org.gridsuite + gridsuite-filter + 1.1.0-SNAPSHOT + test + + + org.gridsuite + gridsuite-filter + 1.1.0-SNAPSHOT + compile + diff --git a/src/main/java/org/gridsuite/ds/server/DynamicSimulationException.java b/src/main/java/org/gridsuite/ds/server/DynamicSimulationException.java index ebc410bc..9501a952 100644 --- a/src/main/java/org/gridsuite/ds/server/DynamicSimulationException.java +++ b/src/main/java/org/gridsuite/ds/server/DynamicSimulationException.java @@ -18,6 +18,7 @@ public enum Type { RESULT_UUID_NOT_FOUND, DYNAMIC_MAPPING_NOT_FOUND, CREATE_MAPPING_SCRIPT_ERROR, + GET_DYNAMIC_MAPPING_ERROR, CREATE_TIME_SERIES_ERROR, DELETE_TIME_SERIES_ERROR } diff --git a/src/main/java/org/gridsuite/ds/server/RestResponseEntityExceptionHandler.java b/src/main/java/org/gridsuite/ds/server/RestResponseEntityExceptionHandler.java index 5f356fc1..3f807dab 100644 --- a/src/main/java/org/gridsuite/ds/server/RestResponseEntityExceptionHandler.java +++ b/src/main/java/org/gridsuite/ds/server/RestResponseEntityExceptionHandler.java @@ -34,6 +34,7 @@ protected ResponseEntity handleDynamicSimulationException(DynamicSimulat PROVIDER_NOT_FOUND -> ResponseEntity.status(HttpStatus.NOT_FOUND).body(exception.getMessage()); case URI_SYNTAX, + GET_DYNAMIC_MAPPING_ERROR, CREATE_MAPPING_SCRIPT_ERROR, CREATE_TIME_SERIES_ERROR, DELETE_TIME_SERIES_ERROR diff --git a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/InputMapping.java b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/InputMapping.java new file mode 100644 index 00000000..f0899565 --- /dev/null +++ b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/InputMapping.java @@ -0,0 +1,27 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.ds.server.dto.dynamicmapping; + +import io.swagger.v3.oas.annotations.media.Schema; +import org.gridsuite.ds.server.dto.dynamicmapping.automata.Automaton; + +import java.util.List; + +/** + * @author Thang PHAM + */ +@Schema(description = "Mapping") +public record InputMapping( + @Schema(description = "Name") + String name, + @Schema(description = "Mapping rules") + List rules, + @Schema(description = "Mapping automata") + List automata +) { + +} diff --git a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Rule.java b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Rule.java new file mode 100644 index 00000000..8a07e415 --- /dev/null +++ b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Rule.java @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.ds.server.dto.dynamicmapping; + +import com.powsybl.dynawaltz.rte.mapping.dynamicmodels.SetGroupType; +import io.swagger.v3.oas.annotations.media.Schema; +import org.gridsuite.filter.expertfilter.ExpertFilter; +import org.gridsuite.filter.utils.EquipmentType; + +/** + * @author Thang PHAM + */ +@Schema(description = "Rule") +public record Rule( + @Schema(description = "Equipment type") + EquipmentType equipmentType, + + @Schema(description = "Mapped Model Instance ID") + String mappedModel, + + @Schema(description = "Mapped Parameter Set Group ID") + String setGroup, + + @Schema(description = "Mapped Parameter Set Group Type") + SetGroupType groupType, + + @Schema(description = "Filter") + ExpertFilter filter +) { + +} + diff --git a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Script.java b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Script.java index 22d37a26..8d4e185b 100644 --- a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Script.java +++ b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Script.java @@ -27,8 +27,6 @@ public class Script { // name of the original mapping private String parentName; - private String script; - private Date createdDate; private String parametersFile; diff --git a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/Automaton.java b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/Automaton.java new file mode 100644 index 00000000..e8095e73 --- /dev/null +++ b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/Automaton.java @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.ds.server.dto.dynamicmapping.automata; + +import io.swagger.v3.oas.annotations.media.Schema; + +import java.util.List; + +/** + * @author Thang PHAM + */ +public record Automaton( + @Schema(description = "Mapped Model Instance ID") + String model, + @Schema(description = "Mapped Parameters Set Group ID") + String setGroup, + @Schema(description = "Properties of automaton model") + List properties +) { + +} diff --git a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/BasicProperty.java b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/BasicProperty.java new file mode 100644 index 00000000..bc849bfc --- /dev/null +++ b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/BasicProperty.java @@ -0,0 +1,17 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +package org.gridsuite.ds.server.dto.dynamicmapping.automata; + +import com.powsybl.dynawaltz.rte.mapping.dynamicmodels.PropertyType; + +/** + * @author Thang PHAM + */ +public record BasicProperty(String name, String value, PropertyType type) { + +} diff --git a/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java b/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java index dfeba37c..ce1c6f7a 100644 --- a/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java +++ b/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java @@ -14,6 +14,8 @@ import com.powsybl.dynamicsimulation.*; import com.powsybl.dynamicsimulation.groovy.*; import com.powsybl.dynawaltz.DynaWaltzProvider; +import com.powsybl.dynawaltz.rte.mapping.dynamicmodels.DynamicModelConfig; +import com.powsybl.dynawaltz.rte.mapping.dynamicmodels.DynawoDynamicModelSupplier; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.VariantManagerConstants; import com.powsybl.network.store.client.NetworkStoreService; @@ -23,6 +25,7 @@ import org.gridsuite.ds.server.computation.service.*; import org.gridsuite.ds.server.dto.DynamicSimulationParametersInfos; import org.gridsuite.ds.server.dto.DynamicSimulationStatus; +import org.gridsuite.ds.server.dto.dynamicmapping.InputMapping; import org.gridsuite.ds.server.dto.dynamicmapping.Script; import org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient; import org.gridsuite.ds.server.service.contexts.DynamicSimulationResultContext; @@ -120,13 +123,21 @@ protected String getComputationType() { return COMPUTATION_TYPE; } + @Override + protected DynamicSimulationResult run(Network network, DynamicSimulationRunContext runContext, UUID resultUuid) throws Exception { + // cache network in run context to use in other methods of the worker + runContext.setNetwork(network); + + return super.run(network, runContext, resultUuid); + } + // open the visibility from protected to public to mock in a test where the stop arrives early @Override public void preRun(DynamicSimulationRunContext runContext, Reporter reporter) { super.preRun(runContext, reporter); DynamicSimulationParametersInfos parametersInfos = runContext.getParameters(); - // get script and parameters file from dynamic mapping server + // get parameters file from dynamic mapping server Script scriptObj = dynamicMappingClient.createFromMapping(runContext.getMapping()); // get all dynamic simulation parameters @@ -134,12 +145,15 @@ public void preRun(DynamicSimulationRunContext runContext, Reporter reporter) { DynamicSimulationParameters parameters = parametersService.getDynamicSimulationParameters( parametersFile.getBytes(StandardCharsets.UTF_8), runContext.getProvider(), parametersInfos); + // get mapping then generate dynamic model configs + InputMapping inputMapping = dynamicMappingClient.getMapping(runContext.getMapping()); + List dynamicModel = parametersService.getDynamicModel(inputMapping, runContext.getNetwork()); + // set start and stop times parameters.setStartTime(parametersInfos.getStartTime().intValue()); // TODO remove intValue() when correct startTime to double in powsybl parameters.setStopTime(parametersInfos.getStopTime().intValue()); // TODO remove intValue() when correct stopTime to double in powsybl // groovy scripts - String dynamicModel = scriptObj.getScript(); String eventModel = parametersService.getEventModel(parametersInfos.getEvents()); String curveModel = parametersService.getCurveModel(parametersInfos.getCurves()); @@ -153,10 +167,7 @@ public void preRun(DynamicSimulationRunContext runContext, Reporter reporter) { @Override public CompletableFuture getCompletableFuture(Network network, DynamicSimulationRunContext runContext, String provider, Reporter reporter) { - List dynamicModelExtensions = GroovyExtension.find(DynamicModelGroovyExtension.class, DynaWaltzProvider.NAME); - DynamicModelsSupplier dynamicModelsSupplier = new GroovyDynamicModelsSupplier( - new ByteArrayInputStream(runContext.getDynamicModelContent().getBytes()), dynamicModelExtensions - ); + DynamicModelsSupplier dynawoDynamicModelsSupplier = new DynawoDynamicModelSupplier(runContext.getDynamicModelContent()); List eventModelExtensions = GroovyExtension.find(EventModelGroovyExtension.class, DynaWaltzProvider.NAME); EventModelsSupplier eventModelsSupplier = new GroovyEventModelsSupplier( @@ -174,7 +185,7 @@ public CompletableFuture getCompletableFuture(Network n DynamicSimulation.Runner runner = DynamicSimulation.find(provider); return runner.runAsync(network, - dynamicModelsSupplier, + dynawoDynamicModelsSupplier, eventModelsSupplier, curvesSupplier, runContext.getVariantId() != null ? runContext.getVariantId() : VariantManagerConstants.INITIAL_VARIANT_ID, diff --git a/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClient.java b/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClient.java index ecc4b32e..30cd70d6 100644 --- a/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClient.java +++ b/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClient.java @@ -6,6 +6,7 @@ */ package org.gridsuite.ds.server.service.client.dynamicmapping; +import org.gridsuite.ds.server.dto.dynamicmapping.InputMapping; import org.gridsuite.ds.server.dto.dynamicmapping.Script; import static org.gridsuite.ds.server.service.client.RestClient.DELIMITER; @@ -16,7 +17,10 @@ public interface DynamicMappingClient { String API_VERSION = ""; String DYNAMIC_MAPPING_SCRIPT_BASE_END_POINT = "scripts"; + String DYNAMIC_MAPPING_MAPPING_BASE_END_POINT = "mappings"; String DYNAMIC_MAPPING_SCRIPT_CREATE_END_POINT = DYNAMIC_MAPPING_SCRIPT_BASE_END_POINT + DELIMITER + "from"; Script createFromMapping(String mappingName); + + InputMapping getMapping(String mappingName); } diff --git a/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/impl/DynamicMappingClientImpl.java b/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/impl/DynamicMappingClientImpl.java index ed7a9227..70974455 100644 --- a/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/impl/DynamicMappingClientImpl.java +++ b/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/impl/DynamicMappingClientImpl.java @@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.gridsuite.ds.server.DynamicSimulationException; +import org.gridsuite.ds.server.dto.dynamicmapping.InputMapping; import org.gridsuite.ds.server.dto.dynamicmapping.Script; import org.gridsuite.ds.server.service.client.AbstractRestClient; import org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient; @@ -17,12 +18,12 @@ import org.springframework.stereotype.Service; import org.springframework.web.client.HttpStatusCodeException; import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; import java.util.Objects; -import static org.gridsuite.ds.server.DynamicSimulationException.Type.CREATE_MAPPING_SCRIPT_ERROR; -import static org.gridsuite.ds.server.DynamicSimulationException.Type.DYNAMIC_MAPPING_NOT_FOUND; +import static org.gridsuite.ds.server.DynamicSimulationException.Type.*; import static org.gridsuite.ds.server.service.client.utils.ExceptionUtils.handleHttpError; import static org.gridsuite.ds.server.service.client.utils.UrlUtils.buildEndPointUrl; @@ -61,4 +62,26 @@ public Script createFromMapping(String mappingName) { } } + @Override + public InputMapping getMapping(String mappingName) { + Objects.requireNonNull(mappingName); + + String endPointUrl = buildEndPointUrl(getBaseUri(), API_VERSION, DYNAMIC_MAPPING_MAPPING_BASE_END_POINT); + + UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromHttpUrl(endPointUrl + DELIMITER + "{mappingName}"); + + UriComponents uriComponents = uriComponentsBuilder.buildAndExpand(mappingName); + + // call dynamic mapping Rest API + try { + return getRestTemplate().getForObject(uriComponents.toUriString(), InputMapping.class); + } catch (HttpStatusCodeException e) { + if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) { + throw new DynamicSimulationException(DYNAMIC_MAPPING_NOT_FOUND, "Mapping not found: " + mappingName); + } else { + throw handleHttpError(e, GET_DYNAMIC_MAPPING_ERROR, getObjectMapper()); + } + } + } + } diff --git a/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java b/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java index e4101c24..25686225 100644 --- a/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java +++ b/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java @@ -7,6 +7,8 @@ package org.gridsuite.ds.server.service.contexts; import com.powsybl.dynamicsimulation.DynamicSimulationParameters; +import com.powsybl.dynawaltz.rte.mapping.dynamicmodels.DynamicModelConfig; +import com.powsybl.iidm.network.Network; import lombok.Builder; import lombok.Getter; import lombok.Setter; @@ -14,6 +16,7 @@ import org.gridsuite.ds.server.computation.utils.ReportContext; import org.gridsuite.ds.server.dto.DynamicSimulationParametersInfos; +import java.util.List; import java.util.UUID; /** @@ -24,8 +27,11 @@ public class DynamicSimulationRunContext extends AbstractComputationRunContext dynamicModelContent; @Setter private String eventModelContent; diff --git a/src/main/java/org/gridsuite/ds/server/service/parameters/ParametersService.java b/src/main/java/org/gridsuite/ds/server/service/parameters/ParametersService.java index 2215cbe5..f3b8fd9f 100644 --- a/src/main/java/org/gridsuite/ds/server/service/parameters/ParametersService.java +++ b/src/main/java/org/gridsuite/ds/server/service/parameters/ParametersService.java @@ -7,9 +7,12 @@ package org.gridsuite.ds.server.service.parameters; import com.powsybl.dynamicsimulation.DynamicSimulationParameters; +import com.powsybl.dynawaltz.rte.mapping.dynamicmodels.DynamicModelConfig; +import com.powsybl.iidm.network.Network; import org.gridsuite.ds.server.computation.utils.ReportContext; import org.gridsuite.ds.server.dto.DynamicSimulationParametersInfos; import org.gridsuite.ds.server.dto.curve.CurveInfos; +import org.gridsuite.ds.server.dto.dynamicmapping.InputMapping; import org.gridsuite.ds.server.dto.event.EventInfos; import org.gridsuite.ds.server.service.contexts.DynamicSimulationRunContext; @@ -29,4 +32,6 @@ public interface ParametersService { DynamicSimulationRunContext createRunContext(UUID networkUuid, String variantId, String receiver, String provider, String mapping, ReportContext reportContext, String userId, DynamicSimulationParametersInfos parameters); + + List getDynamicModel(InputMapping inputMapping, Network network); } diff --git a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java index c6758499..40f1fd36 100644 --- a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java +++ b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java @@ -12,13 +12,22 @@ import com.powsybl.dynawaltz.DynaWaltzParameters; import com.powsybl.dynawaltz.DynaWaltzProvider; import com.powsybl.dynawaltz.parameters.ParametersSet; +import com.powsybl.dynawaltz.rte.mapping.dynamicmodels.DynamicModelConfig; +import com.powsybl.dynawaltz.rte.mapping.dynamicmodels.PropertyBuilder; +import com.powsybl.dynawaltz.rte.mapping.dynamicmodels.PropertyType; import com.powsybl.dynawaltz.xml.ParametersXml; +import com.powsybl.iidm.network.Identifiable; +import com.powsybl.iidm.network.Network; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.ArrayUtils; import org.gridsuite.ds.server.DynamicSimulationException; import org.gridsuite.ds.server.computation.utils.ReportContext; import org.gridsuite.ds.server.dto.DynamicSimulationParametersInfos; import org.gridsuite.ds.server.dto.XmlSerializableParameter; import org.gridsuite.ds.server.dto.curve.CurveInfos; +import org.gridsuite.ds.server.dto.dynamicmapping.InputMapping; +import org.gridsuite.ds.server.dto.dynamicmapping.Rule; +import org.gridsuite.ds.server.dto.dynamicmapping.automata.Automaton; import org.gridsuite.ds.server.dto.event.EventInfos; import org.gridsuite.ds.server.dto.network.NetworkInfos; import org.gridsuite.ds.server.dto.solver.SolverInfos; @@ -26,6 +35,8 @@ import org.gridsuite.ds.server.service.parameters.CurveGroovyGeneratorService; import org.gridsuite.ds.server.service.parameters.EventGroovyGeneratorService; import org.gridsuite.ds.server.service.parameters.ParametersService; +import org.gridsuite.filter.utils.EquipmentType; +import org.gridsuite.filter.utils.FiltersUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -35,10 +46,8 @@ import javax.xml.stream.XMLStreamException; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.UUID; +import java.util.*; +import java.util.stream.Collectors; import static org.gridsuite.ds.server.DynamicSimulationException.Type.MAPPING_NOT_PROVIDED; import static org.gridsuite.ds.server.DynamicSimulationException.Type.PROVIDER_NOT_FOUND; @@ -170,4 +179,60 @@ public DynamicSimulationRunContext createRunContext(UUID networkUuid, String var return runContext; } + + @Override + public List getDynamicModel(InputMapping inputMapping, Network network) { + if (inputMapping == null) { + return Collections.emptyList(); + } + + List dynamicModel = new ArrayList<>(); + + // --- transform equipment rules to DynamicModelConfigs --- // + List allRules = inputMapping.rules(); + // grouping rules by equipment type + Map> rulesByEquipmentTypeMap = allRules.stream().collect(Collectors.groupingBy(Rule::equipmentType)); + // performing transformation + rulesByEquipmentTypeMap.forEach((equipmentType, rules) -> { + // accumulate matched equipment ids to compute otherwise case (last rule without filters) + Set matchedEquipmentIds = new TreeSet<>(); + + dynamicModel.addAll(rules.stream().flatMap(rule -> { + List> matchedEquipments = FiltersUtils.getIdentifiables(rule.filter(), network, uuids -> null); + + if (CollectionUtils.isEmpty(rule.filter().getRules().getRules()) && !matchedEquipmentIds.isEmpty()) { + matchedEquipments = matchedEquipments.stream().filter(elem -> !matchedEquipmentIds.contains(elem.getId())).toList(); + } + + matchedEquipmentIds.addAll(matchedEquipments.stream().map(Identifiable::getId).toList()); + + return matchedEquipments.stream().map(equipment -> new DynamicModelConfig( + rule.mappedModel(), + rule.setGroup(), + rule.groupType(), + List.of(new PropertyBuilder() + .name("staticId") + .value(equipment.getId()) + .type(PropertyType.STRING) + .build()))); + }).toList()); + }); + + // transform automatons to DynamicModelConfigs + List automata = inputMapping.automata(); + dynamicModel.addAll(automata.stream().map(automaton -> + new DynamicModelConfig( + automaton.model(), + automaton.setGroup(), + automaton.properties().stream().map(property -> + new PropertyBuilder() + .name(property.name()) + .value(property.value()) + .type(property.type()) + .build() + ).toList()) + ).toList()); + + return dynamicModel; + } } diff --git a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerIEEE14Test.java b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerIEEE14Test.java index 95f35cdc..b696b476 100644 --- a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerIEEE14Test.java +++ b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerIEEE14Test.java @@ -25,6 +25,7 @@ import org.gridsuite.ds.server.controller.utils.ParameterUtils; import org.gridsuite.ds.server.dto.DynamicSimulationParametersInfos; import org.gridsuite.ds.server.dto.curve.CurveInfos; +import org.gridsuite.ds.server.dto.dynamicmapping.InputMapping; import org.gridsuite.ds.server.dto.dynamicmapping.Script; import org.gridsuite.ds.server.dto.event.EventInfos; import org.gridsuite.ds.server.dto.timeseries.TimeSeriesGroupInfos; @@ -70,6 +71,7 @@ public class DynamicSimulationControllerIEEE14Test extends AbstractDynamicSimula public static final String INPUT = "input"; public static final String OUTPUT = "output"; public static final String MODELS_GROOVY = "models.groovy"; + public static final String MAPPING_FILE = "mapping.json"; public static final String MODELS_PAR = "models.par"; public static final String RESULT_IDA_JSON = "result_IDA.json"; public static final String RESULT_SIM_JSON = "result_SIM.json"; @@ -118,13 +120,6 @@ protected void initDynamicMappingServiceMock() { RESOURCE_PATH_DELIMETER + MAPPING_NAME_01 + RESOURCE_PATH_DELIMETER + INPUT; - // load models.groovy - String scriptPath = inputDir + RESOURCE_PATH_DELIMETER + MODELS_GROOVY; - InputStream scriptIS = getClass().getResourceAsStream(scriptPath); - byte[] scriptBytes; - scriptBytes = StreamUtils.copyToByteArray(scriptIS); - String script = new String(scriptBytes, StandardCharsets.UTF_8); - // load models.par String parametersFilePath = inputDir + RESOURCE_PATH_DELIMETER + MODELS_PAR; InputStream parametersFileIS = getClass().getResourceAsStream(parametersFilePath); @@ -135,10 +130,14 @@ protected void initDynamicMappingServiceMock() { Script scriptObj = new Script( MAPPING_NAME_01 + "-script", MAPPING_NAME_01, - script, dateFormat.parse(FIXED_DATE), parametersFile); given(dynamicMappingClient.createFromMapping(DynamicMappingClientTest.MAPPING_NAME_01)).willReturn(scriptObj); + + // load mapping.json + String mappingPath = inputDir + RESOURCE_PATH_DELIMETER + MAPPING_FILE; + InputMapping inputMapping = objectMapper.readValue(getClass().getResourceAsStream(mappingPath), InputMapping.class); + given(dynamicMappingClient.getMapping(DynamicMappingClientTest.MAPPING_NAME_01)).willReturn(inputMapping); } catch (IOException e) { throw new UncheckedIOException(e); } catch (ParseException e) { diff --git a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java index a92b8c7a..7547eab8 100644 --- a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java +++ b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java @@ -27,6 +27,7 @@ import org.gridsuite.ds.server.dto.DynamicSimulationStatus; import org.gridsuite.ds.server.dto.dynamicmapping.Script; import org.gridsuite.ds.server.dto.timeseries.TimeSeriesGroupInfos; +import org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClientTest; import org.gridsuite.ds.server.service.client.timeseries.TimeSeriesClientTest; import org.junit.Before; import org.junit.Test; @@ -106,10 +107,11 @@ protected void initDynamicMappingServiceMock() { Script scriptObj = new Script( MAPPING_NAME + "-script", MAPPING_NAME, - "", new Date(), ""); given(dynamicMappingClient.createFromMapping(MAPPING_NAME)).willReturn(scriptObj); + + given(dynamicMappingClient.getMapping(DynamicMappingClientTest.MAPPING_NAME_01)).willReturn(null); } @Override diff --git a/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java b/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java index 3d6def04..a3e39420 100644 --- a/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java +++ b/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java @@ -25,7 +25,6 @@ import java.nio.charset.StandardCharsets; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.Optional; import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; @@ -37,7 +36,6 @@ import static org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient.API_VERSION; import static org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient.DYNAMIC_MAPPING_SCRIPT_CREATE_END_POINT; import static org.gridsuite.ds.server.service.client.utils.UrlUtils.buildEndPointUrl; -import static org.junit.Assert.assertEquals; /** * @author Thang PHAM @@ -91,11 +89,6 @@ public void testCreateFromMapping() throws IOException, ParseException { String inputDir = DATA_IEEE14_BASE_DIR + RESOURCE_PATH_DELIMETER + mappingName + RESOURCE_PATH_DELIMETER + INPUT; - String scriptPath = inputDir + RESOURCE_PATH_DELIMETER + MODELS_GROOVY; - InputStream scriptIS = getClass().getResourceAsStream(scriptPath); - byte[] scriptBytes; - scriptBytes = StreamUtils.copyToByteArray(scriptIS); - String script = new String(scriptBytes, StandardCharsets.UTF_8); // load models.par String parametersFilePath = inputDir + RESOURCE_PATH_DELIMETER + MODELS_PAR; @@ -107,7 +100,6 @@ public void testCreateFromMapping() throws IOException, ParseException { Script scriptObj = new Script( mappingName + "-script", mappingName, - script, dateFormat.parse(FIXED_DATE), parametersFile); @@ -127,10 +119,8 @@ public void testCreateFromMapping() throws IOException, ParseException { Script createdScript = dynamicMappingClient.createFromMapping(MAPPING_NAME_01); // check result - // models.groovy - assertEquals(script, Optional.of(createdScript).orElseThrow().getScript()); // load models.par - assertEquals(parametersFile, createdScript.getParametersFile()); + assertThat(createdScript.getParametersFile()).isEqualTo(parametersFile); } @Test diff --git a/src/test/resources/data/ieee14/_01/input/mapping.json b/src/test/resources/data/ieee14/_01/input/mapping.json new file mode 100644 index 00000000..0231607f --- /dev/null +++ b/src/test/resources/data/ieee14/_01/input/mapping.json @@ -0,0 +1,157 @@ +{ + "name": "mapping_01", + "rules": [ + { + "equipmentType": "LOAD", + "mappedModel": "LoadAlphaBeta", + "setGroup": "LAB", + "groupType": "FIXED", + "filter": { + "equipmentType": "LOAD", + "type": "EXPERT", + "rules": { + "combinator" : "AND", + "dataType": "COMBINATOR", + "rules" : [] + } + } + }, + { + "equipmentType": "GENERATOR", + "mappedModel": "GeneratorSynchronousThreeWindingsProportionalRegulations", + "setGroup": "IEEE14", + "groupType": "PREFIX", + "filter": { + "equipmentType": "GENERATOR", + "type": "EXPERT", + "rules" : { + "combinator": "AND", + "dataType": "COMBINATOR", + "rules" : [ + { + "dataType": "NUMBER", + "field": "NOMINAL_VOLTAGE", + "operator": "EQUALS", + "value": 13.8 + } + ] + } + } + }, + { + "equipmentType": "GENERATOR", + "mappedModel": "GeneratorSynchronousFourWindingsProportionalRegulations", + "setGroup": "IEEE14", + "groupType": "PREFIX", + "filter": { + "equipmentType": "GENERATOR", + "type": "EXPERT", + "rules" : { + "combinator": "AND", + "dataType": "COMBINATOR", + "rules" : [ + { + "dataType": "NUMBER", + "field": "NOMINAL_VOLTAGE", + "operator": "EQUALS", + "value": 69.0 + } + ] + } + } + }, + { + "equipmentType": "GENERATOR", + "mappedModel": "GeneratorPQ", + "setGroup": "GPQ", + "groupType": "FIXED", + "filter": { + "equipmentType": "GENERATOR", + "type": "EXPERT", + "rules": { + "combinator" : "AND", + "dataType": "COMBINATOR", + "rules" : [] + } + } + }, + { + "equipmentType": "STATIC_VAR_COMPENSATOR", + "mappedModel": "StaticVarCompensator", + "setGroup": "SVarCT", + "groupType": "FIXED", + "filter": { + "equipmentType": "STATIC_VAR_COMPENSATOR", + "type": "EXPERT", + "rules" : { + "combinator": "AND", + "dataType": "COMBINATOR", + "rules" : [{ + "dataType": "NUMBER", + "field": "NOMINAL_VOLTAGE", + "operator": "EQUALS", + "value": 69.0 + } + ] + } + } + } + ], + "automata": [ + { + "family": "CURRENT_LIMIT", + "model": "CurrentLimitAutomaton", + "setGroup": "CLA_2_4", + "properties": [ + { + "name": "dynamicModelId", + "value": "CLA_1", + "type": "STRING" + }, + { + "name": "iMeasurement", + "value": "_BUS____2-BUS____4-1_AC", + "type": "STRING" + }, + { + "name": "iMeasurementSide", + "value": "TWO", + "type": "TWO_SIDES" + }, + { + "name": "controlledQuadripole", + "value": "_BUS____2-BUS____4-1_AC", + "type": "STRING" + } + ] + }, + { + "family": "CURRENT_LIMIT", + "model": "CurrentLimitAutomaton", + "setGroup": "CLA_2_5", + "properties": [ + { + "name": "dynamicModelId", + "value": "CLA_2", + "type": "STRING" + }, + { + "name": "iMeasurement", + "value": "_BUS____2-BUS____5-1_AC", + "type": "STRING" + }, + { + "name": "iMeasurementSide", + "value": "TWO", + "type": "TWO_SIDES" + }, + { + "name": "controlledQuadripole", + "value": "_BUS____2-BUS____5-1_AC", + "type": "STRING" + } + ] + } + ], + "controlledParameters": false +} \ No newline at end of file From ebb1214e81bd1960f5d2fb1026166784d96056f1 Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Thu, 25 Apr 2024 18:09:12 +0200 Subject: [PATCH 02/25] Accept mapping without filter --- .../impl/ParametersServiceImpl.java | 19 +++++++++++++--- .../data/ieee14/_01/input/mapping.json | 22 ++----------------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java index 40f1fd36..686c7d25 100644 --- a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java +++ b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java @@ -18,7 +18,6 @@ import com.powsybl.dynawaltz.xml.ParametersXml; import com.powsybl.iidm.network.Identifiable; import com.powsybl.iidm.network.Network; -import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.ArrayUtils; import org.gridsuite.ds.server.DynamicSimulationException; import org.gridsuite.ds.server.computation.utils.ReportContext; @@ -35,8 +34,11 @@ import org.gridsuite.ds.server.service.parameters.CurveGroovyGeneratorService; import org.gridsuite.ds.server.service.parameters.EventGroovyGeneratorService; import org.gridsuite.ds.server.service.parameters.ParametersService; +import org.gridsuite.filter.expertfilter.ExpertFilter; +import org.gridsuite.filter.expertfilter.expertrule.CombinatorExpertRule; import org.gridsuite.filter.utils.EquipmentType; import org.gridsuite.filter.utils.FiltersUtils; +import org.gridsuite.filter.utils.expertfilter.CombinatorType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -198,9 +200,20 @@ public List getDynamicModel(InputMapping inputMapping, Netwo Set matchedEquipmentIds = new TreeSet<>(); dynamicModel.addAll(rules.stream().flatMap(rule -> { - List> matchedEquipments = FiltersUtils.getIdentifiables(rule.filter(), network, uuids -> null); + ExpertFilter filter = rule.filter(); + + // otherwise case, create an expert filter with AND operator and empty rules to get all equipments of the same type + if (filter == null) { + filter = ExpertFilter.builder() + .equipmentType(equipmentType) + .rules(CombinatorExpertRule.builder().combinator(CombinatorType.AND).rules(List.of()).build()) + .build(); + } + + List> matchedEquipments = FiltersUtils.getIdentifiables(filter, network, uuids -> null); - if (CollectionUtils.isEmpty(rule.filter().getRules().getRules()) && !matchedEquipmentIds.isEmpty()) { + // eliminate already matched equipments to avoid duplication + if (!matchedEquipmentIds.isEmpty()) { matchedEquipments = matchedEquipments.stream().filter(elem -> !matchedEquipmentIds.contains(elem.getId())).toList(); } diff --git a/src/test/resources/data/ieee14/_01/input/mapping.json b/src/test/resources/data/ieee14/_01/input/mapping.json index 0231607f..f83a1a70 100644 --- a/src/test/resources/data/ieee14/_01/input/mapping.json +++ b/src/test/resources/data/ieee14/_01/input/mapping.json @@ -5,16 +5,7 @@ "equipmentType": "LOAD", "mappedModel": "LoadAlphaBeta", "setGroup": "LAB", - "groupType": "FIXED", - "filter": { - "equipmentType": "LOAD", - "type": "EXPERT", - "rules": { - "combinator" : "AND", - "dataType": "COMBINATOR", - "rules" : [] - } - } + "groupType": "FIXED" }, { "equipmentType": "GENERATOR", @@ -64,16 +55,7 @@ "equipmentType": "GENERATOR", "mappedModel": "GeneratorPQ", "setGroup": "GPQ", - "groupType": "FIXED", - "filter": { - "equipmentType": "GENERATOR", - "type": "EXPERT", - "rules": { - "combinator" : "AND", - "dataType": "COMBINATOR", - "rules" : [] - } - } + "groupType": "FIXED" }, { "equipmentType": "STATIC_VAR_COMPENSATOR", From 4a355cf2fd0c5ab9b3c65eea9169def0032253d3 Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Fri, 26 Apr 2024 11:52:16 +0200 Subject: [PATCH 03/25] Update POM to add gridsuite-filter for compilation --- pom.xml | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 0ce849d1..4099438e 100644 --- a/pom.xml +++ b/pom.xml @@ -157,6 +157,11 @@ powsybl-dynawaltz-dsl-rte 4.4.0-SNAPSHOT + + org.gridsuite + gridsuite-filter + 1.1.0-SNAPSHOT + com.powsybl powsybl-network-store-client @@ -263,17 +268,5 @@ wiremock test - - org.gridsuite - gridsuite-filter - 1.1.0-SNAPSHOT - test - - - org.gridsuite - gridsuite-filter - 1.1.0-SNAPSHOT - compile - From 3936315436b1c6fdce8206bb69680cea0e73032f Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Mon, 6 May 2024 19:58:45 +0200 Subject: [PATCH 04/25] do not need provide FilterLoader --- .../server/service/parameters/impl/ParametersServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java index 686c7d25..d096dc85 100644 --- a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java +++ b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java @@ -210,7 +210,7 @@ public List getDynamicModel(InputMapping inputMapping, Netwo .build(); } - List> matchedEquipments = FiltersUtils.getIdentifiables(filter, network, uuids -> null); + List> matchedEquipments = FiltersUtils.getIdentifiables(filter, network, null); // eliminate already matched equipments to avoid duplication if (!matchedEquipmentIds.isEmpty()) { From 5d245283fb55fbe5f3b1dd108f7a1aa5d442b0c6 Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Tue, 7 May 2024 00:31:59 +0200 Subject: [PATCH 05/25] rename script DTO to parameter DTO --- .../ds/server/DynamicSimulationException.java | 2 +- .../RestResponseEntityExceptionHandler.java | 2 +- .../{Script.java => Parameter.java} | 29 ++++------- .../DynamicSimulationWorkerService.java | 6 +-- .../dynamicmapping/DynamicMappingClient.java | 8 +-- .../impl/DynamicMappingClientImpl.java | 13 ++--- ...stractDynamicSimulationControllerTest.java | 2 +- ...DynamicSimulationControllerIEEE14Test.java | 34 +++++-------- .../DynamicSimulationControllerTest.java | 8 ++- .../DynamicMappingClientTest.java | 49 +++++++------------ 10 files changed, 58 insertions(+), 95 deletions(-) rename src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/{Script.java => Parameter.java} (51%) diff --git a/src/main/java/org/gridsuite/ds/server/DynamicSimulationException.java b/src/main/java/org/gridsuite/ds/server/DynamicSimulationException.java index 9501a952..962da66a 100644 --- a/src/main/java/org/gridsuite/ds/server/DynamicSimulationException.java +++ b/src/main/java/org/gridsuite/ds/server/DynamicSimulationException.java @@ -17,7 +17,7 @@ public enum Type { MAPPING_NOT_PROVIDED, RESULT_UUID_NOT_FOUND, DYNAMIC_MAPPING_NOT_FOUND, - CREATE_MAPPING_SCRIPT_ERROR, + CREATE_MAPPING_PARAMETER_ERROR, GET_DYNAMIC_MAPPING_ERROR, CREATE_TIME_SERIES_ERROR, DELETE_TIME_SERIES_ERROR diff --git a/src/main/java/org/gridsuite/ds/server/RestResponseEntityExceptionHandler.java b/src/main/java/org/gridsuite/ds/server/RestResponseEntityExceptionHandler.java index 3f807dab..008b1a92 100644 --- a/src/main/java/org/gridsuite/ds/server/RestResponseEntityExceptionHandler.java +++ b/src/main/java/org/gridsuite/ds/server/RestResponseEntityExceptionHandler.java @@ -35,7 +35,7 @@ protected ResponseEntity handleDynamicSimulationException(DynamicSimulat -> ResponseEntity.status(HttpStatus.NOT_FOUND).body(exception.getMessage()); case URI_SYNTAX, GET_DYNAMIC_MAPPING_ERROR, - CREATE_MAPPING_SCRIPT_ERROR, + CREATE_MAPPING_PARAMETER_ERROR, CREATE_TIME_SERIES_ERROR, DELETE_TIME_SERIES_ERROR -> ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(exception.getMessage()); diff --git a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Script.java b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Parameter.java similarity index 51% rename from src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Script.java rename to src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Parameter.java index 8d4e185b..e1ae7b7a 100644 --- a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Script.java +++ b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Parameter.java @@ -6,29 +6,18 @@ */ package org.gridsuite.ds.server.dto.dynamicmapping; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -import java.util.Date; +import io.swagger.v3.oas.annotations.media.Schema; /** * @author Thang PHAM */ -@NoArgsConstructor -@AllArgsConstructor -@Getter -@Setter -public class Script { - - private String name; - - // name of the original mapping - private String parentName; - - private Date createdDate; - - private String parametersFile; +@Schema(description = "Parameter set in par format") +public record Parameter( + @Schema(description = "Name of the original mapping") + String parentName, + + @Schema(description = "Parameter file content in par format") + String parametersFile +) { } diff --git a/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java b/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java index 04a3eba4..e7c63e06 100644 --- a/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java +++ b/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java @@ -25,7 +25,7 @@ import org.gridsuite.ds.server.dto.DynamicSimulationParametersInfos; import org.gridsuite.ds.server.dto.DynamicSimulationStatus; import org.gridsuite.ds.server.dto.dynamicmapping.InputMapping; -import org.gridsuite.ds.server.dto.dynamicmapping.Script; +import org.gridsuite.ds.server.dto.dynamicmapping.Parameter; import org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient; import org.gridsuite.ds.server.service.contexts.DynamicSimulationResultContext; import org.gridsuite.ds.server.service.contexts.DynamicSimulationRunContext; @@ -139,10 +139,10 @@ public void preRun(DynamicSimulationRunContext runContext) { DynamicSimulationParametersInfos parametersInfos = runContext.getParameters(); // get parameters file from dynamic mapping server - Script scriptObj = dynamicMappingClient.createFromMapping(runContext.getMapping()); + Parameter parameterObj = dynamicMappingClient.createFromMapping(runContext.getMapping()); // get all dynamic simulation parameters - String parametersFile = scriptObj.getParametersFile(); + String parametersFile = parameterObj.parametersFile(); DynamicSimulationParameters parameters = parametersService.getDynamicSimulationParameters( parametersFile.getBytes(StandardCharsets.UTF_8), runContext.getProvider(), parametersInfos); diff --git a/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClient.java b/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClient.java index 30cd70d6..77b410ad 100644 --- a/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClient.java +++ b/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClient.java @@ -7,7 +7,7 @@ package org.gridsuite.ds.server.service.client.dynamicmapping; import org.gridsuite.ds.server.dto.dynamicmapping.InputMapping; -import org.gridsuite.ds.server.dto.dynamicmapping.Script; +import org.gridsuite.ds.server.dto.dynamicmapping.Parameter; import static org.gridsuite.ds.server.service.client.RestClient.DELIMITER; @@ -16,11 +16,11 @@ */ public interface DynamicMappingClient { String API_VERSION = ""; - String DYNAMIC_MAPPING_SCRIPT_BASE_END_POINT = "scripts"; + String DYNAMIC_MAPPING_PARAMETER_BASE_END_POINT = "parameters"; String DYNAMIC_MAPPING_MAPPING_BASE_END_POINT = "mappings"; - String DYNAMIC_MAPPING_SCRIPT_CREATE_END_POINT = DYNAMIC_MAPPING_SCRIPT_BASE_END_POINT + DELIMITER + "from"; + String DYNAMIC_MAPPING_PARAMETER_CREATE_END_POINT = DYNAMIC_MAPPING_PARAMETER_BASE_END_POINT + DELIMITER + "from"; - Script createFromMapping(String mappingName); + Parameter createFromMapping(String mappingName); InputMapping getMapping(String mappingName); } diff --git a/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/impl/DynamicMappingClientImpl.java b/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/impl/DynamicMappingClientImpl.java index 70974455..e30329be 100644 --- a/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/impl/DynamicMappingClientImpl.java +++ b/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/impl/DynamicMappingClientImpl.java @@ -9,7 +9,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.gridsuite.ds.server.DynamicSimulationException; import org.gridsuite.ds.server.dto.dynamicmapping.InputMapping; -import org.gridsuite.ds.server.dto.dynamicmapping.Script; +import org.gridsuite.ds.server.dto.dynamicmapping.Parameter; import org.gridsuite.ds.server.service.client.AbstractRestClient; import org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient; import org.springframework.beans.factory.annotation.Autowired; @@ -39,25 +39,22 @@ public DynamicMappingClientImpl(@Value("${gridsuite.services.dynamic-mapping-ser } @Override - public Script createFromMapping(String mappingName) { + public Parameter createFromMapping(String mappingName) { Objects.requireNonNull(mappingName); - String endPointUrl = buildEndPointUrl(getBaseUri(), API_VERSION, DYNAMIC_MAPPING_SCRIPT_CREATE_END_POINT); + String endPointUrl = buildEndPointUrl(getBaseUri(), API_VERSION, DYNAMIC_MAPPING_PARAMETER_CREATE_END_POINT); UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromHttpUrl(endPointUrl + DELIMITER + "{mappingName}"); - - // to export script and not persist - uriComponentsBuilder.queryParam("persistent", false); var uriComponents = uriComponentsBuilder.buildAndExpand(mappingName); // call dynamic mapping Rest API try { - return getRestTemplate().getForObject(uriComponents.toUriString(), Script.class); + return getRestTemplate().getForObject(uriComponents.toUriString(), Parameter.class); } catch (HttpStatusCodeException e) { if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) { throw new DynamicSimulationException(DYNAMIC_MAPPING_NOT_FOUND, "Mapping not found: " + mappingName); } else { - throw handleHttpError(e, CREATE_MAPPING_SCRIPT_ERROR, getObjectMapper()); + throw handleHttpError(e, CREATE_MAPPING_PARAMETER_ERROR, getObjectMapper()); } } } diff --git a/src/test/java/org/gridsuite/ds/server/controller/AbstractDynamicSimulationControllerTest.java b/src/test/java/org/gridsuite/ds/server/controller/AbstractDynamicSimulationControllerTest.java index e468b891..78742e29 100644 --- a/src/test/java/org/gridsuite/ds/server/controller/AbstractDynamicSimulationControllerTest.java +++ b/src/test/java/org/gridsuite/ds/server/controller/AbstractDynamicSimulationControllerTest.java @@ -48,7 +48,7 @@ public abstract class AbstractDynamicSimulationControllerTest extends AbstractDy protected final String dsFailedDestination = "ds.failed.destination"; protected final String dsStoppedDestination = "ds.stopped.destination"; - public static final String RESOURCE_PATH_DELIMETER = "/"; + public static final String RESOURCE_PATH_DELIMITER = "/"; @MockBean protected DynamicMappingClient dynamicMappingClient; diff --git a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerIEEE14Test.java b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerIEEE14Test.java index b696b476..529bb990 100644 --- a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerIEEE14Test.java +++ b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerIEEE14Test.java @@ -26,7 +26,7 @@ import org.gridsuite.ds.server.dto.DynamicSimulationParametersInfos; import org.gridsuite.ds.server.dto.curve.CurveInfos; import org.gridsuite.ds.server.dto.dynamicmapping.InputMapping; -import org.gridsuite.ds.server.dto.dynamicmapping.Script; +import org.gridsuite.ds.server.dto.dynamicmapping.Parameter; import org.gridsuite.ds.server.dto.event.EventInfos; import org.gridsuite.ds.server.dto.timeseries.TimeSeriesGroupInfos; import org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClientTest; @@ -45,8 +45,6 @@ import java.io.InputStream; import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; -import java.text.ParseException; -import java.text.SimpleDateFormat; import java.util.*; import static org.assertj.core.api.Assertions.assertThat; @@ -67,10 +65,9 @@ public class DynamicSimulationControllerIEEE14Test extends AbstractDynamicSimula public static final String MAPPING_NAME_01 = "_01"; // directories - public static final String DATA_IEEE14_BASE_DIR = RESOURCE_PATH_DELIMETER + "data" + RESOURCE_PATH_DELIMETER + "ieee14"; + public static final String DATA_IEEE14_BASE_DIR = RESOURCE_PATH_DELIMITER + "data" + RESOURCE_PATH_DELIMITER + "ieee14"; public static final String INPUT = "input"; public static final String OUTPUT = "output"; - public static final String MODELS_GROOVY = "models.groovy"; public static final String MAPPING_FILE = "mapping.json"; public static final String MODELS_PAR = "models.par"; public static final String RESULT_IDA_JSON = "result_IDA.json"; @@ -95,9 +92,6 @@ public class DynamicSimulationControllerIEEE14Test extends AbstractDynamicSimula @Autowired private ObjectMapper objectMapper; - private static final String FIXED_DATE = "01/01/2023"; - private final SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); - @Override public OutputDestination getOutputDestination() { return output; @@ -117,31 +111,27 @@ protected void initNetworkStoreServiceMock() { protected void initDynamicMappingServiceMock() { try { String inputDir = DATA_IEEE14_BASE_DIR + - RESOURCE_PATH_DELIMETER + MAPPING_NAME_01 + - RESOURCE_PATH_DELIMETER + INPUT; + RESOURCE_PATH_DELIMITER + MAPPING_NAME_01 + + RESOURCE_PATH_DELIMITER + INPUT; // load models.par - String parametersFilePath = inputDir + RESOURCE_PATH_DELIMETER + MODELS_PAR; + String parametersFilePath = inputDir + RESOURCE_PATH_DELIMITER + MODELS_PAR; InputStream parametersFileIS = getClass().getResourceAsStream(parametersFilePath); byte[] parametersFileBytes; parametersFileBytes = StreamUtils.copyToByteArray(parametersFileIS); String parametersFile = new String(parametersFileBytes, StandardCharsets.UTF_8); - Script scriptObj = new Script( - MAPPING_NAME_01 + "-script", + Parameter parameterObj = new Parameter( MAPPING_NAME_01, - dateFormat.parse(FIXED_DATE), parametersFile); - given(dynamicMappingClient.createFromMapping(DynamicMappingClientTest.MAPPING_NAME_01)).willReturn(scriptObj); + given(dynamicMappingClient.createFromMapping(DynamicMappingClientTest.MAPPING_NAME_01)).willReturn(parameterObj); // load mapping.json - String mappingPath = inputDir + RESOURCE_PATH_DELIMETER + MAPPING_FILE; + String mappingPath = inputDir + RESOURCE_PATH_DELIMITER + MAPPING_FILE; InputMapping inputMapping = objectMapper.readValue(getClass().getResourceAsStream(mappingPath), InputMapping.class); given(dynamicMappingClient.getMapping(DynamicMappingClientTest.MAPPING_NAME_01)).willReturn(inputMapping); } catch (IOException e) { throw new UncheckedIOException(e); - } catch (ParseException e) { - throw new IllegalArgumentException(e); } } @@ -232,16 +222,16 @@ public void test01GivenCurvesAndEvents() throws Exception { // --- CHECK result at detail level --- // // prepare expected result to compare String outputDir = DATA_IEEE14_BASE_DIR + - RESOURCE_PATH_DELIMETER + testBaseDir + - RESOURCE_PATH_DELIMETER + OUTPUT; - DynamicSimulationResult expectedResult = DynamicSimulationResultDeserializer.read(getClass().getResourceAsStream(outputDir + RESOURCE_PATH_DELIMETER + RESULT_SIM_JSON)); + RESOURCE_PATH_DELIMITER + testBaseDir + + RESOURCE_PATH_DELIMITER + OUTPUT; + DynamicSimulationResult expectedResult = DynamicSimulationResultDeserializer.read(getClass().getResourceAsStream(outputDir + RESOURCE_PATH_DELIMITER + RESULT_SIM_JSON)); String jsonExpectedTimeSeries = TimeSeries.toJson(new ArrayList<>(expectedResult.getCurves().values())); // convert result time series to json String jsonResultTimeSeries = TimeSeries.toJson(resultTimeSeries); // export result to file - FileUtils.writeStringToFile(this, outputDir + RESOURCE_PATH_DELIMETER + "exported_" + RESULT_SIM_JSON, jsonResultTimeSeries); + FileUtils.writeStringToFile(this, outputDir + RESOURCE_PATH_DELIMITER + "exported_" + RESULT_SIM_JSON, jsonResultTimeSeries); // compare result only timeseries assertThat(objectMapper.readTree(jsonResultTimeSeries)).isEqualTo(objectMapper.readTree(jsonExpectedTimeSeries)); diff --git a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java index 58495082..f8ca1f76 100644 --- a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java +++ b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java @@ -25,7 +25,7 @@ import org.gridsuite.ds.server.controller.utils.ParameterUtils; import org.gridsuite.ds.server.dto.DynamicSimulationParametersInfos; import org.gridsuite.ds.server.dto.DynamicSimulationStatus; -import org.gridsuite.ds.server.dto.dynamicmapping.Script; +import org.gridsuite.ds.server.dto.dynamicmapping.Parameter; import org.gridsuite.ds.server.dto.timeseries.TimeSeriesGroupInfos; import org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClientTest; import org.gridsuite.ds.server.service.client.timeseries.TimeSeriesClientTest; @@ -104,12 +104,10 @@ protected void initNetworkStoreServiceMock() { @Override protected void initDynamicMappingServiceMock() { - Script scriptObj = new Script( - MAPPING_NAME + "-script", + Parameter parameterObj = new Parameter( MAPPING_NAME, - new Date(), ""); - given(dynamicMappingClient.createFromMapping(MAPPING_NAME)).willReturn(scriptObj); + given(dynamicMappingClient.createFromMapping(MAPPING_NAME)).willReturn(parameterObj); given(dynamicMappingClient.getMapping(DynamicMappingClientTest.MAPPING_NAME_01)).willReturn(null); } diff --git a/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java b/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java index a3e39420..3c032811 100644 --- a/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java +++ b/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java @@ -12,7 +12,7 @@ import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.client.WireMock; import org.gridsuite.ds.server.DynamicSimulationException; -import org.gridsuite.ds.server.dto.dynamicmapping.Script; +import org.gridsuite.ds.server.dto.dynamicmapping.Parameter; import org.gridsuite.ds.server.service.client.AbstractWireMockRestClientTest; import org.gridsuite.ds.server.service.client.dynamicmapping.impl.DynamicMappingClientImpl; import org.junit.Test; @@ -23,18 +23,16 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; -import java.text.ParseException; -import java.text.SimpleDateFormat; import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowableOfType; -import static org.gridsuite.ds.server.DynamicSimulationException.Type.CREATE_MAPPING_SCRIPT_ERROR; +import static org.gridsuite.ds.server.DynamicSimulationException.Type.CREATE_MAPPING_PARAMETER_ERROR; import static org.gridsuite.ds.server.DynamicSimulationException.Type.DYNAMIC_MAPPING_NOT_FOUND; import static org.gridsuite.ds.server.service.client.RestClient.DELIMITER; import static org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient.API_VERSION; -import static org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient.DYNAMIC_MAPPING_SCRIPT_CREATE_END_POINT; +import static org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient.DYNAMIC_MAPPING_PARAMETER_CREATE_END_POINT; import static org.gridsuite.ds.server.service.client.utils.UrlUtils.buildEndPointUrl; /** @@ -42,20 +40,16 @@ */ public class DynamicMappingClientTest extends AbstractWireMockRestClientTest { - public static final String RESOURCE_PATH_DELIMETER = "/"; + public static final String RESOURCE_PATH_DELIMITER = "/"; // mapping names public static final String MAPPING_NAME_01 = "_01"; // directories - public static final String DATA_IEEE14_BASE_DIR = RESOURCE_PATH_DELIMETER + "data" + RESOURCE_PATH_DELIMETER + "ieee14"; + public static final String DATA_IEEE14_BASE_DIR = RESOURCE_PATH_DELIMITER + "data" + RESOURCE_PATH_DELIMITER + "ieee14"; public static final String INPUT = "input"; - public static final String MODELS_GROOVY = "models.groovy"; public static final String MODELS_PAR = "models.par"; - private static final String FIXED_DATE = "01/01/2023"; - private final SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); - private DynamicMappingClient dynamicMappingClient; @Autowired @@ -66,7 +60,7 @@ public class DynamicMappingClientTest extends AbstractWireMockRestClientTest { private static String getEndpointUrl() { return buildEndPointUrl("", API_VERSION, - DYNAMIC_MAPPING_SCRIPT_CREATE_END_POINT); + DYNAMIC_MAPPING_PARAMETER_CREATE_END_POINT); } @Override @@ -80,54 +74,49 @@ public void setup() { } @Test - public void testCreateFromMapping() throws IOException, ParseException { + public void testCreateFromMapping() throws IOException { String mappingName = MAPPING_NAME_01; - // prepare script - String scriptJson; - // load models.groovy String inputDir = DATA_IEEE14_BASE_DIR + - RESOURCE_PATH_DELIMETER + mappingName + - RESOURCE_PATH_DELIMETER + INPUT; + RESOURCE_PATH_DELIMITER + mappingName + + RESOURCE_PATH_DELIMITER + INPUT; // load models.par - String parametersFilePath = inputDir + RESOURCE_PATH_DELIMETER + MODELS_PAR; + String parametersFilePath = inputDir + RESOURCE_PATH_DELIMITER + MODELS_PAR; InputStream parametersFileIS = getClass().getResourceAsStream(parametersFilePath); byte[] parametersFileBytes; parametersFileBytes = StreamUtils.copyToByteArray(parametersFileIS); String parametersFile = new String(parametersFileBytes, StandardCharsets.UTF_8); - Script scriptObj = new Script( - mappingName + "-script", + Parameter parameterObj = new Parameter( mappingName, - dateFormat.parse(FIXED_DATE), parametersFile); ObjectWriter ow = objectMapper.writer().withDefaultPrettyPrinter(); - scriptJson = ow.writeValueAsString(scriptObj); + String parameterJson = ow.writeValueAsString(parameterObj); - // mock response for test case GET with url - /scripts/from/{mappingName} + // mock response for test case GET with url - /parameters/from/{mappingName} String baseUrl = getEndpointUrl(); wireMockServer.stubFor(WireMock.get(WireMock.urlPathTemplate(baseUrl + DELIMITER + "{mappingName}")) .withPathParam("mappingName", equalTo(mappingName)) .willReturn(WireMock.ok() - .withBody(scriptJson) + .withBody(parameterJson) .withHeader("Content-Type", "application/json; charset=utf-8") )); - Script createdScript = dynamicMappingClient.createFromMapping(MAPPING_NAME_01); + Parameter createdParameter = dynamicMappingClient.createFromMapping(MAPPING_NAME_01); // check result // load models.par - assertThat(createdScript.getParametersFile()).isEqualTo(parametersFile); + assertThat(createdParameter.parametersFile()).isEqualTo(parametersFile); } @Test public void testCreateFromMappingGivenNotFound() { String mappingName = MAPPING_NAME_01; - // mock response for test case GET with url - /scripts/from/{mappingName} + // mock response for test case GET with url - /parameters/from/{mappingName} String baseUrl = getEndpointUrl(); wireMockServer.stubFor(WireMock.get(WireMock.urlPathTemplate(baseUrl + "{mappingName}")) @@ -148,7 +137,7 @@ public void testCreateFromMappingGivenNotFound() { public void testCreateFromMappingGivenException() { String mappingName = MAPPING_NAME_01; - // mock response for test case GET with url - /scripts/from/{mappingName} + // mock response for test case GET with url - /parameters/from/{mappingName} String baseUrl = getEndpointUrl(); wireMockServer.stubFor(WireMock.get(WireMock.urlPathTemplate(baseUrl + DELIMITER + "{mappingName}")) @@ -163,7 +152,7 @@ public void testCreateFromMappingGivenException() { // check result assertThat(dynamicSimulationException.getType()) - .isEqualTo(CREATE_MAPPING_SCRIPT_ERROR); + .isEqualTo(CREATE_MAPPING_PARAMETER_ERROR); assertThat(dynamicSimulationException.getMessage()) .isEqualTo(ERROR_MESSAGE); From 9f71e3bea9d5a5d64402676e1775056527147b2e Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Tue, 21 May 2024 17:40:59 +0200 Subject: [PATCH 06/25] update mapping.json --- .../data/ieee14/_01/input/mapping.json | 66 +++++++++++++++---- 1 file changed, 55 insertions(+), 11 deletions(-) diff --git a/src/test/resources/data/ieee14/_01/input/mapping.json b/src/test/resources/data/ieee14/_01/input/mapping.json index f83a1a70..47542286 100644 --- a/src/test/resources/data/ieee14/_01/input/mapping.json +++ b/src/test/resources/data/ieee14/_01/input/mapping.json @@ -69,11 +69,11 @@ "combinator": "AND", "dataType": "COMBINATOR", "rules" : [{ - "dataType": "NUMBER", - "field": "NOMINAL_VOLTAGE", - "operator": "EQUALS", - "value": 69.0 - } + "dataType": "NUMBER", + "field": "NOMINAL_VOLTAGE", + "operator": "EQUALS", + "value": 69.0 + } ] } } @@ -81,8 +81,8 @@ ], "automata": [ { - "family": "CURRENT_LIMIT", - "model": "CurrentLimitAutomaton", + "family": "CURRENT", + "model": "OverloadManagementSystem", "setGroup": "CLA_2_4", "properties": [ { @@ -101,15 +101,15 @@ "type": "TWO_SIDES" }, { - "name": "controlledQuadripole", + "name": "controlledBranch", "value": "_BUS____2-BUS____4-1_AC", "type": "STRING" } ] }, { - "family": "CURRENT_LIMIT", - "model": "CurrentLimitAutomaton", + "family": "CURRENT", + "model": "OverloadManagementSystem", "setGroup": "CLA_2_5", "properties": [ { @@ -128,11 +128,55 @@ "type": "TWO_SIDES" }, { - "name": "controlledQuadripole", + "name": "controlledBranch", "value": "_BUS____2-BUS____5-1_AC", "type": "STRING" } ] + }, + { + "family": "VOLTAGE", + "model": "TapChangerBlockingAutomaton", + "setGroup": "TCB_2_4", + "properties": [ + { + "name": "dynamicModelId", + "value": "TCB_1", + "type": "STRING" + }, + { + "name": "uMeasurements", + "value": "_BUS___11_TN, _BUS___11_TN", + "type": "STRING" + }, + { + "name": "transformers", + "value": "_LOAD__11_EC, _LOAD__12_EC", + "type": "STRING" + } + ] + }, + { + "family": "VOLTAGE", + "model": "TapChangerBlockingAutomaton", + "setGroup": "TCB_2_5", + "properties": [ + { + "name": "dynamicModelId", + "value": "TCB_2", + "type": "STRING" + }, + { + "name": "uMeasurements", + "value": "_BUS____4_TN", + "type": "STRING" + }, + { + "name": "transformers", + "value": "_BUS____4-BUS____9-1_PT", + "type": "STRING" + } + ] } ], "controlledParameters": false From 772ead44b91168b77402aa663f97873e826ce4ac Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Tue, 4 Jun 2024 17:50:50 +0200 Subject: [PATCH 07/25] Adapt migration powsybl --- pom.xml | 12 +++++----- .../ds/server/dto/dynamicmapping/Rule.java | 2 +- .../automata/BasicProperty.java | 2 +- .../DynamicSimulationWorkerService.java | 6 ++--- .../contexts/DynamicSimulationRunContext.java | 2 +- .../service/parameters/ParametersService.java | 4 ++-- .../impl/ParametersServiceImpl.java | 15 ++++-------- .../org/gridsuite/ds/server/utils/Utils.java | 24 +++++++++++++++++++ .../data/ieee14/_01/input/mapping.json | 2 +- 9 files changed, 44 insertions(+), 25 deletions(-) diff --git a/pom.xml b/pom.xml index bbbdfc76..6b65ad22 100644 --- a/pom.xml +++ b/pom.xml @@ -140,23 +140,23 @@ com.powsybl powsybl-dynawaltz - 2.4.0-SNAPSHOT + 2.5.0-SNAPSHOT com.powsybl powsybl-dynawaltz-dsl - 2.4.0-SNAPSHOT + 2.5.0-SNAPSHOT - + org.gridsuite gridsuite-filter diff --git a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Rule.java b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Rule.java index 8a07e415..2f2e6cc7 100644 --- a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Rule.java +++ b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Rule.java @@ -6,7 +6,7 @@ */ package org.gridsuite.ds.server.dto.dynamicmapping; -import com.powsybl.dynawaltz.rte.mapping.dynamicmodels.SetGroupType; +import com.powsybl.dynawaltz.suppliers.SetGroupType; import io.swagger.v3.oas.annotations.media.Schema; import org.gridsuite.filter.expertfilter.ExpertFilter; import org.gridsuite.filter.utils.EquipmentType; diff --git a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/BasicProperty.java b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/BasicProperty.java index bc849bfc..5fc584da 100644 --- a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/BasicProperty.java +++ b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/BasicProperty.java @@ -7,7 +7,7 @@ package org.gridsuite.ds.server.dto.dynamicmapping.automata; -import com.powsybl.dynawaltz.rte.mapping.dynamicmodels.PropertyType; +import com.powsybl.dynawaltz.suppliers.PropertyType; /** * @author Thang PHAM diff --git a/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java b/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java index e801e372..dcf9ae43 100644 --- a/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java +++ b/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java @@ -13,8 +13,8 @@ import com.powsybl.dynamicsimulation.*; import com.powsybl.dynamicsimulation.groovy.*; import com.powsybl.dynawaltz.DynaWaltzProvider; -import com.powsybl.dynawaltz.rte.mapping.dynamicmodels.DynamicModelConfig; -import com.powsybl.dynawaltz.rte.mapping.dynamicmodels.DynawoDynamicModelSupplier; +import com.powsybl.dynawaltz.suppliers.dynamicmodels.DynamicModelConfig; +import com.powsybl.dynawaltz.suppliers.dynamicmodels.DynawoDynamicModelsSupplier; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.VariantManagerConstants; import com.powsybl.network.store.client.NetworkStoreService; @@ -168,7 +168,7 @@ public void preRun(DynamicSimulationRunContext runContext) { @Override public CompletableFuture getCompletableFuture(Network network, DynamicSimulationRunContext runContext, String provider, UUID resultUuid) { - DynamicModelsSupplier dynawoDynamicModelsSupplier = new DynawoDynamicModelSupplier(runContext.getDynamicModelContent()); + DynamicModelsSupplier dynawoDynamicModelsSupplier = new DynawoDynamicModelsSupplier(runContext.getDynamicModelContent()); List eventModelExtensions = GroovyExtension.find(EventModelGroovyExtension.class, DynaWaltzProvider.NAME); EventModelsSupplier eventModelsSupplier = new GroovyEventModelsSupplier( diff --git a/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java b/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java index 6d768943..40d47b60 100644 --- a/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java +++ b/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java @@ -7,7 +7,7 @@ package org.gridsuite.ds.server.service.contexts; import com.powsybl.dynamicsimulation.DynamicSimulationParameters; -import com.powsybl.dynawaltz.rte.mapping.dynamicmodels.DynamicModelConfig; +import com.powsybl.dynawaltz.suppliers.dynamicmodels.DynamicModelConfig; import com.powsybl.iidm.network.Network; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/org/gridsuite/ds/server/service/parameters/ParametersService.java b/src/main/java/org/gridsuite/ds/server/service/parameters/ParametersService.java index 09f853ca..533c3446 100644 --- a/src/main/java/org/gridsuite/ds/server/service/parameters/ParametersService.java +++ b/src/main/java/org/gridsuite/ds/server/service/parameters/ParametersService.java @@ -7,9 +7,9 @@ package org.gridsuite.ds.server.service.parameters; import com.powsybl.dynamicsimulation.DynamicSimulationParameters; -import org.gridsuite.ds.server.computation.dto.ReportInfos; -import com.powsybl.dynawaltz.rte.mapping.dynamicmodels.DynamicModelConfig; +import com.powsybl.dynawaltz.suppliers.dynamicmodels.DynamicModelConfig; import com.powsybl.iidm.network.Network; +import org.gridsuite.ds.server.computation.dto.ReportInfos; import org.gridsuite.ds.server.dto.DynamicSimulationParametersInfos; import org.gridsuite.ds.server.dto.curve.CurveInfos; import org.gridsuite.ds.server.dto.dynamicmapping.InputMapping; diff --git a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java index 47dda70c..4aedf48a 100644 --- a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java +++ b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java @@ -12,9 +12,9 @@ import com.powsybl.dynawaltz.DynaWaltzParameters; import com.powsybl.dynawaltz.DynaWaltzProvider; import com.powsybl.dynawaltz.parameters.ParametersSet; -import com.powsybl.dynawaltz.rte.mapping.dynamicmodels.DynamicModelConfig; -import com.powsybl.dynawaltz.rte.mapping.dynamicmodels.PropertyBuilder; -import com.powsybl.dynawaltz.rte.mapping.dynamicmodels.PropertyType; +import com.powsybl.dynawaltz.suppliers.PropertyBuilder; +import com.powsybl.dynawaltz.suppliers.PropertyType; +import com.powsybl.dynawaltz.suppliers.dynamicmodels.DynamicModelConfig; import com.powsybl.dynawaltz.xml.ParametersXml; import com.powsybl.iidm.network.Identifiable; import com.powsybl.iidm.network.Network; @@ -34,6 +34,7 @@ import org.gridsuite.ds.server.service.parameters.CurveGroovyGeneratorService; import org.gridsuite.ds.server.service.parameters.EventGroovyGeneratorService; import org.gridsuite.ds.server.service.parameters.ParametersService; +import org.gridsuite.ds.server.utils.Utils; import org.gridsuite.filter.expertfilter.ExpertFilter; import org.gridsuite.filter.expertfilter.expertrule.CombinatorExpertRule; import org.gridsuite.filter.utils.EquipmentType; @@ -237,13 +238,7 @@ public List getDynamicModel(InputMapping inputMapping, Netwo new DynamicModelConfig( automaton.model(), automaton.setGroup(), - automaton.properties().stream().map(property -> - new PropertyBuilder() - .name(property.name()) - .value(property.value()) - .type(property.type()) - .build() - ).toList()) + automaton.properties().stream().map(Utils::convertToProperty).toList()) ).toList()); return dynamicModel; diff --git a/src/main/java/org/gridsuite/ds/server/utils/Utils.java b/src/main/java/org/gridsuite/ds/server/utils/Utils.java index 8d0e5b94..3889766f 100644 --- a/src/main/java/org/gridsuite/ds/server/utils/Utils.java +++ b/src/main/java/org/gridsuite/ds/server/utils/Utils.java @@ -7,6 +7,11 @@ package org.gridsuite.ds.server.utils; +import com.powsybl.dynawaltz.suppliers.Property; +import com.powsybl.dynawaltz.suppliers.PropertyBuilder; +import com.powsybl.dynawaltz.suppliers.PropertyType; +import org.gridsuite.ds.server.dto.dynamicmapping.automata.BasicProperty; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -24,4 +29,23 @@ public static List convertStringToList(String stringArray) { converted.addAll(Arrays.asList(stringArray.split(","))); return converted; } + + public static Property convertToProperty(BasicProperty property) { + String value = property.value(); + PropertyType type = property.type(); + PropertyBuilder propertyBuilder = new PropertyBuilder() + .name(property.name()) + .type(type) + .value(value); + if (type == PropertyType.STRING) { + List values = convertStringToList(value); + // check whether having multiple values + if (values.size() > 1) { + // override single string by multi strings + propertyBuilder.type(PropertyType.STRINGS); + propertyBuilder.values(values); + } + } + return propertyBuilder.build(); + } } diff --git a/src/test/resources/data/ieee14/_01/input/mapping.json b/src/test/resources/data/ieee14/_01/input/mapping.json index 47542286..92f5d720 100644 --- a/src/test/resources/data/ieee14/_01/input/mapping.json +++ b/src/test/resources/data/ieee14/_01/input/mapping.json @@ -146,7 +146,7 @@ }, { "name": "uMeasurements", - "value": "_BUS___11_TN, _BUS___11_TN", + "value": "_BUS___11_TN, _BUS___12_TN", "type": "STRING" }, { From b4a2e728bf469e346363f83bfe0f28c45fa3ab9b Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Wed, 5 Jun 2024 15:39:57 +0200 Subject: [PATCH 08/25] Adapt migration powsybl for PropertyType --- .../ds/server/dto/dynamicmapping/Rule.java | 2 +- .../automata/BasicProperty.java | 2 +- .../impl/ParametersServiceImpl.java | 8 +- .../ds/server/utils/PropertyType.java | 3 +- .../ds/server/utils/SetGroupType.java | 16 ++++ .../org/gridsuite/ds/server/utils/Utils.java | 41 ++++++-- .../data/ieee14/_01/input/mapping.json | 8 +- .../data/ieee14/_01/output/result_SIM.json | 94 +++++++++---------- 8 files changed, 108 insertions(+), 66 deletions(-) create mode 100644 src/main/java/org/gridsuite/ds/server/utils/SetGroupType.java diff --git a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Rule.java b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Rule.java index 2f2e6cc7..bb3deb13 100644 --- a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Rule.java +++ b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Rule.java @@ -6,8 +6,8 @@ */ package org.gridsuite.ds.server.dto.dynamicmapping; -import com.powsybl.dynawaltz.suppliers.SetGroupType; import io.swagger.v3.oas.annotations.media.Schema; +import org.gridsuite.ds.server.utils.SetGroupType; import org.gridsuite.filter.expertfilter.ExpertFilter; import org.gridsuite.filter.utils.EquipmentType; diff --git a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/BasicProperty.java b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/BasicProperty.java index 5fc584da..1c99beee 100644 --- a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/BasicProperty.java +++ b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/BasicProperty.java @@ -7,7 +7,7 @@ package org.gridsuite.ds.server.dto.dynamicmapping.automata; -import com.powsybl.dynawaltz.suppliers.PropertyType; +import org.gridsuite.ds.server.utils.PropertyType; /** * @author Thang PHAM diff --git a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java index 4aedf48a..eb1282e8 100644 --- a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java +++ b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java @@ -14,6 +14,7 @@ import com.powsybl.dynawaltz.parameters.ParametersSet; import com.powsybl.dynawaltz.suppliers.PropertyBuilder; import com.powsybl.dynawaltz.suppliers.PropertyType; +import com.powsybl.dynawaltz.suppliers.SetGroupType; import com.powsybl.dynawaltz.suppliers.dynamicmodels.DynamicModelConfig; import com.powsybl.dynawaltz.xml.ParametersXml; import com.powsybl.iidm.network.Identifiable; @@ -62,6 +63,7 @@ public class ParametersServiceImpl implements ParametersService { private static final Logger LOGGER = LoggerFactory.getLogger(ParametersServiceImpl.class); + public static final String FIELD_STATIC_ID = "staticId"; private final CurveGroovyGeneratorService curveGroovyGeneratorService; @@ -223,9 +225,9 @@ public List getDynamicModel(InputMapping inputMapping, Netwo return matchedEquipments.stream().map(equipment -> new DynamicModelConfig( rule.mappedModel(), rule.setGroup(), - rule.groupType(), + SetGroupType.valueOf(rule.groupType().name()), List.of(new PropertyBuilder() - .name("staticId") + .name(FIELD_STATIC_ID) .value(equipment.getId()) .type(PropertyType.STRING) .build()))); @@ -238,7 +240,7 @@ public List getDynamicModel(InputMapping inputMapping, Netwo new DynamicModelConfig( automaton.model(), automaton.setGroup(), - automaton.properties().stream().map(Utils::convertToProperty).toList()) + automaton.properties().stream().map(Utils::convertProperty).filter(Objects::nonNull).toList()) ).toList()); return dynamicModel; diff --git a/src/main/java/org/gridsuite/ds/server/utils/PropertyType.java b/src/main/java/org/gridsuite/ds/server/utils/PropertyType.java index 969b4a19..cdad6d41 100644 --- a/src/main/java/org/gridsuite/ds/server/utils/PropertyType.java +++ b/src/main/java/org/gridsuite/ds/server/utils/PropertyType.java @@ -10,9 +10,10 @@ * @author Thang PHAM */ public enum PropertyType { - ENUM, BOOLEAN, + ENUM, INTEGER, FLOAT, + DOUBLE, STRING, } diff --git a/src/main/java/org/gridsuite/ds/server/utils/SetGroupType.java b/src/main/java/org/gridsuite/ds/server/utils/SetGroupType.java new file mode 100644 index 00000000..86f80ceb --- /dev/null +++ b/src/main/java/org/gridsuite/ds/server/utils/SetGroupType.java @@ -0,0 +1,16 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.ds.server.utils; + +/** + * @author Mathieu Scalbert + */ +public enum SetGroupType { + FIXED, + PREFIX, + SUFFIX +} diff --git a/src/main/java/org/gridsuite/ds/server/utils/Utils.java b/src/main/java/org/gridsuite/ds/server/utils/Utils.java index 3889766f..10600416 100644 --- a/src/main/java/org/gridsuite/ds/server/utils/Utils.java +++ b/src/main/java/org/gridsuite/ds/server/utils/Utils.java @@ -10,6 +10,8 @@ import com.powsybl.dynawaltz.suppliers.Property; import com.powsybl.dynawaltz.suppliers.PropertyBuilder; import com.powsybl.dynawaltz.suppliers.PropertyType; +import com.powsybl.iidm.network.TwoSides; +import org.apache.commons.lang3.StringUtils; import org.gridsuite.ds.server.dto.dynamicmapping.automata.BasicProperty; import java.util.ArrayList; @@ -30,22 +32,43 @@ public static List convertStringToList(String stringArray) { return converted; } - public static Property convertToProperty(BasicProperty property) { + public static Property convertProperty(BasicProperty property) { String value = property.value(); - PropertyType type = property.type(); PropertyBuilder propertyBuilder = new PropertyBuilder() - .name(property.name()) - .type(type) - .value(value); - if (type == PropertyType.STRING) { + .name(property.name()); + + if (property.type() == org.gridsuite.ds.server.utils.PropertyType.ENUM) { + // using value to infer the enum + if (StringUtils.isEmpty(value) || value.split(".").length != 2) { + return null; + } + + String[] splitValue = value.split("."); + String enumType = splitValue[0]; + String enumValue = splitValue[1]; + + // at moment process only TwoSides + if (TwoSides.class.getName().equals(enumType)) { + propertyBuilder.value(enumValue) + .type(PropertyType.TWO_SIDES); + } else { + return null; + } + } else if (property.type() == org.gridsuite.ds.server.utils.PropertyType.STRING) { List values = convertStringToList(value); // check whether having multiple values if (values.size() > 1) { - // override single string by multi strings - propertyBuilder.type(PropertyType.STRINGS); - propertyBuilder.values(values); + propertyBuilder.values(values) + .type(PropertyType.STRINGS); + } else { + propertyBuilder.value(value) + .type(PropertyType.valueOf(property.type().name())); } + } else { + propertyBuilder.value(value) + .type(PropertyType.valueOf(property.type().name())); } + return propertyBuilder.build(); } } diff --git a/src/test/resources/data/ieee14/_01/input/mapping.json b/src/test/resources/data/ieee14/_01/input/mapping.json index 92f5d720..1b38c671 100644 --- a/src/test/resources/data/ieee14/_01/input/mapping.json +++ b/src/test/resources/data/ieee14/_01/input/mapping.json @@ -97,8 +97,8 @@ }, { "name": "iMeasurementSide", - "value": "TWO", - "type": "TWO_SIDES" + "value": "TwoSides.TWO", + "type": "ENUM" }, { "name": "controlledBranch", @@ -124,8 +124,8 @@ }, { "name": "iMeasurementSide", - "value": "TWO", - "type": "TWO_SIDES" + "value": "TwoSides.TWO", + "type": "ENUM" }, { "name": "controlledBranch", diff --git a/src/test/resources/data/ieee14/_01/output/result_SIM.json b/src/test/resources/data/ieee14/_01/output/result_SIM.json index 133a5a64..c4effd25 100644 --- a/src/test/resources/data/ieee14/_01/output/result_SIM.json +++ b/src/test/resources/data/ieee14/_01/output/result_SIM.json @@ -6,156 +6,156 @@ "name" : "SVC2_SVarC_injector_QInjPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ -0.031738, -0.007935, -0.003222, 0.172601, 0.191644, 0.189343, 0.184884, 0.197732, 0.203929, 0.200946, 0.199999, 0.185314, 0.313312, 0.415058, 0.39714, 0.380065, 0.376941, 0.377728 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 53, + "stepValues" : [ -0.031754, -0.007935, -0.003222, 0.172496, 0.191611, 0.190078 ], + "stepLengths" : [ 1, 1, 1, 2, 1, 47 ] } ] }, { "metadata" : { "name" : "_GEN____3_SM_generator_omegaPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ 1.0, 0.999831, 0.999806, 0.999657, 0.999646, 0.999615, 0.999581, 0.998868, 0.998811, 0.998709, 0.99856, 0.998442, 0.998362 ], - "stepLengths" : [ 3, 3, 5, 2, 1, 1, 9, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 53, + "stepValues" : [ 1.0, 0.999831, 0.99983, 0.999799 ], + "stepLengths" : [ 3, 2, 1, 47 ] } ] }, { "metadata" : { "name" : "_LOAD___2_EC_load_QPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ 0.126839, 0.126962, 0.126691, 0.126715, 0.126749, 0.126759, 0.127039, 0.126746, 0.12674, 0.126747, 0.127671, 0.126586, 0.12648, 0.12654, 0.126558, 0.126557, 0.126555 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 9, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 53, + "stepValues" : [ 0.126839, 0.126962, 0.126691, 0.126715, 0.126749, 0.126758 ], + "stepLengths" : [ 1, 1, 1, 2, 1, 47 ] } ] }, { "metadata" : { "name" : "_LOAD___2_EC_load_PPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ 0.216863, 0.216968, 0.216736, 0.216757, 0.216785, 0.216794, 0.217034, 0.216783, 0.216778, 0.216784, 0.217573, 0.216646, 0.216555, 0.216607, 0.216622, 0.216621, 0.216619 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 9, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 53, + "stepValues" : [ 0.216862, 0.216968, 0.216736, 0.216757, 0.216785, 0.216793 ], + "stepLengths" : [ 1, 1, 1, 2, 1, 47 ] } ] }, { "metadata" : { "name" : "_GEN____3_SM_generator_QGen", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ 25.432854, 25.119541, 23.633342, 29.121397, 29.829532, 29.573958, 28.63852, 37.534679, 38.845762, 38.622417, 38.521909, 29.999842, 92.036606, 109.12902, 107.191712, 105.214641, 104.881032, 104.978456 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 53, + "stepValues" : [ 25.433065, 25.119541, 23.633342, 29.116793, 29.833218, 29.623577 ], + "stepLengths" : [ 1, 1, 1, 2, 1, 47 ] } ] }, { "metadata" : { "name" : "SVC2_SVarC_modeHandling_mode_value", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, + "uncompressedLength" : 53, "stepValues" : [ 3.0 ], - "stepLengths" : [ 56 ] + "stepLengths" : [ 53 ] } ] }, { "metadata" : { "name" : "SVC2_SVarC_injector_BPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ -0.012932, -0.00323, -0.001314, 0.070395, 0.078141, 0.077197, 0.075212, 0.080625, 0.083156, 0.081936, 0.08155, 0.075014, 0.127917, 0.169596, 0.162198, 0.155202, 0.153927, 0.154252 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 53, + "stepValues" : [ -0.012931, -0.00323, -0.001314, 0.070345, 0.078126, 0.077502 ], + "stepLengths" : [ 1, 1, 1, 2, 1, 47 ] } ] }, { "metadata" : { "name" : "SVC2_SVarC_injector_PInjPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ -0.0, -1.0E-6, 1.0E-6, 1.2E-5, 0.0, -3.0E-6, -1.0E-6, 7.0E-6, 1.7E-5, 0.0, 1.0E-6, 0.0, 1.0E-6, 6.0E-6, -5.9E-5, 5.0E-6 ], - "stepLengths" : [ 3, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 53, + "stepValues" : [ 0.0, 9.0E-6, 8.0E-6, 1.51E-4 ], + "stepLengths" : [ 3, 2, 1, 47 ] } ] }, { "metadata" : { "name" : "SVC2_SVarC_injector_UPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ 1.04441, 1.044917, 1.043801, 1.043901, 1.044039, 1.04408, 1.045235, 1.044028, 1.044004, 1.04403, 1.044031, 1.047831, 1.043368, 1.042931, 1.043178, 1.043254, 1.043248, 1.043239 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 53, + "stepValues" : [ 1.04441, 1.044917, 1.043801, 1.043901, 1.044039, 1.044076 ], + "stepLengths" : [ 1, 1, 1, 2, 1, 47 ] } ] }, { "metadata" : { "name" : "_GEN____3_SM_voltageRegulator_EfdPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ 1.113815, 1.112414, 1.106843, 1.126104, 1.123718, 1.120924, 1.117658, 1.146109, 1.141868, 1.137235, 1.135909, 1.103233, 1.308934, 1.308534, 1.267248, 1.25156, 1.249371, 1.249583 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 53, + "stepValues" : [ 1.113815, 1.112414, 1.106843, 1.126098, 1.123741, 1.121164 ], + "stepLengths" : [ 1, 1, 1, 2, 1, 47 ] } ] }, { "metadata" : { "name" : "_GEN____3_SM_generator_PGen", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ 0.036881, -0.007339, 15.349408, 3.143088, 1.248892, 1.954053, 16.691385, 5.296473, 2.840279, 3.427963, 3.7307, 52.684413, 21.622315, 9.857958, 11.458084, 13.42682, 13.752483, 13.614968 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 53, + "stepValues" : [ 0.036939, -0.007339, 15.349408, 3.147903, 1.237428, 1.824559 ], + "stepLengths" : [ 1, 1, 1, 2, 1, 47 ] } ] }, { "metadata" : { "name" : "_GEN____3_SM_generator_UStatorPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ 1.011427, 1.011497, 1.011775, 1.010812, 1.010931, 1.011071, 1.011234, 1.009812, 1.010024, 1.010256, 1.010322, 1.011956, 1.001671, 1.001691, 1.003755, 1.004539, 1.004649, 1.004638 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 53, + "stepValues" : [ 1.011427, 1.011497, 1.011775, 1.010812, 1.01093, 1.011059 ], + "stepLengths" : [ 1, 1, 1, 2, 1, 47 ] } ] } ], "timeLine" : [] From 21e0844b5525fb275b41cf238e9206b116aa0f09 Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Wed, 5 Jun 2024 18:44:50 +0200 Subject: [PATCH 09/25] Adaptation to evolution in powsybl-dynawo on property type --- .../service/DynamicSimulationWorkerService.java | 4 ++-- .../java/org/gridsuite/ds/server/utils/Utils.java | 13 ++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java b/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java index dcf9ae43..c84ab88c 100644 --- a/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java +++ b/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java @@ -14,7 +14,7 @@ import com.powsybl.dynamicsimulation.groovy.*; import com.powsybl.dynawaltz.DynaWaltzProvider; import com.powsybl.dynawaltz.suppliers.dynamicmodels.DynamicModelConfig; -import com.powsybl.dynawaltz.suppliers.dynamicmodels.DynawoDynamicModelsSupplier; +import com.powsybl.dynawaltz.suppliers.dynamicmodels.DynawoModelsSupplier; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.VariantManagerConstants; import com.powsybl.network.store.client.NetworkStoreService; @@ -168,7 +168,7 @@ public void preRun(DynamicSimulationRunContext runContext) { @Override public CompletableFuture getCompletableFuture(Network network, DynamicSimulationRunContext runContext, String provider, UUID resultUuid) { - DynamicModelsSupplier dynawoDynamicModelsSupplier = new DynawoDynamicModelsSupplier(runContext.getDynamicModelContent()); + DynamicModelsSupplier dynawoDynamicModelsSupplier = new DynawoModelsSupplier(runContext.getDynamicModelContent()); List eventModelExtensions = GroovyExtension.find(EventModelGroovyExtension.class, DynaWaltzProvider.NAME); EventModelsSupplier eventModelsSupplier = new GroovyEventModelsSupplier( diff --git a/src/main/java/org/gridsuite/ds/server/utils/Utils.java b/src/main/java/org/gridsuite/ds/server/utils/Utils.java index 10600416..cbd0443b 100644 --- a/src/main/java/org/gridsuite/ds/server/utils/Utils.java +++ b/src/main/java/org/gridsuite/ds/server/utils/Utils.java @@ -38,7 +38,7 @@ public static Property convertProperty(BasicProperty property) { .name(property.name()); if (property.type() == org.gridsuite.ds.server.utils.PropertyType.ENUM) { - // using value to infer the enum + // using value to infer enum type if (StringUtils.isEmpty(value) || value.split(".").length != 2) { return null; } @@ -47,7 +47,7 @@ public static Property convertProperty(BasicProperty property) { String enumType = splitValue[0]; String enumValue = splitValue[1]; - // at moment process only TwoSides + // at moment process only TwoSides, e.g. TwoSides.TWO or TwoSides.ONE if (TwoSides.class.getName().equals(enumType)) { propertyBuilder.value(enumValue) .type(PropertyType.TWO_SIDES); @@ -55,14 +55,13 @@ public static Property convertProperty(BasicProperty property) { return null; } } else if (property.type() == org.gridsuite.ds.server.utils.PropertyType.STRING) { + propertyBuilder.value(value) + .type(PropertyType.valueOf(property.type().name())); List values = convertStringToList(value); // check whether having multiple values if (values.size() > 1) { - propertyBuilder.values(values) - .type(PropertyType.STRINGS); - } else { - propertyBuilder.value(value) - .type(PropertyType.valueOf(property.type().name())); + // override by set multiple values + propertyBuilder.values(values); } } else { propertyBuilder.value(value) From 019511675fee80e6a195c3a1e39ed39b057df527 Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Thu, 6 Jun 2024 17:14:54 +0200 Subject: [PATCH 10/25] Code clean --- .../client/dynamicmapping/DynamicMappingClientTest.java | 2 +- .../service/client/timeseries/TimeSeriesClientTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java b/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java index 3c032811..92c7cfc2 100644 --- a/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java +++ b/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java @@ -58,7 +58,7 @@ public class DynamicMappingClientTest extends AbstractWireMockRestClientTest { @Autowired private ObjectMapper objectMapper; - private static String getEndpointUrl() { + private String getEndpointUrl() { return buildEndPointUrl("", API_VERSION, DYNAMIC_MAPPING_PARAMETER_CREATE_END_POINT); } diff --git a/src/test/java/org/gridsuite/ds/server/service/client/timeseries/TimeSeriesClientTest.java b/src/test/java/org/gridsuite/ds/server/service/client/timeseries/TimeSeriesClientTest.java index 7373fe78..fdc0026d 100644 --- a/src/test/java/org/gridsuite/ds/server/service/client/timeseries/TimeSeriesClientTest.java +++ b/src/test/java/org/gridsuite/ds/server/service/client/timeseries/TimeSeriesClientTest.java @@ -50,7 +50,7 @@ public class TimeSeriesClientTest extends AbstractWireMockRestClientTest { @Autowired private ObjectMapper objectMapper; - private static List> createTimeSeriesList() { + private List> createTimeSeriesList() { Map> curves = new HashMap<>(); TimeSeriesIndex index = new IrregularTimeSeriesIndex(new long[]{32, 64, 128, 256}); curves.put("NETWORK__BUS____2-BUS____5-1_AC_iSide2", TimeSeries.createDouble("NETWORK__BUS____2-BUS____5-1_AC_iSide2", index, 333.847331, 333.847321, 333.847300, 333.847259)); @@ -59,7 +59,7 @@ public class TimeSeriesClientTest extends AbstractWireMockRestClientTest { return timeSeries; } - private static String getEndpointUrl() { + private String getEndpointUrl() { return buildEndPointUrl("", API_VERSION, TIME_SERIES_END_POINT); } From 5256adc4b93fa201a7fb72b611638375baf9982c Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Fri, 7 Jun 2024 11:45:12 +0200 Subject: [PATCH 11/25] Correct transforming ENUM TwoSides and trimming string --- .../impl/ParametersServiceImpl.java | 15 ++- .../org/gridsuite/ds/server/utils/Utils.java | 8 +- .../data/ieee14/_01/input/mapping.json | 4 +- .../data/ieee14/_01/output/result_SIM.json | 94 +++++++++---------- 4 files changed, 67 insertions(+), 54 deletions(-) diff --git a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java index eb1282e8..f6cdd1e5 100644 --- a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java +++ b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java @@ -6,6 +6,8 @@ */ package org.gridsuite.ds.server.service.parameters.impl; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import com.powsybl.commons.exceptions.UncheckedXmlStreamException; import com.powsybl.dynamicsimulation.DynamicSimulationParameters; import com.powsybl.dynamicsimulation.DynamicSimulationProvider; @@ -50,6 +52,7 @@ import javax.xml.stream.XMLStreamException; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.UncheckedIOException; import java.util.*; import java.util.stream.Collectors; @@ -65,6 +68,8 @@ public class ParametersServiceImpl implements ParametersService { private static final Logger LOGGER = LoggerFactory.getLogger(ParametersServiceImpl.class); public static final String FIELD_STATIC_ID = "staticId"; + private final ObjectMapper objectMapper; + private final CurveGroovyGeneratorService curveGroovyGeneratorService; private final EventGroovyGeneratorService eventGroovyGeneratorService; @@ -72,9 +77,11 @@ public class ParametersServiceImpl implements ParametersService { private final String defaultProvider; @Autowired - public ParametersServiceImpl(CurveGroovyGeneratorService curveGroovyGeneratorService, + public ParametersServiceImpl(ObjectMapper objectMapper, + CurveGroovyGeneratorService curveGroovyGeneratorService, EventGroovyGeneratorService eventGroovyGeneratorService, @Value("${dynamic-simulation.default-provider}") String defaultProvider) { + this.objectMapper = objectMapper; this.curveGroovyGeneratorService = curveGroovyGeneratorService; this.eventGroovyGeneratorService = eventGroovyGeneratorService; this.defaultProvider = defaultProvider; @@ -243,6 +250,12 @@ public List getDynamicModel(InputMapping inputMapping, Netwo automaton.properties().stream().map(Utils::convertProperty).filter(Objects::nonNull).toList()) ).toList()); + try { + LOGGER.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dynamicModel)); + } catch (JsonProcessingException e) { + throw new UncheckedIOException(e); + } + return dynamicModel; } } diff --git a/src/main/java/org/gridsuite/ds/server/utils/Utils.java b/src/main/java/org/gridsuite/ds/server/utils/Utils.java index cbd0443b..2985b7b4 100644 --- a/src/main/java/org/gridsuite/ds/server/utils/Utils.java +++ b/src/main/java/org/gridsuite/ds/server/utils/Utils.java @@ -39,16 +39,16 @@ public static Property convertProperty(BasicProperty property) { if (property.type() == org.gridsuite.ds.server.utils.PropertyType.ENUM) { // using value to infer enum type - if (StringUtils.isEmpty(value) || value.split(".").length != 2) { + if (StringUtils.isEmpty(value) || value.split("\\.").length != 2) { return null; } - String[] splitValue = value.split("."); + String[] splitValue = value.split("\\."); String enumType = splitValue[0]; String enumValue = splitValue[1]; // at moment process only TwoSides, e.g. TwoSides.TWO or TwoSides.ONE - if (TwoSides.class.getName().equals(enumType)) { + if (TwoSides.class.getSimpleName().equals(enumType)) { propertyBuilder.value(enumValue) .type(PropertyType.TWO_SIDES); } else { @@ -57,7 +57,7 @@ public static Property convertProperty(BasicProperty property) { } else if (property.type() == org.gridsuite.ds.server.utils.PropertyType.STRING) { propertyBuilder.value(value) .type(PropertyType.valueOf(property.type().name())); - List values = convertStringToList(value); + List values = convertStringToList(value).stream().map(StringUtils::trim).toList(); // check whether having multiple values if (values.size() > 1) { // override by set multiple values diff --git a/src/test/resources/data/ieee14/_01/input/mapping.json b/src/test/resources/data/ieee14/_01/input/mapping.json index 1b38c671..be981046 100644 --- a/src/test/resources/data/ieee14/_01/input/mapping.json +++ b/src/test/resources/data/ieee14/_01/input/mapping.json @@ -146,12 +146,12 @@ }, { "name": "uMeasurements", - "value": "_BUS___11_TN, _BUS___12_TN", + "value": "_BUS___11_TN,_BUS___12_TN", "type": "STRING" }, { "name": "transformers", - "value": "_LOAD__11_EC, _LOAD__12_EC", + "value": "_LOAD__11_EC,_LOAD__12_EC", "type": "STRING" } ] diff --git a/src/test/resources/data/ieee14/_01/output/result_SIM.json b/src/test/resources/data/ieee14/_01/output/result_SIM.json index c4effd25..133a5a64 100644 --- a/src/test/resources/data/ieee14/_01/output/result_SIM.json +++ b/src/test/resources/data/ieee14/_01/output/result_SIM.json @@ -6,156 +6,156 @@ "name" : "SVC2_SVarC_injector_QInjPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 53, - "stepValues" : [ -0.031754, -0.007935, -0.003222, 0.172496, 0.191611, 0.190078 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 47 ] + "uncompressedLength" : 56, + "stepValues" : [ -0.031738, -0.007935, -0.003222, 0.172601, 0.191644, 0.189343, 0.184884, 0.197732, 0.203929, 0.200946, 0.199999, 0.185314, 0.313312, 0.415058, 0.39714, 0.380065, 0.376941, 0.377728 ], + "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] } ] }, { "metadata" : { "name" : "_GEN____3_SM_generator_omegaPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 53, - "stepValues" : [ 1.0, 0.999831, 0.99983, 0.999799 ], - "stepLengths" : [ 3, 2, 1, 47 ] + "uncompressedLength" : 56, + "stepValues" : [ 1.0, 0.999831, 0.999806, 0.999657, 0.999646, 0.999615, 0.999581, 0.998868, 0.998811, 0.998709, 0.99856, 0.998442, 0.998362 ], + "stepLengths" : [ 3, 3, 5, 2, 1, 1, 9, 1, 1, 1, 1, 1, 27 ] } ] }, { "metadata" : { "name" : "_LOAD___2_EC_load_QPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 53, - "stepValues" : [ 0.126839, 0.126962, 0.126691, 0.126715, 0.126749, 0.126758 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 47 ] + "uncompressedLength" : 56, + "stepValues" : [ 0.126839, 0.126962, 0.126691, 0.126715, 0.126749, 0.126759, 0.127039, 0.126746, 0.12674, 0.126747, 0.127671, 0.126586, 0.12648, 0.12654, 0.126558, 0.126557, 0.126555 ], + "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 9, 1, 1, 1, 1, 1, 1, 27 ] } ] }, { "metadata" : { "name" : "_LOAD___2_EC_load_PPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 53, - "stepValues" : [ 0.216862, 0.216968, 0.216736, 0.216757, 0.216785, 0.216793 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 47 ] + "uncompressedLength" : 56, + "stepValues" : [ 0.216863, 0.216968, 0.216736, 0.216757, 0.216785, 0.216794, 0.217034, 0.216783, 0.216778, 0.216784, 0.217573, 0.216646, 0.216555, 0.216607, 0.216622, 0.216621, 0.216619 ], + "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 9, 1, 1, 1, 1, 1, 1, 27 ] } ] }, { "metadata" : { "name" : "_GEN____3_SM_generator_QGen", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 53, - "stepValues" : [ 25.433065, 25.119541, 23.633342, 29.116793, 29.833218, 29.623577 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 47 ] + "uncompressedLength" : 56, + "stepValues" : [ 25.432854, 25.119541, 23.633342, 29.121397, 29.829532, 29.573958, 28.63852, 37.534679, 38.845762, 38.622417, 38.521909, 29.999842, 92.036606, 109.12902, 107.191712, 105.214641, 104.881032, 104.978456 ], + "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] } ] }, { "metadata" : { "name" : "SVC2_SVarC_modeHandling_mode_value", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 53, + "uncompressedLength" : 56, "stepValues" : [ 3.0 ], - "stepLengths" : [ 53 ] + "stepLengths" : [ 56 ] } ] }, { "metadata" : { "name" : "SVC2_SVarC_injector_BPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 53, - "stepValues" : [ -0.012931, -0.00323, -0.001314, 0.070345, 0.078126, 0.077502 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 47 ] + "uncompressedLength" : 56, + "stepValues" : [ -0.012932, -0.00323, -0.001314, 0.070395, 0.078141, 0.077197, 0.075212, 0.080625, 0.083156, 0.081936, 0.08155, 0.075014, 0.127917, 0.169596, 0.162198, 0.155202, 0.153927, 0.154252 ], + "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] } ] }, { "metadata" : { "name" : "SVC2_SVarC_injector_PInjPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 53, - "stepValues" : [ 0.0, 9.0E-6, 8.0E-6, 1.51E-4 ], - "stepLengths" : [ 3, 2, 1, 47 ] + "uncompressedLength" : 56, + "stepValues" : [ -0.0, -1.0E-6, 1.0E-6, 1.2E-5, 0.0, -3.0E-6, -1.0E-6, 7.0E-6, 1.7E-5, 0.0, 1.0E-6, 0.0, 1.0E-6, 6.0E-6, -5.9E-5, 5.0E-6 ], + "stepLengths" : [ 3, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] } ] }, { "metadata" : { "name" : "SVC2_SVarC_injector_UPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 53, - "stepValues" : [ 1.04441, 1.044917, 1.043801, 1.043901, 1.044039, 1.044076 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 47 ] + "uncompressedLength" : 56, + "stepValues" : [ 1.04441, 1.044917, 1.043801, 1.043901, 1.044039, 1.04408, 1.045235, 1.044028, 1.044004, 1.04403, 1.044031, 1.047831, 1.043368, 1.042931, 1.043178, 1.043254, 1.043248, 1.043239 ], + "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] } ] }, { "metadata" : { "name" : "_GEN____3_SM_voltageRegulator_EfdPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 53, - "stepValues" : [ 1.113815, 1.112414, 1.106843, 1.126098, 1.123741, 1.121164 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 47 ] + "uncompressedLength" : 56, + "stepValues" : [ 1.113815, 1.112414, 1.106843, 1.126104, 1.123718, 1.120924, 1.117658, 1.146109, 1.141868, 1.137235, 1.135909, 1.103233, 1.308934, 1.308534, 1.267248, 1.25156, 1.249371, 1.249583 ], + "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] } ] }, { "metadata" : { "name" : "_GEN____3_SM_generator_PGen", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 53, - "stepValues" : [ 0.036939, -0.007339, 15.349408, 3.147903, 1.237428, 1.824559 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 47 ] + "uncompressedLength" : 56, + "stepValues" : [ 0.036881, -0.007339, 15.349408, 3.143088, 1.248892, 1.954053, 16.691385, 5.296473, 2.840279, 3.427963, 3.7307, 52.684413, 21.622315, 9.857958, 11.458084, 13.42682, 13.752483, 13.614968 ], + "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] } ] }, { "metadata" : { "name" : "_GEN____3_SM_generator_UStatorPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 53, - "stepValues" : [ 1.011427, 1.011497, 1.011775, 1.010812, 1.01093, 1.011059 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 47 ] + "uncompressedLength" : 56, + "stepValues" : [ 1.011427, 1.011497, 1.011775, 1.010812, 1.010931, 1.011071, 1.011234, 1.009812, 1.010024, 1.010256, 1.010322, 1.011956, 1.001671, 1.001691, 1.003755, 1.004539, 1.004649, 1.004638 ], + "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] } ] } ], "timeLine" : [] From 40ab90ea4f5eb00a19bc65385bd1c64e3dfe464e Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Fri, 7 Jun 2024 16:28:13 +0200 Subject: [PATCH 12/25] Using new event supplier instead of groovy event supplier --- .../DynamicSimulationWorkerService.java | 17 ++++++----- .../contexts/DynamicSimulationRunContext.java | 3 +- .../service/parameters/ParametersService.java | 3 +- .../impl/ParametersServiceImpl.java | 29 +++++++++++++------ .../org/gridsuite/ds/server/utils/Utils.java | 15 ++++++++-- 5 files changed, 46 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java b/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java index c84ab88c..cf61bb2a 100644 --- a/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java +++ b/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java @@ -11,10 +11,14 @@ import com.powsybl.commons.PowsyblException; import com.powsybl.computation.ComputationManager; import com.powsybl.dynamicsimulation.*; -import com.powsybl.dynamicsimulation.groovy.*; +import com.powsybl.dynamicsimulation.groovy.CurveGroovyExtension; +import com.powsybl.dynamicsimulation.groovy.GroovyCurvesSupplier; +import com.powsybl.dynamicsimulation.groovy.GroovyExtension; import com.powsybl.dynawaltz.DynaWaltzProvider; import com.powsybl.dynawaltz.suppliers.dynamicmodels.DynamicModelConfig; import com.powsybl.dynawaltz.suppliers.dynamicmodels.DynawoModelsSupplier; +import com.powsybl.dynawaltz.suppliers.events.DynawoEventModelsSupplier; +import com.powsybl.dynawaltz.suppliers.events.EventModelConfig; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.VariantManagerConstants; import com.powsybl.network.store.client.NetworkStoreService; @@ -149,13 +153,13 @@ public void preRun(DynamicSimulationRunContext runContext) { // get mapping then generate dynamic model configs InputMapping inputMapping = dynamicMappingClient.getMapping(runContext.getMapping()); List dynamicModel = parametersService.getDynamicModel(inputMapping, runContext.getNetwork()); + List eventModel = parametersService.getEventModel(parametersInfos.getEvents()); // set start and stop times parameters.setStartTime(parametersInfos.getStartTime().intValue()); // TODO remove intValue() when correct startTime to double in powsybl parameters.setStopTime(parametersInfos.getStopTime().intValue()); // TODO remove intValue() when correct stopTime to double in powsybl // groovy scripts - String eventModel = parametersService.getEventModel(parametersInfos.getEvents()); String curveModel = parametersService.getCurveModel(parametersInfos.getCurves()); // enrich runContext @@ -168,12 +172,9 @@ public void preRun(DynamicSimulationRunContext runContext) { @Override public CompletableFuture getCompletableFuture(Network network, DynamicSimulationRunContext runContext, String provider, UUID resultUuid) { - DynamicModelsSupplier dynawoDynamicModelsSupplier = new DynawoModelsSupplier(runContext.getDynamicModelContent()); + DynamicModelsSupplier dynamicModelsSupplier = new DynawoModelsSupplier(runContext.getDynamicModelContent()); - List eventModelExtensions = GroovyExtension.find(EventModelGroovyExtension.class, DynaWaltzProvider.NAME); - EventModelsSupplier eventModelsSupplier = new GroovyEventModelsSupplier( - new ByteArrayInputStream(runContext.getEventModelContent().getBytes()), eventModelExtensions - ); + EventModelsSupplier eventModelsSupplier = new DynawoEventModelsSupplier(runContext.getEventModelContent()); List curveExtensions = GroovyExtension.find(CurveGroovyExtension.class, DynaWaltzProvider.NAME); CurvesSupplier curvesSupplier = new GroovyCurvesSupplier( @@ -186,7 +187,7 @@ public CompletableFuture getCompletableFuture(Network n DynamicSimulation.Runner runner = DynamicSimulation.find(provider); return runner.runAsync(network, - dynawoDynamicModelsSupplier, + dynamicModelsSupplier, eventModelsSupplier, curvesSupplier, runContext.getVariantId() != null ? runContext.getVariantId() : VariantManagerConstants.INITIAL_VARIANT_ID, diff --git a/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java b/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java index 40d47b60..de47e2ed 100644 --- a/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java +++ b/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java @@ -8,6 +8,7 @@ import com.powsybl.dynamicsimulation.DynamicSimulationParameters; import com.powsybl.dynawaltz.suppliers.dynamicmodels.DynamicModelConfig; +import com.powsybl.dynawaltz.suppliers.events.EventModelConfig; import com.powsybl.iidm.network.Network; import lombok.Builder; import lombok.Getter; @@ -33,7 +34,7 @@ public class DynamicSimulationRunContext extends AbstractComputationRunContext dynamicModelContent; - @Setter private String eventModelContent; + @Setter private List eventModelContent; @Setter private String curveContent; diff --git a/src/main/java/org/gridsuite/ds/server/service/parameters/ParametersService.java b/src/main/java/org/gridsuite/ds/server/service/parameters/ParametersService.java index 533c3446..e9563380 100644 --- a/src/main/java/org/gridsuite/ds/server/service/parameters/ParametersService.java +++ b/src/main/java/org/gridsuite/ds/server/service/parameters/ParametersService.java @@ -8,6 +8,7 @@ import com.powsybl.dynamicsimulation.DynamicSimulationParameters; import com.powsybl.dynawaltz.suppliers.dynamicmodels.DynamicModelConfig; +import com.powsybl.dynawaltz.suppliers.events.EventModelConfig; import com.powsybl.iidm.network.Network; import org.gridsuite.ds.server.computation.dto.ReportInfos; import org.gridsuite.ds.server.dto.DynamicSimulationParametersInfos; @@ -24,7 +25,7 @@ */ public interface ParametersService { - String getEventModel(List events); + List getEventModel(List events); String getCurveModel(List curves); diff --git a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java index f6cdd1e5..27c497da 100644 --- a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java +++ b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java @@ -18,9 +18,11 @@ import com.powsybl.dynawaltz.suppliers.PropertyType; import com.powsybl.dynawaltz.suppliers.SetGroupType; import com.powsybl.dynawaltz.suppliers.dynamicmodels.DynamicModelConfig; +import com.powsybl.dynawaltz.suppliers.events.EventModelConfig; import com.powsybl.dynawaltz.xml.ParametersXml; import com.powsybl.iidm.network.Identifiable; import com.powsybl.iidm.network.Network; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.ArrayUtils; import org.gridsuite.ds.server.DynamicSimulationException; import org.gridsuite.ds.server.computation.dto.ReportInfos; @@ -35,7 +37,6 @@ import org.gridsuite.ds.server.dto.solver.SolverInfos; import org.gridsuite.ds.server.service.contexts.DynamicSimulationRunContext; import org.gridsuite.ds.server.service.parameters.CurveGroovyGeneratorService; -import org.gridsuite.ds.server.service.parameters.EventGroovyGeneratorService; import org.gridsuite.ds.server.service.parameters.ParametersService; import org.gridsuite.ds.server.utils.Utils; import org.gridsuite.filter.expertfilter.ExpertFilter; @@ -72,26 +73,36 @@ public class ParametersServiceImpl implements ParametersService { private final CurveGroovyGeneratorService curveGroovyGeneratorService; - private final EventGroovyGeneratorService eventGroovyGeneratorService; - private final String defaultProvider; @Autowired public ParametersServiceImpl(ObjectMapper objectMapper, CurveGroovyGeneratorService curveGroovyGeneratorService, - EventGroovyGeneratorService eventGroovyGeneratorService, @Value("${dynamic-simulation.default-provider}") String defaultProvider) { this.objectMapper = objectMapper; this.curveGroovyGeneratorService = curveGroovyGeneratorService; - this.eventGroovyGeneratorService = eventGroovyGeneratorService; this.defaultProvider = defaultProvider; } @Override - public String getEventModel(List events) { - String generatedGroovyEvents = eventGroovyGeneratorService.generate(events != null ? events : Collections.emptyList()); - LOGGER.info(generatedGroovyEvents); - return generatedGroovyEvents; + public List getEventModel(List events) { + if (CollectionUtils.isEmpty(events)) { + return Collections.emptyList(); + } + + List eventModel = events.stream().map(event -> + new EventModelConfig( + event.getEventType(), + event.getProperties().stream().map(Utils::convertProperty).filter(Objects::nonNull).toList())) + .toList(); + + try { + LOGGER.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(eventModel)); + } catch (JsonProcessingException e) { + throw new UncheckedIOException(e); + } + + return eventModel; } @Override diff --git a/src/main/java/org/gridsuite/ds/server/utils/Utils.java b/src/main/java/org/gridsuite/ds/server/utils/Utils.java index 2985b7b4..b0a695e6 100644 --- a/src/main/java/org/gridsuite/ds/server/utils/Utils.java +++ b/src/main/java/org/gridsuite/ds/server/utils/Utils.java @@ -13,6 +13,7 @@ import com.powsybl.iidm.network.TwoSides; import org.apache.commons.lang3.StringUtils; import org.gridsuite.ds.server.dto.dynamicmapping.automata.BasicProperty; +import org.gridsuite.ds.server.dto.event.EventPropertyInfos; import java.util.ArrayList; import java.util.Arrays; @@ -32,12 +33,22 @@ public static List convertStringToList(String stringArray) { return converted; } + public static Property convertProperty(EventPropertyInfos property) { + return convertProperty(new BasicProperty( + property.getName(), + property.getValue(), + property.getType())); + } + public static Property convertProperty(BasicProperty property) { String value = property.value(); PropertyBuilder propertyBuilder = new PropertyBuilder() .name(property.name()); - - if (property.type() == org.gridsuite.ds.server.utils.PropertyType.ENUM) { + if (property.type() == org.gridsuite.ds.server.utils.PropertyType.FLOAT) { + // powsybl-dynawo does not support FLOAT => use DOUBLE + propertyBuilder.value(value) + .type(PropertyType.DOUBLE); + } else if (property.type() == org.gridsuite.ds.server.utils.PropertyType.ENUM) { // using value to infer enum type if (StringUtils.isEmpty(value) || value.split("\\.").length != 2) { return null; From e4995e1e8e46162401d4c7484d46e7d4e01cb472 Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Fri, 7 Jun 2024 16:38:25 +0200 Subject: [PATCH 13/25] Delete unused code and test data --- .../EventGroovyGeneratorService.java | 27 ------ .../impl/EventGroovyGeneratorServiceImpl.java | 88 ------------------- src/main/resources/templates/event/event.st | 3 - .../templates/event/eventProperty.st | 1 - src/main/resources/templates/event/events.st | 10 --- .../data/ieee14/_01/input/models.groovy | 78 ---------------- src/test/resources/dynamicModels.groovy | 35 -------- 7 files changed, 242 deletions(-) delete mode 100644 src/main/java/org/gridsuite/ds/server/service/parameters/EventGroovyGeneratorService.java delete mode 100644 src/main/java/org/gridsuite/ds/server/service/parameters/impl/EventGroovyGeneratorServiceImpl.java delete mode 100644 src/main/resources/templates/event/event.st delete mode 100644 src/main/resources/templates/event/eventProperty.st delete mode 100644 src/main/resources/templates/event/events.st delete mode 100644 src/test/resources/data/ieee14/_01/input/models.groovy delete mode 100644 src/test/resources/dynamicModels.groovy diff --git a/src/main/java/org/gridsuite/ds/server/service/parameters/EventGroovyGeneratorService.java b/src/main/java/org/gridsuite/ds/server/service/parameters/EventGroovyGeneratorService.java deleted file mode 100644 index 7679d430..00000000 --- a/src/main/java/org/gridsuite/ds/server/service/parameters/EventGroovyGeneratorService.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2023, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -package org.gridsuite.ds.server.service.parameters; - -import org.gridsuite.ds.server.dto.event.EventInfos; - -import java.util.List; - -/** - * @author Thang PHAM - */ -public interface EventGroovyGeneratorService { - String RESOURCE_PATH_DELIMETER = "/"; - String EVENTS_TEMPLATE_DIR = "templates/event"; - - /** - * Generate a script groovy which contains events - * @param events given list of events - * @return a script groovy which contains events - */ - String generate(List events); -} diff --git a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/EventGroovyGeneratorServiceImpl.java b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/EventGroovyGeneratorServiceImpl.java deleted file mode 100644 index f91ee0f9..00000000 --- a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/EventGroovyGeneratorServiceImpl.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2023, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -package org.gridsuite.ds.server.service.parameters.impl; - -import com.powsybl.commons.PowsyblException; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; -import org.gridsuite.ds.server.dto.event.EventInfos; -import org.gridsuite.ds.server.dto.event.EventPropertyInfos; -import org.gridsuite.ds.server.service.parameters.EventGroovyGeneratorService; -import org.gridsuite.ds.server.utils.PropertyType; -import org.gridsuite.ds.server.utils.Utils; -import org.springframework.core.io.ClassPathResource; -import org.springframework.stereotype.Service; -import org.stringtemplate.v4.ST; - -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -/** - * @author Thang PHAM - */ -@Service -public class EventGroovyGeneratorServiceImpl implements EventGroovyGeneratorService { - @Override - public String generate(List events) { - Objects.requireNonNull(events); - - String eventsTemplate; - String eventTemplate; - String eventPropertyTemplate; - try { - eventsTemplate = IOUtils.toString(new ClassPathResource(EVENTS_TEMPLATE_DIR + RESOURCE_PATH_DELIMETER + "events.st").getInputStream(), Charset.defaultCharset()); - eventTemplate = IOUtils.toString(new ClassPathResource(EVENTS_TEMPLATE_DIR + RESOURCE_PATH_DELIMETER + "event.st").getInputStream(), Charset.defaultCharset()); - eventPropertyTemplate = IOUtils.toString(new ClassPathResource(EVENTS_TEMPLATE_DIR + RESOURCE_PATH_DELIMETER + "eventProperty.st").getInputStream(), Charset.defaultCharset()); - } catch (IOException e) { - throw new PowsyblException("Unable to load templates for groovy script generation : " + e.getMessage()); - } - // config root template - ST eventsST = new ST(eventsTemplate); - - String[] eventStringList = events.stream().map(event -> generateEvent(eventTemplate, eventPropertyTemplate, event)).toArray(String[]::new); - eventsST.add("events", eventStringList); - - return eventsST.render(); - } - - private String generateEvent(String eventTemplate, String eventPropertyTemplate, EventInfos event) { - ST eventST = new ST(eventTemplate); - eventST.add("eventType", event.getEventType()); - - // --- add properties --- - String[] propertyStringList = event.getProperties().stream() - .map(property -> generateEventProperty(eventPropertyTemplate, property)) - .filter(property -> !StringUtils.isEmpty(property)).toArray(String[]::new); - eventST.add("properties", propertyStringList); - - return eventST.render(); - } - - private String generateEventProperty(String eventPropertyTemplate, EventPropertyInfos property) { - ST eventPropertyST = new ST(eventPropertyTemplate); - String value = property.getValue(); - if (StringUtils.isEmpty(value)) { - return null; - } - - // value => "value" when export groovy string value - if (property.getType() == PropertyType.STRING) { - value = Utils.convertStringToList(value).stream() - .map(elem -> "\"" + elem + "\"") - .collect(Collectors.joining(", ")); - } - - eventPropertyST.add("name", property.getName()); - eventPropertyST.add("value", value); - - return eventPropertyST.render(); - } -} diff --git a/src/main/resources/templates/event/event.st b/src/main/resources/templates/event/event.st deleted file mode 100644 index 8c824947..00000000 --- a/src/main/resources/templates/event/event.st +++ /dev/null @@ -1,3 +0,0 @@ - { - -} \ No newline at end of file diff --git a/src/main/resources/templates/event/eventProperty.st b/src/main/resources/templates/event/eventProperty.st deleted file mode 100644 index 688d7a78..00000000 --- a/src/main/resources/templates/event/eventProperty.st +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/main/resources/templates/event/events.st b/src/main/resources/templates/event/events.st deleted file mode 100644 index 7994ea4e..00000000 --- a/src/main/resources/templates/event/events.st +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Copyright (c) 2020, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -import com.powsybl.iidm.network.TwoSides - - \ No newline at end of file diff --git a/src/test/resources/data/ieee14/_01/input/models.groovy b/src/test/resources/data/ieee14/_01/input/models.groovy deleted file mode 100644 index 2c0dcafb..00000000 --- a/src/test/resources/data/ieee14/_01/input/models.groovy +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Copyright (c) 2021, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -import com.powsybl.iidm.network.Generator -import com.powsybl.iidm.network.StaticVarCompensator -import com.powsybl.iidm.network.Load -import com.powsybl.iidm.network.TwoSides - -for (Generator equipment : network.generators) { - if (equipment.terminal.voltageLevel.nominalV == 13.800000) { - GeneratorSynchronousThreeWindingsProportionalRegulations { - staticId equipment.id - parameterSetId "IEEE14" + equipment.id - } - } else if (equipment.terminal.voltageLevel.nominalV == 69.000000) { - GeneratorSynchronousFourWindingsProportionalRegulations { - staticId equipment.id - parameterSetId "IEEE14" + equipment.id - } - } else if (true) { - GeneratorPQ { - staticId equipment.id - parameterSetId "GPQ" - } - } -} - -for (StaticVarCompensator equipment : network.staticVarCompensators) { - if (equipment.terminal.voltageLevel.nominalV == 69.000000) { - StaticVarCompensator { - staticId equipment.id - parameterSetId "SVarCT" - } - } -} - -for (Load equipment : network.loads) { - if (true) { - LoadAlphaBeta { - staticId equipment.id - parameterSetId "LAB" - } - } -} - -OverloadManagementSystem { - parameterSetId "CLA_2_4" - dynamicModelId "CLA_1" - iMeasurement "_BUS____2-BUS____4-1_AC" - iMeasurementSide TwoSides.TWO - controlledBranch "_BUS____2-BUS____4-1_AC" -} - -OverloadManagementSystem { - parameterSetId "CLA_2_5" - dynamicModelId "CLA_2" - iMeasurement "_BUS____2-BUS____5-1_AC" - iMeasurementSide TwoSides.TWO - controlledBranch "_BUS____2-BUS____5-1_AC" -} - -TapChangerBlockingAutomaton { - parameterSetId "TCB_2_4" - dynamicModelId "TCB_1" - uMeasurements "_BUS___11_TN", "_BUS___12_TN" - transformers "_LOAD__11_EC", "_LOAD__12_EC" -} - -TapChangerBlockingAutomaton { - parameterSetId "TCB_2_5" - dynamicModelId "TCB_2" - uMeasurements "_BUS____4_TN" - transformers "_BUS____4-BUS____9-1_PT" -} \ No newline at end of file diff --git a/src/test/resources/dynamicModels.groovy b/src/test/resources/dynamicModels.groovy deleted file mode 100644 index 3e693696..00000000 --- a/src/test/resources/dynamicModels.groovy +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright (c) 2020, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -import com.powsybl.iidm.network.Load -import com.powsybl.iidm.network.Generator - -for (Load load : network.loads) { - if (load.id != "_LOAD___8_EC") { - LoadAlphaBeta { - staticId load.id - parameterSetId "LAB" - } - } -} - -for (Generator gen : network.generators) { - if (gen.id != "_GEN____6_SM" && gen.id != "_GEN____8_SM") { - GeneratorSynchronousFourWindingsProportionalRegulations { - staticId gen.id - parameterSetId "GSFWPR" + gen.id - } - } else { - GeneratorSynchronousThreeWindingsProportionalRegulations { - staticId gen.id - parameterSetId "GSTWPR" + gen.id - } - } - OmegaRef { - generatorDynamicModelId gen.id - } -} From c5b4ef5d2c5a88185e01aacbcfbf5ebe482738f5 Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Fri, 7 Jun 2024 18:12:39 +0200 Subject: [PATCH 14/25] Add event FaultNode to test --- .../controller/utils/ParameterUtils.java | 9 +- .../data/ieee14/_01/output/result_SIM.json | 90 +++++++++---------- 2 files changed, 53 insertions(+), 46 deletions(-) diff --git a/src/test/java/org/gridsuite/ds/server/controller/utils/ParameterUtils.java b/src/test/java/org/gridsuite/ds/server/controller/utils/ParameterUtils.java index 42050089..4afda0b9 100644 --- a/src/test/java/org/gridsuite/ds/server/controller/utils/ParameterUtils.java +++ b/src/test/java/org/gridsuite/ds/server/controller/utils/ParameterUtils.java @@ -181,8 +181,15 @@ public static List getEventInfosList() { return List.of( new EventInfos(null, null, "_BUS____1-BUS____5-1_AC", null, "Disconnect", List.of( new EventPropertyInfos(null, "staticId", "_BUS____1-BUS____5-1_AC", PropertyType.STRING), - new EventPropertyInfos(null, "startTime", "1", PropertyType.FLOAT), + new EventPropertyInfos(null, "startTime", "10", PropertyType.FLOAT), new EventPropertyInfos(null, "disconnectOnly", "TwoSides.TWO", PropertyType.ENUM) + )), + new EventInfos(null, null, "_BUS____1_TN", null, "FaultNode", List.of( + new EventPropertyInfos(null, "staticId", "_BUS____1_TN", PropertyType.STRING), + new EventPropertyInfos(null, "startTime", "20", PropertyType.FLOAT), + new EventPropertyInfos(null, "faultTime", "2", PropertyType.FLOAT), + new EventPropertyInfos(null, "rPu", "23", PropertyType.FLOAT), + new EventPropertyInfos(null, "xPu", "32", PropertyType.FLOAT) )) ); } diff --git a/src/test/resources/data/ieee14/_01/output/result_SIM.json b/src/test/resources/data/ieee14/_01/output/result_SIM.json index 133a5a64..c15803e6 100644 --- a/src/test/resources/data/ieee14/_01/output/result_SIM.json +++ b/src/test/resources/data/ieee14/_01/output/result_SIM.json @@ -6,156 +6,156 @@ "name" : "SVC2_SVarC_injector_QInjPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 10000, 11000, 11000, 12000, 13000, 14000, 15000, 16000, 16000, 17000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ -0.031738, -0.007935, -0.003222, 0.172601, 0.191644, 0.189343, 0.184884, 0.197732, 0.203929, 0.200946, 0.199999, 0.185314, 0.313312, 0.415058, 0.39714, 0.380065, 0.376941, 0.377728 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 57, + "stepValues" : [ -0.031738, -0.007935, -0.007276, -0.002564, 0.172366, 0.19151, 0.189278, 0.184818, 0.197699, 0.203913, 0.200938, 0.199995, 0.18531, 0.313309, 0.415057, 0.39714, 0.380065, 0.37694, 0.377728 ], + "stepLengths" : [ 1, 2, 9, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 18 ] } ] }, { "metadata" : { "name" : "_GEN____3_SM_generator_omegaPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 10000, 11000, 11000, 12000, 13000, 14000, 15000, 16000, 16000, 17000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, + "uncompressedLength" : 57, "stepValues" : [ 1.0, 0.999831, 0.999806, 0.999657, 0.999646, 0.999615, 0.999581, 0.998868, 0.998811, 0.998709, 0.99856, 0.998442, 0.998362 ], - "stepLengths" : [ 3, 3, 5, 2, 1, 1, 9, 1, 1, 1, 1, 1, 27 ] + "stepLengths" : [ 13, 3, 5, 2, 1, 1, 9, 1, 1, 1, 1, 1, 18 ] } ] }, { "metadata" : { "name" : "_LOAD___2_EC_load_QPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 10000, 11000, 11000, 12000, 13000, 14000, 15000, 16000, 16000, 17000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ 0.126839, 0.126962, 0.126691, 0.126715, 0.126749, 0.126759, 0.127039, 0.126746, 0.12674, 0.126747, 0.127671, 0.126586, 0.12648, 0.12654, 0.126558, 0.126557, 0.126555 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 9, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 57, + "stepValues" : [ 0.126839, 0.126962, 0.12697, 0.126699, 0.126716, 0.126749, 0.126759, 0.127039, 0.126746, 0.12674, 0.126747, 0.127671, 0.126586, 0.12648, 0.12654, 0.126558, 0.126557, 0.126555 ], + "stepLengths" : [ 1, 2, 9, 1, 2, 1, 4, 1, 2, 1, 9, 1, 1, 1, 1, 1, 1, 18 ] } ] }, { "metadata" : { "name" : "_LOAD___2_EC_load_PPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 10000, 11000, 11000, 12000, 13000, 14000, 15000, 16000, 16000, 17000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ 0.216863, 0.216968, 0.216736, 0.216757, 0.216785, 0.216794, 0.217034, 0.216783, 0.216778, 0.216784, 0.217573, 0.216646, 0.216555, 0.216607, 0.216622, 0.216621, 0.216619 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 9, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 57, + "stepValues" : [ 0.216863, 0.216968, 0.216975, 0.216743, 0.216757, 0.216786, 0.216794, 0.217034, 0.216783, 0.216778, 0.216784, 0.217573, 0.216646, 0.216555, 0.216607, 0.216622, 0.216621, 0.216619 ], + "stepLengths" : [ 1, 2, 9, 1, 2, 1, 4, 1, 2, 1, 9, 1, 1, 1, 1, 1, 1, 18 ] } ] }, { "metadata" : { "name" : "_GEN____3_SM_generator_QGen", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 10000, 11000, 11000, 12000, 13000, 14000, 15000, 16000, 16000, 17000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ 25.432854, 25.119541, 23.633342, 29.121397, 29.829532, 29.573958, 28.63852, 37.534679, 38.845762, 38.622417, 38.521909, 29.999842, 92.036606, 109.12902, 107.191712, 105.214641, 104.881032, 104.978456 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 57, + "stepValues" : [ 25.432854, 25.119541, 25.09512, 23.608993, 29.119339, 29.829256, 29.573806, 28.638375, 37.534592, 38.845719, 38.622397, 38.5219, 29.999834, 92.036603, 109.129019, 107.191711, 105.214641, 104.881032, 104.978456 ], + "stepLengths" : [ 1, 2, 9, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 18 ] } ] }, { "metadata" : { "name" : "SVC2_SVarC_modeHandling_mode_value", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 10000, 11000, 11000, 12000, 13000, 14000, 15000, 16000, 16000, 17000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, + "uncompressedLength" : 57, "stepValues" : [ 3.0 ], - "stepLengths" : [ 56 ] + "stepLengths" : [ 57 ] } ] }, { "metadata" : { "name" : "SVC2_SVarC_injector_BPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 10000, 11000, 11000, 12000, 13000, 14000, 15000, 16000, 16000, 17000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ -0.012932, -0.00323, -0.001314, 0.070395, 0.078141, 0.077197, 0.075212, 0.080625, 0.083156, 0.081936, 0.08155, 0.075014, 0.127917, 0.169596, 0.162198, 0.155202, 0.153927, 0.154252 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 57, + "stepValues" : [ -0.012932, -0.00323, -0.002962, -0.001046, 0.070299, 0.078086, 0.077171, 0.075185, 0.080612, 0.083149, 0.081932, 0.081548, 0.075013, 0.127916, 0.169595, 0.162197, 0.155201, 0.153926, 0.154252 ], + "stepLengths" : [ 1, 2, 9, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 18 ] } ] }, { "metadata" : { "name" : "SVC2_SVarC_injector_PInjPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 10000, 11000, 11000, 12000, 13000, 14000, 15000, 16000, 16000, 17000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, + "uncompressedLength" : 57, "stepValues" : [ -0.0, -1.0E-6, 1.0E-6, 1.2E-5, 0.0, -3.0E-6, -1.0E-6, 7.0E-6, 1.7E-5, 0.0, 1.0E-6, 0.0, 1.0E-6, 6.0E-6, -5.9E-5, 5.0E-6 ], - "stepLengths" : [ 3, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] + "stepLengths" : [ 13, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 18 ] } ] }, { "metadata" : { "name" : "SVC2_SVarC_injector_UPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 10000, 11000, 11000, 12000, 13000, 14000, 15000, 16000, 16000, 17000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ 1.04441, 1.044917, 1.043801, 1.043901, 1.044039, 1.04408, 1.045235, 1.044028, 1.044004, 1.04403, 1.044031, 1.047831, 1.043368, 1.042931, 1.043178, 1.043254, 1.043248, 1.043239 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 57, + "stepValues" : [ 1.04441, 1.044917, 1.04495, 1.043834, 1.043903, 1.04404, 1.044081, 1.045235, 1.044028, 1.044004, 1.04403, 1.044031, 1.047831, 1.043368, 1.042931, 1.043178, 1.043254, 1.043248, 1.043239 ], + "stepLengths" : [ 1, 2, 9, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 18 ] } ] }, { "metadata" : { "name" : "_GEN____3_SM_voltageRegulator_EfdPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 10000, 11000, 11000, 12000, 13000, 14000, 15000, 16000, 16000, 17000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ 1.113815, 1.112414, 1.106843, 1.126104, 1.123718, 1.120924, 1.117658, 1.146109, 1.141868, 1.137235, 1.135909, 1.103233, 1.308934, 1.308534, 1.267248, 1.25156, 1.249371, 1.249583 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 57, + "stepValues" : [ 1.113815, 1.112414, 1.112292, 1.106721, 1.126103, 1.123721, 1.120926, 1.117659, 1.146109, 1.141868, 1.137235, 1.135909, 1.103233, 1.308934, 1.308534, 1.267248, 1.25156, 1.249371, 1.249583 ], + "stepLengths" : [ 1, 2, 9, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 18 ] } ] }, { "metadata" : { "name" : "_GEN____3_SM_generator_PGen", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 10000, 11000, 11000, 12000, 13000, 14000, 15000, 16000, 16000, 17000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ 0.036881, -0.007339, 15.349408, 3.143088, 1.248892, 1.954053, 16.691385, 5.296473, 2.840279, 3.427963, 3.7307, 52.684413, 21.622315, 9.857958, 11.458084, 13.42682, 13.752483, 13.614968 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 57, + "stepValues" : [ 0.036881, -0.007339, -2.24E-4, 15.356225, 3.142704, 1.248209, 1.953908, 16.691252, 5.296474, 2.840281, 3.42796, 3.730698, 52.684413, 21.622314, 9.857958, 11.458084, 13.42682, 13.752482, 13.614968 ], + "stepLengths" : [ 1, 2, 9, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 18 ] } ] }, { "metadata" : { "name" : "_GEN____3_SM_generator_UStatorPu", "dataType" : "DOUBLE", "tags" : [ ], - "irregularIndex" : [ 0, 1000, 1000, 2000, 2000, 3000, 4000, 5000, 6000, 7000, 7000, 8000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] + "irregularIndex" : [ 0, 1000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 10000, 11000, 11000, 12000, 13000, 14000, 15000, 16000, 16000, 17000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 27000, 28000, 29000, 30000, 31000, 32000, 33000, 34000, 35000, 36000, 37000, 38000, 39000, 40000, 41000, 42000, 43000, 44000, 45000, 46000, 47000, 48000, 49000, 50000 ] }, "chunks" : [ { "offset" : 0, - "uncompressedLength" : 56, - "stepValues" : [ 1.011427, 1.011497, 1.011775, 1.010812, 1.010931, 1.011071, 1.011234, 1.009812, 1.010024, 1.010256, 1.010322, 1.011956, 1.001671, 1.001691, 1.003755, 1.004539, 1.004649, 1.004638 ], - "stepLengths" : [ 1, 1, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 27 ] + "uncompressedLength" : 57, + "stepValues" : [ 1.011427, 1.011497, 1.011503, 1.011781, 1.010812, 1.010931, 1.011071, 1.011234, 1.009812, 1.010024, 1.010256, 1.010322, 1.011956, 1.001671, 1.001691, 1.003755, 1.004539, 1.004649, 1.004638 ], + "stepLengths" : [ 1, 2, 9, 1, 2, 1, 4, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 1, 18 ] } ] } ], "timeLine" : [] From c8b36afdc64dd48d7dfd8209b4640ec015b21d4e Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Tue, 11 Jun 2024 13:04:35 +0200 Subject: [PATCH 15/25] Add update filters in batch to filter client service --- src/main/java/org/gridsuite/ds/server/utils/SetGroupType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gridsuite/ds/server/utils/SetGroupType.java b/src/main/java/org/gridsuite/ds/server/utils/SetGroupType.java index 86f80ceb..4c9fc3b7 100644 --- a/src/main/java/org/gridsuite/ds/server/utils/SetGroupType.java +++ b/src/main/java/org/gridsuite/ds/server/utils/SetGroupType.java @@ -7,7 +7,7 @@ package org.gridsuite.ds.server.utils; /** - * @author Mathieu Scalbert + * @author Thang PHAM */ public enum SetGroupType { FIXED, From c634e9cf8a49d78b2b0013a3437cd9c42dedb1d5 Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Thu, 13 Jun 2024 14:59:58 +0200 Subject: [PATCH 16/25] Update pom to powsybl-dynawo 2.5.0-alpha-1 --- pom.xml | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 6b65ad22..aa0c8f72 100644 --- a/pom.xml +++ b/pom.xml @@ -140,23 +140,13 @@ com.powsybl powsybl-dynawaltz - 2.5.0-SNAPSHOT + 2.5.0-alpha-1 com.powsybl powsybl-dynawaltz-dsl - 2.5.0-SNAPSHOT + 2.5.0-alpha-1 - org.gridsuite gridsuite-filter From 65a2b135d745eb38ea84265142eba447ae0e0690 Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Thu, 13 Jun 2024 15:05:18 +0200 Subject: [PATCH 17/25] Remove snapshot filter in pom --- pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/pom.xml b/pom.xml index aa0c8f72..7a886a5f 100644 --- a/pom.xml +++ b/pom.xml @@ -150,7 +150,6 @@ org.gridsuite gridsuite-filter - 1.1.0-SNAPSHOT com.powsybl From c229cb1cb373f00b394eaef81d56e15d4b56f697 Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Tue, 18 Jun 2024 13:03:39 +0200 Subject: [PATCH 18/25] Update to filter library 1.0.8 --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 7a886a5f..bc84bfba 100644 --- a/pom.xml +++ b/pom.xml @@ -150,6 +150,7 @@ org.gridsuite gridsuite-filter + 1.0.8 com.powsybl From 3fff16f00331b2f4e565a2664bb4dbf593390710 Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Wed, 26 Jun 2024 14:56:54 +0200 Subject: [PATCH 19/25] Sonar --- .../impl/ParametersServiceImpl.java | 27 +++---------------- .../DynamicMappingClientTest.java | 4 +-- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java index 1a43913b..85f4ff5b 100644 --- a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java +++ b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java @@ -6,8 +6,6 @@ */ package org.gridsuite.ds.server.service.parameters.impl; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import com.powsybl.commons.exceptions.UncheckedXmlStreamException; import com.powsybl.dynamicsimulation.DynamicSimulationParameters; import com.powsybl.dynamicsimulation.DynamicSimulationProvider; @@ -22,10 +20,10 @@ import com.powsybl.dynawaltz.xml.ParametersXml; import com.powsybl.iidm.network.Identifiable; import com.powsybl.iidm.network.Network; +import com.powsybl.ws.commons.computation.dto.ReportInfos; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.ArrayUtils; import org.gridsuite.ds.server.DynamicSimulationException; -import com.powsybl.ws.commons.computation.dto.ReportInfos; import org.gridsuite.ds.server.dto.DynamicSimulationParametersInfos; import org.gridsuite.ds.server.dto.XmlSerializableParameter; import org.gridsuite.ds.server.dto.curve.CurveInfos; @@ -53,7 +51,6 @@ import javax.xml.stream.XMLStreamException; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.UncheckedIOException; import java.util.*; import java.util.stream.Collectors; @@ -69,17 +66,13 @@ public class ParametersServiceImpl implements ParametersService { private static final Logger LOGGER = LoggerFactory.getLogger(ParametersServiceImpl.class); public static final String FIELD_STATIC_ID = "staticId"; - private final ObjectMapper objectMapper; - private final CurveGroovyGeneratorService curveGroovyGeneratorService; private final String defaultProvider; @Autowired - public ParametersServiceImpl(ObjectMapper objectMapper, - CurveGroovyGeneratorService curveGroovyGeneratorService, + public ParametersServiceImpl(CurveGroovyGeneratorService curveGroovyGeneratorService, @Value("${dynamic-simulation.default-provider}") String defaultProvider) { - this.objectMapper = objectMapper; this.curveGroovyGeneratorService = curveGroovyGeneratorService; this.defaultProvider = defaultProvider; } @@ -90,19 +83,11 @@ public List getEventModel(List events) { return Collections.emptyList(); } - List eventModel = events.stream().map(event -> + return events.stream().map(event -> new EventModelConfig( event.getEventType(), event.getProperties().stream().map(Utils::convertProperty).filter(Objects::nonNull).toList())) .toList(); - - try { - LOGGER.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(eventModel)); - } catch (JsonProcessingException e) { - throw new UncheckedIOException(e); - } - - return eventModel; } @Override @@ -261,12 +246,6 @@ public List getDynamicModel(InputMapping inputMapping, Netwo automaton.properties().stream().map(Utils::convertProperty).filter(Objects::nonNull).toList()) ).toList()); - try { - LOGGER.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dynamicModel)); - } catch (JsonProcessingException e) { - throw new UncheckedIOException(e); - } - return dynamicModel; } } diff --git a/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java b/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java index 92c7cfc2..01ec75a7 100644 --- a/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java +++ b/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java @@ -95,7 +95,7 @@ public void testCreateFromMapping() throws IOException { ObjectWriter ow = objectMapper.writer().withDefaultPrettyPrinter(); String parameterJson = ow.writeValueAsString(parameterObj); - // mock response for test case GET with url - /parameters/from/{mappingName} + // mock response for GET parameters/from/ String baseUrl = getEndpointUrl(); wireMockServer.stubFor(WireMock.get(WireMock.urlPathTemplate(baseUrl + DELIMITER + "{mappingName}")) @@ -116,7 +116,7 @@ public void testCreateFromMapping() throws IOException { public void testCreateFromMappingGivenNotFound() { String mappingName = MAPPING_NAME_01; - // mock response for test case GET with url - /parameters/from/{mappingName} + // mock response for GET parameters/from/ String baseUrl = getEndpointUrl(); wireMockServer.stubFor(WireMock.get(WireMock.urlPathTemplate(baseUrl + "{mappingName}")) From 9c1f3283878c39cac8535ed7157cc5e04ff81e14 Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Tue, 2 Jul 2024 14:15:57 +0200 Subject: [PATCH 20/25] Correct following to Etienne comments --- pom.xml | 2 +- .../dto/dynamicmapping/automata/BasicProperty.java | 10 +++++++++- .../parameters/CurveGroovyGeneratorService.java | 1 - .../impl/CurveGroovyGeneratorServiceImpl.java | 10 +++++++--- .../java/org/gridsuite/ds/server/utils/Utils.java | 3 +++ .../AbstractDynamicSimulationControllerTest.java | 2 -- .../DynamicSimulationControllerIEEE14Test.java | 3 ++- .../ds/server/dto/XmlSerializableParameterTest.java | 12 ++++++------ .../dynamicmapping/DynamicMappingClientTest.java | 3 +-- 9 files changed, 29 insertions(+), 17 deletions(-) diff --git a/pom.xml b/pom.xml index 4d7f047c..c810b272 100644 --- a/pom.xml +++ b/pom.xml @@ -151,7 +151,7 @@ org.gridsuite gridsuite-filter - 1.0.8 + 1.0.9 com.powsybl diff --git a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/BasicProperty.java b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/BasicProperty.java index 1c99beee..de5f9325 100644 --- a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/BasicProperty.java +++ b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/BasicProperty.java @@ -7,11 +7,19 @@ package org.gridsuite.ds.server.dto.dynamicmapping.automata; +import io.swagger.v3.oas.annotations.media.Schema; import org.gridsuite.ds.server.utils.PropertyType; /** * @author Thang PHAM */ -public record BasicProperty(String name, String value, PropertyType type) { +public record BasicProperty( + @Schema(description = "Property name") + String name, + @Schema(description = "Property value in string representation") + String value, + @Schema(description = "Property type") + PropertyType type +) { } diff --git a/src/main/java/org/gridsuite/ds/server/service/parameters/CurveGroovyGeneratorService.java b/src/main/java/org/gridsuite/ds/server/service/parameters/CurveGroovyGeneratorService.java index 589853fb..c7b1977f 100644 --- a/src/main/java/org/gridsuite/ds/server/service/parameters/CurveGroovyGeneratorService.java +++ b/src/main/java/org/gridsuite/ds/server/service/parameters/CurveGroovyGeneratorService.java @@ -15,7 +15,6 @@ * @author Thang PHAM */ public interface CurveGroovyGeneratorService { - String RESOURCE_PATH_DELIMETER = "/"; String CURVES_TEMPLATE_DIR = "templates/curve"; /** diff --git a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/CurveGroovyGeneratorServiceImpl.java b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/CurveGroovyGeneratorServiceImpl.java index 4faee6dc..4a76a533 100644 --- a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/CurveGroovyGeneratorServiceImpl.java +++ b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/CurveGroovyGeneratorServiceImpl.java @@ -18,10 +18,14 @@ import java.io.IOException; import java.nio.charset.Charset; -import java.util.*; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; import static org.gridsuite.ds.server.utils.EquipmentType.isStaticType; +import static org.gridsuite.ds.server.utils.Utils.RESOURCE_PATH_DELIMITER; /** * @author Thang PHAM @@ -34,8 +38,8 @@ public String generate(List curveInfosList) { String curvesTemplate; String curveTemplate; try { - curvesTemplate = IOUtils.toString(new ClassPathResource(CURVES_TEMPLATE_DIR + RESOURCE_PATH_DELIMETER + "curves.st").getInputStream(), Charset.defaultCharset()); - curveTemplate = IOUtils.toString(new ClassPathResource(CURVES_TEMPLATE_DIR + RESOURCE_PATH_DELIMETER + "curve.st").getInputStream(), Charset.defaultCharset()); + curvesTemplate = IOUtils.toString(new ClassPathResource(CURVES_TEMPLATE_DIR + RESOURCE_PATH_DELIMITER + "curves.st").getInputStream(), Charset.defaultCharset()); + curveTemplate = IOUtils.toString(new ClassPathResource(CURVES_TEMPLATE_DIR + RESOURCE_PATH_DELIMITER + "curve.st").getInputStream(), Charset.defaultCharset()); } catch (IOException e) { throw new PowsyblException("Unable to load templates for groovy script generation : " + e.getMessage()); } diff --git a/src/main/java/org/gridsuite/ds/server/utils/Utils.java b/src/main/java/org/gridsuite/ds/server/utils/Utils.java index b0a695e6..7efffb5f 100644 --- a/src/main/java/org/gridsuite/ds/server/utils/Utils.java +++ b/src/main/java/org/gridsuite/ds/server/utils/Utils.java @@ -23,6 +23,9 @@ * @author Thang PHAM */ public final class Utils { + + public static final String RESOURCE_PATH_DELIMITER = "/"; + private Utils() { // never called } diff --git a/src/test/java/org/gridsuite/ds/server/controller/AbstractDynamicSimulationControllerTest.java b/src/test/java/org/gridsuite/ds/server/controller/AbstractDynamicSimulationControllerTest.java index 78742e29..9d7b48bb 100644 --- a/src/test/java/org/gridsuite/ds/server/controller/AbstractDynamicSimulationControllerTest.java +++ b/src/test/java/org/gridsuite/ds/server/controller/AbstractDynamicSimulationControllerTest.java @@ -48,8 +48,6 @@ public abstract class AbstractDynamicSimulationControllerTest extends AbstractDy protected final String dsFailedDestination = "ds.failed.destination"; protected final String dsStoppedDestination = "ds.stopped.destination"; - public static final String RESOURCE_PATH_DELIMITER = "/"; - @MockBean protected DynamicMappingClient dynamicMappingClient; diff --git a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerIEEE14Test.java b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerIEEE14Test.java index 62606f97..e0bafc23 100644 --- a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerIEEE14Test.java +++ b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerIEEE14Test.java @@ -47,9 +47,10 @@ import java.nio.charset.StandardCharsets; import java.util.*; -import static org.assertj.core.api.Assertions.assertThat; import static com.powsybl.ws.commons.computation.service.NotificationService.HEADER_RESULT_UUID; import static com.powsybl.ws.commons.computation.service.NotificationService.HEADER_USER_ID; +import static org.assertj.core.api.Assertions.assertThat; +import static org.gridsuite.ds.server.utils.Utils.RESOURCE_PATH_DELIMITER; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.springframework.http.MediaType.APPLICATION_JSON; diff --git a/src/test/java/org/gridsuite/ds/server/dto/XmlSerializableParameterTest.java b/src/test/java/org/gridsuite/ds/server/dto/XmlSerializableParameterTest.java index 81bd6fcf..c5f7d842 100644 --- a/src/test/java/org/gridsuite/ds/server/dto/XmlSerializableParameterTest.java +++ b/src/test/java/org/gridsuite/ds/server/dto/XmlSerializableParameterTest.java @@ -37,6 +37,7 @@ import java.nio.file.Paths; import static com.powsybl.commons.test.ComparisonUtils.compareXml; +import static org.gridsuite.ds.server.utils.Utils.RESOURCE_PATH_DELIMITER; /** * @author Thang PHAM @@ -46,8 +47,7 @@ @ContextHierarchy({@ContextConfiguration(classes = {DynamicSimulationApplication.class, TestChannelBinderConfiguration.class})}) public class XmlSerializableParameterTest { - public static final String RESOURCE_PATH_DELIMETER = "/"; - public static final String DATA_XML = RESOURCE_PATH_DELIMETER + "data" + RESOURCE_PATH_DELIMETER + "xml"; + public static final String DATA_XML = RESOURCE_PATH_DELIMITER + "data" + RESOURCE_PATH_DELIMITER + "xml"; public static final String PAR_SCHEMA = "parameters.xsd"; public static final String OUTPUT = "output"; @@ -83,13 +83,13 @@ public void testWriteParameterGivenSolvers() throws IOException, XMLStreamExcept SolverInfos[] solvers = {idaSolver, simSolver}; // export solvers to par file - String resultDir = getClass().getResource(DATA_XML + RESOURCE_PATH_DELIMETER + OUTPUT).getPath(); + String resultDir = getClass().getResource(DATA_XML + RESOURCE_PATH_DELIMITER + OUTPUT).getPath(); Path exportedSolversFile = Paths.get(resultDir).resolve(EXPORTED_SOLVERS); Files.deleteIfExists(exportedSolversFile); XmlSerializableParameter.writeParameter(exportedSolversFile, XmlSerializableParameter.PARAMETER_SET, solvers); // compare two file - validate(DATA_XML + RESOURCE_PATH_DELIMETER + PAR_SCHEMA, DATA_XML + RESOURCE_PATH_DELIMETER + OUTPUT + RESOURCE_PATH_DELIMETER + EXPECTED_SOLVERS, exportedSolversFile); + validate(DATA_XML + RESOURCE_PATH_DELIMITER + PAR_SCHEMA, DATA_XML + RESOURCE_PATH_DELIMITER + OUTPUT + RESOURCE_PATH_DELIMITER + EXPECTED_SOLVERS, exportedSolversFile); } @Test @@ -97,12 +97,12 @@ public void testWriteParameterGivenNetwork() throws IOException, XMLStreamExcept NetworkInfos network = ParameterUtils.getDefaultNetwork(); // export network to par file - String resultDir = getClass().getResource(DATA_XML + RESOURCE_PATH_DELIMETER + OUTPUT).getPath(); + String resultDir = getClass().getResource(DATA_XML + RESOURCE_PATH_DELIMITER + OUTPUT).getPath(); Path exportedNetworkFile = Paths.get(resultDir).resolve(EXPORTED_NETWORK); Files.deleteIfExists(exportedNetworkFile); XmlSerializableParameter.writeParameter(exportedNetworkFile, XmlSerializableParameter.PARAMETER_SET, network); // compare two file - validate(DATA_XML + RESOURCE_PATH_DELIMETER + PAR_SCHEMA, DATA_XML + RESOURCE_PATH_DELIMETER + OUTPUT + RESOURCE_PATH_DELIMETER + EXPECTED_NETWORK, exportedNetworkFile); + validate(DATA_XML + RESOURCE_PATH_DELIMITER + PAR_SCHEMA, DATA_XML + RESOURCE_PATH_DELIMITER + OUTPUT + RESOURCE_PATH_DELIMITER + EXPECTED_NETWORK, exportedNetworkFile); } } diff --git a/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java b/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java index 01ec75a7..02d15c5e 100644 --- a/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java +++ b/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java @@ -34,14 +34,13 @@ import static org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient.API_VERSION; import static org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient.DYNAMIC_MAPPING_PARAMETER_CREATE_END_POINT; import static org.gridsuite.ds.server.service.client.utils.UrlUtils.buildEndPointUrl; +import static org.gridsuite.ds.server.utils.Utils.RESOURCE_PATH_DELIMITER; /** * @author Thang PHAM */ public class DynamicMappingClientTest extends AbstractWireMockRestClientTest { - public static final String RESOURCE_PATH_DELIMITER = "/"; - // mapping names public static final String MAPPING_NAME_01 = "_01"; From bde60a67ded4c2b3c8f87a3cc3a3f9e7a1396944 Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Tue, 2 Jul 2024 14:25:17 +0200 Subject: [PATCH 21/25] Sonar --- .../controller/AbstractDynamicSimulationControllerTest.java | 2 ++ .../server/controller/DynamicSimulationControllerTest.java | 5 +++-- .../client/dynamicmapping/DynamicMappingClientTest.java | 2 +- .../service/client/timeseries/TimeSeriesClientTest.java | 3 +-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/gridsuite/ds/server/controller/AbstractDynamicSimulationControllerTest.java b/src/test/java/org/gridsuite/ds/server/controller/AbstractDynamicSimulationControllerTest.java index 9d7b48bb..8dadad3e 100644 --- a/src/test/java/org/gridsuite/ds/server/controller/AbstractDynamicSimulationControllerTest.java +++ b/src/test/java/org/gridsuite/ds/server/controller/AbstractDynamicSimulationControllerTest.java @@ -61,6 +61,7 @@ public abstract class AbstractDynamicSimulationControllerTest extends AbstractDy protected DynamicSimulationWorkerService dynamicSimulationWorkerService; @Before + @Override public void setUp() throws IOException { super.setUp(); @@ -78,6 +79,7 @@ public void setUp() throws IOException { } @After + @Override public void tearDown() throws Exception { super.tearDown(); diff --git a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java index b04a8cef..3a3c9d08 100644 --- a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java +++ b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java @@ -20,8 +20,8 @@ import com.powsybl.iidm.network.VariantManagerConstants; import com.powsybl.network.store.client.PreloadingStrategy; import com.powsybl.timeseries.*; -import org.apache.commons.collections4.CollectionUtils; import com.powsybl.ws.commons.computation.service.NotificationService; +import org.apache.commons.collections4.CollectionUtils; import org.gridsuite.ds.server.controller.utils.ParameterUtils; import org.gridsuite.ds.server.dto.DynamicSimulationParametersInfos; import org.gridsuite.ds.server.dto.DynamicSimulationStatus; @@ -50,8 +50,8 @@ import java.util.function.Supplier; import static com.powsybl.network.store.model.NetworkStoreApi.VERSION; -import static org.assertj.core.api.Assertions.assertThat; import static com.powsybl.ws.commons.computation.service.NotificationService.*; +import static org.assertj.core.api.Assertions.assertThat; import static org.gridsuite.ds.server.controller.utils.TestUtils.assertType; import static org.gridsuite.ds.server.service.DynamicSimulationService.COMPUTATION_TYPE; import static org.mockito.ArgumentMatchers.any; @@ -136,6 +136,7 @@ protected void initTimeSeriesServiceMock() { } @Before + @Override public void setUp() throws IOException { super.setUp(); } diff --git a/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java b/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java index 02d15c5e..57f3b7dd 100644 --- a/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java +++ b/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java @@ -136,7 +136,7 @@ public void testCreateFromMappingGivenNotFound() { public void testCreateFromMappingGivenException() { String mappingName = MAPPING_NAME_01; - // mock response for test case GET with url - /parameters/from/{mappingName} + // mock response for test case GET parameters/from/{mappingName} String baseUrl = getEndpointUrl(); wireMockServer.stubFor(WireMock.get(WireMock.urlPathTemplate(baseUrl + DELIMITER + "{mappingName}")) diff --git a/src/test/java/org/gridsuite/ds/server/service/client/timeseries/TimeSeriesClientTest.java b/src/test/java/org/gridsuite/ds/server/service/client/timeseries/TimeSeriesClientTest.java index fdc0026d..856b7d97 100644 --- a/src/test/java/org/gridsuite/ds/server/service/client/timeseries/TimeSeriesClientTest.java +++ b/src/test/java/org/gridsuite/ds/server/service/client/timeseries/TimeSeriesClientTest.java @@ -55,8 +55,7 @@ public class TimeSeriesClientTest extends AbstractWireMockRestClientTest { TimeSeriesIndex index = new IrregularTimeSeriesIndex(new long[]{32, 64, 128, 256}); curves.put("NETWORK__BUS____2-BUS____5-1_AC_iSide2", TimeSeries.createDouble("NETWORK__BUS____2-BUS____5-1_AC_iSide2", index, 333.847331, 333.847321, 333.847300, 333.847259)); curves.put("NETWORK__BUS____1_TN_Upu_value", TimeSeries.createDouble("NETWORK__BUS____1_TN_Upu_value", index, 1.059970, 1.059970, 1.059970, 1.059970)); - List> timeSeries = new ArrayList<>(curves.values()); - return timeSeries; + return new ArrayList<>(curves.values()); } private String getEndpointUrl() { From 00001c676aaae794290f3ad364a61cfadb2c6dc7 Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Tue, 2 Jul 2024 14:33:15 +0200 Subject: [PATCH 22/25] Sonar --- .../service/client/dynamicmapping/DynamicMappingClientTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java b/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java index 57f3b7dd..ae554156 100644 --- a/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java +++ b/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java @@ -136,7 +136,7 @@ public void testCreateFromMappingGivenNotFound() { public void testCreateFromMappingGivenException() { String mappingName = MAPPING_NAME_01; - // mock response for test case GET parameters/from/{mappingName} + // mock response for test case GET parameters/from/ String baseUrl = getEndpointUrl(); wireMockServer.stubFor(WireMock.get(WireMock.urlPathTemplate(baseUrl + DELIMITER + "{mappingName}")) From 56bf784c6c499f2e4e8011fa8212df25483e056a Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Fri, 5 Jul 2024 17:29:16 +0200 Subject: [PATCH 23/25] Correct as suggested by Mathieu --- .../ds/server/DynamicSimulationException.java | 9 +++-- .../RestResponseEntityExceptionHandler.java | 2 +- .../server/dto/dynamicmapping/Parameter.java | 8 ++--- .../DynamicSimulationWorkerService.java | 2 +- .../ds/server/service/client/RestClient.java | 2 +- .../dynamicmapping/DynamicMappingClient.java | 10 +++--- .../impl/DynamicMappingClientImpl.java | 19 +++++----- .../timeseries/impl/TimeSeriesClientImpl.java | 2 +- .../server/service/client/utils/UrlUtils.java | 9 +++-- .../org/gridsuite/ds/server/utils/Utils.java | 2 +- ...DynamicSimulationControllerIEEE14Test.java | 2 +- .../DynamicSimulationControllerTest.java | 2 +- .../ds/server/controller/utils/FileUtils.java | 1 + .../controller/utils/ParameterUtils.java | 2 +- .../ds/server/controller/utils/TestUtils.java | 2 +- .../DynamicMappingClientTest.java | 35 +++++++++---------- 16 files changed, 53 insertions(+), 56 deletions(-) diff --git a/src/main/java/org/gridsuite/ds/server/DynamicSimulationException.java b/src/main/java/org/gridsuite/ds/server/DynamicSimulationException.java index 962da66a..8b85f734 100644 --- a/src/main/java/org/gridsuite/ds/server/DynamicSimulationException.java +++ b/src/main/java/org/gridsuite/ds/server/DynamicSimulationException.java @@ -6,9 +6,12 @@ */ package org.gridsuite.ds.server; +import lombok.Getter; + /** * @author Abdelsalem Hedhili */ +@Getter public class DynamicSimulationException extends RuntimeException { public enum Type { @@ -17,7 +20,7 @@ public enum Type { MAPPING_NOT_PROVIDED, RESULT_UUID_NOT_FOUND, DYNAMIC_MAPPING_NOT_FOUND, - CREATE_MAPPING_PARAMETER_ERROR, + GET_PARAMETER_ERROR, GET_DYNAMIC_MAPPING_ERROR, CREATE_TIME_SERIES_ERROR, DELETE_TIME_SERIES_ERROR @@ -29,8 +32,4 @@ public DynamicSimulationException(Type type, String message) { super(message); this.type = type; } - - public Type getType() { - return type; - } } diff --git a/src/main/java/org/gridsuite/ds/server/RestResponseEntityExceptionHandler.java b/src/main/java/org/gridsuite/ds/server/RestResponseEntityExceptionHandler.java index 008b1a92..85b833f5 100644 --- a/src/main/java/org/gridsuite/ds/server/RestResponseEntityExceptionHandler.java +++ b/src/main/java/org/gridsuite/ds/server/RestResponseEntityExceptionHandler.java @@ -35,7 +35,7 @@ protected ResponseEntity handleDynamicSimulationException(DynamicSimulat -> ResponseEntity.status(HttpStatus.NOT_FOUND).body(exception.getMessage()); case URI_SYNTAX, GET_DYNAMIC_MAPPING_ERROR, - CREATE_MAPPING_PARAMETER_ERROR, + GET_PARAMETER_ERROR, CREATE_TIME_SERIES_ERROR, DELETE_TIME_SERIES_ERROR -> ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(exception.getMessage()); diff --git a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Parameter.java b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Parameter.java index e1ae7b7a..86d49d7d 100644 --- a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Parameter.java +++ b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Parameter.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2022, RTE (http://www.rte-france.com) + * Copyright (c) 2024, RTE (http://www.rte-france.com) * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -11,12 +11,12 @@ /** * @author Thang PHAM */ -@Schema(description = "Parameter set in par format") +@Schema(description = "Parameter sets in *.par format") public record Parameter( - @Schema(description = "Name of the original mapping") + @Schema(description = "Name of the parent mapping") String parentName, - @Schema(description = "Parameter file content in par format") + @Schema(description = "Parameter file content in *.par format") String parametersFile ) { diff --git a/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java b/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java index 7f7d71d8..51a310c3 100644 --- a/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java +++ b/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java @@ -135,7 +135,7 @@ public void preRun(DynamicSimulationRunContext runContext) { DynamicSimulationParametersInfos parametersInfos = runContext.getParameters(); // get parameters file from dynamic mapping server - Parameter parameterObj = dynamicMappingClient.createFromMapping(runContext.getMapping()); + Parameter parameterObj = dynamicMappingClient.getParameters(runContext.getMapping()); // get all dynamic simulation parameters String parametersFile = parameterObj.parametersFile(); diff --git a/src/main/java/org/gridsuite/ds/server/service/client/RestClient.java b/src/main/java/org/gridsuite/ds/server/service/client/RestClient.java index 6f3e8417..a0072777 100644 --- a/src/main/java/org/gridsuite/ds/server/service/client/RestClient.java +++ b/src/main/java/org/gridsuite/ds/server/service/client/RestClient.java @@ -14,7 +14,7 @@ * @author Thang PHAM */ public interface RestClient { - String DELIMITER = "/"; + String URL_DELIMITER = "/"; RestTemplate getRestTemplate(); diff --git a/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClient.java b/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClient.java index 77b410ad..9c203c7a 100644 --- a/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClient.java +++ b/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClient.java @@ -9,18 +9,16 @@ import org.gridsuite.ds.server.dto.dynamicmapping.InputMapping; import org.gridsuite.ds.server.dto.dynamicmapping.Parameter; -import static org.gridsuite.ds.server.service.client.RestClient.DELIMITER; - /** * @author Thang PHAM */ public interface DynamicMappingClient { String API_VERSION = ""; - String DYNAMIC_MAPPING_PARAMETER_BASE_END_POINT = "parameters"; - String DYNAMIC_MAPPING_MAPPING_BASE_END_POINT = "mappings"; - String DYNAMIC_MAPPING_PARAMETER_CREATE_END_POINT = DYNAMIC_MAPPING_PARAMETER_BASE_END_POINT + DELIMITER + "from"; + String DYNAMIC_MAPPING_PARAMETER_BASE_ENDPOINT = "parameters"; + String DYNAMIC_MAPPING_MAPPING_BASE_ENDPOINT = "mappings"; + String DYNAMIC_MAPPING_PARAMETER_GET_ENDPOINT = DYNAMIC_MAPPING_PARAMETER_BASE_ENDPOINT; - Parameter createFromMapping(String mappingName); + Parameter getParameters(String mappingName); InputMapping getMapping(String mappingName); } diff --git a/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/impl/DynamicMappingClientImpl.java b/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/impl/DynamicMappingClientImpl.java index e30329be..80b730b6 100644 --- a/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/impl/DynamicMappingClientImpl.java +++ b/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/impl/DynamicMappingClientImpl.java @@ -39,22 +39,23 @@ public DynamicMappingClientImpl(@Value("${gridsuite.services.dynamic-mapping-ser } @Override - public Parameter createFromMapping(String mappingName) { + public Parameter getParameters(String mappingName) { Objects.requireNonNull(mappingName); - String endPointUrl = buildEndPointUrl(getBaseUri(), API_VERSION, DYNAMIC_MAPPING_PARAMETER_CREATE_END_POINT); + String endPointUrl = buildEndPointUrl(getBaseUri(), API_VERSION, DYNAMIC_MAPPING_PARAMETER_GET_ENDPOINT); - UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromHttpUrl(endPointUrl + DELIMITER + "{mappingName}"); - var uriComponents = uriComponentsBuilder.buildAndExpand(mappingName); + UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromHttpUrl(endPointUrl); + uriComponentsBuilder.queryParam("mappingName", mappingName); + var uriComponents = uriComponentsBuilder.build(); // call dynamic mapping Rest API try { return getRestTemplate().getForObject(uriComponents.toUriString(), Parameter.class); } catch (HttpStatusCodeException e) { if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) { - throw new DynamicSimulationException(DYNAMIC_MAPPING_NOT_FOUND, "Mapping not found: " + mappingName); + throw new DynamicSimulationException(DYNAMIC_MAPPING_NOT_FOUND, "No mapping has been found with name: " + mappingName); } else { - throw handleHttpError(e, CREATE_MAPPING_PARAMETER_ERROR, getObjectMapper()); + throw handleHttpError(e, GET_PARAMETER_ERROR, getObjectMapper()); } } } @@ -63,9 +64,9 @@ public Parameter createFromMapping(String mappingName) { public InputMapping getMapping(String mappingName) { Objects.requireNonNull(mappingName); - String endPointUrl = buildEndPointUrl(getBaseUri(), API_VERSION, DYNAMIC_MAPPING_MAPPING_BASE_END_POINT); + String endPointUrl = buildEndPointUrl(getBaseUri(), API_VERSION, DYNAMIC_MAPPING_MAPPING_BASE_ENDPOINT); - UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromHttpUrl(endPointUrl + DELIMITER + "{mappingName}"); + UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromHttpUrl(endPointUrl + URL_DELIMITER + "{mappingName}"); UriComponents uriComponents = uriComponentsBuilder.buildAndExpand(mappingName); @@ -74,7 +75,7 @@ public InputMapping getMapping(String mappingName) { return getRestTemplate().getForObject(uriComponents.toUriString(), InputMapping.class); } catch (HttpStatusCodeException e) { if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) { - throw new DynamicSimulationException(DYNAMIC_MAPPING_NOT_FOUND, "Mapping not found: " + mappingName); + throw new DynamicSimulationException(DYNAMIC_MAPPING_NOT_FOUND, "No mapping has been found with name: " + mappingName); } else { throw handleHttpError(e, GET_DYNAMIC_MAPPING_ERROR, getObjectMapper()); } diff --git a/src/main/java/org/gridsuite/ds/server/service/client/timeseries/impl/TimeSeriesClientImpl.java b/src/main/java/org/gridsuite/ds/server/service/client/timeseries/impl/TimeSeriesClientImpl.java index 56473e7c..42aca434 100644 --- a/src/main/java/org/gridsuite/ds/server/service/client/timeseries/impl/TimeSeriesClientImpl.java +++ b/src/main/java/org/gridsuite/ds/server/service/client/timeseries/impl/TimeSeriesClientImpl.java @@ -74,7 +74,7 @@ public void deleteTimeSeriesGroup(UUID groupUuid) { String endPointUrl = buildEndPointUrl(getBaseUri(), API_VERSION, TIME_SERIES_END_POINT); - UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromHttpUrl(endPointUrl + DELIMITER + "{groupUuid}"); + UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromHttpUrl(endPointUrl + URL_DELIMITER + "{groupUuid}"); var uriComponents = uriComponentsBuilder.buildAndExpand(groupUuid); // call time-series Rest API diff --git a/src/main/java/org/gridsuite/ds/server/service/client/utils/UrlUtils.java b/src/main/java/org/gridsuite/ds/server/service/client/utils/UrlUtils.java index 48004ead..8d6b0335 100644 --- a/src/main/java/org/gridsuite/ds/server/service/client/utils/UrlUtils.java +++ b/src/main/java/org/gridsuite/ds/server/service/client/utils/UrlUtils.java @@ -14,14 +14,14 @@ import java.net.URISyntaxException; import static org.gridsuite.ds.server.DynamicSimulationException.Type.URI_SYNTAX; -import static org.gridsuite.ds.server.service.client.RestClient.DELIMITER; +import static org.gridsuite.ds.server.service.client.RestClient.URL_DELIMITER; /** * @author Thang PHAM */ public final class UrlUtils { private UrlUtils() { - throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + throw new AssertionError("Utility class should not be instantiated"); } /** @@ -34,12 +34,11 @@ private UrlUtils() { public static String buildEndPointUrl(String baseUri, String apiVersion, String endPoint) { try { var sb = new StringBuilder(baseUri); - sb.append(DELIMITER); if (Strings.isNotBlank(apiVersion)) { - sb.append(apiVersion).append(DELIMITER); + sb.append(URL_DELIMITER).append(apiVersion); } if (Strings.isNotBlank(endPoint)) { - sb.append(endPoint); + sb.append(URL_DELIMITER).append(endPoint); } var url = sb.toString(); diff --git a/src/main/java/org/gridsuite/ds/server/utils/Utils.java b/src/main/java/org/gridsuite/ds/server/utils/Utils.java index 7efffb5f..25d51558 100644 --- a/src/main/java/org/gridsuite/ds/server/utils/Utils.java +++ b/src/main/java/org/gridsuite/ds/server/utils/Utils.java @@ -27,7 +27,7 @@ public final class Utils { public static final String RESOURCE_PATH_DELIMITER = "/"; private Utils() { - // never called + throw new AssertionError("Utility class should not be instantiated"); } public static List convertStringToList(String stringArray) { diff --git a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerIEEE14Test.java b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerIEEE14Test.java index e0bafc23..c60d7f16 100644 --- a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerIEEE14Test.java +++ b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerIEEE14Test.java @@ -125,7 +125,7 @@ protected void initDynamicMappingServiceMock() { Parameter parameterObj = new Parameter( MAPPING_NAME_01, parametersFile); - given(dynamicMappingClient.createFromMapping(DynamicMappingClientTest.MAPPING_NAME_01)).willReturn(parameterObj); + given(dynamicMappingClient.getParameters(DynamicMappingClientTest.MAPPING_NAME_01)).willReturn(parameterObj); // load mapping.json String mappingPath = inputDir + RESOURCE_PATH_DELIMITER + MAPPING_FILE; diff --git a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java index 3a3c9d08..1b2f2d96 100644 --- a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java +++ b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java @@ -107,7 +107,7 @@ protected void initDynamicMappingServiceMock() { Parameter parameterObj = new Parameter( MAPPING_NAME, ""); - given(dynamicMappingClient.createFromMapping(MAPPING_NAME)).willReturn(parameterObj); + given(dynamicMappingClient.getParameters(MAPPING_NAME)).willReturn(parameterObj); given(dynamicMappingClient.getMapping(DynamicMappingClientTest.MAPPING_NAME_01)).willReturn(null); } diff --git a/src/test/java/org/gridsuite/ds/server/controller/utils/FileUtils.java b/src/test/java/org/gridsuite/ds/server/controller/utils/FileUtils.java index 572897f6..0935e52d 100644 --- a/src/test/java/org/gridsuite/ds/server/controller/utils/FileUtils.java +++ b/src/test/java/org/gridsuite/ds/server/controller/utils/FileUtils.java @@ -17,6 +17,7 @@ */ public final class FileUtils { private FileUtils() { + throw new AssertionError("Utility class should not be instantiated"); } public static void writeStringToFile(Object caller, String filePathName, String content) throws IOException { diff --git a/src/test/java/org/gridsuite/ds/server/controller/utils/ParameterUtils.java b/src/test/java/org/gridsuite/ds/server/controller/utils/ParameterUtils.java index 4afda0b9..ba51dab6 100644 --- a/src/test/java/org/gridsuite/ds/server/controller/utils/ParameterUtils.java +++ b/src/test/java/org/gridsuite/ds/server/controller/utils/ParameterUtils.java @@ -26,7 +26,7 @@ */ public final class ParameterUtils { private ParameterUtils() { - + throw new AssertionError("Utility class should not be instantiated"); } /** diff --git a/src/test/java/org/gridsuite/ds/server/controller/utils/TestUtils.java b/src/test/java/org/gridsuite/ds/server/controller/utils/TestUtils.java index 6e6e413c..f541497f 100644 --- a/src/test/java/org/gridsuite/ds/server/controller/utils/TestUtils.java +++ b/src/test/java/org/gridsuite/ds/server/controller/utils/TestUtils.java @@ -22,7 +22,7 @@ public final class TestUtils { private static final long TIMEOUT = 100; private TestUtils() { - + throw new AssertionError("Utility class should not be instantiated"); } public static void assertQueuesEmptyThenClear(List destinations, OutputDestination output) throws InterruptedException { diff --git a/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java b/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java index ae554156..e6a9877b 100644 --- a/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java +++ b/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java @@ -28,11 +28,10 @@ import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowableOfType; -import static org.gridsuite.ds.server.DynamicSimulationException.Type.CREATE_MAPPING_PARAMETER_ERROR; import static org.gridsuite.ds.server.DynamicSimulationException.Type.DYNAMIC_MAPPING_NOT_FOUND; -import static org.gridsuite.ds.server.service.client.RestClient.DELIMITER; +import static org.gridsuite.ds.server.DynamicSimulationException.Type.GET_PARAMETER_ERROR; import static org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient.API_VERSION; -import static org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient.DYNAMIC_MAPPING_PARAMETER_CREATE_END_POINT; +import static org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient.DYNAMIC_MAPPING_PARAMETER_GET_ENDPOINT; import static org.gridsuite.ds.server.service.client.utils.UrlUtils.buildEndPointUrl; import static org.gridsuite.ds.server.utils.Utils.RESOURCE_PATH_DELIMITER; @@ -59,7 +58,7 @@ public class DynamicMappingClientTest extends AbstractWireMockRestClientTest { private String getEndpointUrl() { return buildEndPointUrl("", API_VERSION, - DYNAMIC_MAPPING_PARAMETER_CREATE_END_POINT); + DYNAMIC_MAPPING_PARAMETER_GET_ENDPOINT); } @Override @@ -73,7 +72,7 @@ public void setup() { } @Test - public void testCreateFromMapping() throws IOException { + public void testGetParameters() throws IOException { String mappingName = MAPPING_NAME_01; String inputDir = DATA_IEEE14_BASE_DIR + @@ -94,17 +93,17 @@ public void testCreateFromMapping() throws IOException { ObjectWriter ow = objectMapper.writer().withDefaultPrettyPrinter(); String parameterJson = ow.writeValueAsString(parameterObj); - // mock response for GET parameters/from/ + // mock response for GET parameters?mappingName= String baseUrl = getEndpointUrl(); - wireMockServer.stubFor(WireMock.get(WireMock.urlPathTemplate(baseUrl + DELIMITER + "{mappingName}")) - .withPathParam("mappingName", equalTo(mappingName)) + wireMockServer.stubFor(WireMock.get(WireMock.urlPathTemplate(baseUrl)) + .withQueryParam("mappingName", equalTo(mappingName)) .willReturn(WireMock.ok() .withBody(parameterJson) .withHeader("Content-Type", "application/json; charset=utf-8") )); - Parameter createdParameter = dynamicMappingClient.createFromMapping(MAPPING_NAME_01); + Parameter createdParameter = dynamicMappingClient.getParameters(MAPPING_NAME_01); // check result // load models.par @@ -115,16 +114,16 @@ public void testCreateFromMapping() throws IOException { public void testCreateFromMappingGivenNotFound() { String mappingName = MAPPING_NAME_01; - // mock response for GET parameters/from/ + // mock response for GET parameters?mappingName= String baseUrl = getEndpointUrl(); - wireMockServer.stubFor(WireMock.get(WireMock.urlPathTemplate(baseUrl + "{mappingName}")) - .withPathParam("mappingName", equalTo(mappingName)) + wireMockServer.stubFor(WireMock.get(WireMock.urlPathTemplate(baseUrl)) + .withQueryParam("mappingName", equalTo(mappingName)) .willReturn(WireMock.notFound() )); // test service - DynamicSimulationException dynamicSimulationException = catchThrowableOfType(() -> dynamicMappingClient.createFromMapping(MAPPING_NAME_01), + DynamicSimulationException dynamicSimulationException = catchThrowableOfType(() -> dynamicMappingClient.getParameters(MAPPING_NAME_01), DynamicSimulationException.class); // check result @@ -136,22 +135,22 @@ public void testCreateFromMappingGivenNotFound() { public void testCreateFromMappingGivenException() { String mappingName = MAPPING_NAME_01; - // mock response for test case GET parameters/from/ + // mock response for test case GET parameters?mappingName= String baseUrl = getEndpointUrl(); - wireMockServer.stubFor(WireMock.get(WireMock.urlPathTemplate(baseUrl + DELIMITER + "{mappingName}")) - .withPathParam("mappingName", equalTo(mappingName)) + wireMockServer.stubFor(WireMock.get(WireMock.urlPathTemplate(baseUrl)) + .withQueryParam("mappingName", equalTo(mappingName)) .willReturn(WireMock.serverError() .withBody(ERROR_MESSAGE) )); // test service - DynamicSimulationException dynamicSimulationException = catchThrowableOfType(() -> dynamicMappingClient.createFromMapping(MAPPING_NAME_01), + DynamicSimulationException dynamicSimulationException = catchThrowableOfType(() -> dynamicMappingClient.getParameters(MAPPING_NAME_01), DynamicSimulationException.class); // check result assertThat(dynamicSimulationException.getType()) - .isEqualTo(CREATE_MAPPING_PARAMETER_ERROR); + .isEqualTo(GET_PARAMETER_ERROR); assertThat(dynamicSimulationException.getMessage()) .isEqualTo(ERROR_MESSAGE); From 3f2f55b576f7e0b3ade71c709a55bcbdd3572e9e Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Tue, 9 Jul 2024 18:21:53 +0200 Subject: [PATCH 24/25] Correct following to Mathieu comments --- .../ds/server/DynamicSimulationException.java | 3 ++- .../RestResponseEntityExceptionHandler.java | 3 ++- .../dto/dynamicmapping/InputMapping.java | 4 +-- .../dynamicmapping/automata/Automaton.java | 1 + .../automata/BasicProperty.java | 1 + .../dynamicmapping/DynamicMappingClient.java | 5 ++-- .../impl/DynamicMappingClientImpl.java | 4 +-- .../contexts/DynamicSimulationRunContext.java | 11 ++++---- .../impl/ParametersServiceImpl.java | 25 +++++++++++++------ .../ds/server/utils/SetGroupType.java | 9 +++++++ .../controller/utils/ParameterUtils.java | 6 +++-- .../DynamicMappingClientTest.java | 4 +-- 12 files changed, 50 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/gridsuite/ds/server/DynamicSimulationException.java b/src/main/java/org/gridsuite/ds/server/DynamicSimulationException.java index 8b85f734..b3dd2b66 100644 --- a/src/main/java/org/gridsuite/ds/server/DynamicSimulationException.java +++ b/src/main/java/org/gridsuite/ds/server/DynamicSimulationException.java @@ -23,7 +23,8 @@ public enum Type { GET_PARAMETER_ERROR, GET_DYNAMIC_MAPPING_ERROR, CREATE_TIME_SERIES_ERROR, - DELETE_TIME_SERIES_ERROR + DELETE_TIME_SERIES_ERROR, + MAPPING_NOT_LAST_RULE_WITH_EMPTY_FILTER_ERROR, } private final Type type; diff --git a/src/main/java/org/gridsuite/ds/server/RestResponseEntityExceptionHandler.java b/src/main/java/org/gridsuite/ds/server/RestResponseEntityExceptionHandler.java index 85b833f5..4439fe33 100644 --- a/src/main/java/org/gridsuite/ds/server/RestResponseEntityExceptionHandler.java +++ b/src/main/java/org/gridsuite/ds/server/RestResponseEntityExceptionHandler.java @@ -39,7 +39,8 @@ protected ResponseEntity handleDynamicSimulationException(DynamicSimulat CREATE_TIME_SERIES_ERROR, DELETE_TIME_SERIES_ERROR -> ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(exception.getMessage()); - case MAPPING_NOT_PROVIDED + case MAPPING_NOT_PROVIDED, + MAPPING_NOT_LAST_RULE_WITH_EMPTY_FILTER_ERROR -> ResponseEntity.status(HttpStatus.BAD_REQUEST).body(exception.getMessage()); }; } diff --git a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/InputMapping.java b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/InputMapping.java index f0899565..9f94ab0c 100644 --- a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/InputMapping.java +++ b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/InputMapping.java @@ -18,9 +18,9 @@ public record InputMapping( @Schema(description = "Name") String name, - @Schema(description = "Mapping rules") + @Schema(description = "Rules") List rules, - @Schema(description = "Mapping automata") + @Schema(description = "Automata") List automata ) { diff --git a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/Automaton.java b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/Automaton.java index e8095e73..56deea6b 100644 --- a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/Automaton.java +++ b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/Automaton.java @@ -13,6 +13,7 @@ /** * @author Thang PHAM */ +@Schema(description = "Automaton") public record Automaton( @Schema(description = "Mapped Model Instance ID") String model, diff --git a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/BasicProperty.java b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/BasicProperty.java index de5f9325..d03864bd 100644 --- a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/BasicProperty.java +++ b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/automata/BasicProperty.java @@ -13,6 +13,7 @@ /** * @author Thang PHAM */ +@Schema(description = "Basic property") public record BasicProperty( @Schema(description = "Property name") String name, diff --git a/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClient.java b/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClient.java index 9c203c7a..3cf9a83f 100644 --- a/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClient.java +++ b/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClient.java @@ -14,9 +14,8 @@ */ public interface DynamicMappingClient { String API_VERSION = ""; - String DYNAMIC_MAPPING_PARAMETER_BASE_ENDPOINT = "parameters"; - String DYNAMIC_MAPPING_MAPPING_BASE_ENDPOINT = "mappings"; - String DYNAMIC_MAPPING_PARAMETER_GET_ENDPOINT = DYNAMIC_MAPPING_PARAMETER_BASE_ENDPOINT; + String DYNAMIC_MAPPING_PARAMETERS_BASE_ENDPOINT = "parameters"; + String DYNAMIC_MAPPING_MAPPINGS_BASE_ENDPOINT = "mappings"; Parameter getParameters(String mappingName); diff --git a/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/impl/DynamicMappingClientImpl.java b/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/impl/DynamicMappingClientImpl.java index 80b730b6..38a74f75 100644 --- a/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/impl/DynamicMappingClientImpl.java +++ b/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/impl/DynamicMappingClientImpl.java @@ -42,7 +42,7 @@ public DynamicMappingClientImpl(@Value("${gridsuite.services.dynamic-mapping-ser public Parameter getParameters(String mappingName) { Objects.requireNonNull(mappingName); - String endPointUrl = buildEndPointUrl(getBaseUri(), API_VERSION, DYNAMIC_MAPPING_PARAMETER_GET_ENDPOINT); + String endPointUrl = buildEndPointUrl(getBaseUri(), API_VERSION, DYNAMIC_MAPPING_PARAMETERS_BASE_ENDPOINT); UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromHttpUrl(endPointUrl); uriComponentsBuilder.queryParam("mappingName", mappingName); @@ -64,7 +64,7 @@ public Parameter getParameters(String mappingName) { public InputMapping getMapping(String mappingName) { Objects.requireNonNull(mappingName); - String endPointUrl = buildEndPointUrl(getBaseUri(), API_VERSION, DYNAMIC_MAPPING_MAPPING_BASE_ENDPOINT); + String endPointUrl = buildEndPointUrl(getBaseUri(), API_VERSION, DYNAMIC_MAPPING_MAPPINGS_BASE_ENDPOINT); UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromHttpUrl(endPointUrl + URL_DELIMITER + "{mappingName}"); diff --git a/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java b/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java index ad36939c..5a38c4ff 100644 --- a/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java +++ b/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java @@ -23,18 +23,19 @@ * @author Abdelsalem Hedhili */ @Getter +@Setter public class DynamicSimulationRunContext extends AbstractComputationRunContext { - @Setter private String mapping; + private String mapping; // fields which are enriched in worker service - @Setter private List dynamicModelContent; + private List dynamicModelContent; - @Setter private List eventModelContent; + private List eventModelContent; - @Setter private String curveContent; + private String curveContent; - @Setter private DynamicSimulationParameters dynamicSimulationParameters; + private DynamicSimulationParameters dynamicSimulationParameters; @Builder public DynamicSimulationRunContext(UUID networkUuid, String variantId, String receiver, String provider, String mapping, diff --git a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java index 85f4ff5b..cd0d3851 100644 --- a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java +++ b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java @@ -54,8 +54,7 @@ import java.util.*; import java.util.stream.Collectors; -import static org.gridsuite.ds.server.DynamicSimulationException.Type.MAPPING_NOT_PROVIDED; -import static org.gridsuite.ds.server.DynamicSimulationException.Type.PROVIDER_NOT_FOUND; +import static org.gridsuite.ds.server.DynamicSimulationException.Type.*; /** * @author Thang PHAM @@ -200,10 +199,20 @@ public List getDynamicModel(InputMapping inputMapping, Netwo List allRules = inputMapping.rules(); // grouping rules by equipment type Map> rulesByEquipmentTypeMap = allRules.stream().collect(Collectors.groupingBy(Rule::equipmentType)); + + // Only last rule can have empty filter checking + rulesByEquipmentTypeMap.forEach((equipmentType, rules) -> { + Rule ruleWithEmptyFilter = rules.stream().filter(rule -> rule.filter() == null).findFirst().orElse(null); + if (ruleWithEmptyFilter != null && rules.indexOf(ruleWithEmptyFilter) != (rules.size() - 1)) { + throw new DynamicSimulationException(MAPPING_NOT_LAST_RULE_WITH_EMPTY_FILTER_ERROR, + "Only last rule can have empty filter: type " + equipmentType + ", rule index " + rules.indexOf(ruleWithEmptyFilter) + 1); + } + }); + // performing transformation rulesByEquipmentTypeMap.forEach((equipmentType, rules) -> { // accumulate matched equipment ids to compute otherwise case (last rule without filters) - Set matchedEquipmentIds = new TreeSet<>(); + Set matchedEquipmentIdsOfCurrentType = new TreeSet<>(); dynamicModel.addAll(rules.stream().flatMap(rule -> { ExpertFilter filter = rule.filter(); @@ -216,16 +225,16 @@ public List getDynamicModel(InputMapping inputMapping, Netwo .build(); } - List> matchedEquipments = FiltersUtils.getIdentifiables(filter, network, null); + List> matchedEquipmentsOfCurrentRule = FiltersUtils.getIdentifiables(filter, network, null); // eliminate already matched equipments to avoid duplication - if (!matchedEquipmentIds.isEmpty()) { - matchedEquipments = matchedEquipments.stream().filter(elem -> !matchedEquipmentIds.contains(elem.getId())).toList(); + if (!matchedEquipmentIdsOfCurrentType.isEmpty()) { + matchedEquipmentsOfCurrentRule = matchedEquipmentsOfCurrentRule.stream().filter(elem -> !matchedEquipmentIdsOfCurrentType.contains(elem.getId())).toList(); } - matchedEquipmentIds.addAll(matchedEquipments.stream().map(Identifiable::getId).toList()); + matchedEquipmentIdsOfCurrentType.addAll(matchedEquipmentsOfCurrentRule.stream().map(Identifiable::getId).toList()); - return matchedEquipments.stream().map(equipment -> new DynamicModelConfig( + return matchedEquipmentsOfCurrentRule.stream().map(equipment -> new DynamicModelConfig( rule.mappedModel(), rule.setGroup(), SetGroupType.valueOf(rule.groupType().name()), diff --git a/src/main/java/org/gridsuite/ds/server/utils/SetGroupType.java b/src/main/java/org/gridsuite/ds/server/utils/SetGroupType.java index 4c9fc3b7..e23133e6 100644 --- a/src/main/java/org/gridsuite/ds/server/utils/SetGroupType.java +++ b/src/main/java/org/gridsuite/ds/server/utils/SetGroupType.java @@ -10,7 +10,16 @@ * @author Thang PHAM */ public enum SetGroupType { + /** + * group is used as a parameter set id + */ FIXED, + /** + * the parameter set id comprise the model dynamic id (or the equipment static id if not found) prefixed by group + */ PREFIX, + /** + * the parameter set id comprise the model dynamic id (or the equipment static id if not found) suffixed by group + */ SUFFIX } diff --git a/src/test/java/org/gridsuite/ds/server/controller/utils/ParameterUtils.java b/src/test/java/org/gridsuite/ds/server/controller/utils/ParameterUtils.java index ba51dab6..d0fdb330 100644 --- a/src/test/java/org/gridsuite/ds/server/controller/utils/ParameterUtils.java +++ b/src/test/java/org/gridsuite/ds/server/controller/utils/ParameterUtils.java @@ -21,6 +21,8 @@ import java.util.List; +import static org.gridsuite.ds.server.service.parameters.impl.ParametersServiceImpl.FIELD_STATIC_ID; + /** * @author Thang PHAM */ @@ -180,12 +182,12 @@ public static List getCurveInfosList() { public static List getEventInfosList() { return List.of( new EventInfos(null, null, "_BUS____1-BUS____5-1_AC", null, "Disconnect", List.of( - new EventPropertyInfos(null, "staticId", "_BUS____1-BUS____5-1_AC", PropertyType.STRING), + new EventPropertyInfos(null, FIELD_STATIC_ID, "_BUS____1-BUS____5-1_AC", PropertyType.STRING), new EventPropertyInfos(null, "startTime", "10", PropertyType.FLOAT), new EventPropertyInfos(null, "disconnectOnly", "TwoSides.TWO", PropertyType.ENUM) )), new EventInfos(null, null, "_BUS____1_TN", null, "FaultNode", List.of( - new EventPropertyInfos(null, "staticId", "_BUS____1_TN", PropertyType.STRING), + new EventPropertyInfos(null, FIELD_STATIC_ID, "_BUS____1_TN", PropertyType.STRING), new EventPropertyInfos(null, "startTime", "20", PropertyType.FLOAT), new EventPropertyInfos(null, "faultTime", "2", PropertyType.FLOAT), new EventPropertyInfos(null, "rPu", "23", PropertyType.FLOAT), diff --git a/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java b/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java index e6a9877b..e9536fc3 100644 --- a/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java +++ b/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java @@ -31,7 +31,7 @@ import static org.gridsuite.ds.server.DynamicSimulationException.Type.DYNAMIC_MAPPING_NOT_FOUND; import static org.gridsuite.ds.server.DynamicSimulationException.Type.GET_PARAMETER_ERROR; import static org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient.API_VERSION; -import static org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient.DYNAMIC_MAPPING_PARAMETER_GET_ENDPOINT; +import static org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient.DYNAMIC_MAPPING_PARAMETERS_BASE_ENDPOINT; import static org.gridsuite.ds.server.service.client.utils.UrlUtils.buildEndPointUrl; import static org.gridsuite.ds.server.utils.Utils.RESOURCE_PATH_DELIMITER; @@ -58,7 +58,7 @@ public class DynamicMappingClientTest extends AbstractWireMockRestClientTest { private String getEndpointUrl() { return buildEndPointUrl("", API_VERSION, - DYNAMIC_MAPPING_PARAMETER_GET_ENDPOINT); + DYNAMIC_MAPPING_PARAMETERS_BASE_ENDPOINT); } @Override From a49b389354bf1b39f8e2f0e8100c2351c144712b Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Wed, 10 Jul 2024 10:03:18 +0200 Subject: [PATCH 25/25] Rectify namming for export parameters --- .../ds/server/DynamicSimulationException.java | 2 +- .../RestResponseEntityExceptionHandler.java | 2 +- .../{Parameter.java => ParameterFile.java} | 6 ++-- .../DynamicSimulationWorkerService.java | 8 ++--- .../dynamicmapping/DynamicMappingClient.java | 7 +++-- .../impl/DynamicMappingClientImpl.java | 10 +++---- ...DynamicSimulationControllerIEEE14Test.java | 6 ++-- .../DynamicSimulationControllerTest.java | 6 ++-- .../DynamicMappingClientTest.java | 30 +++++++++---------- 9 files changed, 40 insertions(+), 37 deletions(-) rename src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/{Parameter.java => ParameterFile.java} (89%) diff --git a/src/main/java/org/gridsuite/ds/server/DynamicSimulationException.java b/src/main/java/org/gridsuite/ds/server/DynamicSimulationException.java index b3dd2b66..f1043b4b 100644 --- a/src/main/java/org/gridsuite/ds/server/DynamicSimulationException.java +++ b/src/main/java/org/gridsuite/ds/server/DynamicSimulationException.java @@ -20,7 +20,7 @@ public enum Type { MAPPING_NOT_PROVIDED, RESULT_UUID_NOT_FOUND, DYNAMIC_MAPPING_NOT_FOUND, - GET_PARAMETER_ERROR, + EXPORT_PARAMETERS_ERROR, GET_DYNAMIC_MAPPING_ERROR, CREATE_TIME_SERIES_ERROR, DELETE_TIME_SERIES_ERROR, diff --git a/src/main/java/org/gridsuite/ds/server/RestResponseEntityExceptionHandler.java b/src/main/java/org/gridsuite/ds/server/RestResponseEntityExceptionHandler.java index 4439fe33..685672aa 100644 --- a/src/main/java/org/gridsuite/ds/server/RestResponseEntityExceptionHandler.java +++ b/src/main/java/org/gridsuite/ds/server/RestResponseEntityExceptionHandler.java @@ -35,7 +35,7 @@ protected ResponseEntity handleDynamicSimulationException(DynamicSimulat -> ResponseEntity.status(HttpStatus.NOT_FOUND).body(exception.getMessage()); case URI_SYNTAX, GET_DYNAMIC_MAPPING_ERROR, - GET_PARAMETER_ERROR, + EXPORT_PARAMETERS_ERROR, CREATE_TIME_SERIES_ERROR, DELETE_TIME_SERIES_ERROR -> ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(exception.getMessage()); diff --git a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Parameter.java b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/ParameterFile.java similarity index 89% rename from src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Parameter.java rename to src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/ParameterFile.java index 86d49d7d..d11d12cc 100644 --- a/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Parameter.java +++ b/src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/ParameterFile.java @@ -12,12 +12,12 @@ * @author Thang PHAM */ @Schema(description = "Parameter sets in *.par format") -public record Parameter( +public record ParameterFile( @Schema(description = "Name of the parent mapping") - String parentName, + String mappingName, @Schema(description = "Parameter file content in *.par format") - String parametersFile + String fileContent ) { } diff --git a/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java b/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java index 51a310c3..41803e38 100644 --- a/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java +++ b/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java @@ -29,7 +29,7 @@ import org.gridsuite.ds.server.dto.DynamicSimulationParametersInfos; import org.gridsuite.ds.server.dto.DynamicSimulationStatus; import org.gridsuite.ds.server.dto.dynamicmapping.InputMapping; -import org.gridsuite.ds.server.dto.dynamicmapping.Parameter; +import org.gridsuite.ds.server.dto.dynamicmapping.ParameterFile; import org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient; import org.gridsuite.ds.server.service.contexts.DynamicSimulationResultContext; import org.gridsuite.ds.server.service.contexts.DynamicSimulationRunContext; @@ -135,12 +135,12 @@ public void preRun(DynamicSimulationRunContext runContext) { DynamicSimulationParametersInfos parametersInfos = runContext.getParameters(); // get parameters file from dynamic mapping server - Parameter parameterObj = dynamicMappingClient.getParameters(runContext.getMapping()); + ParameterFile parameterFile = dynamicMappingClient.exportParameters(runContext.getMapping()); // get all dynamic simulation parameters - String parametersFile = parameterObj.parametersFile(); + String parameterFileContent = parameterFile.fileContent(); DynamicSimulationParameters parameters = parametersService.getDynamicSimulationParameters( - parametersFile.getBytes(StandardCharsets.UTF_8), runContext.getProvider(), parametersInfos); + parameterFileContent.getBytes(StandardCharsets.UTF_8), runContext.getProvider(), parametersInfos); // get mapping then generate dynamic model configs InputMapping inputMapping = dynamicMappingClient.getMapping(runContext.getMapping()); diff --git a/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClient.java b/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClient.java index 3cf9a83f..40118108 100644 --- a/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClient.java +++ b/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClient.java @@ -7,7 +7,9 @@ package org.gridsuite.ds.server.service.client.dynamicmapping; import org.gridsuite.ds.server.dto.dynamicmapping.InputMapping; -import org.gridsuite.ds.server.dto.dynamicmapping.Parameter; +import org.gridsuite.ds.server.dto.dynamicmapping.ParameterFile; + +import static org.gridsuite.ds.server.service.client.RestClient.URL_DELIMITER; /** * @author Thang PHAM @@ -15,9 +17,10 @@ public interface DynamicMappingClient { String API_VERSION = ""; String DYNAMIC_MAPPING_PARAMETERS_BASE_ENDPOINT = "parameters"; + String DYNAMIC_MAPPING_PARAMETERS_EXPORT_ENDPOINT = DYNAMIC_MAPPING_PARAMETERS_BASE_ENDPOINT + URL_DELIMITER + "export"; String DYNAMIC_MAPPING_MAPPINGS_BASE_ENDPOINT = "mappings"; - Parameter getParameters(String mappingName); + ParameterFile exportParameters(String mappingName); InputMapping getMapping(String mappingName); } diff --git a/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/impl/DynamicMappingClientImpl.java b/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/impl/DynamicMappingClientImpl.java index 38a74f75..a8348568 100644 --- a/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/impl/DynamicMappingClientImpl.java +++ b/src/main/java/org/gridsuite/ds/server/service/client/dynamicmapping/impl/DynamicMappingClientImpl.java @@ -9,7 +9,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.gridsuite.ds.server.DynamicSimulationException; import org.gridsuite.ds.server.dto.dynamicmapping.InputMapping; -import org.gridsuite.ds.server.dto.dynamicmapping.Parameter; +import org.gridsuite.ds.server.dto.dynamicmapping.ParameterFile; import org.gridsuite.ds.server.service.client.AbstractRestClient; import org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient; import org.springframework.beans.factory.annotation.Autowired; @@ -39,10 +39,10 @@ public DynamicMappingClientImpl(@Value("${gridsuite.services.dynamic-mapping-ser } @Override - public Parameter getParameters(String mappingName) { + public ParameterFile exportParameters(String mappingName) { Objects.requireNonNull(mappingName); - String endPointUrl = buildEndPointUrl(getBaseUri(), API_VERSION, DYNAMIC_MAPPING_PARAMETERS_BASE_ENDPOINT); + String endPointUrl = buildEndPointUrl(getBaseUri(), API_VERSION, DYNAMIC_MAPPING_PARAMETERS_EXPORT_ENDPOINT); UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromHttpUrl(endPointUrl); uriComponentsBuilder.queryParam("mappingName", mappingName); @@ -50,12 +50,12 @@ public Parameter getParameters(String mappingName) { // call dynamic mapping Rest API try { - return getRestTemplate().getForObject(uriComponents.toUriString(), Parameter.class); + return getRestTemplate().getForObject(uriComponents.toUriString(), ParameterFile.class); } catch (HttpStatusCodeException e) { if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) { throw new DynamicSimulationException(DYNAMIC_MAPPING_NOT_FOUND, "No mapping has been found with name: " + mappingName); } else { - throw handleHttpError(e, GET_PARAMETER_ERROR, getObjectMapper()); + throw handleHttpError(e, EXPORT_PARAMETERS_ERROR, getObjectMapper()); } } } diff --git a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerIEEE14Test.java b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerIEEE14Test.java index c60d7f16..778e5ec4 100644 --- a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerIEEE14Test.java +++ b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerIEEE14Test.java @@ -26,7 +26,7 @@ import org.gridsuite.ds.server.dto.DynamicSimulationParametersInfos; import org.gridsuite.ds.server.dto.curve.CurveInfos; import org.gridsuite.ds.server.dto.dynamicmapping.InputMapping; -import org.gridsuite.ds.server.dto.dynamicmapping.Parameter; +import org.gridsuite.ds.server.dto.dynamicmapping.ParameterFile; import org.gridsuite.ds.server.dto.event.EventInfos; import org.gridsuite.ds.server.dto.timeseries.TimeSeriesGroupInfos; import org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClientTest; @@ -122,10 +122,10 @@ protected void initDynamicMappingServiceMock() { parametersFileBytes = StreamUtils.copyToByteArray(parametersFileIS); String parametersFile = new String(parametersFileBytes, StandardCharsets.UTF_8); - Parameter parameterObj = new Parameter( + ParameterFile parameterFile = new ParameterFile( MAPPING_NAME_01, parametersFile); - given(dynamicMappingClient.getParameters(DynamicMappingClientTest.MAPPING_NAME_01)).willReturn(parameterObj); + given(dynamicMappingClient.exportParameters(DynamicMappingClientTest.MAPPING_NAME_01)).willReturn(parameterFile); // load mapping.json String mappingPath = inputDir + RESOURCE_PATH_DELIMITER + MAPPING_FILE; diff --git a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java index 1b2f2d96..32bce131 100644 --- a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java +++ b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java @@ -25,7 +25,7 @@ import org.gridsuite.ds.server.controller.utils.ParameterUtils; import org.gridsuite.ds.server.dto.DynamicSimulationParametersInfos; import org.gridsuite.ds.server.dto.DynamicSimulationStatus; -import org.gridsuite.ds.server.dto.dynamicmapping.Parameter; +import org.gridsuite.ds.server.dto.dynamicmapping.ParameterFile; import org.gridsuite.ds.server.dto.timeseries.TimeSeriesGroupInfos; import org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClientTest; import org.gridsuite.ds.server.service.client.timeseries.TimeSeriesClientTest; @@ -104,10 +104,10 @@ protected void initNetworkStoreServiceMock() { @Override protected void initDynamicMappingServiceMock() { - Parameter parameterObj = new Parameter( + ParameterFile parameterFile = new ParameterFile( MAPPING_NAME, ""); - given(dynamicMappingClient.getParameters(MAPPING_NAME)).willReturn(parameterObj); + given(dynamicMappingClient.exportParameters(MAPPING_NAME)).willReturn(parameterFile); given(dynamicMappingClient.getMapping(DynamicMappingClientTest.MAPPING_NAME_01)).willReturn(null); } diff --git a/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java b/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java index e9536fc3..e3746209 100644 --- a/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java +++ b/src/test/java/org/gridsuite/ds/server/service/client/dynamicmapping/DynamicMappingClientTest.java @@ -12,7 +12,7 @@ import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.client.WireMock; import org.gridsuite.ds.server.DynamicSimulationException; -import org.gridsuite.ds.server.dto.dynamicmapping.Parameter; +import org.gridsuite.ds.server.dto.dynamicmapping.ParameterFile; import org.gridsuite.ds.server.service.client.AbstractWireMockRestClientTest; import org.gridsuite.ds.server.service.client.dynamicmapping.impl.DynamicMappingClientImpl; import org.junit.Test; @@ -29,9 +29,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowableOfType; import static org.gridsuite.ds.server.DynamicSimulationException.Type.DYNAMIC_MAPPING_NOT_FOUND; -import static org.gridsuite.ds.server.DynamicSimulationException.Type.GET_PARAMETER_ERROR; +import static org.gridsuite.ds.server.DynamicSimulationException.Type.EXPORT_PARAMETERS_ERROR; import static org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient.API_VERSION; -import static org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient.DYNAMIC_MAPPING_PARAMETERS_BASE_ENDPOINT; +import static org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient.DYNAMIC_MAPPING_PARAMETERS_EXPORT_ENDPOINT; import static org.gridsuite.ds.server.service.client.utils.UrlUtils.buildEndPointUrl; import static org.gridsuite.ds.server.utils.Utils.RESOURCE_PATH_DELIMITER; @@ -58,7 +58,7 @@ public class DynamicMappingClientTest extends AbstractWireMockRestClientTest { private String getEndpointUrl() { return buildEndPointUrl("", API_VERSION, - DYNAMIC_MAPPING_PARAMETERS_BASE_ENDPOINT); + DYNAMIC_MAPPING_PARAMETERS_EXPORT_ENDPOINT); } @Override @@ -72,7 +72,7 @@ public void setup() { } @Test - public void testGetParameters() throws IOException { + public void testExportParameters() throws IOException { String mappingName = MAPPING_NAME_01; String inputDir = DATA_IEEE14_BASE_DIR + @@ -86,12 +86,12 @@ public void testGetParameters() throws IOException { parametersFileBytes = StreamUtils.copyToByteArray(parametersFileIS); String parametersFile = new String(parametersFileBytes, StandardCharsets.UTF_8); - Parameter parameterObj = new Parameter( + ParameterFile parameterFile = new ParameterFile( mappingName, parametersFile); ObjectWriter ow = objectMapper.writer().withDefaultPrettyPrinter(); - String parameterJson = ow.writeValueAsString(parameterObj); + String parameterFileJson = ow.writeValueAsString(parameterFile); // mock response for GET parameters?mappingName= String baseUrl = getEndpointUrl(); @@ -99,22 +99,22 @@ public void testGetParameters() throws IOException { wireMockServer.stubFor(WireMock.get(WireMock.urlPathTemplate(baseUrl)) .withQueryParam("mappingName", equalTo(mappingName)) .willReturn(WireMock.ok() - .withBody(parameterJson) + .withBody(parameterFileJson) .withHeader("Content-Type", "application/json; charset=utf-8") )); - Parameter createdParameter = dynamicMappingClient.getParameters(MAPPING_NAME_01); + ParameterFile createdParameterFile = dynamicMappingClient.exportParameters(MAPPING_NAME_01); // check result // load models.par - assertThat(createdParameter.parametersFile()).isEqualTo(parametersFile); + assertThat(createdParameterFile.fileContent()).isEqualTo(parametersFile); } @Test public void testCreateFromMappingGivenNotFound() { String mappingName = MAPPING_NAME_01; - // mock response for GET parameters?mappingName= + // mock response for GET parameters/export?mappingName= String baseUrl = getEndpointUrl(); wireMockServer.stubFor(WireMock.get(WireMock.urlPathTemplate(baseUrl)) @@ -123,7 +123,7 @@ public void testCreateFromMappingGivenNotFound() { )); // test service - DynamicSimulationException dynamicSimulationException = catchThrowableOfType(() -> dynamicMappingClient.getParameters(MAPPING_NAME_01), + DynamicSimulationException dynamicSimulationException = catchThrowableOfType(() -> dynamicMappingClient.exportParameters(MAPPING_NAME_01), DynamicSimulationException.class); // check result @@ -135,7 +135,7 @@ public void testCreateFromMappingGivenNotFound() { public void testCreateFromMappingGivenException() { String mappingName = MAPPING_NAME_01; - // mock response for test case GET parameters?mappingName= + // mock response for test case GET parameters/export?mappingName= String baseUrl = getEndpointUrl(); wireMockServer.stubFor(WireMock.get(WireMock.urlPathTemplate(baseUrl)) @@ -145,12 +145,12 @@ public void testCreateFromMappingGivenException() { )); // test service - DynamicSimulationException dynamicSimulationException = catchThrowableOfType(() -> dynamicMappingClient.getParameters(MAPPING_NAME_01), + DynamicSimulationException dynamicSimulationException = catchThrowableOfType(() -> dynamicMappingClient.exportParameters(MAPPING_NAME_01), DynamicSimulationException.class); // check result assertThat(dynamicSimulationException.getType()) - .isEqualTo(GET_PARAMETER_ERROR); + .isEqualTo(EXPORT_PARAMETERS_ERROR); assertThat(dynamicSimulationException.getMessage()) .isEqualTo(ERROR_MESSAGE);