diff --git a/src/main/java/org/gridsuite/modification/server/dto/byfilter/assignment/AssignmentInfos.java b/src/main/java/org/gridsuite/modification/server/dto/byfilter/assignment/AssignmentInfos.java index 78e5ef2d0..2dd980a66 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/byfilter/assignment/AssignmentInfos.java +++ b/src/main/java/org/gridsuite/modification/server/dto/byfilter/assignment/AssignmentInfos.java @@ -18,7 +18,7 @@ import lombok.experimental.SuperBuilder; import org.gridsuite.modification.server.dto.byfilter.AbstractAssignmentInfos; import org.gridsuite.modification.server.dto.byfilter.DataType; -import org.gridsuite.modification.server.entities.equipment.modification.byfilter.simple.AssignmentEntity; +import org.gridsuite.modification.server.entities.equipment.modification.byfilter.assignment.AssignmentEntity; /** * @author Thang PHAM diff --git a/src/main/java/org/gridsuite/modification/server/dto/byfilter/assignment/PropertyAssignmentInfos.java b/src/main/java/org/gridsuite/modification/server/dto/byfilter/assignment/PropertyAssignmentInfos.java index 993e279fc..383ed2368 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/byfilter/assignment/PropertyAssignmentInfos.java +++ b/src/main/java/org/gridsuite/modification/server/dto/byfilter/assignment/PropertyAssignmentInfos.java @@ -14,7 +14,7 @@ import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; import org.gridsuite.modification.server.dto.byfilter.DataType; -import org.gridsuite.modification.server.entities.equipment.modification.byfilter.simple.AssignmentEntity; +import org.gridsuite.modification.server.entities.equipment.modification.byfilter.assignment.AssignmentEntity; /** * @author Thang PHAM diff --git a/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/byfilter/ModificationByAssignmentEntity.java b/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/byfilter/ModificationByAssignmentEntity.java index 9c4dac376..960197583 100644 --- a/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/byfilter/ModificationByAssignmentEntity.java +++ b/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/byfilter/ModificationByAssignmentEntity.java @@ -15,7 +15,7 @@ import org.gridsuite.modification.server.dto.ModificationInfos; import org.gridsuite.modification.server.dto.byfilter.assignment.AssignmentInfos; import org.gridsuite.modification.server.entities.ModificationEntity; -import org.gridsuite.modification.server.entities.equipment.modification.byfilter.simple.AssignmentEntity; +import org.gridsuite.modification.server.entities.equipment.modification.byfilter.assignment.AssignmentEntity; import java.util.List; diff --git a/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/byfilter/simple/AssignmentEntity.java b/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/byfilter/assignment/AssignmentEntity.java similarity index 99% rename from src/main/java/org/gridsuite/modification/server/entities/equipment/modification/byfilter/simple/AssignmentEntity.java rename to src/main/java/org/gridsuite/modification/server/entities/equipment/modification/byfilter/assignment/AssignmentEntity.java index 6fd4abbb0..ae1f2ee8c 100644 --- a/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/byfilter/simple/AssignmentEntity.java +++ b/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/byfilter/assignment/AssignmentEntity.java @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.modification.server.entities.equipment.modification.byfilter.simple; +package org.gridsuite.modification.server.entities.equipment.modification.byfilter.assignment; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; diff --git a/src/main/java/org/gridsuite/modification/server/modifications/byfilter/AbstractModificationByAssignment.java b/src/main/java/org/gridsuite/modification/server/modifications/byfilter/AbstractModificationByAssignment.java index 9e2212051..6c43d6bbf 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/byfilter/AbstractModificationByAssignment.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/byfilter/AbstractModificationByAssignment.java @@ -140,10 +140,10 @@ public void apply(Network network, ReportNode subReportNode) { // collect all filters from all variations Map filters = getFilters(); - Map exportFilters = + Map filterUuidEquipmentsMap = ModificationUtils.getUuidFilterEquipmentsMap(filterService, network, subReportNode, filters, getModificationInfos().getErrorType()); - if (exportFilters != null) { + if (filterUuidEquipmentsMap != null) { ReportNode subReporter = subReportNode.newReportNode() .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())) @@ -158,7 +158,7 @@ public void apply(Network network, ReportNode subReportNode) { .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)); + abstractAssignmentInfos.getFilters().forEach(filterInfos -> applyOnFilterEquipments(network, filterUuidEquipmentsMap, reports, abstractAssignmentInfos, filterInfos)); reports.forEach(report -> insertReportNode(eachAssignmentReporter, report)); }); // reporting @@ -328,11 +328,11 @@ private Map getFilters() { } private void applyOnFilterEquipments(Network network, - Map exportFilters, + Map filterUuidEquipmentsMap, List reports, AbstractAssignmentInfos abstractAssignmentInfos, FilterInfos filterInfos) { - FilterEquipments filterEquipments = exportFilters.get(filterInfos.getId()); + FilterEquipments filterEquipments = filterUuidEquipmentsMap.get(filterInfos.getId()); if (CollectionUtils.isEmpty(filterEquipments.getIdentifiableAttributes())) { reports.add(ReportNode.newRootReportNode() diff --git a/src/main/java/org/gridsuite/modification/server/modifications/byfilter/ByFormulaModification.java b/src/main/java/org/gridsuite/modification/server/modifications/byfilter/ByFormulaModification.java index c29225cdc..d8071d983 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/byfilter/ByFormulaModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/byfilter/ByFormulaModification.java @@ -69,7 +69,8 @@ protected boolean preCheckValue(Identifiable equipment, AbstractAssignmentInf equipmentNotModifiedCount += 1; notEditableEquipments.add(equipment.getId()); reports.add(ReportNode.newRootReportNode() - .withMessageTemplate(REPORT_KEY_EQUIPMENT_MODIFIED_ERROR, " Cannot modify equipment ${" + VALUE_KEY_EQUIPMENT_NAME + "} : At least one of the value or referenced field is null") + .withMessageTemplate(REPORT_KEY_EQUIPMENT_MODIFIED_ERROR, " Cannot modify equipment ${" + + VALUE_KEY_EQUIPMENT_NAME + "} : At least one of the value or referenced field is null") .withUntypedValue(VALUE_KEY_EQUIPMENT_NAME, equipment.getId()) .withSeverity(TypedValue.TRACE_SEVERITY) .build()); @@ -79,6 +80,12 @@ protected boolean preCheckValue(Identifiable equipment, AbstractAssignmentInf if (value2 == 0 && formulaInfos.getOperator() == Operator.DIVISION) { equipmentNotModifiedCount += 1; notEditableEquipments.add(equipment.getId()); + reports.add(ReportNode.newRootReportNode() + .withMessageTemplate(REPORT_KEY_EQUIPMENT_MODIFIED_ERROR, " Cannot modify equipment ${" + + VALUE_KEY_EQUIPMENT_NAME + "} : The value or referenced field of the second operand in the division operator is zero") + .withUntypedValue(VALUE_KEY_EQUIPMENT_NAME, equipment.getId()) + .withSeverity(TypedValue.TRACE_SEVERITY) + .build()); return false; } return true; diff --git a/src/main/java/org/gridsuite/modification/server/modifications/byfilter/ModificationByAssignment.java b/src/main/java/org/gridsuite/modification/server/modifications/byfilter/ModificationByAssignment.java index 6fccbf7e5..421e6656f 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/byfilter/ModificationByAssignment.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/byfilter/ModificationByAssignment.java @@ -86,11 +86,11 @@ protected String getOldValue(Identifiable equipment, AbstractAssignmentInfos @Override protected String getNewValue(Identifiable equipment, AbstractAssignmentInfos abstractAssignmentInfos) { - AssignmentInfos simpleModificationInfos = (AssignmentInfos) abstractAssignmentInfos; - if (simpleModificationInfos.getValue() == null) { - throw new NetworkModificationException(MODIFICATION_BY_ASSIGNMENT_ERROR, "There is no value in assignment"); + AssignmentInfos assignmentInfos = (AssignmentInfos) abstractAssignmentInfos; + if (assignmentInfos.getValue() == null) { + throw new NetworkModificationException(MODIFICATION_BY_ASSIGNMENT_ERROR, "Missing a value in the assignment"); } - return simpleModificationInfos.getValue().toString(); + return assignmentInfos.getValue().toString(); } @Override diff --git a/src/main/resources/db/changelog/changesets/changelog_20240902T071959Z.xml b/src/main/resources/db/changelog/changesets/changelog_20240902T071959Z.xml deleted file mode 100644 index 81f00e3a7..000000000 --- a/src/main/resources/db/changelog/changesets/changelog_20240902T071959Z.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/AbstractModificationByAssignmentTest.java b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/AbstractModificationByAssignmentTest.java index eea2d37f9..9bb0958e2 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/AbstractModificationByAssignmentTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/AbstractModificationByAssignmentTest.java @@ -16,8 +16,8 @@ import org.gridsuite.filter.identifierlistfilter.IdentifierListFilter; import org.gridsuite.filter.identifierlistfilter.IdentifierListFilterEquipmentAttributes; import org.gridsuite.filter.utils.EquipmentType; -import org.gridsuite.modification.server.dto.ModificationByAssignmentInfos; import org.gridsuite.modification.server.dto.FilterInfos; +import org.gridsuite.modification.server.dto.ModificationByAssignmentInfos; import org.gridsuite.modification.server.dto.NetworkModificationResult; import org.gridsuite.modification.server.dto.byfilter.DataType; import org.gridsuite.modification.server.dto.byfilter.assignment.AssignmentInfos; @@ -87,25 +87,22 @@ public void testByModificationError() throws Exception { mockMvc.perform(post(getNetworkModificationUri()).content(mapper.writeValueAsString(null)).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isBadRequest()); - // Test with empty list of simple modification - checkCreationApplicationStatus(ModificationByAssignmentInfos.builder().equipmentType(getIdentifiableType()).assignmentInfosList(List.of()).build(), - NetworkModificationResult.ApplicationStatus.WITH_ERRORS); + // Test with empty list of assignment + checkCreationApplicationStatus(List.of(), NetworkModificationResult.ApplicationStatus.WITH_ERRORS); - // Test with empty list of filters in simple modification - List> simpleInfosWithNoFilters = getAssignmentInfos().stream().peek(simpleInfos -> simpleInfos.setFilters(List.of())).toList(); - checkCreationApplicationStatus(ModificationByAssignmentInfos.builder().equipmentType(getIdentifiableType()).assignmentInfosList(simpleInfosWithNoFilters).build(), - NetworkModificationResult.ApplicationStatus.WITH_ERRORS); + // Test with empty list of filters in assignment + List> assignmentsWithNoFilters = getAssignmentInfos().stream().peek(assignmentInfos -> assignmentInfos.setFilters(List.of())).toList(); + checkCreationApplicationStatus(assignmentsWithNoFilters, NetworkModificationResult.ApplicationStatus.WITH_ERRORS); // Test with editedField = null - AssignmentInfos simpleInfosWithNoEditedField = DoubleAssignmentInfos.builder() + AssignmentInfos assignmentWithNoEditedField = DoubleAssignmentInfos.builder() .value(50.) .filters(List.of()) .build(); - checkCreationApplicationStatus(ModificationByAssignmentInfos.builder().equipmentType(getIdentifiableType()).assignmentInfosList(List.of(simpleInfosWithNoEditedField)).build(), - NetworkModificationResult.ApplicationStatus.WITH_ERRORS); + checkCreationApplicationStatus(List.of(assignmentWithNoEditedField), NetworkModificationResult.ApplicationStatus.WITH_ERRORS); } - protected void checkCreateWithWarning(List> simpleInfos, List existingEquipmentList) throws Exception { + protected void checkCreateWithWarning(List> assignments, List existingEquipmentList) throws Exception { AbstractFilter filter = getFilterEquipments(FILTER_WITH_ONE_WRONG_ID, existingEquipmentList); UUID stubId = wireMockServer.stubFor(WireMock.get(WireMock.urlMatching("/v1/filters/metadata\\?ids=" + FILTER_WITH_ONE_WRONG_ID)) @@ -113,17 +110,12 @@ protected void checkCreateWithWarning(List> simpleInfos, List .withBody(mapper.writeValueAsString(List.of(filter))) .withHeader("Content-Type", "application/json"))).getId(); - ModificationByAssignmentInfos modificationByAssignmentInfos = ModificationByAssignmentInfos.builder() - .assignmentInfosList(simpleInfos) - .equipmentType(getIdentifiableType()) - .build(); - - checkCreationApplicationStatus(modificationByAssignmentInfos, NetworkModificationResult.ApplicationStatus.WITH_WARNINGS); + checkCreationApplicationStatus(assignments, NetworkModificationResult.ApplicationStatus.WITH_WARNINGS); wireMockUtils.verifyGetRequest(stubId, PATH, handleQueryParams(List.of(FILTER_WITH_ONE_WRONG_ID)), false); } - protected void checkCreateWithError(List> simpleInfos, List filterEquipments) throws Exception { + protected void checkCreateWithError(List> assignments, List filterEquipments) throws Exception { String filterIds = filterEquipments.stream() .map(AbstractFilter::getId) .map(UUID::toString) @@ -134,16 +126,11 @@ protected void checkCreateWithError(List> simpleInfos, List> simpleInfos, List> simpleInfosList = getAssignmentInfos().stream() - .peek(simpleInfos -> simpleInfos.setFilters(List.of(new FilterInfos(FILTER_WITH_ALL_WRONG_IDS, "filterWithWrongId")))) + List> assignmentsWithWrongFilter = getAssignmentInfos().stream() + .peek(assignmentInfos -> assignmentInfos.setFilters(List.of(new FilterInfos(FILTER_WITH_ALL_WRONG_IDS, "filterWithWrongId")))) .toList(); UUID stubId = wireMockServer.stubFor(WireMock.get(WireMock.urlMatching("/v1/filters/metadata\\?ids=" + FILTER_WITH_ALL_WRONG_IDS)) @@ -160,12 +147,7 @@ public void testModificationWithAllWrongEquipmentIds() throws Exception { .withBody(mapper.writeValueAsString(List.of(filter))) .withHeader("Content-Type", "application/json"))).getId(); - ModificationByAssignmentInfos modificationByAssignmentInfos = ModificationByAssignmentInfos.builder() - .assignmentInfosList(simpleInfosList) - .equipmentType(getIdentifiableType()) - .build(); - - checkCreationApplicationStatus(modificationByAssignmentInfos, NetworkModificationResult.ApplicationStatus.WITH_ERRORS); + checkCreationApplicationStatus(assignmentsWithWrongFilter, NetworkModificationResult.ApplicationStatus.WITH_ERRORS); wireMockUtils.verifyGetRequest(stubId, PATH, handleQueryParams(List.of(FILTER_WITH_ALL_WRONG_IDS)), false); } @@ -181,7 +163,7 @@ public void testCreate() throws Exception { super.testCreate(); - wireMockUtils.verifyGetRequest(stubId, PATH, handleQueryParams(filters.stream().map(AbstractFilter::getId).collect(Collectors.toList())), false); + wireMockUtils.verifyGetRequest(stubId, PATH, handleQueryParams(filters.stream().map(AbstractFilter::getId).toList()), false); } @Test @@ -195,11 +177,15 @@ public void testCopy() throws Exception { super.testCopy(); - wireMockUtils.verifyGetRequest(stubId, PATH, handleQueryParams(filters.stream().map(AbstractFilter::getId).collect(Collectors.toList())), false); + wireMockUtils.verifyGetRequest(stubId, PATH, handleQueryParams(filters.stream().map(AbstractFilter::getId).toList()), false); } - protected void checkCreationApplicationStatus(ModificationByAssignmentInfos modificationByAssignmentInfos, + protected void checkCreationApplicationStatus(List> assignmentInfos, NetworkModificationResult.ApplicationStatus applicationStatus) throws Exception { + ModificationByAssignmentInfos modificationByAssignmentInfos = ModificationByAssignmentInfos.builder() + .equipmentType(getIdentifiableType()) + .assignmentInfosList(assignmentInfos) + .build(); String modificationToCreateJson = mapper.writeValueAsString(modificationByAssignmentInfos); MvcResult mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(modificationToCreateJson).contentType(MediaType.APPLICATION_JSON)) @@ -259,14 +245,14 @@ String getPath(boolean isRegexPath) { protected abstract List getTestFilters(); protected List> getAssignmentInfos() { - PropertyAssignmentInfos spySimpleInfos = spy(PropertyAssignmentInfos.builder() + PropertyAssignmentInfos spyAssignmentInfos = spy(PropertyAssignmentInfos.builder() .editedField(DataType.PROPERTY.name()) .propertyName("propertyName") .value("propertyValue") .filters(List.of(filter1)) .build()); - doReturn(DataType.PROPERTY).when(spySimpleInfos).getDataType(); - return new ArrayList<>(List.of(spySimpleInfos)); + doReturn(DataType.PROPERTY).when(spyAssignmentInfos).getDataType(); + return new ArrayList<>(List.of(spyAssignmentInfos)); } protected abstract List> getUpdatedAssignmentInfos(); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/TwoWindingsTransformerModificationByAssignmentTest.java b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/TwoWindingsTransformerModificationByAssignmentTest.java index 50096a941..6bf3b9252 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/TwoWindingsTransformerModificationByAssignmentTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/TwoWindingsTransformerModificationByAssignmentTest.java @@ -14,11 +14,10 @@ import org.gridsuite.filter.identifierlistfilter.IdentifierListFilter; import org.gridsuite.filter.identifierlistfilter.IdentifierListFilterEquipmentAttributes; import org.gridsuite.filter.utils.EquipmentType; -import org.gridsuite.modification.server.dto.ModificationByAssignmentInfos; import org.gridsuite.modification.server.dto.NetworkModificationResult; -import org.gridsuite.modification.server.dto.byfilter.equipmentfield.TwoWindingsTransformerField; import org.gridsuite.modification.server.dto.byfilter.assignment.AssignmentInfos; import org.gridsuite.modification.server.dto.byfilter.assignment.DoubleAssignmentInfos; +import org.gridsuite.modification.server.dto.byfilter.equipmentfield.TwoWindingsTransformerField; import org.junit.Test; import java.util.Date; @@ -92,11 +91,7 @@ public void testModifyTwtWithWarning() throws Exception { .value(4.) .build(); - checkCreationApplicationStatus(ModificationByAssignmentInfos.builder() - .equipmentType(getIdentifiableType()) - .assignmentInfosList(List.of(assignmentInfos)) - .build(), - NetworkModificationResult.ApplicationStatus.WITH_WARNINGS); + checkCreationApplicationStatus(List.of(assignmentInfos), NetworkModificationResult.ApplicationStatus.WITH_WARNINGS); assertNotNull(getNetwork().getTwoWindingsTransformer(TWT_ID_1).getRatioTapChanger()); assertNotNull(getNetwork().getTwoWindingsTransformer(TWT_ID_2).getRatioTapChanger());