Implemnted new flow for application form data
This commit is contained in:
@@ -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);
|
||||
}
|
||||
@@ -251,4 +253,37 @@ public class FormDao {
|
||||
}
|
||||
return error;
|
||||
}
|
||||
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);
|
||||
ApplicationFormEntity applicationFormEntity=applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(),formEntity.getId());
|
||||
Boolean isApplicationFormExist= getApplicationFormExist(applicationFormEntity);
|
||||
FieldValidator validator = FieldValidator.create();
|
||||
formResponseBean.getContent().forEach(contentResponseBean -> {
|
||||
String fieldId = contentResponseBean.getId();
|
||||
String value = (String) formFieldMap.get(fieldId);
|
||||
|
||||
if(value == null && isApplicationFormExist) {
|
||||
return;
|
||||
}
|
||||
FieldValidatorBean fieldValidatorBean = Utils.convertSourceObjectToDestinationObject(contentResponseBean.getValidators(), FieldValidatorBean.class);
|
||||
validator
|
||||
.isRequired(value,fieldValidatorBean.getIsRequired(),fieldId);
|
||||
if (fieldValidatorBean.getCustom() != null && fieldValidatorBean.getCustom().equals(GepafinConstant.IS_PIVA)) {
|
||||
String error = validateVatNumber(value, fieldValidatorBean.getCustom(), fieldId);
|
||||
if(error != null) {
|
||||
validator.addError(error);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (validator.hasErrors()) {
|
||||
return false; // Validation failed, return false
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user