From 7f2e44a96816eeb524863cdd6455c246e1e466d0 Mon Sep 17 00:00:00 2001 From: rajesh Date: Tue, 4 Mar 2025 12:32:24 +0530 Subject: [PATCH] Updated code for changes in evaluation Api --- .../tendermanagement/dao/ApplicationDao.java | 45 ---------------- .../dao/ApplicationEvaluationDao.java | 54 ++++++++++++++++++- .../enums/ApplicationStatusForEvaluation.java | 4 +- 3 files changed, 56 insertions(+), 47 deletions(-) diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java index 62289ed7..0b565c89 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java @@ -964,14 +964,6 @@ public class ApplicationDao { applicationEntity.setStatus(status.getValue()); log.info("Status updated to DRAFT for applicationId: " + applicationId); } - if(status.equals(ApplicationStatusTypeEnum.ADMISSIBLE) && Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.APPOINTMENT.getValue()))){ - applicationEntity.setStatus(status.getValue()); - log.info("Status updated to ADMISSIBLE for applicationId: " + applicationId); - emailNotificationDao.sendAdmissibilityNotificationEmailForAdmissibleApplication(applicationEntity); - } - if(status.equals(ApplicationStatusTypeEnum.TECHNICAL_EVALUATION) && Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.ADMISSIBLE.getValue()))){ - processTechnicalEvaluation(applicationId, applicationEntity, status); - } applicationEntity = applicationRepository.save(applicationEntity); log.info("Application status updated successfully | applicationId: {}, newStatus: {}", applicationId, applicationEntity.getStatus()); @@ -983,43 +975,6 @@ public class ApplicationDao { return getApplicationResponse(applicationEntity); } - private void processTechnicalEvaluation(Long applicationId, ApplicationEntity applicationEntity, ApplicationStatusTypeEnum status){ - Optional evaluationEntityOpt = applicationEvaluationRepository.findByApplicationIdAndIsDeletedFalse(applicationId); - if (evaluationEntityOpt.isPresent()){ - ApplicationEvaluationEntity evaluationEntity = evaluationEntityOpt.get(); - String criteriaJson = evaluationEntity.getCriteria(); - if (criteriaJson != null){ - Integer totalScore = calculateTotalScore(evaluationEntity.getCriteria()); - if (totalScore > 40) { - applicationEntity.setStatus(status.getValue()); - log.info("Status updated to TECHNICAL_EVALUATION for applicationId: " + applicationId); - } - else{ - throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.INSUFFICIENT_SCORE_MESSAGE)); - } - } - } - } - - private Integer calculateTotalScore(String criteriaJson){ - try { - ObjectMapper objectMapper = new ObjectMapper(); - // Convert JSON string to List of Maps - List> criteriaList = objectMapper.readValue(criteriaJson, new TypeReference<>() { - }); - - // Sum all scores (ignoring null scores) - Integer totalScore = criteriaList.stream() - .mapToInt(obj -> obj.get("score") != null ? ((Number) obj.get("score")).intValue() : 0) - .sum(); - - return totalScore; - } - catch (Exception e) { - log.error(" Error parsing criteria JSON: {}", e.getMessage()); - return 0; - } - } public Integer calculateProgress(Long totalSteps, Long completedSteps) { if (FieldValidator.isNullOrZero(totalSteps)) { throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.TOTAL_STEPS_NOT_BE_ZERO)); diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java index e07a65d2..336db880 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java @@ -1862,7 +1862,21 @@ public class ApplicationEvaluationDao { // UserEntity userEntity = userService.validateUser(application.getUserId()); // callService.validatePublishedCall(application.getCall().getId(), userEntity.getHub().getId()); ApplicationEntity oldApplicationEntity = Utils.getClonedEntityForData(application); - application.setStatus(newStatus.getValue()); + + + if(newStatus.equals(ApplicationStatusForEvaluation.ADMISSIBLE) && Boolean.TRUE.equals(application.getStatus().equals(ApplicationStatusTypeEnum.APPOINTMENT.getValue()))){ + application.setStatus(newStatus.getValue()); + log.info("Status updated to ADMISSIBLE for applicationId: " + application.getId()); + emailNotificationDao.sendAdmissibilityNotificationEmailForAdmissibleApplication(application); + } + + if(newStatus.equals(ApplicationStatusForEvaluation.TECHNICAL_EVALUATION) && Boolean.TRUE.equals(application.getStatus().equals(ApplicationStatusTypeEnum.ADMISSIBLE.getValue()))){ + processTechnicalEvaluation(application.getId(), application, newStatus); + } + + if((newStatus.equals(ApplicationStatusForEvaluation.APPROVED) || newStatus.equals(ApplicationStatusForEvaluation.REJECTED)) && application.getStatus().equals(ApplicationStatusTypeEnum.EVALUATION.getValue())) { + application.setStatus(newStatus.getValue()); + } application = applicationRepository.save(application); /** This code is responsible for adding a version history log for the "Update Application" operation. **/ @@ -2423,5 +2437,43 @@ public class ApplicationEvaluationDao { } return false; } + private void processTechnicalEvaluation(Long applicationId, ApplicationEntity applicationEntity, ApplicationStatusForEvaluation status){ + Optional evaluationEntityOpt = applicationEvaluationRepository.findByApplicationIdAndIsDeletedFalse(applicationId); + if (evaluationEntityOpt.isPresent()){ + ApplicationEvaluationEntity evaluationEntity = evaluationEntityOpt.get(); + String criteriaJson = evaluationEntity.getCriteria(); + if (criteriaJson != null){ + Integer totalScore = calculateTotalScore(evaluationEntity.getCriteria()); + if (totalScore > 40) { + applicationEntity.setStatus(status.getValue()); + log.info("Status updated to TECHNICAL_EVALUATION for applicationId: " + applicationId); + } + else{ + throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.INSUFFICIENT_SCORE_MESSAGE)); + } + } + } + } + + private Integer calculateTotalScore(String criteriaJson){ + try { + ObjectMapper objectMapper = new ObjectMapper(); + // Convert JSON string to List of Maps + List> criteriaList = objectMapper.readValue(criteriaJson, new TypeReference<>() { + }); + + // Sum all scores (ignoring null scores) + Integer totalScore = criteriaList.stream() + .mapToInt(obj -> obj.get("score") != null ? ((Number) obj.get("score")).intValue() : 0) + .sum(); + + return totalScore; + } + catch (Exception e) { + log.error(" Error parsing criteria JSON: {}", e.getMessage()); + return 0; + } + } + } diff --git a/src/main/java/net/gepafin/tendermanagement/enums/ApplicationStatusForEvaluation.java b/src/main/java/net/gepafin/tendermanagement/enums/ApplicationStatusForEvaluation.java index 61c39b8e..f0f6acb8 100644 --- a/src/main/java/net/gepafin/tendermanagement/enums/ApplicationStatusForEvaluation.java +++ b/src/main/java/net/gepafin/tendermanagement/enums/ApplicationStatusForEvaluation.java @@ -4,7 +4,9 @@ import com.fasterxml.jackson.annotation.JsonValue; public enum ApplicationStatusForEvaluation { APPROVED("APPROVED"), - REJECTED("REJECTED"); + REJECTED("REJECTED"), + ADMISSIBLE("ADMISSIBLE"), + TECHNICAL_EVALUATION("TECHNICAL_EVALUATION"); private String value;