resolved conflicts

This commit is contained in:
rajesh
2024-09-25 20:15:12 +05:30
11 changed files with 121 additions and 17 deletions

View File

@@ -13,19 +13,23 @@ import net.gepafin.tendermanagement.model.response.*;
import net.gepafin.tendermanagement.repositories.ApplicationFormFieldRepository;
import net.gepafin.tendermanagement.repositories.ApplicationFormRepository;
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
import net.gepafin.tendermanagement.repositories.FlowEdgesRepository;
import net.gepafin.tendermanagement.service.CallService;
import net.gepafin.tendermanagement.service.DocumentService;
import net.gepafin.tendermanagement.service.FormService;
import net.gepafin.tendermanagement.util.DateTimeUtil;
import net.gepafin.tendermanagement.util.FieldValidator;
import net.gepafin.tendermanagement.util.Utils;
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;
import org.checkerframework.checker.units.qual.A;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.text.MessageFormat;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@@ -56,9 +60,16 @@ public class ApplicationDao {
@Autowired
private CallDao callDao;
@Autowired
private FlowFormDao flowFormDao;
@Autowired
private FlowEdgesRepository flowEdgesRepository;
public ApplicationResponseBean createApplication(ApplicationRequestBean applicationRequestBean, UserEntity userEntity, Long formId,Long applicationId) {
FormEntity formEntity = formService.validateForm(formId);
CallEntity call = callService.validatePublishedCall(formEntity.getCall().getId());
validateFormFields(applicationRequestBean,formEntity);
ApplicationEntity applicationEntity = validateApplication(applicationId);
if(Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.SUBMIT.getValue()))){
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_SUBMITTED));
@@ -165,10 +176,9 @@ public class ApplicationDao {
}
public List<ApplicationResponse> getAllApplications(UserEntity userEntity, Long callId) {
RoleStatusEnum roleStatus = RoleStatusEnum.valueOf(userEntity.getRoleEntity().getRoleType());
boolean isBeneficiary = RoleStatusEnum.ROLE_BENEFICIARY.equals(roleStatus);
boolean isBeneficiary = isBeneficiary(userEntity);
log.info("Fetching applications for RoleType: {}", roleStatus);
log.info("Fetching applications for RoleType: {}", userEntity.getRoleEntity().getRoleType());
List<ApplicationResponse> applicationResponses = new ArrayList<>();
if (callId != null) {
@@ -204,7 +214,16 @@ public class ApplicationDao {
private ApplicationResponse getApplicationResponse(ApplicationEntity applicationEntity) {
ApplicationResponse responseBean = new ApplicationResponse();
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
Long totalFormSteps = flowFormDao.calculateTotalSteps(flowEdgesList);
List<ApplicationFormEntity> applicationFormList = applicationFormRepository.findByApplicationId(applicationEntity.getId());
Long completedSteps=(Long.valueOf(applicationFormList.size()));
Integer progress=calculateProgress(totalFormSteps,completedSteps);
responseBean.setId(applicationEntity.getId());
responseBean.setProgress(progress);
responseBean.setCallTitle(applicationEntity.getCall().getName());
responseBean.setCallEndDate(applicationEntity.getCall().getEndDate());
responseBean.setModifiedDate(applicationEntity.getCall().getUpdatedDate());
responseBean.setCallId(applicationEntity.getCall().getId());
responseBean.setSubmissionDate(applicationEntity.getSubmissionDate());
responseBean.setStatus(applicationEntity.getStatus());
@@ -267,7 +286,7 @@ public class ApplicationDao {
}
}
Utils.setIfUpdated(applicationFormFieldEntity::getFieldId, applicationFormFieldEntity::setFieldId, applicationFormFieldRequestBean.getFieldId());
Utils.setIfUpdated(applicationFormFieldEntity::getFieldValue, applicationFormFieldEntity::setFieldValue, applicationFormFieldRequestBean.getFieldValue());
applicationFormFieldEntity.setFieldValue(applicationFormFieldRequestBean.getFieldValue());
return applicationFormFieldRepository.save(applicationFormFieldEntity);
}
@@ -333,7 +352,12 @@ public class ApplicationDao {
public ApplicationGetResponseBean getApplicationByFormId( Long applicationId,Long formId, UserEntity userEntity) {
List<FormApplicationResponse> formApplicationResponses = new ArrayList<>();
List<FormEntity> formEntities = new ArrayList<>();
ApplicationEntity applicationEntity = applicationRepository.findById(applicationId)
boolean isBeneficiary = isBeneficiary(userEntity);
ApplicationEntity applicationEntity = isBeneficiary
? applicationRepository.findByIdAndUserIdAndIsDeletedFalse(applicationId,userEntity.getId())
.orElseThrow(() -> new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_NOT_FOUND_MSG)))
: applicationRepository.findById(applicationId)
.stream().findFirst()
.orElseThrow(() -> new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_NOT_FOUND_MSG)));
if (formId != null) {
@@ -356,6 +380,12 @@ public class ApplicationDao {
return createApplicationGetResponseBean(applicationEntity, formEntities, formApplicationResponses);
}
private boolean isBeneficiary(UserEntity userEntity) {
RoleStatusEnum roleStatus = RoleStatusEnum.valueOf(userEntity.getRoleEntity().getRoleType());
boolean isBeneficiary = RoleStatusEnum.ROLE_BENEFICIARY.equals(roleStatus);
return isBeneficiary;
}
private void addFormApplication(FormEntity formEntity, ApplicationEntity applicationEntity,
List<FormApplicationResponse> formApplicationResponses) {
FormApplicationResponse formApplicationResponse = processForm(formEntity, applicationEntity);
@@ -451,4 +481,37 @@ public class ApplicationDao {
}
saveApplicationEntity(applicationEntity);
}
public Integer calculateProgress(Long totalSteps, Long completedSteps) {
if (FieldValidator.isNullOrZero(totalSteps)) {
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.TOTAL_STEPS_NOT_BE_ZERO));
}
if (completedSteps < 0 || completedSteps > totalSteps) {
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.COMPLETED_STEPS_NOT_VALID));
}
double progress = ((double) completedSteps / totalSteps) * 100;
return (int) Math.round(progress);
}
public void validateFormFields(ApplicationRequestBean request, FormEntity formEntity) {
List<String> errors=new ArrayList<>();
List<ContentResponseBean> contentResponseBeans=Utils.convertJsonStringToList(formEntity.getContent(),ContentResponseBean.class);
List<ApplicationFormFieldRequestBean> requestFields = request.getFormFields();
Map<String, String> contentMap = contentResponseBeans.stream()
.collect(Collectors.toMap(ContentResponseBean::getId, ContentResponseBean::getLabel)); // Change getLabel() if needed
FieldValidator validator = FieldValidator.create();
for (ApplicationFormFieldRequestBean requestField : requestFields) {
String fieldId = requestField.getFieldId();
if (!contentMap.containsKey(fieldId)) {
validator.addError(MessageFormat.format(Translator.toLocale(GepafinConstant.FIELD_ID_NOT_FOUND), fieldId));
}
}
validator.validate();
}
}

