Fixed next pervious issue

This commit is contained in:
harish
2024-10-04 19:03:33 +05:30
parent 2bae3675f8
commit f838da73ef
2 changed files with 22 additions and 11 deletions

View File

@@ -240,15 +240,17 @@ public class FlowFormDao {
List<Long> previousFormIds = flowEdgesList.stream() List<Long> previousFormIds = flowEdgesList.stream()
.map(FlowEdgesEntity::getSourceId) .map(FlowEdgesEntity::getSourceId)
.toList(); .toList();
if (previousFormIds.size() == 1) {
return previousFormIds.get(0);
}
List<ApplicationFormEntity> applicationFormEntities=applicationFormRepository.findByFormIdInAndApplicationId(previousFormIds,applicationEntity.getId()); List<ApplicationFormEntity> applicationFormEntities=applicationFormRepository.findByFormIdInAndApplicationId(previousFormIds,applicationEntity.getId());
applicationFormEntities.sort(Comparator.comparing(ApplicationFormEntity::getCreatedDate).reversed()); applicationFormEntities.sort(Comparator.comparing(ApplicationFormEntity::getCreatedDate).reversed());
return applicationFormEntities.isEmpty() ? null : applicationFormEntities.get(0).getForm().getId(); return applicationFormEntities.isEmpty() ? null : applicationFormEntities.get(0).getForm().getId();
} }
public NextOrPreviousFormResponse getnextOrPreviousForm(ApplicationEntity applicationEntity, Long formId, public NextOrPreviousFormResponse getNextOrPreviousForm(ApplicationEntity applicationEntity, Long formId,
FormActionEnum action) { FormActionEnum action) {
Long calculatedFormId = null; Long calculatedFormId = null;
FormEntity formEntity = null; FormEntity formEntity = null;
if (formId == null) { if (formId == null) {
@@ -299,7 +301,7 @@ public class FlowFormDao {
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId()); List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
Long totalFormSteps = calculateTotalSteps(flowEdgesList); Long totalFormSteps = calculateTotalSteps(flowEdgesList);
Long currentStep = calculateCurrentStep(formEntity); Long currentStep = calculateCurrentStep(flowEdgesList, formEntity);
nextOrPreviousFormResponse.setTotalFormSteps(totalFormSteps); nextOrPreviousFormResponse.setTotalFormSteps(totalFormSteps);
completedSteps = getCompletedSteps(applicationEntity); completedSteps = getCompletedSteps(applicationEntity);
nextOrPreviousFormResponse.setCompletedSteps(Long.valueOf(completedSteps)); nextOrPreviousFormResponse.setCompletedSteps(Long.valueOf(completedSteps));
@@ -321,11 +323,11 @@ public class FlowFormDao {
return completedSteps; return completedSteps;
} }
public Long calculateCurrentStep(FormEntity formEntity) { public Long calculateCurrentStep(List<FlowEdgesEntity> flowEdgesList, FormEntity formEntity) {
Long currentStep = 2l; Long currentStep = 2l;
if (formEntity.getId().equals(formEntity.getCall().getInitialForm())) { if (formEntity.getId().equals(formEntity.getCall().getInitialForm())) {
currentStep = 1l; currentStep = 1l;
} else if (formEntity.getId().equals(formEntity.getCall().getFinalForm())) { } else if (flowEdgesList.size()>1 && formEntity.getId().equals(formEntity.getCall().getFinalForm())) {
currentStep = 3l; currentStep = 3l;
} }
return currentStep; return currentStep;
@@ -341,13 +343,22 @@ public class FlowFormDao {
private Long getDefaultForm(ApplicationEntity applicationEntity) { private Long getDefaultForm(ApplicationEntity applicationEntity) {
List<ApplicationFormEntity> applicationFormList = applicationFormRepository.findByApplicationIdOrderByCreatedDateAsc(applicationEntity.getId()); List<ApplicationFormEntity> applicationFormList = applicationFormRepository.findByApplicationIdOrderByCreatedDateAsc(applicationEntity.getId());
if(applicationFormList.isEmpty()) { if (applicationFormList.isEmpty()) {
return applicationEntity.getCall().getInitialForm(); return applicationEntity.getCall().getInitialForm();
} }
if(applicationFormList.get(applicationFormList.size()-1).getForm().getId().equals(applicationEntity.getCall().getFinalForm())) { if (applicationFormList.get(applicationFormList.size() - 1).getForm().getId().equals(applicationEntity.getCall().getFinalForm())) {
return applicationEntity.getCall().getInitialForm(); return applicationEntity.getCall().getInitialForm();
} }
return getNextForm(applicationFormList.get(applicationFormList.size()-1).getForm(), applicationEntity); FormEntity currentFormEntity = applicationFormList.get(applicationFormList.size() - 1).getForm();
for (ApplicationFormEntity applicationFormEntity : applicationFormList) {
Boolean isCompleted = formDao.validateCompletedSteps(applicationFormFieldRepository.findByApplicationFormId(applicationFormEntity.getId()), applicationEntity, applicationFormEntity.getForm());
if (Boolean.FALSE.equals(isCompleted)) {
currentFormEntity = applicationFormEntity.getForm();
break;
}
}
return getNextForm(currentFormEntity, applicationEntity);
} }

View File

@@ -72,7 +72,7 @@ public class ApplicationServiceImpl implements ApplicationService {
public NextOrPreviousFormResponse getNextOrPreviousForm(HttpServletRequest request, Long applicationId, Long formId, public NextOrPreviousFormResponse getNextOrPreviousForm(HttpServletRequest request, Long applicationId, Long formId,
FormActionEnum action) { FormActionEnum action) {
ApplicationEntity applicationEntity = validateApplication(applicationId); ApplicationEntity applicationEntity = validateApplication(applicationId);
return flowFormDao.getnextOrPreviousForm(applicationEntity, formId, action); return flowFormDao.getNextOrPreviousForm(applicationEntity, formId, action);
} }
@Override @Override