Implemnted new flow for application form data
This commit is contained in:
@@ -10,10 +10,7 @@ import net.gepafin.tendermanagement.model.request.ApplicationFormFieldRequestBea
|
|||||||
import net.gepafin.tendermanagement.model.request.ApplicationRequest;
|
import net.gepafin.tendermanagement.model.request.ApplicationRequest;
|
||||||
import net.gepafin.tendermanagement.model.request.ApplicationRequestBean;
|
import net.gepafin.tendermanagement.model.request.ApplicationRequestBean;
|
||||||
import net.gepafin.tendermanagement.model.response.*;
|
import net.gepafin.tendermanagement.model.response.*;
|
||||||
import net.gepafin.tendermanagement.repositories.ApplicationFormFieldRepository;
|
import net.gepafin.tendermanagement.repositories.*;
|
||||||
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.CallService;
|
||||||
import net.gepafin.tendermanagement.service.DocumentService;
|
import net.gepafin.tendermanagement.service.DocumentService;
|
||||||
import net.gepafin.tendermanagement.service.FormService;
|
import net.gepafin.tendermanagement.service.FormService;
|
||||||
@@ -66,6 +63,10 @@ public class ApplicationDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private FlowEdgesRepository flowEdgesRepository;
|
private FlowEdgesRepository flowEdgesRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private FlowDataRepository flowDataRepository;
|
||||||
|
|
||||||
|
|
||||||
public ApplicationResponseBean createApplication(ApplicationRequestBean applicationRequestBean, UserEntity userEntity, Long formId,Long applicationId) {
|
public ApplicationResponseBean createApplication(ApplicationRequestBean applicationRequestBean, UserEntity userEntity, Long formId,Long applicationId) {
|
||||||
FormEntity formEntity = formService.validateForm(formId);
|
FormEntity formEntity = formService.validateForm(formId);
|
||||||
CallEntity call = callService.validatePublishedCall(formEntity.getCall().getId());
|
CallEntity call = callService.validatePublishedCall(formEntity.getCall().getId());
|
||||||
@@ -85,12 +86,6 @@ public class ApplicationDao {
|
|||||||
return applicationFormEntity1;
|
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) {
|
public ApplicationFormEntity createApplicationFormEntity(ApplicationEntity application, FormEntity formEntity) {
|
||||||
ApplicationFormEntity applicationFormEntity = new ApplicationFormEntity();
|
ApplicationFormEntity applicationFormEntity = new ApplicationFormEntity();
|
||||||
applicationFormEntity.setApplication(application);
|
applicationFormEntity.setApplication(application);
|
||||||
@@ -278,6 +273,9 @@ public class ApplicationDao {
|
|||||||
for (ApplicationFormFieldEntity applicationFormFieldEntity1 : applicationFormFieldEntities) {
|
for (ApplicationFormFieldEntity applicationFormFieldEntity1 : applicationFormFieldEntities) {
|
||||||
if (applicationFormFieldEntity1.getFieldId().equals(applicationFormFieldRequestBean.getFieldId())) {
|
if (applicationFormFieldEntity1.getFieldId().equals(applicationFormFieldRequestBean.getFieldId())) {
|
||||||
applicationFormFieldEntity = applicationFormFieldEntity1;
|
applicationFormFieldEntity = applicationFormFieldEntity1;
|
||||||
|
if(applicationFormEntity.getForm().getId().equals(applicationFormEntity.getApplication().getCall().getInitialForm())){
|
||||||
|
validateRequiredFields(applicationFormEntity.getForm(),applicationFormEntity.getApplication(), applicationFormFieldRequestBean.getFieldId());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
applicationFormFieldEntity = new ApplicationFormFieldEntity();
|
applicationFormFieldEntity = new ApplicationFormFieldEntity();
|
||||||
@@ -286,7 +284,9 @@ public class ApplicationDao {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Utils.setIfUpdated(applicationFormFieldEntity::getFieldId, applicationFormFieldEntity::setFieldId, applicationFormFieldRequestBean.getFieldId());
|
Utils.setIfUpdated(applicationFormFieldEntity::getFieldId, applicationFormFieldEntity::setFieldId, applicationFormFieldRequestBean.getFieldId());
|
||||||
|
if(applicationFormFieldRequestBean.getFieldValue() ==null || Boolean.FALSE.equals(applicationFormFieldRequestBean.getFieldValue().isEmpty())) {
|
||||||
applicationFormFieldEntity.setFieldValue(applicationFormFieldRequestBean.getFieldValue());
|
applicationFormFieldEntity.setFieldValue(applicationFormFieldRequestBean.getFieldValue());
|
||||||
|
}
|
||||||
return applicationFormFieldRepository.save(applicationFormFieldEntity);
|
return applicationFormFieldRepository.save(applicationFormFieldEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -464,14 +464,20 @@ public class ApplicationDao {
|
|||||||
|
|
||||||
if (status.equals(ApplicationStatusTypeEnum.SUBMIT)) {
|
if (status.equals(ApplicationStatusTypeEnum.SUBMIT)) {
|
||||||
CallEntity callEntity = applicationEntity.getCall();
|
CallEntity callEntity = applicationEntity.getCall();
|
||||||
Long initialFormId = callEntity.getInitialForm();
|
// Long initialFormId = callEntity.getInitialForm();
|
||||||
Long finalFormId = callEntity.getFinalForm();
|
// Long finalFormId = callEntity.getFinalForm();
|
||||||
// if (initialFormId == null || finalFormId == null) {
|
//// 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));
|
// throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_IS_INCOMPLETE_MSG));
|
||||||
// }
|
// }
|
||||||
ApplicationFormEntity initialApplicationForm = applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(), initialFormId);
|
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
|
||||||
ApplicationFormEntity finalApplicationForm = applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(), finalFormId);
|
Long totalSteps=flowFormDao.calculateTotalSteps(flowEdgesList);
|
||||||
if (initialApplicationForm == null || finalApplicationForm == null) {
|
Integer completedSteps=flowFormDao.getCompletedSteps(applicationEntity);
|
||||||
|
if (totalSteps.intValue() != completedSteps) {
|
||||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_IS_INCOMPLETE_MSG));
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_IS_INCOMPLETE_MSG));
|
||||||
}
|
}
|
||||||
applicationEntity.setStatus(ApplicationStatusTypeEnum.SUBMIT.getValue());
|
applicationEntity.setStatus(ApplicationStatusTypeEnum.SUBMIT.getValue());
|
||||||
@@ -514,4 +520,45 @@ public class ApplicationDao {
|
|||||||
validator.validate();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
package net.gepafin.tendermanagement.dao;
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||||
import net.gepafin.tendermanagement.repositories.*;
|
import net.gepafin.tendermanagement.repositories.*;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -46,7 +44,9 @@ public class FlowFormDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private FormService formService;
|
private FormService formService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private FormRepository formRepository;
|
private FormDao formDao;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Long getNextForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
|
// Long getNextForm(FormEntity currentFormEntity, ApplicationEntity applicationEntity) {
|
||||||
// // vlaidation if next form findout and cuuent from is not fill the give error
|
// // vlaidation if next form findout and cuuent from is not fill the give error
|
||||||
@@ -274,16 +274,24 @@ public class FlowFormDao {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
NextOrPreviousFormResponse nextOrPreviousFormResponse = null;
|
NextOrPreviousFormResponse nextOrPreviousFormResponse = null;
|
||||||
if (calculatedFormId != null) {
|
if (calculatedFormId == null && formId == null) {
|
||||||
nextOrPreviousFormResponse = setNextOrPreviousResponse(calculatedFormId, applicationEntity);
|
FormEntity form=formService.validateForm(applicationEntity.getCall().getInitialForm());
|
||||||
|
calculatedFormId=form.getId();
|
||||||
}
|
}
|
||||||
|
if (calculatedFormId == null) {
|
||||||
|
calculatedFormId=formId;
|
||||||
|
}
|
||||||
|
nextOrPreviousFormResponse = setNextOrPreviousResponse(calculatedFormId, applicationEntity);
|
||||||
|
|
||||||
return nextOrPreviousFormResponse;
|
return nextOrPreviousFormResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
private NextOrPreviousFormResponse setNextOrPreviousResponse(Long calculatedFormId, ApplicationEntity applicationEntity) {
|
private NextOrPreviousFormResponse setNextOrPreviousResponse(Long calculatedFormId, ApplicationEntity applicationEntity) {
|
||||||
NextOrPreviousFormResponse nextOrPreviousFormResponse = new NextOrPreviousFormResponse();
|
NextOrPreviousFormResponse nextOrPreviousFormResponse = new NextOrPreviousFormResponse();
|
||||||
|
Integer completedSteps=0;
|
||||||
FormEntity formEntity = formService.validateForm(calculatedFormId);
|
FormEntity formEntity = formService.validateForm(calculatedFormId);
|
||||||
nextOrPreviousFormResponse.setFormId(calculatedFormId);
|
nextOrPreviousFormResponse.setFormId(calculatedFormId);
|
||||||
|
nextOrPreviousFormResponse.setApplicationStatus(ApplicationStatusTypeEnum.valueOf(applicationEntity.getStatus()));
|
||||||
nextOrPreviousFormResponse.setApplicationFormResponse(
|
nextOrPreviousFormResponse.setApplicationFormResponse(
|
||||||
applicationDao.processForm(formEntity, applicationEntity));
|
applicationDao.processForm(formEntity, applicationEntity));
|
||||||
nextOrPreviousFormResponse.setCallId(applicationEntity.getCall().getId());
|
nextOrPreviousFormResponse.setCallId(applicationEntity.getCall().getId());
|
||||||
@@ -292,13 +300,27 @@ public class FlowFormDao {
|
|||||||
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
|
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
|
||||||
Long totalFormSteps = calculateTotalSteps(flowEdgesList);
|
Long totalFormSteps = calculateTotalSteps(flowEdgesList);
|
||||||
Long currentStep = calculateCurrentStep(formEntity);
|
Long currentStep = calculateCurrentStep(formEntity);
|
||||||
List<ApplicationFormEntity> applicationFormList = applicationFormRepository.findByApplicationId(applicationEntity.getId());
|
|
||||||
nextOrPreviousFormResponse.setTotalFormSteps(totalFormSteps);
|
nextOrPreviousFormResponse.setTotalFormSteps(totalFormSteps);
|
||||||
nextOrPreviousFormResponse.setCompletedSteps(Long.valueOf(applicationFormList.size()));
|
completedSteps = getCompletedSteps(applicationEntity);
|
||||||
|
nextOrPreviousFormResponse.setCompletedSteps(Long.valueOf(completedSteps));
|
||||||
nextOrPreviousFormResponse.setCurrentStep(currentStep);
|
nextOrPreviousFormResponse.setCurrentStep(currentStep);
|
||||||
return nextOrPreviousFormResponse;
|
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) {
|
public Long calculateCurrentStep(FormEntity formEntity) {
|
||||||
Long currentStep = 2l;
|
Long currentStep = 2l;
|
||||||
if (formEntity.getId().equals(formEntity.getCall().getInitialForm())) {
|
if (formEntity.getId().equals(formEntity.getCall().getInitialForm())) {
|
||||||
|
|||||||
@@ -198,6 +198,8 @@ public class FormDao {
|
|||||||
public void validateFormField(List<ApplicationFormFieldRequestBean> applicationFormFieldRequestList, ApplicationEntity applicationEntity, FormEntity formEntity) {
|
public void validateFormField(List<ApplicationFormFieldRequestBean> applicationFormFieldRequestList, ApplicationEntity applicationEntity, FormEntity formEntity) {
|
||||||
Map<String, Object> formFieldMap = new LinkedHashMap<String, Object>();
|
Map<String, Object> formFieldMap = new LinkedHashMap<String, Object>();
|
||||||
for(ApplicationFormFieldRequestBean applicationFormFieldRequestBean:applicationFormFieldRequestList) {
|
for(ApplicationFormFieldRequestBean applicationFormFieldRequestBean:applicationFormFieldRequestList) {
|
||||||
|
if(applicationFormFieldRequestBean.getFieldValue()==null || applicationFormFieldRequestBean.getFieldValue().isEmpty())
|
||||||
|
continue;
|
||||||
formFieldMap.put(applicationFormFieldRequestBean.getFieldId(),applicationFormFieldRequestBean.getFieldValue());
|
formFieldMap.put(applicationFormFieldRequestBean.getFieldId(),applicationFormFieldRequestBean.getFieldValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,19 +210,19 @@ public class FormDao {
|
|||||||
formResponseBean.getContent().forEach(contentResponseBean -> {
|
formResponseBean.getContent().forEach(contentResponseBean -> {
|
||||||
String fieldId = contentResponseBean.getId();
|
String fieldId = contentResponseBean.getId();
|
||||||
String value = (String) formFieldMap.get(fieldId);
|
String value = (String) formFieldMap.get(fieldId);
|
||||||
|
String fieldLabel=contentResponseBean.getLabel();
|
||||||
|
|
||||||
if(value == null && isApplicationFormExist) {
|
if(value == null && isApplicationFormExist) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FieldValidatorBean fieldValidatorBean = Utils.convertSourceObjectToDestinationObject(contentResponseBean.getValidators(), FieldValidatorBean.class);
|
FieldValidatorBean fieldValidatorBean = Utils.convertSourceObjectToDestinationObject(contentResponseBean.getValidators(), FieldValidatorBean.class);
|
||||||
validator
|
validator
|
||||||
.isRequired(value,fieldValidatorBean.getIsRequired(),fieldId)
|
.minLength(value, fieldValidatorBean.getMinLength(), fieldLabel) // Only applies if minLength is not null
|
||||||
.minLength(value, fieldValidatorBean.getMinLength(), fieldId) // Only applies if minLength is not null
|
.maxLength(value, fieldValidatorBean.getMaxLength(), fieldLabel) // Only applies if maxLength is not null
|
||||||
.maxLength(value, fieldValidatorBean.getMaxLength(), fieldId) // Only applies if maxLength is not null
|
.matchesPattern(value, fieldValidatorBean.getPattern(), fieldLabel) // Only applies if pattern is present
|
||||||
.matchesPattern(value, fieldValidatorBean.getPattern(), fieldId) // Only applies if pattern is present
|
.validateCustom(value, fieldValidatorBean.getCustom(), fieldLabel); // Add the custom validation here
|
||||||
.validateCustom(value, fieldValidatorBean.getCustom(), fieldId); // Add the custom validation here
|
|
||||||
if (fieldValidatorBean.getCustom() != null && fieldValidatorBean.getCustom().equals(GepafinConstant.IS_PIVA)) {
|
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) {
|
if(error != null) {
|
||||||
validator.addError(error);
|
validator.addError(error);
|
||||||
}
|
}
|
||||||
@@ -251,4 +253,37 @@ public class FormDao {
|
|||||||
}
|
}
|
||||||
return error;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.gepafin.tendermanagement.model.response;
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class NextOrPreviousFormResponse {
|
public class NextOrPreviousFormResponse {
|
||||||
@@ -16,6 +17,8 @@ public class NextOrPreviousFormResponse {
|
|||||||
private Long completedSteps;
|
private Long completedSteps;
|
||||||
|
|
||||||
private Long currentStep;
|
private Long currentStep;
|
||||||
|
|
||||||
|
private ApplicationStatusTypeEnum applicationStatus;
|
||||||
|
|
||||||
private FormApplicationResponse applicationFormResponse;
|
private FormApplicationResponse applicationFormResponse;
|
||||||
|
|
||||||
|
|||||||
@@ -27,16 +27,16 @@ public class FieldValidator {
|
|||||||
private VatCheckDao vatCheckDao;
|
private VatCheckDao vatCheckDao;
|
||||||
|
|
||||||
|
|
||||||
public FieldValidator notNull(Object object, String fieldName) {
|
public FieldValidator notNull(Object object, String fieldLabel) {
|
||||||
if (Objects.isNull(object)) {
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FieldValidator notEmpty(List<?> list, String fieldName) {
|
public FieldValidator notEmpty(List<?> list, String fieldLabel) {
|
||||||
if (list == null || list.isEmpty()) {
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -46,23 +46,23 @@ public class FieldValidator {
|
|||||||
throw new ValidationException(Status.VALIDATION_ERROR, errors, Translator.toLocale(GepafinConstant.VALIDATION_MESSAGE));
|
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) {
|
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;
|
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) {
|
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;
|
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)) {
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -147,4 +147,7 @@ public class FieldValidator {
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
public boolean hasErrors() {
|
||||||
|
return !errors.isEmpty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user