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

[CP-V6]- Bug/vas 11649 handle wrong stats on accession register v6 #1460

Merged
Merged
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 @@ -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