updated code for next of previous api

This commit is contained in:
rajesh
2024-09-16 16:22:28 +05:30
parent 7babf437d6
commit 721451586b
5 changed files with 44 additions and 32 deletions

View File

@@ -22,6 +22,7 @@ import net.gepafin.tendermanagement.repositories.ApplicationFormFieldRepository;
import net.gepafin.tendermanagement.repositories.ApplicationFormRepository;
import net.gepafin.tendermanagement.repositories.FlowDataRepository;
import net.gepafin.tendermanagement.repositories.FlowEdgesRepository;
import net.gepafin.tendermanagement.service.FormService;
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
@@ -41,6 +42,12 @@ public class FlowFormDao {
@Autowired
private ApplicationFormRepository applicationFormRepository;
@Autowired
private ApplicationDao applicationDao;
@Autowired
private FormService formService;
// Long getNextForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
// // vlaidation if next form findout and cuuent from is not fill the give error
@@ -218,23 +225,28 @@ public class FlowFormDao {
public NextOrPreviousFormResponse getnextOrPreviousForm(ApplicationEntity applicationEntity, Long formId,
FormActionEnum action) {
Long calculatedFormId = null;
FormEntity fromEntity = null;
if(formId == null) {
NextOrPreviousFormResponse nextOrPreviousFormResponse = new NextOrPreviousFormResponse();
nextOrPreviousFormResponse.setNextFormId(getDefaultForm(applicationEntity));
return nextOrPreviousFormResponse;
}
fromEntity = Optional
.of(applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(), formId))
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.FORM_NOT_FOUND)))
.getForm();
NextOrPreviousFormResponse nextOrPreviousFormResponse = new NextOrPreviousFormResponse();
if (action.equals(FormActionEnum.NEXT)) {
nextOrPreviousFormResponse.setNextFormId(getNextForm(fromEntity, applicationEntity));
if (formId == null) {
calculatedFormId = getDefaultForm(applicationEntity);
} else {
nextOrPreviousFormResponse.setPreviousFormId(getPreviousForm(fromEntity, applicationEntity));
fromEntity = Optional
.of(applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(), formId))
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.FORM_NOT_FOUND)))
.getForm();
if (action.equals(FormActionEnum.NEXT)) {
calculatedFormId = getNextForm(fromEntity, applicationEntity);
} else {
calculatedFormId = getPreviousForm(fromEntity, applicationEntity);
}
}
NextOrPreviousFormResponse nextOrPreviousFormResponse = new NextOrPreviousFormResponse();
if (calculatedFormId != null) {
nextOrPreviousFormResponse.setFormId(calculatedFormId);
nextOrPreviousFormResponse.setApplicationFormResponse(
applicationDao.processForm(formService.validateForm(calculatedFormId), applicationEntity));
}
return nextOrPreviousFormResponse;
}