Applied validation application form field
This commit is contained in:
@@ -158,4 +158,5 @@ public class GepafinConstant {
|
||||
public static final String FAILED_RETAIN_FIELD="failed.retain.field";
|
||||
public static final String TOTAL_STEPS_NOT_BE_ZERO="total.steps.not.zero";
|
||||
public static final String COMPLETED_STEPS_NOT_VALID="completed.steps.not.valid";
|
||||
public static final String FIELD_ID_NOT_FOUND="field.id.not.found";
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ 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;
|
||||
@@ -68,6 +69,7 @@ public class ApplicationDao {
|
||||
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));
|
||||
@@ -492,5 +494,24 @@ public class ApplicationDao {
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user