Skip to content

Commit

Permalink
Use enum for equipmentType
Browse files Browse the repository at this point in the history
Signed-off-by: BOUHOURS Antoine <[email protected]>
  • Loading branch information
antoinebhs committed Dec 19, 2023
1 parent 00dde0b commit 26db753
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.powsybl.commons.reporter.Reporter;
import com.powsybl.commons.reporter.ReporterModel;
import com.powsybl.iidm.network.IdentifiableType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -38,7 +39,7 @@
@ModificationErrorTypeName("BY_FILTER_DELETION_ERROR")
public class ByFilterDeletionInfos extends ModificationInfos {
@Schema(description = "Equipment type")
private String equipmentType;
private IdentifiableType equipmentType;

@Schema(description = "List of filters")
@JsonInclude(JsonInclude.Include.NON_NULL)
Expand All @@ -62,7 +63,7 @@ public Reporter createSubReporter(ReporterModel reporter) {
@Override
public Map<String, String> getMapMessageValues() {
Map<String, String> mapMessageValues = new HashMap<>();
mapMessageValues.put("equipmentType", getEquipmentType());
mapMessageValues.put("equipmentType", getEquipmentType().name());
return mapMessageValues;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package org.gridsuite.modification.server.entities.equipment.deletion;

import com.powsybl.iidm.network.IdentifiableType;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -28,8 +29,9 @@
@Table(name = "byFilterDeletion")
@PrimaryKeyJoinColumn(foreignKey = @ForeignKey(name = "by_filter_deletion_id_fk_constraint"))
public class ByFilterDeletionEntity extends ModificationEntity {
@Enumerated(EnumType.STRING)
@Column(name = "equipmentType")
private String equipmentType;
private IdentifiableType equipmentType;

@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
@JoinTable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ public void apply(Network network, Reporter subReporter) {
subReporter.report(Report.builder()
.withKey("equipmentDeleted")
.withDefaultMessage("equipment of type=${type} and ids=${ids} deleted")
.withValue("type", modificationInfos.getEquipmentType())
.withValue("type", modificationInfos.getEquipmentType().name())
.withValue("ids", identifiableAttributes.stream().map(IdentifiableAttributes::getId).collect(Collectors.joining(", ")))
.withSeverity(TypedValue.INFO_SEVERITY)
.build());
}
}

private void applyFilterDeletion(Network network, Reporter subReporter, List<IdentifiableAttributes> identifiableAttributes) {
IdentifiableType identifiableType = IdentifiableType.valueOf(modificationInfos.getEquipmentType());
IdentifiableType identifiableType = modificationInfos.getEquipmentType();
if (CONNECTABLE_EQUIPMENTS.contains(identifiableType)) {
identifiableAttributes.forEach(identifiableAttribute -> new RemoveFeederBay(identifiableAttribute.getId()).apply(network, true, subReporter));
} else if (identifiableType == IdentifiableType.VOLTAGE_LEVEL) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void testCreateWithErrors() throws Exception {

ByFilterDeletionInfos byFilterDeletionInfos = ByFilterDeletionInfos.builder()
.stashed(false)
.equipmentType(getIdentifiableType().toString())
.equipmentType(getIdentifiableType())
.filters(List.of(filter1))
.build();

Expand Down Expand Up @@ -98,7 +98,7 @@ public void testCreateAllFiltersWrong() throws Exception {

ByFilterDeletionInfos byFilterDeletionInfos = ByFilterDeletionInfos.builder()
.stashed(false)
.equipmentType(getIdentifiableType().toString())
.equipmentType(getIdentifiableType())
.filters(List.of(filter1))
.build();

Expand Down Expand Up @@ -154,7 +154,7 @@ protected ModificationInfos buildModification() {

return ByFilterDeletionInfos.builder()
.stashed(false)
.equipmentType(getIdentifiableType().toString())
.equipmentType(getIdentifiableType())
.filters(List.of(filter1, filter2))
.build();
}
Expand All @@ -168,7 +168,7 @@ protected ModificationInfos buildModificationUpdate() {

return ByFilterDeletionInfos.builder()
.stashed(false)
.equipmentType(getIdentifiableType().toString())
.equipmentType(getIdentifiableType())
.filters(List.of(filter2))
.build();
}
Expand All @@ -178,14 +178,14 @@ protected ModificationInfos buildModificationUpdate() {
protected void testCreationModificationMessage(ModificationInfos modificationInfos) {
assertEquals("BY_FILTER_DELETION", modificationInfos.getMessageType());
Map<String, String> createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { });
assertEquals(getIdentifiableType().toString(), createdValues.get("equipmentType"));
assertEquals(getIdentifiableType().name(), createdValues.get("equipmentType"));
}

@Override
@SneakyThrows
protected void testUpdateModificationMessage(ModificationInfos modificationInfos) {
assertEquals("BY_FILTER_DELETION", modificationInfos.getMessageType());
Map<String, String> createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { });
assertEquals(getIdentifiableType().toString(), createdValues.get("equipmentType"));
assertEquals(getIdentifiableType().name(), createdValues.get("equipmentType"));
}
}

0 comments on commit 26db753

Please sign in to comment.