-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor hvdc logs for creation and modification (#498)
--------- Signed-off-by: Etienne LESOT <[email protected]>
- Loading branch information
Showing
19 changed files
with
61 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 43 additions & 25 deletions
68
src/main/java/org/gridsuite/modification/server/modifications/PropertiesUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,70 @@ | ||
package org.gridsuite.modification.server.modifications; | ||
|
||
import com.powsybl.commons.report.ReportNode; | ||
import com.powsybl.commons.report.TypedValue; | ||
import com.powsybl.commons.report.*; | ||
import com.powsybl.iidm.network.Identifiable; | ||
import org.gridsuite.modification.server.dto.FreePropertyInfos; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.*; | ||
|
||
public final class PropertiesUtils { | ||
public static final String PROPERTIES = "Properties"; | ||
|
||
private PropertiesUtils() { | ||
// Should not be instantiated | ||
} | ||
|
||
public static void applyProperties(Identifiable<?> identifiable, ReportNode subReportNode, @Nullable List<FreePropertyInfos> properties) { | ||
public static void applyProperties(Identifiable<?> identifiable, ReportNode subReportNode, @Nullable List<FreePropertyInfos> properties, String propertiesLabelKey) { | ||
List<ReportNode> reportNodes = new ArrayList<>(); | ||
ReportNode propertiesReporter = subReportNode.newReportNode().withMessageTemplate(PROPERTIES, PROPERTIES).add(); | ||
Optional.ofNullable(properties).ifPresent(props -> | ||
props.forEach(prop -> PropertiesUtils.applyProperty(identifiable, prop, subReportNode))); | ||
props.forEach(prop -> | ||
Optional.ofNullable(PropertiesUtils.applyProperty(identifiable, prop)) | ||
.ifPresent(reportNodes::add) | ||
) | ||
); | ||
ModificationUtils.getInstance().reportModifications(propertiesReporter, reportNodes, | ||
propertiesLabelKey, PROPERTIES, Map.of()); | ||
} | ||
|
||
private static void applyProperty(Identifiable<?> identifiable, FreePropertyInfos prop, ReportNode subReportNode) { | ||
private static ReportNode applyProperty(Identifiable<?> identifiable, FreePropertyInfos prop) { | ||
ReportNodeBuilder builder = ReportNode.newRootReportNode(); | ||
if (prop.isDeletionMark()) { | ||
if (identifiable.removeProperty(prop.getName())) { | ||
subReportNode.newReportNode() | ||
.withMessageTemplate("propertyDeleted", " Property ${name} deleted") | ||
.withUntypedValue("name", prop.getName()) | ||
.withSeverity(TypedValue.INFO_SEVERITY) | ||
.add(); | ||
reportPropertyDeletion(builder, prop); | ||
return builder.build(); | ||
} | ||
} else { | ||
String oldValue = identifiable.setProperty(prop.getName(), prop.getValue()); | ||
if (oldValue != null) { // update | ||
subReportNode.newReportNode() | ||
.withMessageTemplate("propertyChanged", " Property ${name} changed : ${from} -> ${to}") | ||
.withUntypedValue("name", prop.getName()) | ||
.withUntypedValue("from", oldValue) | ||
.withUntypedValue("to", prop.getValue()) | ||
.withSeverity(TypedValue.INFO_SEVERITY) | ||
.add(); | ||
reportPropertyModification(builder, prop); | ||
return builder.build(); | ||
} else { // insert | ||
subReportNode.newReportNode() | ||
.withMessageTemplate("propertyAdded", " Property ${name} added with value ${value}") | ||
.withUntypedValue("name", prop.getName()) | ||
.withUntypedValue("value", prop.getValue()) | ||
.withSeverity(TypedValue.INFO_SEVERITY) | ||
.add(); | ||
reportPropertyCreation(builder, prop); | ||
return builder.build(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private static void reportPropertyCreation(ReportNodeAdderOrBuilder<?> adderOrBuilder, FreePropertyInfos prop) { | ||
adderOrBuilder.withMessageTemplate("propertyAdded", " Property ${name} added with value ${value}") | ||
.withUntypedValue("name", prop.getName()) | ||
.withUntypedValue("value", prop.getValue()) | ||
.withSeverity(TypedValue.INFO_SEVERITY); | ||
} | ||
|
||
private static void reportPropertyModification(ReportNodeAdderOrBuilder<?> adderOrBuilder, FreePropertyInfos prop) { | ||
adderOrBuilder.withMessageTemplate("propertyChanged", " Property ${name} changed : ${from} -> ${to}") | ||
.withUntypedValue("name", prop.getName()) | ||
.withUntypedValue("to", prop.getValue()) | ||
.withUntypedValue("from", prop.getPreviousValue() == null ? "null" : prop.getPreviousValue()) | ||
.withSeverity(TypedValue.INFO_SEVERITY); | ||
} | ||
|
||
private static void reportPropertyDeletion(ReportNodeAdderOrBuilder<?> adderOrBuilder, FreePropertyInfos prop) { | ||
adderOrBuilder.withMessageTemplate("propertyDeleted", " Property ${name} deleted") | ||
.withUntypedValue("name", prop.getName()) | ||
.withSeverity(TypedValue.INFO_SEVERITY); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters