Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace models.cfg with json #281

Merged
merged 7 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dynawaltz-dsl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
<groupId>com.powsybl</groupId>
<artifactId>powsybl-dynawaltz</artifactId>
</dependency>
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy-json</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ import com.powsybl.dynawaltz.DynaWaltzProvider
import com.powsybl.iidm.network.Network

import java.util.function.Consumer

/**
* @author Laurent Issertial <laurent.issertial at rte-france.com>
*/
abstract class AbstractEquipmentGroovyExtension<T> {

protected static final String MODELS_CONFIG = "models.cfg"
protected static final String MODEL_PREFIX = "prefix"
protected static final String MODEL_PROPERTIES = "properties"
protected static final String MODELS_CONFIG = "models.json"

protected final List<EquipmentConfig> equipmentConfigs

Expand All @@ -28,14 +25,7 @@ abstract class AbstractEquipmentGroovyExtension<T> {
}

protected AbstractEquipmentGroovyExtension(String modelTag, URL modelConfigUrl) {
ConfigSlurper config = new ConfigSlurper()
equipmentConfigs = config.parse(modelConfigUrl).get(modelTag).collect {
new EquipmentConfig(
it.key as String,
it.value.get(MODEL_PREFIX) as String,
it.value.get(MODEL_PROPERTIES).collect{it.toUpperCase()} as String[]
)
}
equipmentConfigs = ModelsSlurper.instance.getEquipmentConfigs(modelConfigUrl, modelTag)
}

abstract protected ModelBuilder<T> createBuilder(Network network, EquipmentConfig equipmentConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class EquipmentConfig {
EquipmentConfig(String lib, String prefix, String... properties) {
this.lib = lib
this.prefix = prefix
this.properties = properties
this.properties = properties ? properties.collect{it.toUpperCase()} as List<String> : [] as List<String>
}

boolean isControllable() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* 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/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.dynawaltz.dsl

import groovy.json.JsonSlurper
import org.apache.groovy.json.internal.LazyMap

/**
* @author Laurent Issertial <laurent.issertial at rte-france.com>
*/
@Singleton
class ModelsSlurper {

private static final String MODEL_LIB = "lib"
private static final String MODEL_PREFIX = "prefix"
private static final String MODEL_PROPERTIES = "properties"

private final slurper = new JsonSlurper()
private final Map<URL, LazyMap> libsList = new HashMap<>()

def getEquipmentConfigs(URL url, String modelTag) {
libsList.computeIfAbsent(url, u -> slurper.parse(u))[modelTag].collect() {
new EquipmentConfig(
it[MODEL_LIB] as String,
it[MODEL_PREFIX] as String,
it[MODEL_PROPERTIES] as String[])
}
}
}
107 changes: 0 additions & 107 deletions dynawaltz-dsl/src/main/resources/models.cfg

This file was deleted.

Loading
Loading