View File

@@ -290,21 +290,31 @@ public class FlowFormDao {
nextOrPreviousFormResponse.setCallTitle(applicationEntity.getCall().getName());
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
Long totalFormSteps = 3l;
if (flowEdgesList.size() == 1) {
totalFormSteps = 2l;
}
Long totalFormSteps = calculateTotalSteps(flowEdgesList);
Long currentStep = calculateCurrentStep(formEntity);
List<ApplicationFormEntity> applicationFormList = applicationFormRepository.findByApplicationId(applicationEntity.getId());
nextOrPreviousFormResponse.setTotalFormSteps(totalFormSteps);
nextOrPreviousFormResponse.setCompletedSteps(Long.valueOf(applicationFormList.size()));
nextOrPreviousFormResponse.setCurrentStep(currentStep);
return nextOrPreviousFormResponse;
}
public Long calculateCurrentStep(FormEntity formEntity) {
Long currentStep = 2l;
if (formEntity.getId().equals(formEntity.getCall().getInitialForm())) {
currentStep = 1l;
} else if (formEntity.getId().equals(formEntity.getCall().getFinalForm())) {
currentStep = 3l;
}
List<ApplicationFormEntity> applicationFormList = applicationFormRepository.findByApplicationId(applicationEntity.getId());
nextOrPreviousFormResponse.setTotalFormSteps(totalFormSteps);
nextOrPreviousFormResponse.setCompletedSteps(Long.valueOf(applicationFormList.size()));
nextOrPreviousFormResponse.setCurrentStep(currentStep);
return nextOrPreviousFormResponse;
return currentStep;
}
public Long calculateTotalSteps(List<FlowEdgesEntity> flowEdgesList) {
Long totalFormSteps = 3l;
if (flowEdgesList.size() == 1) {
totalFormSteps = 2l;
}
return totalFormSteps;
}
private Long getDefaultForm(ApplicationEntity applicationEntity) {

View File

@@ -73,6 +73,7 @@ public class FormDao {
formResponseBean.setContent(Utils.convertJsonStringToList(formEntity.getContent(), ContentResponseBean.class));
formResponseBean.setLabel(formEntity.getLabel());
formResponseBean.setCallId(formEntity.getCall().getId());
formResponseBean.setCallStatus(formEntity.getCall().getStatus());
return formResponseBean;
}
public FormResponseBean createForm(Long callId,FormRequest formRequest){