Merge pull request #319 from Kitzanos/extraction-changes-prod

Cherry-pick (Updated logic for extraction)
This commit is contained in:
Rinaldo
2025-07-02 11:36:08 +02:00
committed by GitHub
2 changed files with 71 additions and 42 deletions

View File

@@ -2423,61 +2423,90 @@ public class ApplicationDao {
public byte[] downloadRankingCsv(Long callId) { public byte[] downloadRankingCsv(Long callId) {
CallEntity callEntity = callService.validateCall(callId); CallEntity callEntity = callService.validateCall(callId);
BigDecimal scoreList = BigDecimal.ZERO; List<ApplicationEntity> applications =
List<EvaluationCriteriaEntity> evaluationCriteriaEntities = applicationRepository.findByCallIdAndIsDeletedFalseAndStatusIn(
evaluationCriteriaRepository.findByCallIdAndIsDeletedFalse(callId); callId,
List<String> headers = Arrays.asList( List.of(
"ApplicationID", ApplicationStatusForEvaluation.APPROVED.getValue(),
"VatNumber", ApplicationStatusForEvaluation.ADMISSIBLE.getValue(),
"Company Name", ApplicationStatusForEvaluation.TECHNICAL_EVALUATION.getValue()
"Protocol", ));
"Requested Amount",
"Status",
"Total Score",
"Individual Scores"
);
List<String> dynamicLabels = new ArrayList<>(); // Maintain insertion order, allow duplicates only once
Map<Long, Map<String, BigDecimal>> appLabelScoresMap = new HashMap<>();
for (EvaluationCriteriaEntity evaluationCriteria : evaluationCriteriaEntities) { Map<Long, ApplicationEntity> applicationMap = new HashMap<>();
scoreList = scoreList.add(evaluationCriteria.getScore()); Map<Long, BigDecimal> appTotalScoreMap = new HashMap<>();
for (ApplicationEntity app : applications) {
Long appId = app.getId();
applicationMap.put(appId, app);
ApplicationEvaluationEntity evaluation =
applicationEvaluationRepository.findByApplicationId(appId);
BigDecimal totalScore = applicationEvaluationDao.calculateTotalScore(evaluation.getCriteria());
appTotalScoreMap.put(appId, totalScore);
List<CriteriaResponse> criteriaList =
evaluation.getCriteria() != null ?
Utils.convertJsonToList(evaluation.getCriteria(), new TypeReference<List<CriteriaResponse>>() {}) :
List.of();
List<CriteriaResponse> dbCriteriaList = applicationEvaluationDao.getCriteriaResponse(appId);
Map<String, BigDecimal> scoreByLabel = new HashMap<>();
for (CriteriaResponse criteria : criteriaList) {
Optional<CriteriaResponse> matchedDb = dbCriteriaList.stream()
.filter(db -> Objects.equals(db.getId(), criteria.getId()))
.findFirst();
String label = matchedDb.map(CriteriaResponse::getLabel).orElse("");
if (!dynamicLabels.contains(label)) {
dynamicLabels.add(label);
}
scoreByLabel.put(label, criteria.getScore() != null ? criteria.getScore() : BigDecimal.ZERO);
}
appLabelScoresMap.put(appId, scoreByLabel);
} }
List<ApplicationEntity> applications = // Build headers dynamically
applicationRepository.findByCallIdAndIsDeletedFalseAndStatusIn(callId,List.of(ApplicationStatusForEvaluation.APPROVED.getValue(),ApplicationStatusForEvaluation.ADMISSIBLE.getValue(),ApplicationStatusForEvaluation.TECHNICAL_EVALUATION.getValue())); List<String> headers = new ArrayList<>(List.of(
"ApplicationID", "VatNumber", "Company Name", "Protocol", "Requested Amount", "Status", "Total Score"
));
headers.addAll(dynamicLabels);
// Collect all rows with totalScore for sorting // Prepare data rows
List<List<Object>> rows = new ArrayList<>(); List<List<Object>> rows = new ArrayList<>();
for (ApplicationEntity app : applications) { for (ApplicationEntity app : applications) {
Long appId = app.getId();
CompanyEntity company = companyService.validateCompany(app.getCompanyId()); CompanyEntity company = companyService.validateCompany(app.getCompanyId());
String name = company.getCompanyName();
String vat = company.getVatNumber();
Long applicationId = app.getId();
ProtocolEntity protocolEntity = app.getProtocol(); ProtocolEntity protocolEntity = app.getProtocol();
Long protocol = (protocolEntity != null) ? protocolEntity.getProtocolNumber() : 0L;
BigDecimal requestedAmount = app.getAmountRequested();
String status = app.getStatus();
ApplicationEvaluationEntity applicationEvaluationEntity = List<Object> row = new ArrayList<>();
applicationEvaluationRepository.findByApplicationId(app.getId()); row.add(appId);
row.add(company.getVatNumber());
row.add(company.getCompanyName());
row.add(protocolEntity != null ? protocolEntity.getProtocolNumber() : 0L);
row.add(app.getAmountRequested());
row.add(app.getStatus());
row.add(appTotalScoreMap.get(appId));
BigDecimal totalScore = applicationEvaluationDao.calculateTotalScore( Map<String, BigDecimal> scores = appLabelScoresMap.getOrDefault(appId, Collections.emptyMap());
applicationEvaluationEntity.getCriteria()
);
rows.add(Arrays.asList( for (String label : dynamicLabels) {
applicationId, row.add(scores.getOrDefault(label, BigDecimal.ZERO));
vat, }
name,
protocol, rows.add(row);
requestedAmount,
status,
scoreList,
totalScore
));
} }
// 5. Write the CSV using Commons CSV, with headers: // Generate CSV
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
try (OutputStreamWriter writer = new OutputStreamWriter(out, StandardCharsets.UTF_8); try (OutputStreamWriter writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
CSVPrinter csvPrinter = new CSVPrinter(writer, CSVPrinter csvPrinter = new CSVPrinter(writer,

View File

@@ -1549,13 +1549,13 @@ public class ApplicationEvaluationDao {
return callRepository.findCallEntityByApplicationId(applicationId); return callRepository.findCallEntityByApplicationId(applicationId);
} }
private List<EvaluationCriteriaEntity> getEvaluationCriterias(CallEntity call) { public List<EvaluationCriteriaEntity> getEvaluationCriterias(CallEntity call) {
log.info("Fetching evaluation criterias for callId: {}", call.getId()); log.info("Fetching evaluation criterias for callId: {}", call.getId());
return evaluationCriteriaRepository return evaluationCriteriaRepository
.findByCallIdAndLookupDataTypeAndIsDeletedFalse(call.getId(), LookUpDataEntity.LookUpDataTypeEnum.EVALUATION_CRITERIA.getValue()); .findByCallIdAndLookupDataTypeAndIsDeletedFalse(call.getId(), LookUpDataEntity.LookUpDataTypeEnum.EVALUATION_CRITERIA.getValue());
} }
private CriteriaResponse buildCriteriaResponse(Long applicationId, EvaluationCriteriaEntity criteria) { public CriteriaResponse buildCriteriaResponse(Long applicationId, EvaluationCriteriaEntity criteria) {
CriteriaResponse response = new CriteriaResponse(); CriteriaResponse response = new CriteriaResponse();
response.setId(criteria.getId()); response.setId(criteria.getId());
response.setLabel(criteria.getLookupData().getValue()); response.setLabel(criteria.getLookupData().getValue());