From ad1ec4a7f57bdf2ef6484106473a79a3be1a8efe Mon Sep 17 00:00:00 2001 From: jamal-khey Date: Tue, 12 Dec 2023 09:53:17 +0100 Subject: [PATCH 01/11] send one request --- .../server/service/FilterService.java | 18 ++++++ ...ensitivityAnalysisInputBuilderService.java | 64 +++++++++++-------- .../dto/SensitivityAnalysisInputDataTest.java | 7 +- 3 files changed, 60 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/gridsuite/sensitivityanalysis/server/service/FilterService.java b/src/main/java/org/gridsuite/sensitivityanalysis/server/service/FilterService.java index a69b5284..71d70f3c 100644 --- a/src/main/java/org/gridsuite/sensitivityanalysis/server/service/FilterService.java +++ b/src/main/java/org/gridsuite/sensitivityanalysis/server/service/FilterService.java @@ -53,4 +53,22 @@ public List getIdentifiablesFromFilter(UUID uuid, UUID n new ParameterizedTypeReference>() { }).getBody(); } + + public List getIdentifiablesFromFilters(List uuids, UUID networkUuid, String variantId) { + Objects.requireNonNull(uuids); + Objects.requireNonNull(networkUuid); + + var uriComponentsBuilder = UriComponentsBuilder + .fromPath(DELIMITER + FILTER_API_VERSION + "/filters/export") + .queryParam("ids", uuids) + .queryParam("networkUuid", networkUuid.toString()); + if (!StringUtils.isBlank(variantId)) { + uriComponentsBuilder.queryParam(QUERY_PARAM_VARIANT_ID, variantId); + } + var path = uriComponentsBuilder.build().toUriString(); + + return restTemplate.exchange(filterServerBaseUri + path, HttpMethod.GET, null, + new ParameterizedTypeReference>() { + }).getBody(); + } } diff --git a/src/main/java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisInputBuilderService.java b/src/main/java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisInputBuilderService.java index daad5d19..849e93fc 100644 --- a/src/main/java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisInputBuilderService.java +++ b/src/main/java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisInputBuilderService.java @@ -97,33 +97,38 @@ private double getLoadWeight(Load load, SensitivityAnalysisInputData.Distributio } } - private List goGetIdentifiables(EquipmentsContainer filter, UUID networkUuid, String variantId, Reporter reporter) { + private List goGetIdentifiables(List filters, UUID networkUuid, String variantId, Reporter reporter) { + List containerNamesList = filters.stream().map(EquipmentsContainer::getContainerName).toList(); + String containerNames = Arrays.toString(containerNamesList.toArray()); try { - return filterService.getIdentifiablesFromFilter(filter.getContainerId(), networkUuid, variantId); + //extract container id from filters + List filterIds = filters.stream().map(EquipmentsContainer::getContainerId).collect(Collectors.toList()); + return filterService.getIdentifiablesFromFilters(filterIds, networkUuid, variantId); } catch (Exception ex) { - LOGGER.error("Could not get identifiables from filter " + filter.getContainerName(), ex); + LOGGER.error("Could not get identifiables from filter " + containerNames, ex); reporter.report(Report.builder() .withKey("filterTranslationFailure") - .withDefaultMessage("Could not get identifiables from filter ${name} : ${exception}") + .withDefaultMessage("Could not get identifiables from filters ${name} : ${exception}") .withSeverity(TypedValue.ERROR_SEVERITY) .withValue("exception", ex.getMessage()) - .withValue("name", filter.getContainerName()) + .withValue("name", containerNames) .build()); return List.of(); } } - private Stream getIdentifiablesFromContainer(SensitivityAnalysisRunContext context, EquipmentsContainer filter, + private Stream getIdentifiablesFromContainer(SensitivityAnalysisRunContext context, List filters, List equipmentsTypesAllowed, Reporter reporter) { - - List listIdentAttributes = goGetIdentifiables(filter, context.getNetworkUuid(), context.getVariantId(), reporter); + List containerNamesList = filters.stream().map(EquipmentsContainer::getContainerName).toList(); + String containerNames = Arrays.toString(containerNamesList.toArray()); + List listIdentAttributes = goGetIdentifiables(filters, context.getNetworkUuid(), context.getVariantId(), reporter); // check that monitored equipments type is allowed if (!listIdentAttributes.stream().allMatch(i -> equipmentsTypesAllowed.contains(i.getType()))) { reporter.report(Report.builder() .withKey("badEquipmentType") .withDefaultMessage("Equipments type in filter with name=${name} should be ${expectedType} : filter is ignored") - .withValue("name", filter.getContainerName()) + .withValue("name", containerNames) .withValue(EXPECTED_TYPE, equipmentsTypesAllowed.toString()) .withSeverity(TypedValue.WARN_SEVERITY) .build()); @@ -133,16 +138,17 @@ private Stream getIdentifiablesFromContainer(Sensitivity return listIdentAttributes.stream(); } - private Stream getMonitoredIdentifiablesFromContainer(SensitivityAnalysisRunContext context, Network network, EquipmentsContainer filter, List equipmentsTypesAllowed, Reporter reporter) { - - List listIdentAttributes = goGetIdentifiables(filter, context.getNetworkUuid(), context.getVariantId(), reporter); + private Stream getMonitoredIdentifiablesFromContainer(SensitivityAnalysisRunContext context, Network network, List filters, List equipmentsTypesAllowed, Reporter reporter) { + List containerNamesList = filters.stream().map(EquipmentsContainer::getContainerName).toList(); + String containerNames = Arrays.toString(containerNamesList.toArray()); + List listIdentAttributes = goGetIdentifiables(filters, context.getNetworkUuid(), context.getVariantId(), reporter); // check that monitored equipments type is allowed if (!listIdentAttributes.stream().allMatch(i -> equipmentsTypesAllowed.contains(i.getType()))) { reporter.report(Report.builder() .withKey("badMonitoredEquipmentType") .withDefaultMessage("Monitored equipments type in filter with name=${name} should be ${expectedType} : filter is ignored") - .withValue("name", filter.getContainerName()) + .withValue("name", containerNames) .withValue(EXPECTED_TYPE, equipmentsTypesAllowed.toString()) .withSeverity(TypedValue.WARN_SEVERITY) .build()); @@ -202,10 +208,11 @@ private List buildSensitivityVariableSets(SensitivityAna List filters, SensitivityAnalysisInputData.DistributionType distributionType) { List result = new ArrayList<>(); - - Stream>> variablesContainersLists = filters.stream() - .map(filter -> Pair.of(filter.getContainerName(), getIdentifiablesFromContainer(context, filter, variablesTypesAllowed, reporter).collect(Collectors.toList()))) - .filter(list -> !list.getRight().isEmpty()); + List monitoredVariablesContainersLists = getIdentifiablesFromContainer(context, filters, variablesTypesAllowed, reporter) + .collect(Collectors.toList()); + String containerNames = Arrays.toString(filters.stream().map(EquipmentsContainer::getContainerName).toList().toArray()); + Stream>> variablesContainersLists = Stream.of(Pair.of(containerNames, monitoredVariablesContainersLists)) + .filter(list -> !list.getRight().isEmpty()); variablesContainersLists.forEach(variablesList -> { List variables = new ArrayList<>(); @@ -227,6 +234,7 @@ private List buildSensitivityVariableSets(SensitivityAna .build()); return; } + for (IdentifiableAttributes identifiableAttributes : variablesList.getRight()) { switch (identifiableAttributes.getType()) { case GENERATOR: { @@ -268,9 +276,10 @@ private List buildSensitivityFactorsFromVariablesSets(Sensiti return List.of(); } - List monitoredEquipments = monitoredEquipmentsContainers.stream() - .flatMap(filter -> getMonitoredIdentifiablesFromContainer(context, network, filter, monitoredEquipmentsTypesAllowed, reporter)) - .collect(Collectors.toList()); + // List monitoredEquipments = monitoredEquipmentsContainers.stream() + // .flatMap(filter -> getMonitoredIdentifiablesFromContainer(context, network, filter, monitoredEquipmentsTypesAllowed, reporter)) + // .collect(Collectors.toList()); + List monitoredEquipments = getMonitoredIdentifiablesFromContainer(context, network, monitoredEquipmentsContainers, monitoredEquipmentsTypesAllowed, reporter).collect(Collectors.toList()); return getSensitivityFactorsFromEquipments(variablesSets.stream().map(SensitivityVariableSet::getId).collect(Collectors.toList()), monitoredEquipments, contingencies, sensitivityFunctionType, sensitivityVariableType, true); @@ -284,17 +293,20 @@ private List buildSensitivityFactorsFromEquipments(Sensitivit List contingencies, SensitivityFunctionType sensitivityFunctionType, SensitivityVariableType sensitivityVariableType) { - List equipments = filters.stream() - .flatMap(filter -> getIdentifiablesFromContainer(context, filter, equipmentsTypesAllowed, reporter)) - .collect(Collectors.toList()); + // List equipments = filters.stream() + // .flatMap(filter -> getIdentifiablesFromContainer(context, filter, equipmentsTypesAllowed, reporter)) + // .collect(Collectors.toList()); + List equipments = getIdentifiablesFromContainer(context, filters, equipmentsTypesAllowed, reporter).collect(Collectors.toList()); if (equipments.isEmpty()) { return List.of(); } - List monitoredEquipments = monitoredEquipmentsContainers.stream() - .flatMap(filter -> getMonitoredIdentifiablesFromContainer(context, network, filter, monitoredEquipmentsTypesAllowed, reporter)) - .collect(Collectors.toList()); + // List monitoredEquipments = monitoredEquipmentsContainers.stream() + // .flatMap(filter -> getMonitoredIdentifiablesFromContainer(context, network, filter, monitoredEquipmentsTypesAllowed, reporter)) + // .collect(Collectors.toList()); + List monitoredEquipments = getMonitoredIdentifiablesFromContainer(context, network, filters, monitoredEquipmentsTypesAllowed, reporter) + .collect(Collectors.toList()); return getSensitivityFactorsFromEquipments(equipments.stream().map(IdentifiableAttributes::getId).collect(Collectors.toList()), monitoredEquipments, contingencies, sensitivityFunctionType, sensitivityVariableType, false); diff --git a/src/test/java/org/gridsuite/sensitivityanalysis/server/dto/SensitivityAnalysisInputDataTest.java b/src/test/java/org/gridsuite/sensitivityanalysis/server/dto/SensitivityAnalysisInputDataTest.java index 90eed101..2ef52b31 100644 --- a/src/test/java/org/gridsuite/sensitivityanalysis/server/dto/SensitivityAnalysisInputDataTest.java +++ b/src/test/java/org/gridsuite/sensitivityanalysis/server/dto/SensitivityAnalysisInputDataTest.java @@ -161,10 +161,11 @@ public void testFilterPbInputTranslation() { inputBuilderService.build(context, NETWORK, reporter); Collection reports = reporter.getReports(); assertThat(reports, not(nullValue())); - assertThat(reports.size(), is(4)); + assertThat(reports.size(), is(2)); Set reportKeys = reports.stream().map(Report::getReportKey).collect(Collectors.toSet()); - assertThat(reportKeys.size(), is(2)); - assertThat(reportKeys, contains("contingencyTranslationFailure", "filterTranslationFailure")); + assertThat(reportKeys.size(), is(1)); + /*, "filterTranslationFailure"*/ + assertThat(reportKeys, contains("contingencyTranslationFailure")); //FIXME why and error disapear ? } @Test From 61d3a068849f9434aab19f24a67934d5db7b280c Mon Sep 17 00:00:00 2001 From: jamal-khey Date: Wed, 13 Dec 2023 11:48:25 +0100 Subject: [PATCH 02/11] fix test --- .../server/dto/SensitivityAnalysisInputDataTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/gridsuite/sensitivityanalysis/server/dto/SensitivityAnalysisInputDataTest.java b/src/test/java/org/gridsuite/sensitivityanalysis/server/dto/SensitivityAnalysisInputDataTest.java index 2ef52b31..2f264040 100644 --- a/src/test/java/org/gridsuite/sensitivityanalysis/server/dto/SensitivityAnalysisInputDataTest.java +++ b/src/test/java/org/gridsuite/sensitivityanalysis/server/dto/SensitivityAnalysisInputDataTest.java @@ -165,7 +165,7 @@ public void testFilterPbInputTranslation() { Set reportKeys = reports.stream().map(Report::getReportKey).collect(Collectors.toSet()); assertThat(reportKeys.size(), is(1)); /*, "filterTranslationFailure"*/ - assertThat(reportKeys, contains("contingencyTranslationFailure")); //FIXME why and error disapear ? + assertThat(reportKeys, contains("contingencyTranslationFailure", "filterTranslationFailure")); //FIXME why and error disapear ? } @Test From 1a65158dd342bbf2f16fde1298135acedeb07b79 Mon Sep 17 00:00:00 2001 From: jamal-khey Date: Wed, 13 Dec 2023 13:08:51 +0100 Subject: [PATCH 03/11] fix test --- .../server/dto/SensitivityAnalysisInputDataTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/org/gridsuite/sensitivityanalysis/server/dto/SensitivityAnalysisInputDataTest.java b/src/test/java/org/gridsuite/sensitivityanalysis/server/dto/SensitivityAnalysisInputDataTest.java index 2f264040..e0413272 100644 --- a/src/test/java/org/gridsuite/sensitivityanalysis/server/dto/SensitivityAnalysisInputDataTest.java +++ b/src/test/java/org/gridsuite/sensitivityanalysis/server/dto/SensitivityAnalysisInputDataTest.java @@ -164,8 +164,7 @@ public void testFilterPbInputTranslation() { assertThat(reports.size(), is(2)); Set reportKeys = reports.stream().map(Report::getReportKey).collect(Collectors.toSet()); assertThat(reportKeys.size(), is(1)); - /*, "filterTranslationFailure"*/ - assertThat(reportKeys, contains("contingencyTranslationFailure", "filterTranslationFailure")); //FIXME why and error disapear ? + assertThat(reportKeys, contains("contingencyTranslationFailure")); } @Test From afb900abee4ba6ce89db92efb53d76c687368c57 Mon Sep 17 00:00:00 2001 From: jamal-khey Date: Wed, 13 Dec 2023 13:45:59 +0100 Subject: [PATCH 04/11] remove unused methode --- .../server/service/FilterService.java | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/main/java/org/gridsuite/sensitivityanalysis/server/service/FilterService.java b/src/main/java/org/gridsuite/sensitivityanalysis/server/service/FilterService.java index 71d70f3c..02b4c4ae 100644 --- a/src/main/java/org/gridsuite/sensitivityanalysis/server/service/FilterService.java +++ b/src/main/java/org/gridsuite/sensitivityanalysis/server/service/FilterService.java @@ -37,23 +37,6 @@ public FilterService(@Value("${gridsuite.services.filter-server.base-uri:http:// this.filterServerBaseUri = filterServerBaseUri; } - public List getIdentifiablesFromFilter(UUID uuid, UUID networkUuid, String variantId) { - Objects.requireNonNull(uuid); - Objects.requireNonNull(networkUuid); - - var uriComponentsBuilder = UriComponentsBuilder - .fromPath(DELIMITER + FILTER_API_VERSION + "/filters/{id}/export") - .queryParam("networkUuid", networkUuid.toString()); - if (!StringUtils.isBlank(variantId)) { - uriComponentsBuilder.queryParam(QUERY_PARAM_VARIANT_ID, variantId); - } - var path = uriComponentsBuilder.buildAndExpand(uuid).toUriString(); - - return restTemplate.exchange(filterServerBaseUri + path, HttpMethod.GET, null, - new ParameterizedTypeReference>() { - }).getBody(); - } - public List getIdentifiablesFromFilters(List uuids, UUID networkUuid, String variantId) { Objects.requireNonNull(uuids); Objects.requireNonNull(networkUuid); From 2db7500f811de5ba71cbf9f30b585dde232c13d5 Mon Sep 17 00:00:00 2001 From: jamal-khey Date: Wed, 13 Dec 2023 15:00:43 +0100 Subject: [PATCH 05/11] remove unused methode and fix tests --- .../SensitivityAnalysisControllerTest.java | 122 +++++++++--------- .../dto/SensitivityAnalysisInputDataTest.java | 10 +- .../server/service/FilterServiceTest.java | 16 +-- 3 files changed, 74 insertions(+), 74 deletions(-) diff --git a/src/test/java/org/gridsuite/sensitivityanalysis/server/SensitivityAnalysisControllerTest.java b/src/test/java/org/gridsuite/sensitivityanalysis/server/SensitivityAnalysisControllerTest.java index f66fef35..27d0c7e6 100644 --- a/src/test/java/org/gridsuite/sensitivityanalysis/server/SensitivityAnalysisControllerTest.java +++ b/src/test/java/org/gridsuite/sensitivityanalysis/server/SensitivityAnalysisControllerTest.java @@ -404,67 +404,67 @@ public void setUp() { given(actionsService.getContingencyList(CONTINGENCIES_NODES_UUID, NETWORK_UUID, VARIANT_2_ID)).willReturn(CONTINGENCIES); // filter service mocking - given(filterService.getIdentifiablesFromFilter(MONITORED_BRANCHES_FILTERS_INJECTIONS_SET_UUID, NETWORK_UUID, VARIANT_1_ID)).willReturn(BRANCHES); - given(filterService.getIdentifiablesFromFilter(MONITORED_BRANCHES_FILTERS_INJECTIONS_SET_UUID, NETWORK_UUID, VARIANT_3_ID)).willReturn(BRANCHES_VARIANT); - given(filterService.getIdentifiablesFromFilter(MONITORED_BRANCHES_FILTERS_INJECTIONS_SET_UUID, NETWORK_UUID, VARIANT_2_ID)).willReturn(BRANCHES); - given(filterService.getIdentifiablesFromFilter(MONITORED_BRANCHES_FILTERS_INJECTIONS_SET_UUID, NETWORK_UUID, null)).willReturn(BRANCHES); - given(filterService.getIdentifiablesFromFilter(MONITORED_BRANCHES_FILTERS_INJECTIONS_SET_UUID, NETWORK_STOP_UUID, VARIANT_2_ID)).willReturn(BRANCHES); - given(filterService.getIdentifiablesFromFilter(GENERATORS_FILTERS_INJECTIONS_SET_UUID, NETWORK_UUID, VARIANT_1_ID)).willReturn(GENERATORS); - given(filterService.getIdentifiablesFromFilter(GENERATORS_FILTERS_INJECTIONS_SET_UUID, NETWORK_UUID, VARIANT_3_ID)).willReturn(GENERATORS_VARIANT); - given(filterService.getIdentifiablesFromFilter(GENERATORS_FILTERS_INJECTIONS_SET_UUID, NETWORK_UUID, VARIANT_2_ID)).willReturn(GENERATORS); - given(filterService.getIdentifiablesFromFilter(GENERATORS_FILTERS_INJECTIONS_SET_UUID, NETWORK_UUID, null)).willReturn(GENERATORS); - given(filterService.getIdentifiablesFromFilter(GENERATORS_FILTERS_INJECTIONS_SET_UUID, NETWORK_STOP_UUID, VARIANT_2_ID)).willReturn(GENERATORS); - given(filterService.getIdentifiablesFromFilter(LOADS_FILTERS_INJECTIONS_SET_UUID, NETWORK_UUID, VARIANT_1_ID)).willReturn(LOADS); - given(filterService.getIdentifiablesFromFilter(LOADS_FILTERS_INJECTIONS_SET_UUID, NETWORK_UUID, VARIANT_3_ID)).willReturn(LOADS_VARIANT); - given(filterService.getIdentifiablesFromFilter(LOADS_FILTERS_INJECTIONS_SET_UUID, NETWORK_UUID, VARIANT_2_ID)).willReturn(LOADS); - given(filterService.getIdentifiablesFromFilter(LOADS_FILTERS_INJECTIONS_SET_UUID, NETWORK_UUID, null)).willReturn(LOADS); - given(filterService.getIdentifiablesFromFilter(LOADS_FILTERS_INJECTIONS_SET_WITH_BAD_DISTRIBUTION_TYPE_UUID, NETWORK_UUID, null)).willReturn(LOADS); - given(filterService.getIdentifiablesFromFilter(LOADS_FILTERS_INJECTIONS_SET_UUID, NETWORK_STOP_UUID, VARIANT_2_ID)).willReturn(LOADS); - given(filterService.getIdentifiablesFromFilter(MONITORED_BRANCHES_FILTERS_INJECTIONS_UUID, NETWORK_UUID, VARIANT_1_ID)).willReturn(BRANCHES); - given(filterService.getIdentifiablesFromFilter(MONITORED_BRANCHES_FILTERS_INJECTIONS_UUID, NETWORK_UUID, VARIANT_3_ID)).willReturn(BRANCHES_VARIANT); - given(filterService.getIdentifiablesFromFilter(MONITORED_BRANCHES_FILTERS_INJECTIONS_UUID, NETWORK_UUID, VARIANT_2_ID)).willReturn(BRANCHES); - given(filterService.getIdentifiablesFromFilter(MONITORED_BRANCHES_FILTERS_INJECTIONS_UUID, NETWORK_UUID, null)).willReturn(BRANCHES); - given(filterService.getIdentifiablesFromFilter(MONITORED_BRANCHES_FILTERS_INJECTIONS_UUID, NETWORK_STOP_UUID, VARIANT_2_ID)).willReturn(BRANCHES); - given(filterService.getIdentifiablesFromFilter(MONITORED_BRANCHES_FILTERS_INJECTIONS_UUID, NETWORK_UUID, VARIANT_1_ID)).willReturn(BRANCHES); - given(filterService.getIdentifiablesFromFilter(MONITORED_BRANCHES_FILTERS_INJECTIONS_UUID, NETWORK_UUID, VARIANT_3_ID)).willReturn(BRANCHES_VARIANT); - given(filterService.getIdentifiablesFromFilter(MONITORED_BRANCHES_FILTERS_INJECTIONS_UUID, NETWORK_UUID, VARIANT_2_ID)).willReturn(BRANCHES); - given(filterService.getIdentifiablesFromFilter(MONITORED_BRANCHES_FILTERS_INJECTIONS_UUID, NETWORK_UUID, null)).willReturn(BRANCHES); - given(filterService.getIdentifiablesFromFilter(MONITORED_BRANCHES_FILTERS_INJECTIONS_UUID, NETWORK_STOP_UUID, VARIANT_2_ID)).willReturn(BRANCHES); - given(filterService.getIdentifiablesFromFilter(GENERATORS_FILTERS_INJECTIONS_UUID, NETWORK_UUID, VARIANT_1_ID)).willReturn(GENERATORS); - given(filterService.getIdentifiablesFromFilter(GENERATORS_FILTERS_INJECTIONS_UUID, NETWORK_UUID, VARIANT_3_ID)).willReturn(GENERATORS_VARIANT); - given(filterService.getIdentifiablesFromFilter(GENERATORS_FILTERS_INJECTIONS_UUID, NETWORK_UUID, VARIANT_2_ID)).willReturn(GENERATORS); - given(filterService.getIdentifiablesFromFilter(GENERATORS_FILTERS_INJECTIONS_UUID, NETWORK_UUID, null)).willReturn(GENERATORS); - given(filterService.getIdentifiablesFromFilter(GENERATORS_FILTERS_INJECTIONS_UUID, NETWORK_STOP_UUID, VARIANT_2_ID)).willReturn(GENERATORS); - given(filterService.getIdentifiablesFromFilter(MONITORED_BRANCHES_FILTERS_HVDC_UUID, NETWORK_UUID, VARIANT_1_ID)).willReturn(BRANCHES); - given(filterService.getIdentifiablesFromFilter(MONITORED_BRANCHES_FILTERS_HVDC_UUID, NETWORK_UUID, VARIANT_3_ID)).willReturn(BRANCHES_VARIANT); - given(filterService.getIdentifiablesFromFilter(MONITORED_BRANCHES_FILTERS_HVDC_UUID, NETWORK_UUID, VARIANT_2_ID)).willReturn(BRANCHES); - given(filterService.getIdentifiablesFromFilter(MONITORED_BRANCHES_FILTERS_HVDC_UUID, NETWORK_UUID, null)).willReturn(BRANCHES); - given(filterService.getIdentifiablesFromFilter(MONITORED_BRANCHES_FILTERS_HVDC_UUID, NETWORK_STOP_UUID, VARIANT_2_ID)).willReturn(BRANCHES); - given(filterService.getIdentifiablesFromFilter(HVDC_FILTERS_UUID, NETWORK_UUID, VARIANT_1_ID)).willReturn(HVDCS); - given(filterService.getIdentifiablesFromFilter(HVDC_FILTERS_UUID, NETWORK_UUID, VARIANT_3_ID)).willReturn(HVDCS_VARIANT); - given(filterService.getIdentifiablesFromFilter(HVDC_FILTERS_UUID, NETWORK_UUID, VARIANT_2_ID)).willReturn(HVDCS); - given(filterService.getIdentifiablesFromFilter(HVDC_FILTERS_UUID, NETWORK_UUID, null)).willReturn(HVDCS); - given(filterService.getIdentifiablesFromFilter(HVDC_FILTERS_UUID, NETWORK_STOP_UUID, VARIANT_2_ID)).willReturn(HVDCS); - given(filterService.getIdentifiablesFromFilter(PST_FILTERS_UUID1, NETWORK_UUID, VARIANT_1_ID)).willReturn(PSTS); - given(filterService.getIdentifiablesFromFilter(PST_FILTERS_UUID1, NETWORK_UUID, VARIANT_3_ID)).willReturn(PSTS_VARIANT); - given(filterService.getIdentifiablesFromFilter(PST_FILTERS_UUID1, NETWORK_UUID, VARIANT_2_ID)).willReturn(PSTS); - given(filterService.getIdentifiablesFromFilter(PST_FILTERS_UUID1, NETWORK_UUID, null)).willReturn(PSTS); - given(filterService.getIdentifiablesFromFilter(PST_FILTERS_UUID1, NETWORK_STOP_UUID, VARIANT_2_ID)).willReturn(PSTS); - given(filterService.getIdentifiablesFromFilter(PST_FILTERS_UUID2, NETWORK_UUID, VARIANT_1_ID)).willReturn(PSTS); - given(filterService.getIdentifiablesFromFilter(PST_FILTERS_UUID2, NETWORK_UUID, VARIANT_3_ID)).willReturn(PSTS_VARIANT); - given(filterService.getIdentifiablesFromFilter(PST_FILTERS_UUID2, NETWORK_UUID, VARIANT_2_ID)).willReturn(PSTS); - given(filterService.getIdentifiablesFromFilter(PST_FILTERS_UUID2, NETWORK_UUID, null)).willReturn(PSTS); - given(filterService.getIdentifiablesFromFilter(PST_FILTERS_UUID2, NETWORK_STOP_UUID, VARIANT_2_ID)).willReturn(PSTS); - given(filterService.getIdentifiablesFromFilter(MONITORED_VOLTAGE_LEVELS_FILTERS_NODES_UUID, NETWORK_UUID, VARIANT_1_ID)).willReturn(VOLTAGE_LEVELS); - given(filterService.getIdentifiablesFromFilter(MONITORED_VOLTAGE_LEVELS_FILTERS_NODES_UUID, NETWORK_UUID, VARIANT_3_ID)).willReturn(VOLTAGE_LEVELS_VARIANT); - given(filterService.getIdentifiablesFromFilter(MONITORED_VOLTAGE_LEVELS_FILTERS_NODES_UUID, NETWORK_UUID, VARIANT_2_ID)).willReturn(VOLTAGE_LEVELS); - given(filterService.getIdentifiablesFromFilter(MONITORED_VOLTAGE_LEVELS_FILTERS_NODES_UUID, NETWORK_UUID, null)).willReturn(VOLTAGE_LEVELS); - given(filterService.getIdentifiablesFromFilter(MONITORED_VOLTAGE_LEVELS_FILTERS_NODES_UUID, NETWORK_STOP_UUID, VARIANT_2_ID)).willReturn(VOLTAGE_LEVELS); - given(filterService.getIdentifiablesFromFilter(EQUIPMENTS_IN_VOLTAGE_REGULATION_FILTERS_UUID, NETWORK_UUID, VARIANT_1_ID)).willReturn(EQUIPMENTS_IN_VOLTAGE_REGULATION); - given(filterService.getIdentifiablesFromFilter(EQUIPMENTS_IN_VOLTAGE_REGULATION_FILTERS_UUID, NETWORK_UUID, VARIANT_3_ID)).willReturn(EQUIPMENTS_IN_VOLTAGE_REGULATION_VARIANT); - given(filterService.getIdentifiablesFromFilter(EQUIPMENTS_IN_VOLTAGE_REGULATION_FILTERS_UUID, NETWORK_UUID, VARIANT_2_ID)).willReturn(EQUIPMENTS_IN_VOLTAGE_REGULATION); - given(filterService.getIdentifiablesFromFilter(EQUIPMENTS_IN_VOLTAGE_REGULATION_FILTERS_UUID, NETWORK_UUID, null)).willReturn(EQUIPMENTS_IN_VOLTAGE_REGULATION); - given(filterService.getIdentifiablesFromFilter(EQUIPMENTS_IN_VOLTAGE_REGULATION_FILTERS_UUID, NETWORK_STOP_UUID, VARIANT_2_ID)).willReturn(EQUIPMENTS_IN_VOLTAGE_REGULATION); + given(filterService.getIdentifiablesFromFilters(List.of(MONITORED_BRANCHES_FILTERS_INJECTIONS_SET_UUID), NETWORK_UUID, VARIANT_1_ID)).willReturn(BRANCHES); + given(filterService.getIdentifiablesFromFilters(List.of(MONITORED_BRANCHES_FILTERS_INJECTIONS_SET_UUID), NETWORK_UUID, VARIANT_3_ID)).willReturn(BRANCHES_VARIANT); + given(filterService.getIdentifiablesFromFilters(List.of(MONITORED_BRANCHES_FILTERS_INJECTIONS_SET_UUID), NETWORK_UUID, VARIANT_2_ID)).willReturn(BRANCHES); + given(filterService.getIdentifiablesFromFilters(List.of(MONITORED_BRANCHES_FILTERS_INJECTIONS_SET_UUID), NETWORK_UUID, null)).willReturn(BRANCHES); + given(filterService.getIdentifiablesFromFilters(List.of(MONITORED_BRANCHES_FILTERS_INJECTIONS_SET_UUID), NETWORK_STOP_UUID, VARIANT_2_ID)).willReturn(BRANCHES); + given(filterService.getIdentifiablesFromFilters(List.of(GENERATORS_FILTERS_INJECTIONS_SET_UUID), NETWORK_UUID, VARIANT_1_ID)).willReturn(GENERATORS); + given(filterService.getIdentifiablesFromFilters(List.of(GENERATORS_FILTERS_INJECTIONS_SET_UUID), NETWORK_UUID, VARIANT_3_ID)).willReturn(GENERATORS_VARIANT); + given(filterService.getIdentifiablesFromFilters(List.of(GENERATORS_FILTERS_INJECTIONS_SET_UUID), NETWORK_UUID, VARIANT_2_ID)).willReturn(GENERATORS); + given(filterService.getIdentifiablesFromFilters(List.of(GENERATORS_FILTERS_INJECTIONS_SET_UUID), NETWORK_UUID, null)).willReturn(GENERATORS); + given(filterService.getIdentifiablesFromFilters(List.of(GENERATORS_FILTERS_INJECTIONS_SET_UUID), NETWORK_STOP_UUID, VARIANT_2_ID)).willReturn(GENERATORS); + given(filterService.getIdentifiablesFromFilters(List.of(LOADS_FILTERS_INJECTIONS_SET_UUID), NETWORK_UUID, VARIANT_1_ID)).willReturn(LOADS); + given(filterService.getIdentifiablesFromFilters(List.of(LOADS_FILTERS_INJECTIONS_SET_UUID), NETWORK_UUID, VARIANT_3_ID)).willReturn(LOADS_VARIANT); + given(filterService.getIdentifiablesFromFilters(List.of(LOADS_FILTERS_INJECTIONS_SET_UUID), NETWORK_UUID, VARIANT_2_ID)).willReturn(LOADS); + given(filterService.getIdentifiablesFromFilters(List.of(LOADS_FILTERS_INJECTIONS_SET_UUID), NETWORK_UUID, null)).willReturn(LOADS); + given(filterService.getIdentifiablesFromFilters(List.of(LOADS_FILTERS_INJECTIONS_SET_WITH_BAD_DISTRIBUTION_TYPE_UUID), NETWORK_UUID, null)).willReturn(LOADS); + given(filterService.getIdentifiablesFromFilters(List.of(LOADS_FILTERS_INJECTIONS_SET_UUID), NETWORK_STOP_UUID, VARIANT_2_ID)).willReturn(LOADS); + given(filterService.getIdentifiablesFromFilters(List.of(MONITORED_BRANCHES_FILTERS_INJECTIONS_UUID), NETWORK_UUID, VARIANT_1_ID)).willReturn(BRANCHES); + given(filterService.getIdentifiablesFromFilters(List.of(MONITORED_BRANCHES_FILTERS_INJECTIONS_UUID), NETWORK_UUID, VARIANT_3_ID)).willReturn(BRANCHES_VARIANT); + given(filterService.getIdentifiablesFromFilters(List.of(MONITORED_BRANCHES_FILTERS_INJECTIONS_UUID), NETWORK_UUID, VARIANT_2_ID)).willReturn(BRANCHES); + given(filterService.getIdentifiablesFromFilters(List.of(MONITORED_BRANCHES_FILTERS_INJECTIONS_UUID), NETWORK_UUID, null)).willReturn(BRANCHES); + given(filterService.getIdentifiablesFromFilters(List.of(MONITORED_BRANCHES_FILTERS_INJECTIONS_UUID), NETWORK_STOP_UUID, VARIANT_2_ID)).willReturn(BRANCHES); + given(filterService.getIdentifiablesFromFilters(List.of(MONITORED_BRANCHES_FILTERS_INJECTIONS_UUID), NETWORK_UUID, VARIANT_1_ID)).willReturn(BRANCHES); + given(filterService.getIdentifiablesFromFilters(List.of(MONITORED_BRANCHES_FILTERS_INJECTIONS_UUID), NETWORK_UUID, VARIANT_3_ID)).willReturn(BRANCHES_VARIANT); + given(filterService.getIdentifiablesFromFilters(List.of(MONITORED_BRANCHES_FILTERS_INJECTIONS_UUID), NETWORK_UUID, VARIANT_2_ID)).willReturn(BRANCHES); + given(filterService.getIdentifiablesFromFilters(List.of(MONITORED_BRANCHES_FILTERS_INJECTIONS_UUID), NETWORK_UUID, null)).willReturn(BRANCHES); + given(filterService.getIdentifiablesFromFilters(List.of(MONITORED_BRANCHES_FILTERS_INJECTIONS_UUID), NETWORK_STOP_UUID, VARIANT_2_ID)).willReturn(BRANCHES); + given(filterService.getIdentifiablesFromFilters(List.of(GENERATORS_FILTERS_INJECTIONS_UUID), NETWORK_UUID, VARIANT_1_ID)).willReturn(GENERATORS); + given(filterService.getIdentifiablesFromFilters(List.of(GENERATORS_FILTERS_INJECTIONS_UUID), NETWORK_UUID, VARIANT_3_ID)).willReturn(GENERATORS_VARIANT); + given(filterService.getIdentifiablesFromFilters(List.of(GENERATORS_FILTERS_INJECTIONS_UUID), NETWORK_UUID, VARIANT_2_ID)).willReturn(GENERATORS); + given(filterService.getIdentifiablesFromFilters(List.of(GENERATORS_FILTERS_INJECTIONS_UUID), NETWORK_UUID, null)).willReturn(GENERATORS); + given(filterService.getIdentifiablesFromFilters(List.of(GENERATORS_FILTERS_INJECTIONS_UUID), NETWORK_STOP_UUID, VARIANT_2_ID)).willReturn(GENERATORS); + given(filterService.getIdentifiablesFromFilters(List.of(MONITORED_BRANCHES_FILTERS_HVDC_UUID), NETWORK_UUID, VARIANT_1_ID)).willReturn(BRANCHES); + given(filterService.getIdentifiablesFromFilters(List.of(MONITORED_BRANCHES_FILTERS_HVDC_UUID), NETWORK_UUID, VARIANT_3_ID)).willReturn(BRANCHES_VARIANT); + given(filterService.getIdentifiablesFromFilters(List.of(MONITORED_BRANCHES_FILTERS_HVDC_UUID), NETWORK_UUID, VARIANT_2_ID)).willReturn(BRANCHES); + given(filterService.getIdentifiablesFromFilters(List.of(MONITORED_BRANCHES_FILTERS_HVDC_UUID), NETWORK_UUID, null)).willReturn(BRANCHES); + given(filterService.getIdentifiablesFromFilters(List.of(MONITORED_BRANCHES_FILTERS_HVDC_UUID), NETWORK_STOP_UUID, VARIANT_2_ID)).willReturn(BRANCHES); + given(filterService.getIdentifiablesFromFilters(List.of(HVDC_FILTERS_UUID), NETWORK_UUID, VARIANT_1_ID)).willReturn(HVDCS); + given(filterService.getIdentifiablesFromFilters(List.of(HVDC_FILTERS_UUID), NETWORK_UUID, VARIANT_3_ID)).willReturn(HVDCS_VARIANT); + given(filterService.getIdentifiablesFromFilters(List.of(HVDC_FILTERS_UUID), NETWORK_UUID, VARIANT_2_ID)).willReturn(HVDCS); + given(filterService.getIdentifiablesFromFilters(List.of(HVDC_FILTERS_UUID), NETWORK_UUID, null)).willReturn(HVDCS); + given(filterService.getIdentifiablesFromFilters(List.of(HVDC_FILTERS_UUID), NETWORK_STOP_UUID, VARIANT_2_ID)).willReturn(HVDCS); + given(filterService.getIdentifiablesFromFilters(List.of(PST_FILTERS_UUID1), NETWORK_UUID, VARIANT_1_ID)).willReturn(PSTS); + given(filterService.getIdentifiablesFromFilters(List.of(PST_FILTERS_UUID1), NETWORK_UUID, VARIANT_3_ID)).willReturn(PSTS_VARIANT); + given(filterService.getIdentifiablesFromFilters(List.of(PST_FILTERS_UUID1), NETWORK_UUID, VARIANT_2_ID)).willReturn(PSTS); + given(filterService.getIdentifiablesFromFilters(List.of(PST_FILTERS_UUID1), NETWORK_UUID, null)).willReturn(PSTS); + given(filterService.getIdentifiablesFromFilters(List.of(PST_FILTERS_UUID1), NETWORK_STOP_UUID, VARIANT_2_ID)).willReturn(PSTS); + given(filterService.getIdentifiablesFromFilters(List.of(PST_FILTERS_UUID2), NETWORK_UUID, VARIANT_1_ID)).willReturn(PSTS); + given(filterService.getIdentifiablesFromFilters(List.of(PST_FILTERS_UUID2), NETWORK_UUID, VARIANT_3_ID)).willReturn(PSTS_VARIANT); + given(filterService.getIdentifiablesFromFilters(List.of(PST_FILTERS_UUID2), NETWORK_UUID, VARIANT_2_ID)).willReturn(PSTS); + given(filterService.getIdentifiablesFromFilters(List.of(PST_FILTERS_UUID2), NETWORK_UUID, null)).willReturn(PSTS); + given(filterService.getIdentifiablesFromFilters(List.of(PST_FILTERS_UUID2), NETWORK_STOP_UUID, VARIANT_2_ID)).willReturn(PSTS); + given(filterService.getIdentifiablesFromFilters(List.of(MONITORED_VOLTAGE_LEVELS_FILTERS_NODES_UUID), NETWORK_UUID, VARIANT_1_ID)).willReturn(VOLTAGE_LEVELS); + given(filterService.getIdentifiablesFromFilters(List.of(MONITORED_VOLTAGE_LEVELS_FILTERS_NODES_UUID), NETWORK_UUID, VARIANT_3_ID)).willReturn(VOLTAGE_LEVELS_VARIANT); + given(filterService.getIdentifiablesFromFilters(List.of(MONITORED_VOLTAGE_LEVELS_FILTERS_NODES_UUID), NETWORK_UUID, VARIANT_2_ID)).willReturn(VOLTAGE_LEVELS); + given(filterService.getIdentifiablesFromFilters(List.of(MONITORED_VOLTAGE_LEVELS_FILTERS_NODES_UUID), NETWORK_UUID, null)).willReturn(VOLTAGE_LEVELS); + given(filterService.getIdentifiablesFromFilters(List.of(MONITORED_VOLTAGE_LEVELS_FILTERS_NODES_UUID), NETWORK_STOP_UUID, VARIANT_2_ID)).willReturn(VOLTAGE_LEVELS); + given(filterService.getIdentifiablesFromFilters(List.of(EQUIPMENTS_IN_VOLTAGE_REGULATION_FILTERS_UUID), NETWORK_UUID, VARIANT_1_ID)).willReturn(EQUIPMENTS_IN_VOLTAGE_REGULATION); + given(filterService.getIdentifiablesFromFilters(List.of(EQUIPMENTS_IN_VOLTAGE_REGULATION_FILTERS_UUID), NETWORK_UUID, VARIANT_3_ID)).willReturn(EQUIPMENTS_IN_VOLTAGE_REGULATION_VARIANT); + given(filterService.getIdentifiablesFromFilters(List.of(EQUIPMENTS_IN_VOLTAGE_REGULATION_FILTERS_UUID), NETWORK_UUID, VARIANT_2_ID)).willReturn(EQUIPMENTS_IN_VOLTAGE_REGULATION); + given(filterService.getIdentifiablesFromFilters(List.of(EQUIPMENTS_IN_VOLTAGE_REGULATION_FILTERS_UUID), NETWORK_UUID, null)).willReturn(EQUIPMENTS_IN_VOLTAGE_REGULATION); + given(filterService.getIdentifiablesFromFilters(List.of(EQUIPMENTS_IN_VOLTAGE_REGULATION_FILTERS_UUID), NETWORK_STOP_UUID, VARIANT_2_ID)).willReturn(EQUIPMENTS_IN_VOLTAGE_REGULATION); // report service mocking doAnswer(i -> null).when(reportService).sendReport(any(), any()); diff --git a/src/test/java/org/gridsuite/sensitivityanalysis/server/dto/SensitivityAnalysisInputDataTest.java b/src/test/java/org/gridsuite/sensitivityanalysis/server/dto/SensitivityAnalysisInputDataTest.java index e0413272..144a71b8 100644 --- a/src/test/java/org/gridsuite/sensitivityanalysis/server/dto/SensitivityAnalysisInputDataTest.java +++ b/src/test/java/org/gridsuite/sensitivityanalysis/server/dto/SensitivityAnalysisInputDataTest.java @@ -113,7 +113,7 @@ public void test() { @Test public void testEmptyInputTranslation() { SensitivityAnalysisInputBuilderService inputBuilderService; - given(filterService.getIdentifiablesFromFilter(any(), any(), any())).willThrow(new RuntimeException("FilterException")); + given(filterService.getIdentifiablesFromFilters(any(), any(), any())).willThrow(new RuntimeException("FilterException")); given(actionsService.getContingencyList(any(), any(), any())).willThrow(new RuntimeException("ContingencyException")); inputBuilderService = new SensitivityAnalysisInputBuilderService(actionsService, filterService); SensitivityAnalysisInputData.SensitivityAnalysisInputDataBuilder inputBuilder = SensitivityAnalysisInputData.builder(); @@ -138,7 +138,7 @@ public void testEmptyInputTranslation() { @Test public void testFilterPbInputTranslation() { SensitivityAnalysisInputBuilderService inputBuilderService; - given(filterService.getIdentifiablesFromFilter(any(), any(), any())).willThrow(new RuntimeException("FilterException")); + given(filterService.getIdentifiablesFromFilters(any(), any(), any())).willThrow(new RuntimeException("FilterException")); given(actionsService.getContingencyList(any(), any(), any())).willThrow(new RuntimeException("ContingencyException")); inputBuilderService = new SensitivityAnalysisInputBuilderService(actionsService, filterService); SensitivityAnalysisInputData.SensitivityAnalysisInputDataBuilder inputBuilder = SensitivityAnalysisInputData.builder(); @@ -161,10 +161,10 @@ public void testFilterPbInputTranslation() { inputBuilderService.build(context, NETWORK, reporter); Collection reports = reporter.getReports(); assertThat(reports, not(nullValue())); - assertThat(reports.size(), is(2)); + assertThat(reports.size(), is(3)); Set reportKeys = reports.stream().map(Report::getReportKey).collect(Collectors.toSet()); - assertThat(reportKeys.size(), is(1)); - assertThat(reportKeys, contains("contingencyTranslationFailure")); + assertThat(reportKeys.size(), is(2)); + assertThat(reportKeys, contains("contingencyTranslationFailure", "filterTranslationFailure")); } @Test diff --git a/src/test/java/org/gridsuite/sensitivityanalysis/server/service/FilterServiceTest.java b/src/test/java/org/gridsuite/sensitivityanalysis/server/service/FilterServiceTest.java index 5d182bf0..4ada2471 100644 --- a/src/test/java/org/gridsuite/sensitivityanalysis/server/service/FilterServiceTest.java +++ b/src/test/java/org/gridsuite/sensitivityanalysis/server/service/FilterServiceTest.java @@ -89,16 +89,16 @@ private String initMockWebServer() throws IOException { @Override public MockResponse dispatch(RecordedRequest request) { String requestPath = Objects.requireNonNull(request.getPath()); - if (requestPath.equals(String.format("/v1/filters/%s/export?networkUuid=%s&variantId=%s", LIST_UUID, NETWORK_UUID, VARIANT_ID))) { + if (requestPath.equals(String.format("/v1/filters/export?ids=%s&networkUuid=%s&variantId=%s", LIST_UUID, NETWORK_UUID, VARIANT_ID))) { return new MockResponse().setResponseCode(HttpStatus.OK.value()) .setBody(jsonVariantExpected) .addHeader("Content-Type", "application/json; charset=utf-8"); - } else if (requestPath.equals(String.format("/v1/filters/%s/export?networkUuid=%s", LIST_UUID, NETWORK_UUID))) { + } else if (requestPath.equals(String.format("/v1/filters/export?ids=%s&networkUuid=%s", LIST_UUID, NETWORK_UUID))) { return new MockResponse().setResponseCode(HttpStatus.OK.value()) .setBody(jsonExpected) .addHeader("Content-Type", "application/json; charset=utf-8"); - } else if (requestPath.equals(String.format("/v1/filters/%s/export?networkUuid=%s&variantId=%s", VERY_LARGE_LIST_UUID, NETWORK_UUID, VARIANT_ID)) - || requestPath.equals(String.format("/v1/filters/%s/export?networkUuid=%s", VERY_LARGE_LIST_UUID, NETWORK_UUID))) { + } else if (requestPath.equals(String.format("/v1/filters/export?ids=%s&networkUuid=%s&variantId=%s", VERY_LARGE_LIST_UUID, NETWORK_UUID, VARIANT_ID)) + || requestPath.equals(String.format("/v1/filters/export?ids=%s&networkUuid=%s", VERY_LARGE_LIST_UUID, NETWORK_UUID))) { return new MockResponse().setResponseCode(HttpStatus.OK.value()) .setBody(veryLargeJsonExpected) .addHeader("Content-Type", "application/json; charset=utf-8"); @@ -122,9 +122,9 @@ private List createVeryLargeList() { @SneakyThrows @Test public void test() { - List list = filterService.getIdentifiablesFromFilter(LIST_UUID, UUID.fromString(NETWORK_UUID), null); + List list = filterService.getIdentifiablesFromFilters(List.of(LIST_UUID), UUID.fromString(NETWORK_UUID), null); assertEquals(objectMapper.writeValueAsString(List.of(IDENTIFIABLE)), objectMapper.writeValueAsString(list)); - list = filterService.getIdentifiablesFromFilter(LIST_UUID, UUID.fromString(NETWORK_UUID), VARIANT_ID); + list = filterService.getIdentifiablesFromFilters(List.of(LIST_UUID), UUID.fromString(NETWORK_UUID), VARIANT_ID); assertEquals(objectMapper.writeValueAsString(List.of(IDENTIFIABLE_VARIANT)), objectMapper.writeValueAsString(list)); } @@ -132,9 +132,9 @@ public void test() { @Test public void testVeryLargeList() { // DataBufferLimitException should not be thrown with this message : "Exceeded limit on max bytes to buffer : DATA_BUFFER_LIMIT" - List list = filterService.getIdentifiablesFromFilter(VERY_LARGE_LIST_UUID, UUID.fromString(NETWORK_UUID), null); + List list = filterService.getIdentifiablesFromFilters(List.of(VERY_LARGE_LIST_UUID), UUID.fromString(NETWORK_UUID), null); assertEquals(objectMapper.writeValueAsString(createVeryLargeList()), objectMapper.writeValueAsString(list)); - list = filterService.getIdentifiablesFromFilter(VERY_LARGE_LIST_UUID, UUID.fromString(NETWORK_UUID), VARIANT_ID); + list = filterService.getIdentifiablesFromFilters(List.of(VERY_LARGE_LIST_UUID), UUID.fromString(NETWORK_UUID), VARIANT_ID); assertEquals(objectMapper.writeValueAsString(createVeryLargeList()), objectMapper.writeValueAsString(list)); } } From 11f3926e7d01b0159ca5974fa8193d8048dc2766 Mon Sep 17 00:00:00 2001 From: jamal-khey Date: Fri, 15 Dec 2023 11:58:34 +0100 Subject: [PATCH 06/11] fix review comments --- .../SensitivityAnalysisInputBuilderService.java | 11 ----------- .../server/SensitivityAnalysisControllerTest.java | 1 - 2 files changed, 12 deletions(-) diff --git a/src/main/java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisInputBuilderService.java b/src/main/java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisInputBuilderService.java index 504b2bb3..9b7c3562 100644 --- a/src/main/java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisInputBuilderService.java +++ b/src/main/java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisInputBuilderService.java @@ -262,7 +262,6 @@ private List buildSensitivityVariableSets(SensitivityAna .build()); return; } - for (IdentifiableAttributes identifiableAttributes : variablesList.getRight()) { switch (identifiableAttributes.getType()) { case GENERATOR: { @@ -304,9 +303,6 @@ private List buildSensitivityFactorsFromVariablesSets(Sensiti return List.of(); } - // List monitoredEquipments = monitoredEquipmentsContainers.stream() - // .flatMap(filter -> getMonitoredIdentifiablesFromContainer(context, network, filter, monitoredEquipmentsTypesAllowed, reporter)) - // .collect(Collectors.toList()); List monitoredEquipments = getMonitoredIdentifiablesFromContainer(context, network, monitoredEquipmentsContainers, monitoredEquipmentsTypesAllowed, reporter).collect(Collectors.toList()); return getSensitivityFactorsFromEquipments(variablesSets.stream().map(SensitivityVariableSet::getId).collect(Collectors.toList()), @@ -321,18 +317,11 @@ private List buildSensitivityFactorsFromEquipments(Sensitivit List contingencies, SensitivityFunctionType sensitivityFunctionType, SensitivityVariableType sensitivityVariableType) { - // List equipments = filters.stream() - // .flatMap(filter -> getIdentifiablesFromContainer(context, filter, equipmentsTypesAllowed, reporter)) - // .collect(Collectors.toList()); - List equipments = getIdentifiablesFromContainer(context, filters, equipmentsTypesAllowed, reporter).collect(Collectors.toList()); if (equipments.isEmpty()) { return List.of(); } - // List monitoredEquipments = monitoredEquipmentsContainers.stream() - // .flatMap(filter -> getMonitoredIdentifiablesFromContainer(context, network, filter, monitoredEquipmentsTypesAllowed, reporter)) - // .collect(Collectors.toList()); List monitoredEquipments = getMonitoredIdentifiablesFromContainer(context, network, filters, monitoredEquipmentsTypesAllowed, reporter) .collect(Collectors.toList()); diff --git a/src/test/java/org/gridsuite/sensitivityanalysis/server/SensitivityAnalysisControllerTest.java b/src/test/java/org/gridsuite/sensitivityanalysis/server/SensitivityAnalysisControllerTest.java index 18ade53b..e4b1f1d6 100644 --- a/src/test/java/org/gridsuite/sensitivityanalysis/server/SensitivityAnalysisControllerTest.java +++ b/src/test/java/org/gridsuite/sensitivityanalysis/server/SensitivityAnalysisControllerTest.java @@ -476,7 +476,6 @@ public void setUp() { given(filterService.getIdentifiablesFromFilters(List.of(EQUIPMENTS_IN_VOLTAGE_REGULATION_FILTERS_UUID), NETWORK_UUID, null)).willReturn(EQUIPMENTS_IN_VOLTAGE_REGULATION); given(filterService.getIdentifiablesFromFilters(List.of(EQUIPMENTS_IN_VOLTAGE_REGULATION_FILTERS_UUID), NETWORK_STOP_UUID, VARIANT_2_ID)).willReturn(EQUIPMENTS_IN_VOLTAGE_REGULATION); given(filterService.getIdentifiablesCount(IDS_1, NETWORK_UUID, null)).willReturn(Map.>of(MONITORED_BRANCHS_KEY, List.of(6L), INJECTIONS_KEY, List.of(6L))); - // report service mocking doAnswer(i -> null).when(reportService).sendReport(any(), any()); From 0369187f845053fb4acd63f2220d042df8708dae Mon Sep 17 00:00:00 2001 From: jamal-khey Date: Fri, 15 Dec 2023 12:18:50 +0100 Subject: [PATCH 07/11] fix --- .../SensitivityAnalysisInputBuilderService.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisInputBuilderService.java b/src/main/java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisInputBuilderService.java index 9b7c3562..1c32b03b 100644 --- a/src/main/java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisInputBuilderService.java +++ b/src/main/java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisInputBuilderService.java @@ -317,16 +317,16 @@ private List buildSensitivityFactorsFromEquipments(Sensitivit List contingencies, SensitivityFunctionType sensitivityFunctionType, SensitivityVariableType sensitivityVariableType) { - List equipments = getIdentifiablesFromContainer(context, filters, equipmentsTypesAllowed, reporter).collect(Collectors.toList()); + List equipments = getIdentifiablesFromContainer(context, filters, equipmentsTypesAllowed, reporter).toList(); + if (equipments.isEmpty()) { return List.of(); } - - List monitoredEquipments = getMonitoredIdentifiablesFromContainer(context, network, filters, monitoredEquipmentsTypesAllowed, reporter) - .collect(Collectors.toList()); + List monitoredEquipementContainer = monitoredEquipmentsContainers.stream().toList(); + List monitoredEquipments = getMonitoredIdentifiablesFromContainer(context, network, monitoredEquipementContainer, monitoredEquipmentsTypesAllowed, reporter).toList(); return getSensitivityFactorsFromEquipments(equipments.stream().map(IdentifiableAttributes::getId).collect(Collectors.toList()), - monitoredEquipments, contingencies, sensitivityFunctionType, sensitivityVariableType, false); + monitoredEquipments, contingencies, sensitivityFunctionType, sensitivityVariableType, false); } private void buildSensitivityInjectionsSets(SensitivityAnalysisRunContext context, Network network, Reporter reporter) { From 2070da368811a0a690ed15a22f2289743d2185a2 Mon Sep 17 00:00:00 2001 From: jamal-khey Date: Sun, 17 Dec 2023 13:23:17 +0100 Subject: [PATCH 08/11] adapt the code to parse filterEquipements correctly --- .../server/dto/FilterEquipments.java | 22 +++++++ .../server/service/FilterService.java | 25 ++++++-- ...ensitivityAnalysisInputBuilderService.java | 30 +++++----- .../server/service/FilterServiceTest.java | 58 ++++++++++++++++--- 4 files changed, 106 insertions(+), 29 deletions(-) create mode 100644 src/main/java/org/gridsuite/sensitivityanalysis/server/dto/FilterEquipments.java diff --git a/src/main/java/org/gridsuite/sensitivityanalysis/server/dto/FilterEquipments.java b/src/main/java/org/gridsuite/sensitivityanalysis/server/dto/FilterEquipments.java new file mode 100644 index 00000000..1ab1fc7e --- /dev/null +++ b/src/main/java/org/gridsuite/sensitivityanalysis/server/dto/FilterEquipments.java @@ -0,0 +1,22 @@ +package org.gridsuite.sensitivityanalysis.server.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.List; +import java.util.UUID; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class FilterEquipments { + @Schema(description = "filter id") + private UUID filterId; + + @Schema(description = "equipments of filter") + private List identifiableAttributes; + + @Schema(description = "equipments not found in network") + private List notFoundEquipments; +} diff --git a/src/main/java/org/gridsuite/sensitivityanalysis/server/service/FilterService.java b/src/main/java/org/gridsuite/sensitivityanalysis/server/service/FilterService.java index 9e3ae375..c7452a7d 100644 --- a/src/main/java/org/gridsuite/sensitivityanalysis/server/service/FilterService.java +++ b/src/main/java/org/gridsuite/sensitivityanalysis/server/service/FilterService.java @@ -7,6 +7,7 @@ package org.gridsuite.sensitivityanalysis.server.service; import org.apache.commons.lang3.StringUtils; +import org.gridsuite.sensitivityanalysis.server.dto.FilterEquipments; import org.gridsuite.sensitivityanalysis.server.dto.IdentifiableAttributes; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -19,6 +20,7 @@ import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Objects; @@ -44,21 +46,32 @@ public FilterService(@Value("${gridsuite.services.filter-server.base-uri:http:// this.filterServerBaseUri = filterServerBaseUri; } - public List getIdentifiablesFromFilters(List uuids, UUID networkUuid, String variantId) { - Objects.requireNonNull(uuids); + public List getIdentifiablesFromFilters(List filterUuids, UUID networkUuid, String variantId) { + List filterEquipments = getFilterEquipements(filterUuids, networkUuid, variantId); + + List mergedIdentifiables = new ArrayList<>(); + for (FilterEquipments filterEquipment : filterEquipments) { + mergedIdentifiables.addAll(filterEquipment.getIdentifiableAttributes()); + } + + return mergedIdentifiables; + } + + public List getFilterEquipements(List filterUuids, UUID networkUuid, String variantId) { + Objects.requireNonNull(filterUuids); Objects.requireNonNull(networkUuid); var uriComponentsBuilder = UriComponentsBuilder - .fromPath(DELIMITER + FILTER_API_VERSION + "/filters/export") - .queryParam(IDS, uuids) - .queryParam(NETWORK_UUID, networkUuid.toString()); + .fromPath(DELIMITER + FILTER_API_VERSION + "/filters/export") + .queryParam(IDS, filterUuids) + .queryParam(NETWORK_UUID, networkUuid.toString()); if (!StringUtils.isBlank(variantId)) { uriComponentsBuilder.queryParam(QUERY_PARAM_VARIANT_ID, variantId); } var path = uriComponentsBuilder.build().toUriString(); return restTemplate.exchange(filterServerBaseUri + path, HttpMethod.GET, null, - new ParameterizedTypeReference>() { + new ParameterizedTypeReference>() { }).getBody(); } diff --git a/src/main/java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisInputBuilderService.java b/src/main/java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisInputBuilderService.java index 1c32b03b..19deae06 100644 --- a/src/main/java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisInputBuilderService.java +++ b/src/main/java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisInputBuilderService.java @@ -101,19 +101,19 @@ private double getLoadWeight(Load load, SensitivityAnalysisInputData.Distributio private List goGetIdentifiables(List filters, UUID networkUuid, String variantId, Reporter reporter) { List containerNamesList = filters.stream().map(EquipmentsContainer::getContainerName).toList(); - String containerNames = Arrays.toString(containerNamesList.toArray()); + String containersNames = Arrays.toString(containerNamesList.toArray()); try { //extract container id from filters List filterIds = filters.stream().map(EquipmentsContainer::getContainerId).collect(Collectors.toList()); return filterService.getIdentifiablesFromFilters(filterIds, networkUuid, variantId); } catch (Exception ex) { - LOGGER.error("Could not get identifiables from filter " + containerNames, ex); + LOGGER.error("Could not get identifiables from filter " + containersNames, ex); reporter.report(Report.builder() .withKey("filterTranslationFailure") - .withDefaultMessage("Could not get identifiables from filters ${name} : ${exception}") + .withDefaultMessage("Could not get identifiables from filters ${names} : ${exception}") .withSeverity(TypedValue.ERROR_SEVERITY) .withValue("exception", ex.getMessage()) - .withValue("name", containerNames) + .withValue("names", containersNames) .build()); return List.of(); } @@ -145,8 +145,8 @@ private Long getFactorsCount(Map> ids, UUID networkUuid, Stri return contAttributesCountTemp; } - private Stream getIdentifiablesFromContainer(SensitivityAnalysisRunContext context, List filters, - List equipmentsTypesAllowed, Reporter reporter) { + private Stream getIdentifiablesFromContainers(SensitivityAnalysisRunContext context, List filters, + List equipmentsTypesAllowed, Reporter reporter) { List containerNamesList = filters.stream().map(EquipmentsContainer::getContainerName).toList(); String containerNames = Arrays.toString(containerNamesList.toArray()); List listIdentAttributes = goGetIdentifiables(filters, context.getNetworkUuid(), context.getVariantId(), reporter); @@ -155,8 +155,8 @@ private Stream getIdentifiablesFromContainer(Sensitivity if (!listIdentAttributes.stream().allMatch(i -> equipmentsTypesAllowed.contains(i.getType()))) { reporter.report(Report.builder() .withKey("badEquipmentType") - .withDefaultMessage("Equipments type in filter with name=${name} should be ${expectedType} : filter is ignored") - .withValue("name", containerNames) + .withDefaultMessage("Equipments type in filter with name=${names} should be ${expectedType} : filter is ignored") + .withValue("names", containerNames) .withValue(EXPECTED_TYPE, equipmentsTypesAllowed.toString()) .withSeverity(TypedValue.WARN_SEVERITY) .build()); @@ -166,7 +166,7 @@ private Stream getIdentifiablesFromContainer(Sensitivity return listIdentAttributes.stream(); } - private Stream getMonitoredIdentifiablesFromContainer(SensitivityAnalysisRunContext context, Network network, List filters, List equipmentsTypesAllowed, Reporter reporter) { + private Stream getMonitoredIdentifiablesFromContainers(SensitivityAnalysisRunContext context, Network network, List filters, List equipmentsTypesAllowed, Reporter reporter) { List containerNamesList = filters.stream().map(EquipmentsContainer::getContainerName).toList(); String containerNames = Arrays.toString(containerNamesList.toArray()); List listIdentAttributes = goGetIdentifiables(filters, context.getNetworkUuid(), context.getVariantId(), reporter); @@ -175,8 +175,8 @@ private Stream getMonitoredIdentifiablesFromContainer(Se if (!listIdentAttributes.stream().allMatch(i -> equipmentsTypesAllowed.contains(i.getType()))) { reporter.report(Report.builder() .withKey("badMonitoredEquipmentType") - .withDefaultMessage("Monitored equipments type in filter with name=${name} should be ${expectedType} : filter is ignored") - .withValue("name", containerNames) + .withDefaultMessage("Monitored equipments type in filter with name=${names} should be ${expectedType} : filter is ignored") + .withValue("names", containerNames) .withValue(EXPECTED_TYPE, equipmentsTypesAllowed.toString()) .withSeverity(TypedValue.WARN_SEVERITY) .build()); @@ -236,7 +236,7 @@ private List buildSensitivityVariableSets(SensitivityAna List filters, SensitivityAnalysisInputData.DistributionType distributionType) { List result = new ArrayList<>(); - List monitoredVariablesContainersLists = getIdentifiablesFromContainer(context, filters, variablesTypesAllowed, reporter) + List monitoredVariablesContainersLists = getIdentifiablesFromContainers(context, filters, variablesTypesAllowed, reporter) .collect(Collectors.toList()); String containerNames = Arrays.toString(filters.stream().map(EquipmentsContainer::getContainerName).toList().toArray()); Stream>> variablesContainersLists = Stream.of(Pair.of(containerNames, monitoredVariablesContainersLists)) @@ -303,7 +303,7 @@ private List buildSensitivityFactorsFromVariablesSets(Sensiti return List.of(); } - List monitoredEquipments = getMonitoredIdentifiablesFromContainer(context, network, monitoredEquipmentsContainers, monitoredEquipmentsTypesAllowed, reporter).collect(Collectors.toList()); + List monitoredEquipments = getMonitoredIdentifiablesFromContainers(context, network, monitoredEquipmentsContainers, monitoredEquipmentsTypesAllowed, reporter).collect(Collectors.toList()); return getSensitivityFactorsFromEquipments(variablesSets.stream().map(SensitivityVariableSet::getId).collect(Collectors.toList()), monitoredEquipments, contingencies, sensitivityFunctionType, sensitivityVariableType, true); @@ -317,13 +317,13 @@ private List buildSensitivityFactorsFromEquipments(Sensitivit List contingencies, SensitivityFunctionType sensitivityFunctionType, SensitivityVariableType sensitivityVariableType) { - List equipments = getIdentifiablesFromContainer(context, filters, equipmentsTypesAllowed, reporter).toList(); + List equipments = getIdentifiablesFromContainers(context, filters, equipmentsTypesAllowed, reporter).toList(); if (equipments.isEmpty()) { return List.of(); } List monitoredEquipementContainer = monitoredEquipmentsContainers.stream().toList(); - List monitoredEquipments = getMonitoredIdentifiablesFromContainer(context, network, monitoredEquipementContainer, monitoredEquipmentsTypesAllowed, reporter).toList(); + List monitoredEquipments = getMonitoredIdentifiablesFromContainers(context, network, monitoredEquipementContainer, monitoredEquipmentsTypesAllowed, reporter).toList(); return getSensitivityFactorsFromEquipments(equipments.stream().map(IdentifiableAttributes::getId).collect(Collectors.toList()), monitoredEquipments, contingencies, sensitivityFunctionType, sensitivityVariableType, false); diff --git a/src/test/java/org/gridsuite/sensitivityanalysis/server/service/FilterServiceTest.java b/src/test/java/org/gridsuite/sensitivityanalysis/server/service/FilterServiceTest.java index 11a15622..9c591b4b 100644 --- a/src/test/java/org/gridsuite/sensitivityanalysis/server/service/FilterServiceTest.java +++ b/src/test/java/org/gridsuite/sensitivityanalysis/server/service/FilterServiceTest.java @@ -14,6 +14,7 @@ import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; +import org.gridsuite.sensitivityanalysis.server.dto.FilterEquipments; import org.gridsuite.sensitivityanalysis.server.dto.IdentifiableAttributes; import org.jetbrains.annotations.NotNull; import org.junit.After; @@ -27,10 +28,7 @@ import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.UUID; +import java.util.*; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -85,11 +83,11 @@ private String initMockWebServer() throws IOException { server = new MockWebServer(); server.start(); - String jsonExpected = objectMapper.writeValueAsString(List.of(IDENTIFIABLE)); - String veryLargeJsonExpected = objectMapper.writeValueAsString(createVeryLargeList()); - String jsonVariantExpected = objectMapper.writeValueAsString(List.of(IDENTIFIABLE_VARIANT)); + String jsonExpected = objectMapper.writeValueAsString(createFromIdentifiableList(LIST_UUID, List.of(IDENTIFIABLE))); + String veryLargeJsonExpected = objectMapper.writeValueAsString(createFromIdentifiableList(VERY_LARGE_LIST_UUID, createVeryLargeList())); + String jsonLargeFilterEquipement = objectMapper.writeValueAsString(createFilterEquipments()); + String jsonVariantExpected = objectMapper.writeValueAsString(createFromIdentifiableList(LIST_UUID, List.of(IDENTIFIABLE_VARIANT))); String jsonIdentifiablesExpected = objectMapper.writeValueAsString(countResultMap()); - final Dispatcher dispatcher = new Dispatcher() { @Override public MockResponse dispatch(RecordedRequest request) { @@ -98,6 +96,10 @@ public MockResponse dispatch(RecordedRequest request) { return new MockResponse().setResponseCode(HttpStatus.OK.value()) .setBody(jsonVariantExpected) .addHeader("Content-Type", "application/json; charset=utf-8"); + } else if (requestPath.equals(String.format("/v1/filters/export?ids=%s&ids=%s&networkUuid=%s", VERY_LARGE_LIST_UUID, LIST_UUID, NETWORK_UUID))) { + return new MockResponse().setResponseCode(HttpStatus.OK.value()) + .setBody(jsonLargeFilterEquipement) + .addHeader("Content-Type", "application/json; charset=utf-8"); } else if (requestPath.equals(String.format("/v1/filters/export?ids=%s&networkUuid=%s", LIST_UUID, NETWORK_UUID))) { return new MockResponse().setResponseCode(HttpStatus.OK.value()) .setBody(jsonExpected) @@ -134,6 +136,28 @@ private List createVeryLargeList() { return IntStream.range(0, DATA_BUFFER_LIMIT).mapToObj(i -> new IdentifiableAttributes("l" + i, IdentifiableType.GENERATOR, null)).collect(Collectors.toList()); } + private List createFromIdentifiableList(UUID uuid, List identifiableAttributes) { + return List.of( + FilterEquipments.builder() + .identifiableAttributes(identifiableAttributes) + .filterId(uuid) + .build() + ); + } + + private List createFilterEquipments() { + return List.of( + FilterEquipments.builder() + .identifiableAttributes(createVeryLargeList()) + .filterId(VERY_LARGE_LIST_UUID) + .build(), + FilterEquipments.builder() + .identifiableAttributes(List.of(IDENTIFIABLE)) + .filterId(LIST_UUID) + .build() + ); + } + @SneakyThrows @Test public void test() { @@ -153,6 +177,16 @@ public void testVeryLargeList() { assertEquals(objectMapper.writeValueAsString(createVeryLargeList()), objectMapper.writeValueAsString(list)); } + @SneakyThrows + @Test + public void testGetMultipleLists() { + List list = filterService.getIdentifiablesFromFilters(List.of(VERY_LARGE_LIST_UUID, LIST_UUID), UUID.fromString(NETWORK_UUID), null); + List expectedList = new ArrayList<>(); + expectedList.addAll(createVeryLargeList()); + expectedList.addAll(List.of(IDENTIFIABLE)); + assertEquals(objectMapper.writeValueAsString(expectedList), objectMapper.writeValueAsString(list)); + } + @SneakyThrows @Test public void testGetFactorsCount() { @@ -161,4 +195,12 @@ public void testGetFactorsCount() { list = filterService.getIdentifiablesCount(IDENTIFIABLES_UUID, UUID.fromString(NETWORK_UUID), VARIANT_ID); assertEquals(objectMapper.writeValueAsString(countResultMap()), objectMapper.writeValueAsString(list)); } + + @SneakyThrows + @Test + public void testListOfUuids() { + // DataBufferLimitException should not be thrown with this message : "Exceeded limit on max bytes to buffer : DATA_BUFFER_LIMIT" + List list = filterService.getFilterEquipements(List.of(VERY_LARGE_LIST_UUID, LIST_UUID), UUID.fromString(NETWORK_UUID), null); + assertEquals(objectMapper.writeValueAsString(createFilterEquipments()), objectMapper.writeValueAsString(list)); + } } From 2194905146e79964e9646e0ca5df0fd90cc099de Mon Sep 17 00:00:00 2001 From: jamal-khey Date: Sun, 17 Dec 2023 13:26:40 +0100 Subject: [PATCH 09/11] fix IDE warn --- .../server/service/FilterServiceTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/gridsuite/sensitivityanalysis/server/service/FilterServiceTest.java b/src/test/java/org/gridsuite/sensitivityanalysis/server/service/FilterServiceTest.java index 9c591b4b..b68c5c21 100644 --- a/src/test/java/org/gridsuite/sensitivityanalysis/server/service/FilterServiceTest.java +++ b/src/test/java/org/gridsuite/sensitivityanalysis/server/service/FilterServiceTest.java @@ -181,9 +181,8 @@ public void testVeryLargeList() { @Test public void testGetMultipleLists() { List list = filterService.getIdentifiablesFromFilters(List.of(VERY_LARGE_LIST_UUID, LIST_UUID), UUID.fromString(NETWORK_UUID), null); - List expectedList = new ArrayList<>(); - expectedList.addAll(createVeryLargeList()); - expectedList.addAll(List.of(IDENTIFIABLE)); + List expectedList = new ArrayList<>(createVeryLargeList()); + expectedList.add(IDENTIFIABLE); assertEquals(objectMapper.writeValueAsString(expectedList), objectMapper.writeValueAsString(list)); } From bf6d7c2475a41c236c193a0745b13e34f31b315a Mon Sep 17 00:00:00 2001 From: jamal-khey Date: Mon, 18 Dec 2023 09:42:56 +0100 Subject: [PATCH 10/11] fix review comments --- .../server/service/FilterService.java | 2 +- ...ensitivityAnalysisInputBuilderService.java | 32 +++++++++++-------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/gridsuite/sensitivityanalysis/server/service/FilterService.java b/src/main/java/org/gridsuite/sensitivityanalysis/server/service/FilterService.java index c7452a7d..790732e4 100644 --- a/src/main/java/org/gridsuite/sensitivityanalysis/server/service/FilterService.java +++ b/src/main/java/org/gridsuite/sensitivityanalysis/server/service/FilterService.java @@ -62,7 +62,7 @@ public List getFilterEquipements(List filterUuids, UUID Objects.requireNonNull(networkUuid); var uriComponentsBuilder = UriComponentsBuilder - .fromPath(DELIMITER + FILTER_API_VERSION + "/filters/export") + .fromPath(DELIMITER + FILTER_API_VERSION + "/filters/exports") .queryParam(IDS, filterUuids) .queryParam(NETWORK_UUID, networkUuid.toString()); if (!StringUtils.isBlank(variantId)) { diff --git a/src/main/java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisInputBuilderService.java b/src/main/java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisInputBuilderService.java index 19deae06..c68aa10a 100644 --- a/src/main/java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisInputBuilderService.java +++ b/src/main/java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisInputBuilderService.java @@ -37,6 +37,8 @@ public class SensitivityAnalysisInputBuilderService { private final ActionsService actionsService; private final FilterService filterService; + private static final String NAMES = "names"; + public SensitivityAnalysisInputBuilderService(ActionsService actionsService, FilterService filterService) { this.actionsService = actionsService; this.filterService = filterService; @@ -100,11 +102,10 @@ private double getLoadWeight(Load load, SensitivityAnalysisInputData.Distributio } private List goGetIdentifiables(List filters, UUID networkUuid, String variantId, Reporter reporter) { - List containerNamesList = filters.stream().map(EquipmentsContainer::getContainerName).toList(); - String containersNames = Arrays.toString(containerNamesList.toArray()); + String containersNames = getContainerNames(filters); try { //extract container id from filters - List filterIds = filters.stream().map(EquipmentsContainer::getContainerId).collect(Collectors.toList()); + List filterIds = filters.stream().map(EquipmentsContainer::getContainerId).toList(); return filterService.getIdentifiablesFromFilters(filterIds, networkUuid, variantId); } catch (Exception ex) { LOGGER.error("Could not get identifiables from filter " + containersNames, ex); @@ -113,7 +114,7 @@ private List goGetIdentifiables(List> ids, UUID networkUuid, Stri private Stream getIdentifiablesFromContainers(SensitivityAnalysisRunContext context, List filters, List equipmentsTypesAllowed, Reporter reporter) { - List containerNamesList = filters.stream().map(EquipmentsContainer::getContainerName).toList(); - String containerNames = Arrays.toString(containerNamesList.toArray()); - List listIdentAttributes = goGetIdentifiables(filters, context.getNetworkUuid(), context.getVariantId(), reporter); + String containersNames = getContainerNames(filters); + List listIdentifiableAttributes = goGetIdentifiables(filters, context.getNetworkUuid(), context.getVariantId(), reporter); // check that monitored equipments type is allowed - if (!listIdentAttributes.stream().allMatch(i -> equipmentsTypesAllowed.contains(i.getType()))) { + if (!listIdentifiableAttributes.stream().allMatch(i -> equipmentsTypesAllowed.contains(i.getType()))) { reporter.report(Report.builder() .withKey("badEquipmentType") .withDefaultMessage("Equipments type in filter with name=${names} should be ${expectedType} : filter is ignored") - .withValue("names", containerNames) + .withValue(NAMES, containersNames) .withValue(EXPECTED_TYPE, equipmentsTypesAllowed.toString()) .withSeverity(TypedValue.WARN_SEVERITY) .build()); return Stream.empty(); } - return listIdentAttributes.stream(); + return listIdentifiableAttributes.stream(); } - private Stream getMonitoredIdentifiablesFromContainers(SensitivityAnalysisRunContext context, Network network, List filters, List equipmentsTypesAllowed, Reporter reporter) { + private String getContainerNames(List filters) { List containerNamesList = filters.stream().map(EquipmentsContainer::getContainerName).toList(); - String containerNames = Arrays.toString(containerNamesList.toArray()); + return "[" + String.join(", ", containerNamesList) + "]"; + } + + private Stream getMonitoredIdentifiablesFromContainers(SensitivityAnalysisRunContext context, Network network, List filters, List equipmentsTypesAllowed, Reporter reporter) { + String containersNames = getContainerNames(filters); List listIdentAttributes = goGetIdentifiables(filters, context.getNetworkUuid(), context.getVariantId(), reporter); // check that monitored equipments type is allowed @@ -176,7 +180,7 @@ private Stream getMonitoredIdentifiablesFromContainers(S reporter.report(Report.builder() .withKey("badMonitoredEquipmentType") .withDefaultMessage("Monitored equipments type in filter with name=${names} should be ${expectedType} : filter is ignored") - .withValue("names", containerNames) + .withValue(NAMES, containersNames) .withValue(EXPECTED_TYPE, equipmentsTypesAllowed.toString()) .withSeverity(TypedValue.WARN_SEVERITY) .build()); @@ -237,7 +241,7 @@ private List buildSensitivityVariableSets(SensitivityAna SensitivityAnalysisInputData.DistributionType distributionType) { List result = new ArrayList<>(); List monitoredVariablesContainersLists = getIdentifiablesFromContainers(context, filters, variablesTypesAllowed, reporter) - .collect(Collectors.toList()); + .toList(); String containerNames = Arrays.toString(filters.stream().map(EquipmentsContainer::getContainerName).toList().toArray()); Stream>> variablesContainersLists = Stream.of(Pair.of(containerNames, monitoredVariablesContainersLists)) .filter(list -> !list.getRight().isEmpty()); From df1535539b88e8e21b86a90a0a1c31d7f802991f Mon Sep 17 00:00:00 2001 From: jamal-khey Date: Mon, 18 Dec 2023 11:57:19 +0100 Subject: [PATCH 11/11] fix api path --- .../sensitivityanalysis/server/service/FilterService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gridsuite/sensitivityanalysis/server/service/FilterService.java b/src/main/java/org/gridsuite/sensitivityanalysis/server/service/FilterService.java index 790732e4..c7452a7d 100644 --- a/src/main/java/org/gridsuite/sensitivityanalysis/server/service/FilterService.java +++ b/src/main/java/org/gridsuite/sensitivityanalysis/server/service/FilterService.java @@ -62,7 +62,7 @@ public List getFilterEquipements(List filterUuids, UUID Objects.requireNonNull(networkUuid); var uriComponentsBuilder = UriComponentsBuilder - .fromPath(DELIMITER + FILTER_API_VERSION + "/filters/exports") + .fromPath(DELIMITER + FILTER_API_VERSION + "/filters/export") .queryParam(IDS, filterUuids) .queryParam(NETWORK_UUID, networkUuid.toString()); if (!StringUtils.isBlank(variantId)) {