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

Get modifications from metadata #345

Merged
merged 34 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f87cb01
get metadata modifications
souissimai Oct 10, 2023
8dc4455
Merge branch 'main' into get_modifications_from_metadata
souissimai Oct 10, 2023
a66fb78
fields to store modification type and metadata infos
souissimai Oct 10, 2023
0cd9150
fix tests
souissimai Oct 11, 2023
1134c79
throw exceptions
souissimai Oct 11, 2023
abfaa8d
rename method to get metada depending on modification type
souissimai Oct 11, 2023
c046696
refactor code and adapt unit test
souissimai Oct 24, 2023
9cb7170
Merge branch 'main' into get_modifications_from_metadata
souissimai Oct 24, 2023
ce718a2
migration metadata
souissimai Oct 30, 2023
e05d4cf
Merge branch 'get_modifications_from_metadata' of https://github.com/…
souissimai Oct 30, 2023
b099c62
merge main , resolve conflicts
souissimai Oct 30, 2023
86cc965
fix checkstyle
souissimai Oct 30, 2023
931388a
migration metadata solution
souissimai Oct 30, 2023
00eb7eb
conflicts
souissimai Oct 30, 2023
73d845a
fix
souissimai Oct 30, 2023
eb9db41
clean sql scripts
souissimai Oct 31, 2023
dff0d46
tabular modification case
souissimai Oct 31, 2023
9af610e
delete non useful sql file
souissimai Nov 2, 2023
95e053b
add tests
souissimai Nov 2, 2023
796689e
revert
souissimai Nov 2, 2023
ac795dc
put only metadata true by default
souissimai Nov 3, 2023
dc35d54
fix test
souissimai Nov 3, 2023
f754a12
Save modification type in database
SlimaneAmar Nov 3, 2023
8c23f2d
update tests
souissimai Nov 3, 2023
a62e076
Merge branch 'get_modifications_from_metadata' of https://github.com/…
souissimai Nov 3, 2023
d4d61c0
fix
souissimai Nov 3, 2023
12858cc
Merge branch 'main' into get_modifications_from_metadata
souissimai Nov 3, 2023
4114b1b
other tests
souissimai Nov 3, 2023
fafd4df
Merge branch 'get_modifications_from_metadata' of https://github.com/…
souissimai Nov 3, 2023
f2f9df9
Revert dafault value for 'onlyMetadata'
SlimaneAmar Nov 3, 2023
e59f2aa
Merge branch 'get_modifications_from_metadata' of https://github.com/…
SlimaneAmar Nov 3, 2023
8ec6c37
Remove code smell
SlimaneAmar Nov 3, 2023
09e2e08
fixes
souissimai Nov 6, 2023
5aaf7ac
Merge branch 'get_modifications_from_metadata' of https://github.com/…
souissimai Nov 6, 2023
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
Expand Up @@ -20,6 +20,9 @@
import org.gridsuite.modification.server.entities.equipment.modification.BranchStatusModificationEntity;
import org.gridsuite.modification.server.modifications.AbstractModification;
import org.gridsuite.modification.server.modifications.BranchStatusModification;
import java.util.HashMap;
import java.util.Map;

import static org.gridsuite.modification.server.NetworkModificationException.Type.BRANCH_ACTION_TYPE_EMPTY;

