Skip to content

Commit

Permalink
correct remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
thangqp committed Sep 12, 2024
1 parent 14ad0ff commit eba41e9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public ModificationByAssignmentInfos toModificationInfos() {
.stashed(getStashed())
.equipmentType(equipmentType)
.assignmentInfosList(assignmentEntities.stream()
.map(AssignmentEntity::toSimpleModificationInfos)
.map(AssignmentEntity::toAssignmentInfos)
.toList()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package org.gridsuite.modification.server.entities.equipment.modification.byfilter.simple;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.gridsuite.modification.server.dto.FilterInfos;
Expand All @@ -17,7 +18,6 @@
import org.gridsuite.modification.server.entities.equipment.modification.byfilter.AbstractAssignmentEntity;

import java.util.List;
import java.util.Optional;

/**
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
Expand All @@ -30,6 +30,7 @@ public class AssignmentEntity extends AbstractAssignmentEntity {
@Enumerated(EnumType.STRING)
private DataType dataType;

@NotNull
@Column(name = "value_") // "value" is not supported in UT with H2
private String value; // all values of different data types will be serialized as a string, deserialization is based on dataType

Expand All @@ -45,20 +46,20 @@ public class AssignmentEntity extends AbstractAssignmentEntity {
public AssignmentEntity(AssignmentInfos<?> assignmentInfos) {
super(assignmentInfos);
this.dataType = assignmentInfos.getDataType();
this.value = Optional.ofNullable(assignmentInfos.getValue()).map(Object::toString).orElse(null);
this.value = assignmentInfos.getValue().toString();
this.filters = assignmentInfos.getFilters().stream().map(FilterInfos::toEntity).toList();
}

public AssignmentInfos<?> toSimpleModificationInfos() {
public AssignmentInfos<?> toAssignmentInfos() {
AssignmentInfos<?> assignmentInfos = switch (dataType) {
case BOOLEAN -> BooleanAssignmentInfos.builder()
.value(value != null ? Boolean.valueOf(value) : null)
.value(Boolean.valueOf(value))
.build();
case INTEGER -> IntegerAssignmentInfos.builder()
.value(value != null ? Integer.valueOf(value) : null)
.value(Integer.valueOf(value))
.build();
case DOUBLE -> DoubleAssignmentInfos.builder()
.value(value != null ? Double.valueOf(value) : null)
.value(Double.valueOf(value))
.build();
case ENUM -> EnumAssignmentInfos.builder()
.value(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public abstract class AbstractModificationByAssignment extends AbstractModificat
public static final String VALUE_KEY_OLD_VALUE = "oldValue";
public static final String VALUE_KEY_NEW_VALUE = "newValue";
public static final String VALUE_KEY_MODIFICATION_TYPE_LABEL = "modificationTypeLabel";
public static final String VALUE_KEY_FILTERS_EACH_ASSIGNMENT = "filtersEachAssignment";
public static final String VALUE_KEY_ERROR_MESSAGE = "errorMessage";
public static final String REPORT_KEY_RATIO_TAP_CHANGER_EQUIPMENT_MODIFIED_ERROR = "ratioTapChangerEquipmentModifiedError";
public static final String REPORT_KEY_PHASE_TAP_CHANGER_EQUIPMENT_MODIFIED_ERROR = "phaseTapChangerEquipmentModifiedError";
Expand All @@ -65,7 +66,7 @@ public abstract class AbstractModificationByAssignment extends AbstractModificat
public static final String REPORT_KEY_EQUIPMENT_MODIFIED_REPORT = "equipmentModifiedReport";
public static final String REPORT_KEY_EQUIPMENT_MODIFIED_REPORT_EXCEPTION = "equipmentModifiedReportException";
public static final String REPORT_KEY_APPLIED_BY_FILTER_MODIFICATIONS = "appliedByFilterModifications";
public static final String REPORT_KEY_BY_FILTER_MODIFICATION = "byFilterModification";
public static final String REPORT_KEY_APPLIED_ASSIGNMENT = "appliedAssignment";
public static final String REPORT_KEY_BY_FILTER_MODIFICATION_ALL = "byFilterModificationAll";
public static final String REPORT_KEY_BY_FILTER_MODIFICATION_NONE = "byFilterModificationNone";
public static final String REPORT_KEY_BY_FILTER_MODIFICATION_NOT_FOUND = "byFilterModificationNotFound";
Expand Down Expand Up @@ -144,30 +145,31 @@ public void apply(Network network, ReportNode subReportNode) {

if (exportFilters != null) {
ReportNode subReporter = subReportNode.newReportNode()
.withMessageTemplate(REPORT_KEY_APPLIED_BY_FILTER_MODIFICATIONS, "${" + VALUE_KEY_MODIFICATION_TYPE_LABEL + "}s")
.withMessageTemplate(REPORT_KEY_APPLIED_BY_FILTER_MODIFICATIONS, "${" + VALUE_KEY_MODIFICATION_TYPE_LABEL + "}s on ${" + VALUE_KEY_EQUIPMENT_TYPE + "} type")
.withUntypedValue(VALUE_KEY_MODIFICATION_TYPE_LABEL, StringUtils.capitalize(getModificationTypeLabel()))
.withUntypedValue(VALUE_KEY_EQUIPMENT_TYPE, getEquipmentType().name())
.add();
List<ReportNode> reports = new ArrayList<>();
// perform modifications
getAssignmentInfosList().forEach(abstractAssignmentInfos ->
abstractAssignmentInfos.getFilters().forEach(filterInfos ->
applyOnFilterEquipments(network, exportFilters, reports, abstractAssignmentInfos, filterInfos)));
getAssignmentInfosList().forEach(abstractAssignmentInfos -> {
List<ReportNode> reports = new ArrayList<>();
ReportNode eachAssignmentReporter = subReporter.newReportNode()
.withMessageTemplate(REPORT_KEY_APPLIED_ASSIGNMENT, "${" + VALUE_KEY_MODIFICATION_TYPE_LABEL + "} on filters : ${" + VALUE_KEY_FILTERS_EACH_ASSIGNMENT + "}")
.withUntypedValue(VALUE_KEY_MODIFICATION_TYPE_LABEL, StringUtils.capitalize(getModificationTypeLabel()))
.withUntypedValue(VALUE_KEY_FILTERS_EACH_ASSIGNMENT, abstractAssignmentInfos.getFilters().stream().map(FilterInfos::getName)
.collect(Collectors.joining(", ")))
.add();
abstractAssignmentInfos.getFilters().forEach(filterInfos -> applyOnFilterEquipments(network, exportFilters, reports, abstractAssignmentInfos, filterInfos));
reports.forEach(report -> insertReportNode(eachAssignmentReporter, report));
});
// reporting
subReportNode.newReportNode()
.withMessageTemplate(REPORT_KEY_BY_FILTER_MODIFICATION,
"New ${" + VALUE_KEY_MODIFICATION_TYPE_LABEL + "} on ${" + VALUE_KEY_EQUIPMENT_TYPE + "}")
.withUntypedValue(VALUE_KEY_MODIFICATION_TYPE_LABEL, getModificationTypeLabel())
.withUntypedValue(VALUE_KEY_EQUIPMENT_TYPE, getEquipmentType().name())
.withSeverity(TypedValue.INFO_SEVERITY)
.add();
if (equipmentNotModifiedCount == 0 && equipmentNotFoundCount == 0) {
subReportNode.newReportNode()
.withMessageTemplate(REPORT_KEY_BY_FILTER_MODIFICATION_ALL,
"All equipment have been modified : ${" + VALUE_KEY_EQUIPMENT_COUNT + "} equipment(s)")
"All equipments have been modified : ${" + VALUE_KEY_EQUIPMENT_COUNT + "} equipment(s)")
.withUntypedValue(VALUE_KEY_EQUIPMENT_COUNT, equipmentCount)
.withSeverity(TypedValue.INFO_SEVERITY)
.add();
reports.forEach(report -> insertReportNode(subReporter, report));

} else {
if (equipmentNotModifiedCount == equipmentCount) {
createReport(subReportNode, REPORT_KEY_BY_FILTER_MODIFICATION_NONE,
Expand All @@ -181,7 +183,6 @@ public void apply(Network network, ReportNode subReportNode) {
.withUntypedValue(VALUE_KEY_NB_UNCHANGED, equipmentNotModifiedCount + equipmentNotFoundCount)
.withSeverity(TypedValue.WARN_SEVERITY)
.add();
reports.forEach(report -> insertReportNode(subReporter, report));
}
}
}
Expand Down

0 comments on commit eba41e9

Please sign in to comment.