Skip to content

Commit

Permalink
Bug/Vas-11649: handle wrong stats on accession register (#1460)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbenaissa authored Sep 27, 2023
1 parent d9e306b commit 3585fe4
Showing 1 changed file with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import fr.gouv.vitamui.referential.common.dto.AgencyResponseDto;
import fr.gouv.vitamui.referential.common.dto.ExportAccessionRegisterResultParam;
import fr.gouv.vitamui.referential.common.service.AccessionRegisterService;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ByteArrayResource;
Expand Down Expand Up @@ -135,8 +136,9 @@ public PaginatedValuesDto<AccessionRegisterDetailDto> getAllPaginated(
//Constructing json query for Vitam
LOGGER.debug("List of Accession Registers EvIdAppSession : {} ", vitamContext.getApplicationSessionId());
JsonNode query;
AccessionRegisterSearchDto accessionRegisterSearchDto;
try {
AccessionRegisterSearchDto accessionRegisterSearchDto = criteria.isPresent() ?
accessionRegisterSearchDto = criteria.isPresent() ?
objectMapper.readValue(criteria.get(), AccessionRegisterSearchDto.class) :
new AccessionRegisterSearchDto();
query = AccessRegisterVitamQueryHelper.createQueryDSL(
Expand All @@ -159,19 +161,38 @@ public PaginatedValuesDto<AccessionRegisterDetailDto> getAllPaginated(
resultTotal = hits.getTotal();
}

boolean hasMore = pageNumber * pageSize + resultSize < resultTotal;
boolean hasMoreData = pageNumber * pageSize + resultSize < resultTotal;
List<AccessionRegisterDetailDto> valuesDto = AccessionRegisterConverter.toDetailsDtos(results.getResults());
valuesDto.forEach(value -> {
value.setOriginatingAgencyLabel(agenciesMap.get(value.getOriginatingAgency()));
value.setSubmissionAgencyLabel(agenciesMap.get(value.getSubmissionAgency()));
});
AccessionRegisterStatsDto statsDto;
//Build statistics from paged data
if (hasMoreData || pageNumber > 0) {
//fetch stats from all records with limit 10000
statsDto = buildStatisticData(accessionRegisterSearchDto, vitamContext);
} else {
//extract stats from current results
statsDto = AccessRegisterStatsHelper.fetchStats(results.getResults());
}
return new PaginatedValuesDto<>(valuesDto, pageNumber, pageSize, resultTotal, hasMoreData,
Map.of("stats", statsDto));
}

//Build statistique datas
Map<String, Object> optionalValues = new HashMap<>();
AccessionRegisterStatsDto statsDto = AccessRegisterStatsHelper.fetchStats(results.getResults());
optionalValues.put("stats", statsDto);

return new PaginatedValuesDto<>(valuesDto, pageNumber, pageSize, resultTotal, hasMore, optionalValues);
@NotNull
private AccessionRegisterStatsDto buildStatisticData(AccessionRegisterSearchDto accessionRegisterSearchDto,
VitamContext vitamContext) {
try {
JsonNode bigStatisticQuery =
AccessRegisterVitamQueryHelper.createQueryDSL(accessionRegisterSearchDto, 0, 10000, null, null);
//fetching all 10000 elements as another query to compute statistics as quick solution
AccessionRegisterDetailResponseDto statisticResults =
fetchingAllPaginatedDataFromVitam(vitamContext, bigStatisticQuery);
return AccessRegisterStatsHelper.fetchStats(statisticResults.getResults());
} catch (InvalidCreateOperationException | InvalidParseOperationException e) {
throw new InternalServerException("Can't create dsl query to get paginated accession registers", e);
}
}

/**
Expand Down

0 comments on commit 3585fe4

Please sign in to comment.