Skip to content

Implement global filter #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Implement global filter #120

wants to merge 9 commits into from

Conversation

ghazwarhili
Copy link
Contributor

No description provided.

Mathieu-Deharbe

This comment was marked as resolved.

@ghazwarhili
Copy link
Contributor Author

#120 (review)
fixed

Copy link
Contributor

@Mathieu-Deharbe Mathieu-Deharbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filtering by column seems to be broken :

image

I had the same problems with text and number fields, no matter the filter operation.

Comment on lines -154 to 164
} catch (JsonProcessingException e) {
SensitivityRunQueryResult result = service.getRunResult(resultUuid, networkUuid, variantId, selector, resourceFilters, globalFilter);
return result != null ? ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(result) : ResponseEntity.notFound().build();
} catch (Exception e) {
return ResponseEntity.badRequest().build();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you change JsonProcessingException to Exception doesn't it mean that any throw will be considered a bad request error ?

If you want to catch everything maybe : ?

        } catch (JsonProcessingException e) {
            return ResponseEntity.badRequest().build();
        } catch (Exception e) {
            return ResponseEntity.internalServerError().build();
        }

But if you think that we can consider any error in the controller to be a badRequest, then fine.

Comment on lines +62 to +63
Specification<SensitivityResultEntity> baseSpec = buildSpecification(resultUuid, Collections.emptyList(), false);
Specification<SensitivityResultEntity> resourceFilterSpec = buildCustomResourceFilterSpecification(resourceFilters);
Copy link
Contributor

@Mathieu-Deharbe Mathieu-Deharbe Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is this change that breaks the filter by column (cf request change). Probably because you don't use the specification functions anymore (like appendTextFilterToSpecification...)

return columnSpec;
}

private Specification<SensitivityResultEntity> createSingleFilterSpecification(ResourceFilterDTO filter) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you forgot to take into account the DataType of the Filter. The behavior is different between text and numbers.

if (filter.value() instanceof List<?> valueList && !valueList.isEmpty()) {
Path<Object> fieldPath = getFieldPathForFilter(root, filter.column());

switch (filter.type()) {
Copy link
Contributor

@Mathieu-Deharbe Mathieu-Deharbe Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot more type that should be handled I think : NOT_EQUAL, CONTAINS... (like in appendTextFilterToSpecification).

Actually why don't you use appendTextFilterToSpecification and appendNumberFilterToSpecification ?

@@ -90,4 +208,170 @@ public Map<String, Long> getIdentifiablesCount(SensitivityFactorsIdsByGroup fact
return restTemplate.exchange(filterServerBaseUri + path, HttpMethod.GET, null, new ParameterizedTypeReference<Map<String, Long>>() {
}).getBody();
}

public List<ResourceFilterDTO> getResourceFiltersForSensitivity(UUID networkUuid, String variantId, GlobalFilter globalFilter) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are in sensi Filter service, I don't think this is useful to precise ForSensitivity here. (I took the function declaration from loadflow).

Suggested change
public List<ResourceFilterDTO> getResourceFiltersForSensitivity(UUID networkUuid, String variantId, GlobalFilter globalFilter) {
public List<ResourceFilterDTO> getResourceFilters(@NonNull UUID networkUuid, @NonNull String variantId, @NonNull GlobalFilter globalFilter) {

ResourceFilterDTO.DataType.TEXT,
ResourceFilterDTO.Type.IN,
allSubjectIds,
"functionId"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"functionId"
SensitivityResultEntity.Fields.functionId

));
}

private Map<EquipmentType, List<String>> processEquipmentTypes(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming doesn't explain the function.

return result;
}

private List<String> processEquipmentType(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming doesn't explain the function.

new ArrayList<>(genericFilterResults);
}

private List<String> processGenericFilter(AbstractFilter filter, EquipmentType equipmentType, Network network) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming doesn't explain the function.

Comment on lines +106 to +107
//when(networkStoreService.getNetwork(UUID.fromString(eq(network.getId())), any(PreloadingStrategy.class))).thenReturn(network);
//when(network.getVariantManager()).thenReturn(variantManager);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link

sonarqubecloud bot commented Jul 1, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
57.4% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants