Resolved conflicts
This commit is contained in:
@@ -4,6 +4,7 @@ import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.*;
|
||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationFormFieldRequestBean;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationRequest;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationRequestBean;
|
||||
@@ -47,9 +48,6 @@ public class ApplicationDao {
|
||||
@Autowired
|
||||
private FormService formService;
|
||||
|
||||
@Autowired
|
||||
private FormDao formDao;
|
||||
|
||||
public ApplicationResponseBean createApplication(ApplicationRequestBean applicationRequestBean, UserEntity userEntity, Long formId,Long applicationId) {
|
||||
FormEntity formEntity = formService.validateForm(formId);
|
||||
CallEntity call = callService.validateCall(formEntity.getCall().getId());
|
||||
@@ -116,25 +114,43 @@ public class ApplicationDao {
|
||||
}
|
||||
|
||||
public List<ApplicationResponse> getAllApplications(UserEntity userEntity, Long callId) {
|
||||
log.info("Fetching all applications");
|
||||
RoleStatusEnum roleStatus = RoleStatusEnum.valueOf(userEntity.getRoleEntity().getRoleType());
|
||||
boolean isBeneficiary = RoleStatusEnum.ROLE_BENEFICIARY.equals(roleStatus);
|
||||
|
||||
log.info("Fetching applications for RoleType: {}", roleStatus);
|
||||
List<ApplicationResponse> applicationResponses = new ArrayList<>();
|
||||
|
||||
if (callId != null) {
|
||||
// Fetch based on callId and user if role is BENEFICIARY, otherwise fetch all for the call
|
||||
log.info("Fetching applications for callId: {}", callId);
|
||||
CallEntity call = callService.validateCall(callId);
|
||||
Optional<ApplicationEntity> applicationEntity1 = applicationRepository.findByUserIdAndCallIdAndIsDeletedFalse(userEntity.getId(), call.getId());
|
||||
if (applicationEntity1.isPresent()) {
|
||||
ApplicationResponse responseBean = getApplicationResponse(applicationEntity1.get());
|
||||
applicationResponses.add(responseBean);
|
||||
return applicationResponses;
|
||||
}
|
||||
}
|
||||
List<ApplicationEntity> applicationEntities = applicationRepository.findByUserIdAndIsDeletedFalse(userEntity.getId());
|
||||
for(ApplicationEntity applicationEntity:applicationEntities){
|
||||
ApplicationResponse responseBean = getApplicationResponse(applicationEntity);
|
||||
applicationResponses.add(responseBean);
|
||||
}
|
||||
|
||||
// Use a single method to handle both conditions for consistency
|
||||
List<ApplicationEntity> applicationEntities = isBeneficiary
|
||||
? applicationRepository.findByUserIdAndCallIdAndIsDeletedFalse(userEntity.getId(), call.getId())
|
||||
.map(List::of) // Convert Optional<ApplicationEntity> to a List of one element
|
||||
.orElse(List.of()) // If not present, return an empty list
|
||||
: applicationRepository.findByCallIdAndIsDeletedFalse(call.getId());
|
||||
|
||||
applicationResponses = applicationEntities.stream()
|
||||
.map(this::getApplicationResponse)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
} else {
|
||||
// Fetch all applications for the user if BENEFICIARY, or fetch all applications in general
|
||||
List<ApplicationEntity> applicationEntities = isBeneficiary
|
||||
? applicationRepository.findByUserIdAndIsDeletedFalse(userEntity.getId())
|
||||
: applicationRepository.findByIsDeletedFalse();
|
||||
|
||||
applicationResponses = applicationEntities.stream()
|
||||
.map(this::getApplicationResponse)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return applicationResponses;
|
||||
}
|
||||
|
||||
|
||||
private ApplicationResponse getApplicationResponse(ApplicationEntity applicationEntity) {
|
||||
ApplicationResponse responseBean = new ApplicationResponse();
|
||||
responseBean.setId(applicationEntity.getId());
|
||||
@@ -247,30 +263,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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import lombok.Data;
|
||||
@Data
|
||||
public class NextOrPreviousFormResponse {
|
||||
|
||||
Long nextFormId;
|
||||
Long formId;
|
||||
|
||||
Long previousFormId;
|
||||
FormApplicationResponse applicationFormResponse;
|
||||
|
||||
}
|
||||
@@ -19,4 +19,8 @@ public interface ApplicationRepository extends JpaRepository<ApplicationEntity,L
|
||||
|
||||
@Query("SELECT a FROM ApplicationEntity a WHERE a.id = :id AND a.isDeleted = false")
|
||||
Optional<ApplicationEntity> findById(@Param("id") Long id);
|
||||
|
||||
public List<ApplicationEntity> findByCallIdAndIsDeletedFalse(Long callId);
|
||||
|
||||
public List<ApplicationEntity> findByIsDeletedFalse();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user