/**
Expand Down Expand Up @@ -88,4 +91,16 @@ public void check() {
throw new NetworkModificationException(BRANCH_ACTION_TYPE_EMPTY);
}
}

@Override
public Map<String, String> getMapMessageValues() {
Map<String, String> mapMessageValues = new HashMap<>();
mapMessageValues.put("action", getAction().name());
mapMessageValues.put("equipmentId", getEquipmentId());
if (getEnergizedVoltageLevelId() != null) {
mapMessageValues.put("energizedVoltageLevelId", getEnergizedVoltageLevelId());
}
return mapMessageValues;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import org.gridsuite.modification.server.modifications.AbstractModification;
import org.gridsuite.modification.server.modifications.DeleteAttachingLine;

import java.util.LinkedHashMap;
import java.util.Map;

/**
* @author bendaamerahm <ahmed.bendaamer at rte-france.com>
*/
Expand Down Expand Up @@ -64,4 +67,13 @@ public AbstractModification toModification() {
public Reporter createSubReporter(ReporterModel reporter) {
return reporter.createSubReporter(getType().name(), "Delete attaching line");
}

@Override
public Map<String, String> getMapMessageValues() {
Map<String, String> mapMessageValues = new LinkedHashMap<>();
souissimai marked this conversation as resolved.
Show resolved Hide resolved
mapMessageValues.put("attachedLineId", getAttachedLineId());
mapMessageValues.put("lineToAttachTo1Id", getLineToAttachTo1Id());
mapMessageValues.put("lineToAttachTo2Id", getLineToAttachTo2Id());
return mapMessageValues;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
import org.gridsuite.modification.server.modifications.AbstractModification;
import org.gridsuite.modification.server.modifications.DeleteVoltageLevelOnLine;

import java.util.LinkedHashMap;
import java.util.Map;


/**
* @author bendaamerahm <ahmed.bendaamer at rte-france.com>
Expand Down Expand Up @@ -58,4 +61,13 @@ public AbstractModification toModification() {
public Reporter createSubReporter(ReporterModel reporter) {
return reporter.createSubReporter(getType().name(), "Delete voltage level on line");
}

@Override
public Map<String, String> getMapMessageValues() {
Map<String, String> mapMessageValues = new LinkedHashMap<>();
mapMessageValues.put("lineToAttachTo1Id", getLineToAttachTo1Id());
mapMessageValues.put("lineToAttachTo2Id", getLineToAttachTo2Id());
return mapMessageValues;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.gridsuite.modification.server.modifications.EquipmentAttributeModification;
import org.springframework.lang.NonNull;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -110,6 +111,17 @@ public void check() {
}
}

@Override
public Map<String, String> getMapMessageValues() {
Map<String, String> mapMessageValues = new LinkedHashMap<>();
mapMessageValues.put("equipmentAttributeName", getEquipmentAttributeName());
mapMessageValues.put("equipmentId", getEquipmentId());
mapMessageValues.put("equipmentAttributeValue", getEquipmentAttributeValue() != null
? getEquipmentAttributeValue().toString()
: null);
return mapMessageValues;
}

private void checkSwitchStatusModificationInfos() {
if (!equipmentAttributeName.equals("open")) {
throw new NetworkModificationException(EQUIPMENT_ATTRIBUTE_NAME_ERROR, "For switch status, the attribute name is only 'open'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import lombok.ToString;
import lombok.experimental.SuperBuilder;

import java.util.Map;

/**
* @author Slimane Amar <slimane.amar at rte-france.com>
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
Expand All @@ -29,4 +31,9 @@ public class EquipmentModificationInfos extends ModificationInfos {
@Schema(description = "Equipment ID")
@NonNull
private String equipmentId;

@Override
public Map<String, String> getMapMessageValues() {
return Map.of("equipmentId", getEquipmentId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.gridsuite.modification.server.modifications.GenerationDispatch;

import java.util.List;
import java.util.Map;

/**
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
Expand Down Expand Up @@ -65,4 +66,9 @@ public AbstractModification toModification() {
public Reporter createSubReporter(ReporterModel reporter) {
return reporter.createSubReporter(getType().name(), "Generation dispatch");
}

@Override
public Map<String, String> getMapMessageValues() {
souissimai marked this conversation as resolved.
Show resolved Hide resolved
return Map.of();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.gridsuite.modification.server.entities.equipment.modification.LineAttachToVoltageLevelEntity;
import org.gridsuite.modification.server.modifications.AbstractModification;
import org.gridsuite.modification.server.modifications.LineAttachToVoltageLevel;
import java.util.Map;

/**
* @author Nicolas NOIR <nicolas.noir at rte-france.com>
Expand Down Expand Up @@ -81,4 +82,9 @@ public AbstractModification toModification() {
public Reporter createSubReporter(ReporterModel reporter) {
return reporter.createSubReporter(getType().name(), "Line attach to voltage level");
}

@Override
public Map<String, String> getMapMessageValues() {
return Map.of("lineToAttachToId", getLineToAttachToId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.gridsuite.modification.server.modifications.AbstractModification;
import org.gridsuite.modification.server.modifications.LineSplitWithVoltageLevel;

import java.util.Map;

/**
* @author Laurent GARNIER <laurent.garnier at rte-france.com>
*/
Expand Down Expand Up @@ -73,4 +75,9 @@ public AbstractModification toModification() {
public Reporter createSubReporter(ReporterModel reporter) {
return reporter.createSubReporter(getType().name(), "Line split with voltage level");
}

@Override
public Map<String, String> getMapMessageValues() {
return Map.of("lineToSplitId", getLineToSplitId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.gridsuite.modification.server.entities.equipment.modification.LinesAttachToSplitLinesEntity;
import org.gridsuite.modification.server.modifications.AbstractModification;
import org.gridsuite.modification.server.modifications.LinesAttachToSplitLines;
import java.util.Map;


/**
Expand Down Expand Up @@ -73,4 +74,9 @@ public AbstractModification toModification() {
public Reporter createSubReporter(ReporterModel reporter) {
return reporter.createSubReporter(getType().name(), "Lines attach to split lines");
}

@Override
public Map<String, String> getMapMessageValues() {
return Map.of("attachedLineId", getAttachedLineId());
}
}
souissimai marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.gridsuite.modification.server.modifications.AbstractModification;

import java.time.ZonedDateTime;
import java.util.Map;
import java.util.UUID;

/**
Expand Down Expand Up @@ -84,6 +85,12 @@ public class ModificationInfos {
@Schema(description = "Modification flag")
private Boolean stashed;

@Schema(description = "Message type")
private String messageType;
Meklo marked this conversation as resolved.
Show resolved Hide resolved

@Schema(description = "Message values")
private String messageValues;
souissimai marked this conversation as resolved.
Show resolved Hide resolved

@JsonIgnore
public ModificationEntity toEntity() {
throw new UnsupportedOperationException("TODO");
Expand All @@ -109,6 +116,11 @@ public final ModificationType getType() {
return ModificationType.valueOf(this.getClass().getAnnotation(JsonTypeName.class).value());
}

@JsonIgnore
public Map<String, String> getMapMessageValues() {
return Map.of();
}

@JsonIgnore
public void check() {
// To check input DTO before hypothesis creation. Nothing to check here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.gridsuite.modification.server.VariationType;

import java.util.List;
import java.util.Map;

/**
* @author bendaamerahm <ahmed.bendaamer at rte-france.com>
Expand All @@ -31,4 +32,10 @@ public class ScalingInfos extends ModificationInfos {

@Schema(description = "variation type")
private VariationType variationType;

@Override
public Map<String, String> getMapMessageValues() {
return Map.of("variationType", getVariationType().name());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.experimental.SuperBuilder;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author Etienne Homer <etienne.homer at rte-france.com>
Expand Down Expand Up @@ -54,4 +56,11 @@ public AbstractModification toModification() {
public Reporter createSubReporter(ReporterModel reporter) {
return reporter.createSubReporter(ModificationType.TABULAR_MODIFICATION.name(), "Tabular modification");
}

@Override
public Map<String, String> getMapMessageValues() {
Map<String, String> mapMessageValues = new HashMap<>();
mapMessageValues.put("tabularModificationType", getModificationType());
return mapMessageValues;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
*/
package org.gridsuite.modification.server.entities;

import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.SneakyThrows;
import org.gridsuite.modification.server.NetworkModificationException;
import org.gridsuite.modification.server.dto.ModificationInfos;

import jakarta.persistence.*;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
Expand Down Expand Up @@ -50,10 +52,18 @@ public class ModificationEntity {
@Column(name = "modifications_order")
private int modificationsOrder;

public ModificationEntity(UUID id, ZonedDateTime date, Boolean stashed) {
@Column(name = "message_type")
private String messageType;
souissimai marked this conversation as resolved.
Show resolved Hide resolved

@Column(name = "message_values")
private String messageValues;
Meklo marked this conversation as resolved.
Show resolved Hide resolved

public ModificationEntity(UUID id, ZonedDateTime date, Boolean stashed, String messageType, String messageValues) {
this.id = id;
this.date = date;
this.stashed = stashed;
this.messageType = messageType;
this.messageValues = messageValues;
}

protected ModificationEntity(ModificationInfos modificationInfos) {
Expand All @@ -62,13 +72,17 @@ protected ModificationEntity(ModificationInfos modificationInfos) {
}
//We need to limit the precision to avoid database precision storage limit issue (postgres has a precision of 6 digits while h2 can go to 9)
this.date = ZonedDateTime.now(ZoneOffset.UTC).truncatedTo(ChronoUnit.MICROS);

assignAttributes(modificationInfos);
}

public ModificationInfos toModificationInfos() {
return ModificationInfos.builder()
.uuid(this.id)
.date(this.date)
.stashed(this.stashed)
.messageType(this.messageType)
.messageValues(this.messageValues)
.build();
}

Expand All @@ -77,6 +91,13 @@ public void update(ModificationInfos modificationInfos) {
if (modificationInfos == null) {
throw new NullPointerException("Impossible to update entity from null DTO");
}
assignAttributes(modificationInfos);
}

@SneakyThrows
private void assignAttributes(ModificationInfos modificationInfos) {
this.setMessageType(modificationInfos.getType().name());
this.setMessageValues(new ObjectMapper().writeValueAsString(modificationInfos.getMapMessageValues()));
}

public ModificationEntity copy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public TabularModificationInfos toModificationInfos() {
.uuid(getId())
.modificationType(modificationType)
.modifications(modificationsInfos)
.messageType(getMessageType())
.messageValues(getMessageValues())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public BranchStatusModificationInfos toModificationInfos() {
.builder()
.uuid(getId())
.date(getDate())
.messageType(getMessageType())
.messageValues(getMessageValues())
.equipmentId(getEquipmentId())
.action(getAction())
.energizedVoltageLevelId(getEnergizedVoltageLevelId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public DeleteAttachingLineInfos toModificationInfos() {
.builder()
.uuid(getId())
.date(getDate())
.messageType(getMessageType())
.messageValues(getMessageValues())
.lineToAttachTo1Id(getLineToAttachTo1Id())
.lineToAttachTo2Id(getLineToAttachTo2Id())
.attachedLineId(getAttachedLineId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public DeleteVoltageLevelOnLineInfos toModificationInfos() {
.builder()
.uuid(getId())
.date(getDate())
.messageType(getMessageType())
.messageValues(getMessageValues())
.lineToAttachTo1Id(getLineToAttachTo1Id())
.lineToAttachTo2Id(getLineToAttachTo2Id())
.replacingLine1Id(getReplacingLine1Id())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
*/
package org.gridsuite.modification.server.entities.equipment.modification;

import jakarta.persistence.Column;
import jakarta.persistence.MappedSuperclass;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.gridsuite.modification.server.dto.EquipmentModificationInfos;
import org.gridsuite.modification.server.dto.ModificationInfos;
import org.gridsuite.modification.server.entities.ModificationEntity;

import jakarta.persistence.Column;
import jakarta.persistence.MappedSuperclass;

/**
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public LineAttachToVoltageLevelInfos toModificationInfos() {
.builder()
.uuid(getId())
.date(getDate())
.messageType(getMessageType())
.messageValues(getMessageValues())
.lineToAttachToId(getLineToAttachToId())
.percent(getPercent())
.attachmentPointId(getAttachmentPointId())
Expand Down
Loading
Loading