Skip to content

Commit

Permalink
Get modifications from metadata (#345)
Browse files Browse the repository at this point in the history
* get metadata modifications
---------

Signed-off-by: Maissa SOUISSI <[email protected]>
Co-authored-by: Slimane AMAR <[email protected]>
  • Loading branch information
souissimai and SlimaneAmar authored Nov 6, 2023
1 parent 0625ca3 commit 8d9fe7e
Show file tree
Hide file tree
Showing 66 changed files with 1,336 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public NetworkModificationController(NetworkModificationService networkModificat
@ApiResponse(responseCode = "200", description = "List of modifications of the group")
public ResponseEntity<List<ModificationInfos>> getNetworkModifications(@Parameter(description = "Group UUID") @PathVariable("groupUuid") UUID groupUuid,
@Parameter(description = "Only metadata") @RequestParam(name = "onlyMetadata", required = false, defaultValue = "false") Boolean onlyMetadata,
@Parameter(description = "Stashed modifications") @RequestParam(name = "stashed", required = false, defaultValue = "false") Boolean stashed,
@Parameter(description = "Stashed modifications") @RequestParam(name = "stashed", required = false, defaultValue = "false") Boolean stashed,
@Parameter(description = "Return 404 if group is not found or an empty list") @RequestParam(name = "errorOnGroupNotFound", required = false, defaultValue = "true") Boolean errorOnGroupNotFound) {
return ResponseEntity.ok().body(networkModificationService.getNetworkModifications(groupUuid, onlyMetadata, errorOnGroupNotFound, stashed));
}
Expand Down
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.HashMap;
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 HashMap<>();
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.HashMap;
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 HashMap<>();
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.HashMap;
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 HashMap<>();
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 @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
import com.powsybl.commons.reporter.Reporter;
import com.powsybl.commons.reporter.ReporterModel;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.gridsuite.modification.server.ModificationType;
import org.gridsuite.modification.server.NetworkModificationException;
Expand All @@ -25,14 +22,17 @@
import org.gridsuite.modification.server.modifications.AbstractModification;

import java.time.ZonedDateTime;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;

/**
* @author Slimane Amar <slimane.amar at rte-france.com>
*/
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
property = "type"
property = "type",
include = JsonTypeInfo.As.EXISTING_PROPERTY
)
@JsonSubTypes({
@JsonSubTypes.Type(value = GroovyScriptInfos.class),
Expand Down Expand Up @@ -78,12 +78,35 @@ public class ModificationInfos {
@Schema(description = "Modification id")
private UUID uuid;

@Schema(description = "Modification type")
@Setter(AccessLevel.NONE)
private final AtomicReference<ModificationType> type = new AtomicReference<>(null); // Only accessor (automatically initialized)

@Schema(description = "Modification date")
private ZonedDateTime date;

@Schema(description = "Modification flag")
private Boolean stashed;

@Schema(description = "Message type")
private String messageType;

@Schema(description = "Message values")
private String messageValues;

// Only for metadata
public static ModificationInfos fromEntity(@NonNull ModificationEntity entity) {
ModificationInfos modificationInfos = ModificationInfos.builder()
.uuid(entity.getId())
.date(entity.getDate())
.stashed(entity.getStashed())
.messageType(entity.getMessageType())
.messageValues(entity.getMessageValues())
.build();
modificationInfos.type.set(ModificationType.valueOf(entity.getType()));
return modificationInfos;
}

@JsonIgnore
public ModificationEntity toEntity() {
throw new UnsupportedOperationException("TODO");
Expand All @@ -104,9 +127,13 @@ public final NetworkModificationException.Type getErrorType() {
return NetworkModificationException.Type.valueOf(this.getClass().getAnnotation(ModificationErrorTypeName.class).value());
}

@JsonIgnore
public final ModificationType getType() {
return ModificationType.valueOf(this.getClass().getAnnotation(JsonTypeName.class).value());
return type.get() != null ? type.get() : ModificationType.valueOf(this.getClass().getAnnotation(JsonTypeName.class).value());
}

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

@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ public class ScalingInfos extends ModificationInfos {

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

}
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 All @@ -36,6 +38,9 @@ public class ModificationEntity {
@Column(name = "id")
private UUID id;

@Column(name = "type")
private String type;

@Column(name = "date")
private ZonedDateTime date;

Expand All @@ -50,10 +55,19 @@ 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;

@Column(name = "message_values")
private String messageValues;

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

protected ModificationEntity(ModificationInfos modificationInfos) {
Expand All @@ -62,21 +76,27 @@ 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)
.build();
return ModificationInfos.fromEntity(this);
}

public void update(ModificationInfos modificationInfos) {
// Basic attributes are immutable in the database
if (modificationInfos == null) {
throw new NullPointerException("Impossible to update entity from null DTO");
}
assignAttributes(modificationInfos);
}

@SneakyThrows
private void assignAttributes(ModificationInfos modificationInfos) {
this.setType(modificationInfos.getType().name());
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 @@ -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
Loading

0 comments on commit 8d9fe7e

Please sign in to comment.