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

CGMES metadata models extension #2898

Merged
merged 30 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
39b04b0
CGMES metadata models extension
zamarrenolm Feb 13, 2024
5348e0f
checkstyle: whitespace
zamarrenolm Feb 13, 2024
01dd060
Merge branch 'main' into cgmes_metadata_models
zamarrenolm Feb 19, 2024
53f5051
Merge branch 'main' into cgmes_metadata_models
zamarrenolm Mar 7, 2024
10c32b9
Merge branch 'main' into cgmes_metadata_models
zamarrenolm Mar 7, 2024
c1dfc40
remove previous sv, ssh extensions and replace with new generic exten…
zamarrenolm Mar 7, 2024
04d3863
fixes from failing unit tests
zamarrenolm Mar 8, 2024
db2bb00
names in extension
zamarrenolm Mar 8, 2024
d43c1ae
always export models sorted; adjust names in test expected data
zamarrenolm Mar 8, 2024
fc6defd
remove debug code
zamarrenolm Mar 8, 2024
88d7f50
Merge branch 'main' into cgmes_metadata_models
zamarrenolm Mar 8, 2024
8b85452
add source of model (import or export); use enum for part (cgmes subset)
zamarrenolm Mar 11, 2024
3a8ba5e
Merge branch 'main' into cgmes_metadata_models
zamarrenolm Mar 11, 2024
7510cb1
ignore unknown subset in test
zamarrenolm Mar 11, 2024
0ca3f24
Merge branch 'main' into cgmes_metadata_models
zamarrenolm Mar 12, 2024
f8d998a
remove source of metadata model
zamarrenolm Mar 12, 2024
5bd9507
use a single class for storing CGMES metadata model information
zamarrenolm Mar 13, 2024
54fe16e
Merge branch 'main' into cgmes_metadata_models
zamarrenolm Mar 13, 2024
9d39929
Merge branch 'main' into cgmes_metadata_models
zamarrenolm Mar 14, 2024
705e84c
we do not need to store multiple identifiers in a metadata model
zamarrenolm Mar 14, 2024
17a2425
query fullModel for profile replace by fullModels
zamarrenolm Mar 15, 2024
9759a96
fix license data
zamarrenolm Mar 15, 2024
e1707e4
Merge branch 'main' into cgmes_metadata_models
zamarrenolm Mar 15, 2024
3c80f77
Merge branch 'main' into cgmes_metadata_models
zamarrenolm Mar 18, 2024
feeef19
Model part is an enum
zamarrenolm Mar 18, 2024
7ebd5c0
Merge branch 'main' into cgmes_metadata_models
zamarrenolm Mar 19, 2024
6e535d4
naming: uniform use of cgmes "subset" instead of "part"
zamarrenolm Mar 22, 2024
78e0c49
Merge branch 'main' into cgmes_metadata_models
zamarrenolm Mar 22, 2024
514e137
Add javadoc
rcourtier Mar 26, 2024
d27b2bd
Merge branch 'main' into cgmes_metadata_models
rcourtier Mar 26, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* 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/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.cgmes.extensions;

import com.powsybl.commons.extensions.Extension;
import com.powsybl.iidm.network.Network;

import java.util.Collection;
import java.util.Optional;
import java.util.Set;

