Fixed next pervious issue
This commit is contained in:
@@ -240,14 +240,16 @@ 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;
|
||||||
@@ -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;
|
||||||
@@ -347,7 +349,16 @@ public class FlowFormDao {
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user