Updated code for changes in evaluation Api

This commit is contained in:
rajesh
2025-03-04 12:32:24 +05:30
parent befad3851f
commit 7f2e44a968
3 changed files with 56 additions and 47 deletions

View File

@@ -964,14 +964,6 @@ public class ApplicationDao {
applicationEntity.setStatus(status.getValue()); applicationEntity.setStatus(status.getValue());
log.info("Status updated to DRAFT for applicationId: " + applicationId); 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); applicationEntity = applicationRepository.save(applicationEntity);
log.info("Application status updated successfully | applicationId: {}, newStatus: {}", applicationId, applicationEntity.getStatus()); log.info("Application status updated successfully | applicationId: {}, newStatus: {}", applicationId, applicationEntity.getStatus());
@@ -983,43 +975,6 @@ public class ApplicationDao {
return getApplicationResponse(applicationEntity); return getApplicationResponse(applicationEntity);
} }
private void processTechnicalEvaluation(Long applicationId, ApplicationEntity applicationEntity, ApplicationStatusTypeEnum status){
Optional<ApplicationEvaluationEntity> 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<Map<String, Object>> 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) { public Integer calculateProgress(Long totalSteps, Long completedSteps) {
if (FieldValidator.isNullOrZero(totalSteps)) { if (FieldValidator.isNullOrZero(totalSteps)) {
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.TOTAL_STEPS_NOT_BE_ZERO)); throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.TOTAL_STEPS_NOT_BE_ZERO));

View File

@@ -1862,7 +1862,21 @@ public class ApplicationEvaluationDao {
// UserEntity userEntity = userService.validateUser(application.getUserId()); // UserEntity userEntity = userService.validateUser(application.getUserId());
// callService.validatePublishedCall(application.getCall().getId(), userEntity.getHub().getId()); // callService.validatePublishedCall(application.getCall().getId(), userEntity.getHub().getId());
ApplicationEntity oldApplicationEntity = Utils.getClonedEntityForData(application); ApplicationEntity oldApplicationEntity = Utils.getClonedEntityForData(application);
if(newStatus.equals(ApplicationStatusForEvaluation.ADMISSIBLE) && Boolean.TRUE.equals(application.getStatus().equals(ApplicationStatusTypeEnum.APPOINTMENT.getValue()))){
application.setStatus(newStatus.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); application = applicationRepository.save(application);
/** This code is responsible for adding a version history log for the "Update Application" operation. **/ /** This code is responsible for adding a version history log for the "Update Application" operation. **/
@@ -2423,5 +2437,43 @@ public class ApplicationEvaluationDao {
} }
return false; return false;
} }
private void processTechnicalEvaluation(Long applicationId, ApplicationEntity applicationEntity, ApplicationStatusForEvaluation status){
Optional<ApplicationEvaluationEntity> 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<Map<String, Object>> 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;
}
}
} }

View File

@@ -4,7 +4,9 @@ import com.fasterxml.jackson.annotation.JsonValue;
public enum ApplicationStatusForEvaluation { public enum ApplicationStatusForEvaluation {
APPROVED("APPROVED"), APPROVED("APPROVED"),
REJECTED("REJECTED"); REJECTED("REJECTED"),
ADMISSIBLE("ADMISSIBLE"),
TECHNICAL_EVALUATION("TECHNICAL_EVALUATION");
private String value; private String value;