Merge branch 'develop' of https://github.com/Kitzanos/GEPAFIN-BE into create-beneficiary-and-company-crud

This commit is contained in:
rajesh
2024-09-29 15:00:41 +05:30
7 changed files with 154 additions and 43 deletions

View File

@@ -10,10 +10,7 @@ import net.gepafin.tendermanagement.model.request.ApplicationFormFieldRequestBea
import net.gepafin.tendermanagement.model.request.ApplicationRequest;
import net.gepafin.tendermanagement.model.request.ApplicationRequestBean;
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.repositories.*;
import net.gepafin.tendermanagement.service.CallService;
import net.gepafin.tendermanagement.service.DocumentService;
import net.gepafin.tendermanagement.service.FormService;
@@ -66,6 +63,10 @@ public class ApplicationDao {
@Autowired
private FlowEdgesRepository flowEdgesRepository;
@Autowired
private FlowDataRepository flowDataRepository;
public ApplicationResponseBean createApplication(ApplicationRequestBean applicationRequestBean, UserEntity userEntity, Long formId,Long applicationId) {
FormEntity formEntity = formService.validateForm(formId);
CallEntity call = callService.validatePublishedCall(formEntity.getCall().getId());
@@ -85,12 +86,6 @@ public class ApplicationDao {
return applicationFormEntity1;
}
public void validateFormId(FormEntity formEntity, CallEntity callEntity) {
if (Boolean.FALSE.equals(formEntity.getId().equals(callEntity.getInitialForm()))) {
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.FORM_ID_DOES_NOT_MACTHES));
}
}
public ApplicationFormEntity createApplicationFormEntity(ApplicationEntity application, FormEntity formEntity) {
ApplicationFormEntity applicationFormEntity = new ApplicationFormEntity();
applicationFormEntity.setApplication(application);
@@ -278,6 +273,9 @@ public class ApplicationDao {
for (ApplicationFormFieldEntity applicationFormFieldEntity1 : applicationFormFieldEntities) {
if (applicationFormFieldEntity1.getFieldId().equals(applicationFormFieldRequestBean.getFieldId())) {
applicationFormFieldEntity = applicationFormFieldEntity1;
if(applicationFormEntity.getForm().getId().equals(applicationFormEntity.getApplication().getCall().getInitialForm())){
validateRequiredFields(applicationFormEntity.getForm(),applicationFormEntity.getApplication(), applicationFormFieldRequestBean.getFieldId());
}
break;
} else {
applicationFormFieldEntity = new ApplicationFormFieldEntity();
@@ -286,7 +284,9 @@ public class ApplicationDao {
}
}
Utils.setIfUpdated(applicationFormFieldEntity::getFieldId, applicationFormFieldEntity::setFieldId, applicationFormFieldRequestBean.getFieldId());
if(applicationFormFieldRequestBean.getFieldValue() ==null || Boolean.FALSE.equals(applicationFormFieldRequestBean.getFieldValue().isEmpty())) {
applicationFormFieldEntity.setFieldValue(applicationFormFieldRequestBean.getFieldValue());
}
return applicationFormFieldRepository.save(applicationFormFieldEntity);
}
@@ -464,14 +464,20 @@ public class ApplicationDao {
if (status.equals(ApplicationStatusTypeEnum.SUBMIT)) {
CallEntity callEntity = applicationEntity.getCall();
Long initialFormId = callEntity.getInitialForm();
Long finalFormId = callEntity.getFinalForm();
// if (initialFormId == null || finalFormId == null) {
// Long initialFormId = callEntity.getInitialForm();
// Long finalFormId = callEntity.getFinalForm();
//// if (initialFormId == null || finalFormId == null) {
//// throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_IS_INCOMPLETE_MSG));
//// }
// ApplicationFormEntity initialApplicationForm = applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(), initialFormId);
// ApplicationFormEntity finalApplicationForm = applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(), finalFormId);
// if (initialApplicationForm == null || finalApplicationForm == null) {
// throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_IS_INCOMPLETE_MSG));
// }
ApplicationFormEntity initialApplicationForm = applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(), initialFormId);
ApplicationFormEntity finalApplicationForm = applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(), finalFormId);
if (initialApplicationForm == null || finalApplicationForm == null) {
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
Long totalSteps=flowFormDao.calculateTotalSteps(flowEdgesList);
Integer completedSteps=flowFormDao.getCompletedSteps(applicationEntity);
if (totalSteps.intValue() != completedSteps) {
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_IS_INCOMPLETE_MSG));
}
applicationEntity.setStatus(ApplicationStatusTypeEnum.SUBMIT.getValue());
@@ -514,4 +520,45 @@ public class ApplicationDao {
validator.validate();
}
public void validateRequiredFields(FormEntity formEntity, ApplicationEntity applicationEntity, String fieldId) {
FlowDataEntity flowDataEntity = flowDataRepository.findByFormIdAndCallId(
formEntity.getId(), applicationEntity.getCall().getId());
if (flowDataEntity == null) {
return;
}
ApplicationFormFieldEntity applicationFormFieldEntity = applicationFormFieldRepository
.findByFieldIdAndApplicationFormFormIdAndApplicationFormApplicationId(
flowDataEntity.getChoosenField(), formEntity.getId(), applicationEntity.getId())
.orElse(null);
if (applicationFormFieldEntity == null || !fieldId.equals(applicationFormFieldEntity.getFieldId())) {
return;
}
List<Long> nextFormIds = flowEdgesRepository.findBySourceIdAndCallId(
formEntity.getId(), applicationEntity.getCall().getId())
.stream()
.map(FlowEdgesEntity::getTargetId)
.collect(Collectors.toList());
Optional<Long> nextFormIdOptional = flowDataRepository.findByChoosenValueAndFormIdIn(
applicationFormFieldEntity.getFieldValue(), nextFormIds)
.map(FlowDataEntity::getFormId);
if (nextFormIdOptional.isPresent()) {
Long nextFormId = nextFormIdOptional.get();
FormEntity nextForm = formService.validateForm(nextFormId);
ApplicationFormEntity nextApplicationFormEntity = applicationFormRepository.findByApplicationIdAndFormId(
applicationEntity.getId(), nextForm.getId());
if (nextApplicationFormEntity != null) {
List<ApplicationFormFieldEntity> nextApplicationFormFieldEntities = applicationFormFieldRepository.findByApplicationFormId(nextApplicationFormEntity.getId());
applicationFormFieldRepository.deleteAll(nextApplicationFormFieldEntities);
applicationFormRepository.delete(nextApplicationFormEntity);
}
}
}
}

View File

@@ -1,11 +1,9 @@
package net.gepafin.tendermanagement.dao;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
import net.gepafin.tendermanagement.repositories.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -46,7 +44,9 @@ public class FlowFormDao {
@Autowired
private FormService formService;
@Autowired
private FormRepository formRepository;
private FormDao formDao;
// Long getNextForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
// // vlaidation if next form findout and cuuent from is not fill the give error
@@ -274,16 +274,24 @@ public class FlowFormDao {
}
}
NextOrPreviousFormResponse nextOrPreviousFormResponse = null;
if (calculatedFormId != null) {
nextOrPreviousFormResponse = setNextOrPreviousResponse(calculatedFormId, applicationEntity);
if (calculatedFormId == null && formId == null) {
FormEntity form=formService.validateForm(applicationEntity.getCall().getInitialForm());
calculatedFormId=form.getId();
}
if (calculatedFormId == null) {
calculatedFormId=formId;
}
nextOrPreviousFormResponse = setNextOrPreviousResponse(calculatedFormId, applicationEntity);
return nextOrPreviousFormResponse;
}
private NextOrPreviousFormResponse setNextOrPreviousResponse(Long calculatedFormId, ApplicationEntity applicationEntity) {
NextOrPreviousFormResponse nextOrPreviousFormResponse = new NextOrPreviousFormResponse();
Integer completedSteps=0;
FormEntity formEntity = formService.validateForm(calculatedFormId);
nextOrPreviousFormResponse.setFormId(calculatedFormId);
nextOrPreviousFormResponse.setApplicationStatus(ApplicationStatusTypeEnum.valueOf(applicationEntity.getStatus()));
nextOrPreviousFormResponse.setApplicationFormResponse(
applicationDao.processForm(formEntity, applicationEntity));
nextOrPreviousFormResponse.setCallId(applicationEntity.getCall().getId());
@@ -292,13 +300,27 @@ public class FlowFormDao {
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
Long totalFormSteps = calculateTotalSteps(flowEdgesList);
Long currentStep = calculateCurrentStep(formEntity);
List<ApplicationFormEntity> applicationFormList = applicationFormRepository.findByApplicationId(applicationEntity.getId());
nextOrPreviousFormResponse.setTotalFormSteps(totalFormSteps);
nextOrPreviousFormResponse.setCompletedSteps(Long.valueOf(applicationFormList.size()));
completedSteps = getCompletedSteps(applicationEntity);
nextOrPreviousFormResponse.setCompletedSteps(Long.valueOf(completedSteps));
nextOrPreviousFormResponse.setCurrentStep(currentStep);
return nextOrPreviousFormResponse;
}
public Integer getCompletedSteps(ApplicationEntity applicationEntity) {
Integer completedSteps=0;
List<ApplicationFormEntity> applicationFormList = applicationFormRepository.findByApplicationId(applicationEntity.getId());
List<ApplicationFormFieldEntity> applicationFormFieldEntities=new ArrayList<>();
for (ApplicationFormEntity applicationFormEntity:applicationFormList){
applicationFormFieldEntities=applicationFormFieldRepository.findByApplicationFormId(applicationFormEntity.getId());
Boolean isCompleted=formDao.validateCompletedSteps(applicationFormFieldEntities, applicationEntity, applicationFormEntity.getForm());
if(Boolean.TRUE.equals(isCompleted)){
completedSteps++;
}
}
return completedSteps;
}
public Long calculateCurrentStep(FormEntity formEntity) {
Long currentStep = 2l;
if (formEntity.getId().equals(formEntity.getCall().getInitialForm())) {

View File

@@ -198,6 +198,8 @@ public class FormDao {
public void validateFormField(List<ApplicationFormFieldRequestBean> applicationFormFieldRequestList, ApplicationEntity applicationEntity, FormEntity formEntity) {
Map<String, Object> formFieldMap = new LinkedHashMap<String, Object>();
for(ApplicationFormFieldRequestBean applicationFormFieldRequestBean:applicationFormFieldRequestList) {
if(applicationFormFieldRequestBean.getFieldValue()==null || applicationFormFieldRequestBean.getFieldValue().isEmpty())
continue;
formFieldMap.put(applicationFormFieldRequestBean.getFieldId(),applicationFormFieldRequestBean.getFieldValue());
}
@@ -208,19 +210,19 @@ public class FormDao {
formResponseBean.getContent().forEach(contentResponseBean -> {
String fieldId = contentResponseBean.getId();
String value = (String) formFieldMap.get(fieldId);
String fieldLabel=contentResponseBean.getLabel();
if(value == null && isApplicationFormExist) {
return;
}
FieldValidatorBean fieldValidatorBean = Utils.convertSourceObjectToDestinationObject(contentResponseBean.getValidators(), FieldValidatorBean.class);
validator
.isRequired(value,fieldValidatorBean.getIsRequired(),fieldId)
.minLength(value, fieldValidatorBean.getMinLength(), fieldId) // Only applies if minLength is not null
.maxLength(value, fieldValidatorBean.getMaxLength(), fieldId) // Only applies if maxLength is not null
.matchesPattern(value, fieldValidatorBean.getPattern(), fieldId) // Only applies if pattern is present
.validateCustom(value, fieldValidatorBean.getCustom(), fieldId); // Add the custom validation here
.minLength(value, fieldValidatorBean.getMinLength(), fieldLabel) // Only applies if minLength is not null
.maxLength(value, fieldValidatorBean.getMaxLength(), fieldLabel) // Only applies if maxLength is not null
.matchesPattern(value, fieldValidatorBean.getPattern(), fieldLabel) // Only applies if pattern is present
.validateCustom(value, fieldValidatorBean.getCustom(), fieldLabel); // Add the custom validation here
if (fieldValidatorBean.getCustom() != null && fieldValidatorBean.getCustom().equals(GepafinConstant.IS_PIVA)) {
String error = validateVatNumber(value, fieldValidatorBean.getCustom(), fieldId);
String error = validateVatNumber(value, fieldValidatorBean.getCustom(), fieldLabel);
if(error != null) {
validator.addError(error);
}
@@ -236,9 +238,31 @@ public class FormDao {
return false;
}
public Boolean validateCompletedSteps(List<ApplicationFormFieldEntity> applicationFormFieldEntityList, ApplicationEntity applicationEntity, FormEntity formEntity) {
Map<String, Object> formFieldMap = new LinkedHashMap<String, Object>();
for(ApplicationFormFieldEntity applicationFormFieldEntity:applicationFormFieldEntityList) {
formFieldMap.put(applicationFormFieldEntity.getFieldId(),applicationFormFieldEntity.getFieldValue());
}
FormResponseBean formResponseBean = convertFormEntityToFormResponseBean(formEntity);
FieldValidator validator = FieldValidator.create();
formResponseBean.getContent().forEach(contentResponseBean -> {
String fieldId = contentResponseBean.getId();
String value = (String) formFieldMap.get(fieldId);
FieldValidatorBean fieldValidatorBean = Utils.convertSourceObjectToDestinationObject(contentResponseBean.getValidators(), FieldValidatorBean.class);
validator
.isRequired(value,fieldValidatorBean.getIsRequired(),fieldId);
});
if (validator.hasErrors()) {
return false; // Validation failed, return false
}
return true;
}
public String validateVatNumber(String value,String customRule,String fieldId){
String error=null;
if (value.matches("^\\d{1,11}$")) {
if (value!=null && value.matches("^\\d{1,11}$")) {
Map<String, Object> customData=null;
try {
Map<String, Object> vatCheckResponse = vatCheckDao.checkVatNumberApi(value);
@@ -251,4 +275,5 @@ public class FormDao {
}
return error;
}
}

View File

@@ -1,6 +1,7 @@
package net.gepafin.tendermanagement.model.response;
import lombok.Data;
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
@Data
public class NextOrPreviousFormResponse {
@@ -16,6 +17,8 @@ public class NextOrPreviousFormResponse {
private Long completedSteps;
private Long currentStep;
private ApplicationStatusTypeEnum applicationStatus;
private FormApplicationResponse applicationFormResponse;

View File

@@ -27,16 +27,16 @@ public class FieldValidator {
private VatCheckDao vatCheckDao;
public FieldValidator notNull(Object object, String fieldName) {
public FieldValidator notNull(Object object, String fieldLabel) {
if (Objects.isNull(object)) {
errors.add(MessageFormat.format(Translator.toLocale(GepafinConstant.FIELD_NOT_NULL), fieldName));
errors.add(MessageFormat.format(Translator.toLocale(GepafinConstant.FIELD_NOT_NULL), fieldLabel));
}
return this;
}
public FieldValidator notEmpty(List<?> list, String fieldName) {
public FieldValidator notEmpty(List<?> list, String fieldLabel) {
if (list == null || list.isEmpty()) {
errors.add(MessageFormat.format(Translator.toLocale(GepafinConstant.FIELD_NOT_EMPTY), fieldName));
errors.add(MessageFormat.format(Translator.toLocale(GepafinConstant.FIELD_NOT_EMPTY), fieldLabel));
}
return this;
}
@@ -46,23 +46,23 @@ public class FieldValidator {
throw new ValidationException(Status.VALIDATION_ERROR, errors, Translator.toLocale(GepafinConstant.VALIDATION_MESSAGE));
}
}
public FieldValidator minLength(String value, Long minLength, String fieldName) {
public FieldValidator minLength(String value, Long minLength, String fieldLabel) {
if (minLength != null && value != null && value.length() < minLength) {
errors.add(MessageFormat.format(Translator.toLocale(GepafinConstant.VALIDATION_FIELD_MIN_LENGTH), fieldName, minLength));
errors.add(MessageFormat.format(Translator.toLocale(GepafinConstant.VALIDATION_FIELD_MIN_LENGTH), fieldLabel, minLength));
}
return this;
}
public FieldValidator maxLength(String value, Long maxLength, String fieldName) {
public FieldValidator maxLength(String value, Long maxLength, String fieldLabel) {
if (maxLength != null && value != null && value.length() > maxLength) {
errors.add(MessageFormat.format(Translator.toLocale(GepafinConstant.VALIDATION_FIELD_MAX_LENGTH), fieldName, maxLength));
errors.add(MessageFormat.format(Translator.toLocale(GepafinConstant.VALIDATION_FIELD_MAX_LENGTH), fieldLabel, maxLength));
}
return this;
}
public FieldValidator matchesPattern(String value, String pattern, String fieldName) {
public FieldValidator matchesPattern(String value, String pattern, String fieldLabel) {
if (value != null && pattern != null && !value.matches(pattern)) {
errors.add(MessageFormat.format(Translator.toLocale(GepafinConstant.VALIDATION_FIELD_PATTERN), fieldName));
errors.add(MessageFormat.format(Translator.toLocale(GepafinConstant.VALIDATION_FIELD_PATTERN), fieldLabel));
}
return this;
}
@@ -147,4 +147,7 @@ public class FieldValidator {
}
return this;
}
public boolean hasErrors() {
return !errors.isEmpty();
}
}

View File

@@ -0,0 +1,11 @@
# DataSource Configuration
spring.datasource.url=jdbc:postgresql://bandidb.gepafin.it:21543/gepaDb
spring.datasource.username=usergepa
spring.datasource.password=nRHMi7esdgHJiIm3L5ctrSJ0
spring.datasource.driver-class-name=org.postgresql.Driver
# JPA Configuration
spring.h2.console.enabled=true
base-url=http://bandi-api.gepafin.it
isVatCheckGloballyDisabled = false