/**
* @author Luma Zamarreño {@literal <zamarrenolm at aia.es>}
*/
public interface CgmesMetadataModels extends Extension<Network> {

String NAME = "cgmesMetadataModels";

interface Model {
String getPart();

String getId();

String getDescription();

int getVersion();

String getModelingAuthoritySet();

Set<String> getProfiles();

Set<String> getDependentOn();

Set<String> getSupersedes();
}

Collection<Model> getModels();

Optional<Model> getModelForPart(String part);

Optional<Model> getModelForProfile(String profile);

@Override
default String getName() {
return NAME;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* 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/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.cgmes.extensions;

import com.powsybl.commons.extensions.ExtensionAdder;
import com.powsybl.iidm.network.Network;

/**
* @author Luma Zamarreño {@literal <zamarrenolm at aia.es>}
*/
public interface CgmesMetadataModelsAdder extends ExtensionAdder<Network, CgmesMetadataModels> {

interface ModelAdder {
ModelAdder setPart(String part);

ModelAdder setId(String id);

ModelAdder setDescription(String description);

ModelAdder setVersion(int sshVersion);

ModelAdder setModelingAuthoritySet(String modelingAuthoritySet);

ModelAdder addProfile(String profile);

ModelAdder addDependentOn(String dependentOn);

ModelAdder addSupersedes(String supersedes);

CgmesMetadataModelsAdder add();
}

ModelAdder newModel();

@Override
default Class<CgmesMetadataModels> getExtensionClass() {
return CgmesMetadataModels.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/**
* 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/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.cgmes.extensions;

import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.extensions.AbstractExtensionAdder;
import com.powsybl.iidm.network.Network;

import java.util.*;

/**
* @author Luma Zamarreño {@literal <zamarrenolm at aia.es>}
*/
class CgmesMetadataModelsAdderImpl extends AbstractExtensionAdder<Network, CgmesMetadataModels> implements CgmesMetadataModelsAdder {

class ModelAdderImpl implements ModelAdder {

private String part;
private String id;
private String description;
private int version = 0;
private String modelingAuthoritySet;
private final Set<String> profiles = new HashSet<>();
private final Set<String> dependentOn = new HashSet<>();
private final Set<String> supersedes = new HashSet<>();

@Override
public ModelAdder setPart(String part) {
this.part = part;
return this;
}

@Override
public ModelAdder setId(String id) {
this.id = id;
return this;
}

@Override
public ModelAdderImpl setDescription(String description) {
this.description = description;
return this;
}

@Override
public ModelAdderImpl setVersion(int version) {
this.version = version;
return this;
}

@Override
public ModelAdderImpl setModelingAuthoritySet(String modelingAuthoritySet) {
this.modelingAuthoritySet = modelingAuthoritySet;
return this;
}

@Override
public ModelAdder addProfile(String profile) {
profiles.add(Objects.requireNonNull(profile));
return this;
}

@Override
public ModelAdderImpl addDependentOn(String dependentOn) {
this.dependentOn.add(Objects.requireNonNull(dependentOn));
return this;
}

@Override
public ModelAdderImpl addSupersedes(String supersedes) {
this.supersedes.add(Objects.requireNonNull(supersedes));
return this;
}

@Override
public CgmesMetadataModelsAdderImpl add() {
if (id == null) {
throw new PowsyblException("Model id is undefined");
}
if (modelingAuthoritySet == null) {
throw new PowsyblException("Model modelingAuthoritySet is undefined");
}
if (profiles.isEmpty()) {
throw new PowsyblException("Model must contain at least one profile");
}
models.add(new CgmesMetadataModelsImpl.ModelImpl(part, id, description, version, modelingAuthoritySet, profiles, dependentOn, supersedes));
return CgmesMetadataModelsAdderImpl.this;
}
}

private final Set<CgmesMetadataModels.Model> models = new HashSet<>();

CgmesMetadataModelsAdderImpl(Network extendable) {
super(extendable);
}

@Override
public ModelAdder newModel() {
return new ModelAdderImpl();
}

@Override
protected CgmesMetadataModels createExtension(Network extendable) {
if (models.isEmpty()) {
throw new PowsyblException("Must contain at least one model");
}
return new CgmesMetadataModelsImpl(models);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* 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/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.cgmes.extensions;

import com.google.auto.service.AutoService;
import com.powsybl.commons.extensions.ExtensionAdderProvider;
import com.powsybl.iidm.network.Network;

/**
* @author Luma Zamarreño {@literal <zamarrenolm at aia.es>}
*/
@AutoService(ExtensionAdderProvider.class)
public class CgmesMetadataModelsAdderImplProvider implements
ExtensionAdderProvider<Network, CgmesMetadataModels, CgmesMetadataModelsAdderImpl> {

@Override
public String getImplementationName() {
return "Default";
}

@Override
public String getExtensionName() {
return CgmesMetadataModels.NAME;
}

@Override
public Class<? super CgmesMetadataModelsAdderImpl> getAdderClass() {
return CgmesMetadataModelsAdderImpl.class;
}

@Override
public CgmesMetadataModelsAdderImpl newAdder(Network extendable) {
return new CgmesMetadataModelsAdderImpl(extendable);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/**
* 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/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.cgmes.extensions;

import com.powsybl.commons.extensions.AbstractExtension;
import com.powsybl.iidm.network.Network;

import java.util.*;

/**
* @author Luma Zamarreño {@literal <zamarrenolm at aia.es>}
*/
class CgmesMetadataModelsImpl extends AbstractExtension<Network> implements CgmesMetadataModels {

static class ModelImpl implements Model {

private final String part;
private final String id;
private final String description;
private final int version;
private final String modelingAuthoritySet;
private final Set<String> profiles = new HashSet<>();
private final Set<String> dependentOn = new HashSet<>();
private final Set<String> supersedes = new HashSet<>();

ModelImpl(String part, String id, String description, int version, String modelingAuthoritySet,
Set<String> profiles, Set<String> dependentOn, Set<String> supersedes) {
this.part = part;
this.id = id;
this.description = description;
this.version = version;
this.modelingAuthoritySet = modelingAuthoritySet;
this.profiles.addAll(profiles);
this.dependentOn.addAll(dependentOn);
this.supersedes.addAll(supersedes);
}

@Override
public String getPart() {
return part;
}

@Override
public String getId() {
return id;
}

@Override
public String getDescription() {
return description;
}

@Override
public int getVersion() {
return version;
}

@Override
public String getModelingAuthoritySet() {
return modelingAuthoritySet;
}

@Override
public Set<String> getProfiles() {
return Collections.unmodifiableSet(profiles);
}

@Override
public Set<String> getDependentOn() {
return Collections.unmodifiableSet(dependentOn);
}

@Override
public Set<String> getSupersedes() {
return Collections.unmodifiableSet(supersedes);
}
}

private final List<Model> models = new ArrayList<>();
private final Map<String, Model> partModel = new HashMap<>();
private final Map<String, Model> profileModel = new HashMap<>();

CgmesMetadataModelsImpl(Set<Model> models) {
this.models.addAll(models);
models.forEach(m -> partModel.put(m.getPart(), m));
models.forEach(m -> m.getProfiles().forEach(profile -> profileModel.put(profile, m)));
}

@Override
public Optional<Model> getModelForPart(String part) {
return Optional.ofNullable(partModel.get(part));
}

@Override
public Optional<Model> getModelForProfile(String profile) {
return Optional.ofNullable(profileModel.get(profile));
}

@Override
public Collection<Model> getModels() {
return Collections.unmodifiableCollection(models);
}

}
Loading