Merge pull request #221 from Kitzanos/feature/GEPAFINBE-172

GEPAFINBE-172 (Valdation Check for Evaluation V2)
This commit is contained in:
Rinaldo
2025-02-24 12:09:42 +01:00
committed by GitHub
6 changed files with 71 additions and 11 deletions

View File

@@ -426,6 +426,10 @@ public class GepafinConstant {
public static final String APPOINTMENT_CANNOT_BE_CREATED = "appointment.cannot.be.created"; public static final String APPOINTMENT_CANNOT_BE_CREATED = "appointment.cannot.be.created";
public static final String APPOINTMENT_NOT_CREATED = "appointment.not.created"; public static final String APPOINTMENT_NOT_CREATED = "appointment.not.created";
public static final String SWITCH="switch";
public static final String IS_CHECK_LIST_ITEM="isChecklistItem";
public static final String VALIDATION_FAILED_FOR_CHECKLIST="validation.failed.checklist";
} }

View File

@@ -119,6 +119,15 @@ public class ApplicationAmendmentRequestDao {
@Autowired @Autowired
private UserRepository userRepository; private UserRepository userRepository;
@Autowired
private EvaluationFormRepository evaluationFormRepository;
@Autowired
private ApplicationEvaluationFormFieldRepository applicationEvaluationFormFieldRepository;
@Autowired
private ApplicationEvaluationFormRepository applicationEvaluationFormRepository;
public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(Long applicationEvaluationId) { public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(Long applicationEvaluationId) {
log.info("Fetching the application data for the Amendment process {}", applicationEvaluationId); log.info("Fetching the application data for the Amendment process {}", applicationEvaluationId);
ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluation(applicationEvaluationId); ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluation(applicationEvaluationId);
@@ -132,16 +141,10 @@ public class ApplicationAmendmentRequestDao {
if(file != null){ if(file != null){
evaluationFileRequests=Utils.convertJsonStringToList(file,FieldRequest.class); evaluationFileRequests=Utils.convertJsonStringToList(file,FieldRequest.class);
} }
Boolean allValid = evaluationFileRequests.stream() if(applicationEvaluationEntity.getEvaluationVersion().equals(EvaluationVersionEnum.V1.getValue())) {
.anyMatch(fieldRequest -> fieldRequest.getValid() == null); checklistValidationForEvaluationV1(evaluationFileRequests, checkList, checklistRequests);
if(checkList != null) { } else if (applicationEvaluationEntity.getEvaluationVersion().equals(EvaluationVersionEnum.V2.getValue())) {
checklistRequests=Utils.convertJsonStringToList(checkList,ChecklistRequest.class); validationCheckEvaluationV2(applicationEvaluationEntity, application);
}
boolean resultCheckList = checklistRequests.stream()
.anyMatch(checklistRequest -> Boolean.TRUE.equals(checklistRequest.getValid())) ? false : true;
if(Boolean.TRUE.equals(allValid) || Boolean.TRUE.equals(resultCheckList)){
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.All_DOCUMENT_CHECKED_AND_ONE_CHECKLIST_CHECKED));
} }
// Set common application-level details // Set common application-level details
String callName = application.getCall().getName(); String callName = application.getCall().getName();
@@ -186,6 +189,47 @@ public class ApplicationAmendmentRequestDao {
return response; return response;
} }
private void validationCheckEvaluationV2(ApplicationEvaluationEntity applicationEvaluationEntity, ApplicationEntity application) {
Long callId= applicationEvaluationEntity.getAssignedApplicationsEntity().getApplication().getCall().getId();
EvaluationFormEntity evaluationFormEntity=evaluationFormRepository.findByCallIdAndIsDeletedFalse(callId);
Long numberOfCheck= application.getCall().getNumberOfCheck();
ApplicationEvaluationFormEntity applicationEvaluationForm=applicationEvaluationFormRepository.findByApplicationEvaluation_IdAndIsDeletedFalse(applicationEvaluationEntity.getId());
List<ContentResponseBean> contentResponseBeans=Utils.convertJsonStringToList(evaluationFormEntity.getContent(),ContentResponseBean.class);
int count = 0;
for (ContentResponseBean content : contentResponseBeans) {
if (GepafinConstant.SWITCH.equals(content.getName()) && content.getSettings().stream()
.anyMatch(setting -> GepafinConstant.IS_CHECK_LIST_ITEM.equals(setting.getName()))) {
ApplicationEvaluationFormFieldEntity field = applicationEvaluationFormFieldRepository
.findByFieldIdAndApplicationEvaluationFormId(content.getId(), applicationEvaluationForm.getId());
if (field != null && Utils.isValidBoolean(field.getFieldValue())) {
Boolean fieldValueAsBoolean = Boolean.parseBoolean(field.getFieldValue());
if (Boolean.FALSE.equals(fieldValueAsBoolean)) {
throw new CustomValidationException(Status.VALIDATION_ERROR,GepafinConstant.VALIDATION_FAILED_FOR_CHECKLIST);
}
if (++count >= numberOfCheck) break;
}
}
}
}
private static void checklistValidationForEvaluationV1(List<FieldRequest> evaluationFileRequests, String checkList, List<ChecklistRequest> checklistRequests) {
Boolean allValid = evaluationFileRequests.stream()
.anyMatch(fieldRequest -> fieldRequest.getValid() == null);
if(checkList != null) {
checklistRequests =Utils.convertJsonStringToList(checkList,ChecklistRequest.class);
}
boolean resultCheckList = checklistRequests.stream()
.anyMatch(checklistRequest -> Boolean.TRUE.equals(checklistRequest.getValid())) ? false : true;
if(Boolean.TRUE.equals(allValid) || Boolean.TRUE.equals(resultCheckList)){
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.All_DOCUMENT_CHECKED_AND_ONE_CHECKLIST_CHECKED));
}
}
public List<AmendmentFormFieldResponse> getIdAndLabelFromResult(List<Map<String, Object>> result) { public List<AmendmentFormFieldResponse> getIdAndLabelFromResult(List<Map<String, Object>> result) {
List<AmendmentFormFieldResponse> formFieldResponses = new ArrayList<>(); List<AmendmentFormFieldResponse> formFieldResponses = new ArrayList<>();

View File

@@ -15,4 +15,12 @@ public interface ApplicationEvaluationFormFieldRepository extends JpaRepository<
"AND f.isDeleted = false") "AND f.isDeleted = false")
List<ApplicationEvaluationFormFieldEntity> findByApplicationEvaluationFormId( List<ApplicationEvaluationFormFieldEntity> findByApplicationEvaluationFormId(
@Param("applicationEvaluationFormId") Long applicationEvaluationFormId); @Param("applicationEvaluationFormId") Long applicationEvaluationFormId);
@Query("SELECT f FROM ApplicationEvaluationFormFieldEntity f " +
"WHERE f.applicationEvaluationForm.id = :applicationEvaluationFormId " +
"AND f.fieldId = :fieldId " +
"AND f.isDeleted = false")
ApplicationEvaluationFormFieldEntity findByFieldIdAndApplicationEvaluationFormId(
@Param("fieldId") String fieldId,
@Param("applicationEvaluationFormId") Long applicationEvaluationFormId);
} }

View File

@@ -785,5 +785,7 @@ public class Utils {
return input.matches("-?\\d+(\\.\\d+)?"); return input.matches("-?\\d+(\\.\\d+)?");
} }
public static boolean isValidBoolean(String value) {
return "true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value);
}
} }

View File

@@ -373,3 +373,4 @@ formula.amount.not.matches.requested.amount= The {0} does not matches to calcula
appointment.cannot.be.created = Appointment cannot be created because call doesn't have the template id. appointment.cannot.be.created = Appointment cannot be created because call doesn't have the template id.
appointment.not.created = Appointment not created please try again. appointment.not.created = Appointment not created please try again.
validation.failed.checklist=Validation failed for checklist.

View File

@@ -364,3 +364,4 @@ formula.amount.not.matches.requested.amount=Il {0} non corrisponde all'importo c
appointment.cannot.be.created = Impossibile creare l'appuntamento perché la chiamata non ha l'ID del modello di appuntamento. appointment.cannot.be.created = Impossibile creare l'appuntamento perché la chiamata non ha l'ID del modello di appuntamento.
appointment.not.created = Appuntamento non creato, riprova appointment.not.created = Appuntamento non creato, riprova
validation.failed.checklist=Convalida fallita per la checklist.