Skip to content
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

Fix filter options by result uuid #41

Merged
merged 6 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,14 @@ public SensitivityResultFilterOptions getSensitivityResultFilterOptions(UUID res
}

SensitivityResultFilterOptions.SensitivityResultFilterOptionsBuilder sensitivityResultOptionsBuilder = SensitivityResultFilterOptions.builder()
.allFunctionIds(sensitivityRepository.findFunctionByResultResultUuidAndFactorFunctionType(sas.getResultUuid(), selector.getFunctionType()))
.allVariableIds(sensitivityRepository.findVariableByResultResultUuidAndFactorFunctionType(sas.getResultUuid(), selector.getFunctionType()));
.allFunctionIds(sensitivityRepository.getDistinctFunctionIds(sas.getResultUuid(), selector.getFunctionType(), !selector.getIsJustBefore()))
.allVariableIds(sensitivityRepository.getDistinctVariableIds(sas.getResultUuid(), selector.getFunctionType(), !selector.getIsJustBefore()));

if (!selector.getIsJustBefore()) {
sensitivityResultOptionsBuilder.allContingencyIds(sensitivityRepository.findContingencyByResultResultUuidAndFactorFunctionType(sas.getResultUuid(), selector.getFunctionType())
sensitivityResultOptionsBuilder.allContingencyIds(sensitivityRepository.getDistinctContingencyIds(sas.getResultUuid(), selector.getFunctionType())
.stream()
.filter(Objects::nonNull)
.collect(Collectors.toList()))
.build();
.collect(Collectors.toList()));
}

return sensitivityResultOptionsBuilder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,24 @@ public interface SensitivityRepository extends JpaRepository<SensitivityEntity,

Page<SensitivityEntity> findAll(Specification<SensitivityEntity> specification, Pageable pageable);

@Query(value = "SELECT distinct s.factor.functionId from SensitivityEntity as s")
List<String> findFunctionByResultResultUuidAndFactorFunctionType(UUID resultUuid, SensitivityFunctionType sensitivityFunctionType);
@Query(value = "SELECT distinct s.factor.functionId from SensitivityEntity as s " +
"where s.result.resultUuid = :resultUuid " +
"and s.factor.functionType = :sensitivityFunctionType " +
"and ((:withContingency = true and s.contingency is not null ) or (:withContingency = false and s.contingency is null )) " +
"order by s.factor.functionId")
List<String> getDistinctFunctionIds(UUID resultUuid, SensitivityFunctionType sensitivityFunctionType, boolean withContingency);

@Query(value = "SELECT distinct s.factor.variableId from SensitivityEntity as s")
List<String> findVariableByResultResultUuidAndFactorFunctionType(UUID resultUuid, SensitivityFunctionType sensitivityFunctionType);
@Query(value = "SELECT distinct s.factor.variableId from SensitivityEntity as s " +
"where s.result.resultUuid = :resultUuid " +
"and s.factor.functionType = :sensitivityFunctionType " +
"and ((:withContingency = true and s.contingency is not null ) or (:withContingency = false and s.contingency is null )) " +
"order by s.factor.variableId")
List<String> getDistinctVariableIds(UUID resultUuid, SensitivityFunctionType sensitivityFunctionType, boolean withContingency);

@Query(value = "SELECT distinct s.contingency.contingencyId from SensitivityEntity as s")
List<String> findContingencyByResultResultUuidAndFactorFunctionType(UUID resultUuid, SensitivityFunctionType sensitivityFunctionType);
@Query(value = "SELECT distinct s.contingency.contingencyId from SensitivityEntity as s " +
"where s.result.resultUuid = :resultUuid and s.factor.functionType = :sensitivityFunctionType " +
"order by s.contingency.contingencyId")
List<String> getDistinctContingencyIds(UUID resultUuid, SensitivityFunctionType sensitivityFunctionType);

static Specification<SensitivityEntity> getSpecification(AnalysisResultEntity sas,
SensitivityFunctionType functionType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,16 +629,16 @@ public void runAndSaveTest() throws Exception {
assertEquals(2, filterOptions.getAllVariableIds().size());

ResultsSelector filterOptionsSelector2 = ResultsSelector.builder().isJustBefore(true)
.functionType(SensitivityFunctionType.BRANCH_ACTIVE_POWER_2).build();
.functionType(SensitivityFunctionType.BRANCH_CURRENT_1).build();
result = mockMvc.perform(get("/" + VERSION + "/results/{resultUuid}/filter-options?selector={selector}", RESULT_UUID,
mapper.writeValueAsString(filterOptionsSelector2)))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andReturn();
SensitivityResultFilterOptions filterOptions2 = mapper.readValue(result.getResponse().getContentAsString(), new TypeReference<>() { });
assertNull(filterOptions2.getAllContingencyIds());
assertEquals(3, filterOptions2.getAllFunctionIds().size());
assertEquals(2, filterOptions2.getAllVariableIds().size());
assertEquals(0, filterOptions2.getAllFunctionIds().size());
assertEquals(0, filterOptions2.getAllVariableIds().size());

// check that a request for not present contingency does not crash and just brings nothing
ResultsSelector selectorNKz1 = ResultsSelector.builder().isJustBefore(false)
Expand Down