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

@@ -47,9 +47,6 @@ public class ApplicationDao {
@Autowired
private FormService formService;
@Autowired
private FormDao formDao;
public ApplicationResponseBean createApplication(ApplicationRequestBean applicationRequestBean, UserEntity userEntity, Long formId) {
FormEntity formEntity = formService.validateForm(formId);
CallEntity call = callService.validateCall(formEntity.getCall().getId());
@@ -238,30 +235,40 @@ public class ApplicationDao {
formEntity.getCall().getId());
applicationEntity=application.get();
formEntities.add(formEntity);
processForm(formEntity, applicationEntity, formApplicationResponses);
addFormApplication(formEntity, applicationEntity, formApplicationResponses);
}
else {
List<ApplicationFormEntity> applicationFormEntities = applicationFormRepository.findByApplicationId(applicationEntity.getId());
for (ApplicationFormEntity applicationFormEntity : applicationFormEntities) {
FormEntity form = formService.validateForm(applicationFormEntity.getForm().getId());
formEntities.add(form);
processForm(form, applicationEntity, formApplicationResponses);
addFormApplication(form, applicationEntity, formApplicationResponses);
}
}
return createApplicationGetResponseBean(applicationEntity, formEntities, formApplicationResponses);
}
private void processForm(FormEntity formEntity, ApplicationEntity applicationEntity, List<FormApplicationResponse> formApplicationResponses) {
private void addFormApplication(FormEntity formEntity, ApplicationEntity applicationEntity,
List<FormApplicationResponse> formApplicationResponses) {
FormApplicationResponse formApplicationResponse = processForm(formEntity, applicationEntity);
if(formApplicationResponse.getContent() != null && formApplicationResponse.getFormFields() != null) {
formApplicationResponses.add(formApplicationResponse);
}
}
public FormApplicationResponse processForm(FormEntity formEntity, ApplicationEntity applicationEntity) {
FormApplicationResponse formApplicationResponse = createFormApplicationResponse(formEntity);
ApplicationFormEntity applicationFormEntity = applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(), formEntity.getId());
if(applicationFormEntity!=null) {
List<ApplicationFormFieldEntity> applicationFormFieldEntities = applicationFormFieldRepository.findByApplicationFormId(applicationFormEntity.getId());
FormApplicationResponse formApplicationResponse = createFormApplicationResponse(formEntity);
// formApplicationResponse = createFormApplicationResponse(formEntity);
List<ApplicationFormFieldResponseBean> applicationFormFieldResponseBeans = convertApplicationFormFieldEntitiesToApplicationFormFieldResponseBeans(applicationFormFieldEntities, applicationFormEntity.getId());
formApplicationResponse.setFormFields(applicationFormFieldResponseBeans);
formApplicationResponses.add(formApplicationResponse);
}
return formApplicationResponse;
}
private ApplicationGetResponseBean createApplicationGetResponseBean(ApplicationEntity applicationEntity, List<FormEntity> formEntities, List<FormApplicationResponse> formApplicationResponses) {

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;
}
if (formId == null) {
calculatedFormId = getDefaultForm(applicationEntity);
} 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(fromEntity, applicationEntity));
calculatedFormId = getNextForm(fromEntity, applicationEntity);
} else {
nextOrPreviousFormResponse.setPreviousFormId(getPreviousForm(fromEntity, applicationEntity));
calculatedFormId = getPreviousForm(fromEntity, applicationEntity);
}
}
NextOrPreviousFormResponse nextOrPreviousFormResponse = new NextOrPreviousFormResponse();
if (calculatedFormId != null) {
nextOrPreviousFormResponse.setFormId(calculatedFormId);
nextOrPreviousFormResponse.setApplicationFormResponse(
applicationDao.processForm(formService.validateForm(calculatedFormId), applicationEntity));
}
return nextOrPreviousFormResponse;
}

View File

@@ -1,8 +1,6 @@
package net.gepafin.tendermanagement.model.response;
import lombok.Data;
import net.gepafin.tendermanagement.model.response.ApplicationFormFieldResponseBean;
import net.gepafin.tendermanagement.model.response.ContentResponseBean;
import java.util.List;

View File

@@ -5,8 +5,8 @@ import lombok.Data;
@Data
public class NextOrPreviousFormResponse {
Long nextFormId;
Long formId;
Long previousFormId;
FormApplicationResponse applicationFormResponse;
}

View File

@@ -4,7 +4,6 @@ import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.dao.ApplicationDao;
import net.gepafin.tendermanagement.dao.FlowFormDao;
import net.gepafin.tendermanagement.entities.ApplicationEntity;
import net.gepafin.tendermanagement.entities.FormEntity;
import net.gepafin.tendermanagement.entities.UserEntity;
import net.gepafin.tendermanagement.model.request.ApplicationRequest;
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
@@ -15,7 +14,6 @@ import net.gepafin.tendermanagement.model.response.ApplicationResponse;
import net.gepafin.tendermanagement.model.response.ApplicationResponseBean;
import net.gepafin.tendermanagement.model.response.NextOrPreviousFormResponse;
import net.gepafin.tendermanagement.service.ApplicationService;
import net.gepafin.tendermanagement.service.FormService;
import net.gepafin.tendermanagement.util.Validator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -32,9 +30,6 @@ public class ApplicationServiceImpl implements ApplicationService {
@Autowired
private FlowFormDao flowFormDao;
@Autowired
private FormService formService;
@Autowired
private Validator validator;