updated code for next form api
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -22,6 +23,7 @@ import net.gepafin.tendermanagement.repositories.ApplicationFormRepository;
|
||||
import net.gepafin.tendermanagement.repositories.FlowDataRepository;
|
||||
import net.gepafin.tendermanagement.repositories.FlowEdgesRepository;
|
||||
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;
|
||||
|
||||
@Component
|
||||
@@ -39,6 +41,7 @@ public class FlowFormDao {
|
||||
@Autowired
|
||||
private ApplicationFormRepository applicationFormRepository;
|
||||
|
||||
|
||||
// Long getNextForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
|
||||
// // vlaidation if next form findout and cuuent from is not fill the give error
|
||||
// List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findBySourceIdAndCallId(currentFormEntity.getId(), applicationEntity.getCall().getId());
|
||||
@@ -166,11 +169,6 @@ public class FlowFormDao {
|
||||
.map(FlowDataEntity::getFormId)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public Long getPreviousForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
|
||||
// Retrieve the flow edges for the previous forms
|
||||
@@ -218,20 +216,40 @@ public class FlowFormDao {
|
||||
.findFirst().orElse(null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public NextOrPreviousFormResponse getnextOrPreviousForm(ApplicationEntity applicationEntity, FormEntity formEntity,
|
||||
public NextOrPreviousFormResponse getnextOrPreviousForm(ApplicationEntity applicationEntity, Long formId,
|
||||
FormActionEnum action) {
|
||||
FormEntity fromEntity = null;
|
||||
if(formId == null) {
|
||||
NextOrPreviousFormResponse nextOrPreviousFormResponse = new NextOrPreviousFormResponse();
|
||||
nextOrPreviousFormResponse.setNextFormId(getDefaultForm(applicationEntity));
|
||||
return nextOrPreviousFormResponse;
|
||||
}else {
|
||||
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(formEntity, applicationEntity));
|
||||
nextOrPreviousFormResponse.setNextFormId(getNextForm(fromEntity, applicationEntity));
|
||||
} else {
|
||||
nextOrPreviousFormResponse.setPreviousFormId(getPreviousForm(formEntity, applicationEntity));
|
||||
nextOrPreviousFormResponse.setPreviousFormId(getPreviousForm(fromEntity, applicationEntity));
|
||||
}
|
||||
return nextOrPreviousFormResponse;
|
||||
}
|
||||
|
||||
private Long getDefaultForm(ApplicationEntity applicationEntity) {
|
||||
List<ApplicationFormEntity> applicationFormList = applicationFormRepository.findByApplicationIdOrderByCreatedDateAsc(applicationEntity.getId());
|
||||
if(applicationFormList.isEmpty()) {
|
||||
return applicationEntity.getCall().getInitialForm();
|
||||
}
|
||||
if(applicationFormList.get(applicationFormList.size()-1).getForm().getId().equals(applicationEntity.getCall().getFinalForm())) {
|
||||
return applicationEntity.getCall().getInitialForm();
|
||||
}
|
||||
return getNextForm(applicationFormList.get(applicationFormList.size()-1).getForm(), applicationEntity);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user