Applied validation

This commit is contained in:
rajesh
2024-09-17 16:15:15 +05:30
parent 6959ac0a65
commit d2fed5e168
14 changed files with 57 additions and 10 deletions

View File

@@ -128,4 +128,8 @@ public class GepafinConstant {
public static final String FLOW_NOT_FOUND = "flow.not.found"; public static final String FLOW_NOT_FOUND = "flow.not.found";
public static final String VALIDATION_MESSAGE = "validation.message"; public static final String VALIDATION_MESSAGE = "validation.message";
public static final String ACTION_REQUIRED = "action.required"; public static final String ACTION_REQUIRED = "action.required";
public static final String CALL_NOT_PUBLISHED="call.not.published";
public static final String APPLICATION_ALREADY_SUBMITTED="application.already.submitted";
public static final String INITAL_AND_FINAL_FORM_CANNOT_NULL="initial.and.final.form.cannot.null";
} }

View File

@@ -50,8 +50,11 @@ public class ApplicationDao {
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.validateCall(formEntity.getCall().getId()); CallEntity call = callService.validatePublishedCall(formEntity.getCall().getId());
ApplicationEntity applicationEntity = validateApplication(applicationId); 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));
}
formService.validateFormField(applicationRequestBean.getFormFields(),applicationEntity,formEntity); formService.validateFormField(applicationRequestBean.getFormFields(),applicationEntity,formEntity);
ApplicationFormEntity applicationFormEntity = getApplicationFormOrCreate(formEntity, applicationEntity); ApplicationFormEntity applicationFormEntity = getApplicationFormOrCreate(formEntity, applicationEntity);
createOrUpdateMultipleFormFields(applicationRequestBean.getFormFields(), applicationFormEntity); createOrUpdateMultipleFormFields(applicationRequestBean.getFormFields(), applicationFormEntity);
@@ -326,7 +329,8 @@ public class ApplicationDao {
public ApplicationResponse createApplicationByCallId(ApplicationRequest applicationRequest,Long callId,UserEntity userEntity){ public ApplicationResponse createApplicationByCallId(ApplicationRequest applicationRequest,Long callId,UserEntity userEntity){
CallEntity call=callService.validateCall(callId); CallEntity call=callService.validateCall(callId);
checkIfApplicationExists(call,userEntity); call = callService.validatePublishedCall(call.getId());
checkIfApplicationExists(call,userEntity);
ApplicationEntity applicationEntity=createApplicationEntity(userEntity,call); ApplicationEntity applicationEntity=createApplicationEntity(userEntity,call);
applicationEntity.setComments(applicationRequest.getComments()); applicationEntity.setComments(applicationRequest.getComments());
applicationEntity=saveApplicationEntity(applicationEntity); applicationEntity=saveApplicationEntity(applicationEntity);

View File

@@ -387,7 +387,7 @@ public class CallDao {
return createCallResponseBean; return createCallResponseBean;
} }
private void validateUpdate(CallEntity callEntity) { public void validateUpdate(CallEntity callEntity) {
if(callEntity.getStatus().equals(CallStatusEnum.PUBLISH.getValue())) { if(callEntity.getStatus().equals(CallStatusEnum.PUBLISH.getValue())) {
throw new CustomValidationException(Status.VALIDATION_ERROR, throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.PUBLISHED_CALL_NOT_UPDATE)); Translator.toLocale(GepafinConstant.PUBLISHED_CALL_NOT_UPDATE));
@@ -622,5 +622,15 @@ public class CallDao {
} }
} }
public CallEntity validatePublishedCall(Long callId) {
CallEntity callEntity= callRepository
.findByIdAndStatus(callId, CallStatusEnum.PUBLISH.getValue());
if(callEntity==null){
throw new ResourceNotFoundException(
Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.CALL_NOT_PUBLISHED));
}
return callEntity;
}
} }

View File

@@ -21,6 +21,7 @@ import net.gepafin.tendermanagement.repositories.FlowEdgesRepository;
import net.gepafin.tendermanagement.service.CallService; import net.gepafin.tendermanagement.service.CallService;
import net.gepafin.tendermanagement.service.FormService; import net.gepafin.tendermanagement.service.FormService;
import net.gepafin.tendermanagement.util.DateTimeUtil; import net.gepafin.tendermanagement.util.DateTimeUtil;
import net.gepafin.tendermanagement.util.FieldValidator;
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException; import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
import net.gepafin.tendermanagement.web.rest.api.errors.Status; import net.gepafin.tendermanagement.web.rest.api.errors.Status;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -49,6 +50,9 @@ public class FlowDao {
@Autowired @Autowired
private FormService formService; private FormService formService;
@Autowired
private CallDao callDao;
public FlowResponseBean createOrUpdateFlow(FlowRequestBean flowRequestBean, Long callId) { public FlowResponseBean createOrUpdateFlow(FlowRequestBean flowRequestBean, Long callId) {
validateFlowRequestBean(flowRequestBean); validateFlowRequestBean(flowRequestBean);
CallEntity call = callService.validateCall(callId); CallEntity call = callService.validateCall(callId);
@@ -62,12 +66,17 @@ public class FlowDao {
} }
public void validateFlowRequestBean(FlowRequestBean flowRequestBean){ public void validateFlowRequestBean(FlowRequestBean flowRequestBean){
if (FieldValidator.isNullOrZero(flowRequestBean.getInitialForm()) || FieldValidator.isNullOrZero(flowRequestBean.getFinalForm())) {
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.INITAL_AND_FINAL_FORM_CANNOT_NULL));
}
if (flowRequestBean.getFlowEdges() == null || flowRequestBean.getFlowEdges().isEmpty()) { if (flowRequestBean.getFlowEdges() == null || flowRequestBean.getFlowEdges().isEmpty()) {
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.FLOW_REQUEST_NOT_PROPER)); throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.FLOW_REQUEST_NOT_PROPER));
} }
} }
public void checkIfFlowExits(CallEntity call) { public void checkIfFlowExits(CallEntity call) {
callDao.validateUpdate(call);
List<FlowDataEntity> flowDataEntities = flowDataRepository.findByCallId(call.getId()); List<FlowDataEntity> flowDataEntities = flowDataRepository.findByCallId(call.getId());
List<FlowEdgesEntity> flowEdgesEntities = flowEdgesRepository.findByCallId(call.getId()); List<FlowEdgesEntity> flowEdgesEntities = flowEdgesRepository.findByCallId(call.getId());
if (Boolean.FALSE.equals(flowDataEntities.isEmpty()) || Boolean.FALSE.equals(flowEdgesEntities.isEmpty())) { if (Boolean.FALSE.equals(flowDataEntities.isEmpty()) || Boolean.FALSE.equals(flowEdgesEntities.isEmpty())) {

View File

@@ -38,6 +38,9 @@ public class FormDao {
@Autowired @Autowired
private ApplicationFormRepository applicationFormRepository; private ApplicationFormRepository applicationFormRepository;
@Autowired
private CallDao callDao;
public FormEntity saveFormEntity(FormEntity formEntity){ public FormEntity saveFormEntity(FormEntity formEntity){
formEntity=formRepository.save(formEntity); formEntity=formRepository.save(formEntity);
return formEntity; return formEntity;
@@ -72,6 +75,7 @@ public class FormDao {
} }
public FormResponseBean updateForm(Long formId, FormRequest formRequest){ public FormResponseBean updateForm(Long formId, FormRequest formRequest){
FormEntity formEntity = validateForm(formId); FormEntity formEntity = validateForm(formId);
callDao.validateUpdate(formEntity.getCall());
Utils.setIfUpdated(formEntity::getLabel,formEntity::setLabel,formRequest.getLabel()); Utils.setIfUpdated(formEntity::getLabel,formEntity::setLabel,formRequest.getLabel());
Utils.setIfUpdated(formEntity::getContent,formEntity::setContent,setContentResponseBean(formRequest.getContent())); Utils.setIfUpdated(formEntity::getContent,formEntity::setContent,setContentResponseBean(formRequest.getContent()));
formEntity.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); formEntity.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));

View File

@@ -7,8 +7,6 @@ import net.gepafin.tendermanagement.entities.ApplicationFormEntity;
@Data @Data
public class ApplicationFormFieldRequestBean { public class ApplicationFormFieldRequestBean {
private Long id;
private String fieldId; private String fieldId;
private String fieldValue; private String fieldValue;

View File

@@ -11,4 +11,6 @@ public interface CallRepository extends JpaRepository<CallEntity, Long> {
public CallEntity findByIdAndStatusNotIn(Long id, List<String> status); public CallEntity findByIdAndStatusNotIn(Long id, List<String> status);
List<CallEntity> findByStatusIn(List<String> callStatus); List<CallEntity> findByStatusIn(List<String> callStatus);
public CallEntity findByIdAndStatus(Long id,String status);
} }

View File

@@ -31,4 +31,6 @@ public interface CallService {
CallEntity validateCall(Long callId); CallEntity validateCall(Long callId);
} CallEntity validatePublishedCall(Long callId);
}

View File

@@ -87,4 +87,9 @@ public class CallServiceImpl implements CallService {
public CallEntity validateCall(Long callId) { public CallEntity validateCall(Long callId) {
return callDao.validateCall(callId); return callDao.validateCall(callId);
} }
}
@Override
public CallEntity validatePublishedCall(Long callId) {
return callDao.validatePublishedCall(callId);
}
}

View File

@@ -62,4 +62,7 @@ public class FieldValidator {
errors.add(errorMessage); errors.add(errorMessage);
return this; return this;
} }
public static boolean isNullOrZero(Long value) {
return value == null || value == 0L;
}
} }

View File

@@ -28,7 +28,7 @@ import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
@Validated @Validated
public interface ApplicationApi { public interface ApplicationApi {
@Operation(summary = "Api to create application form", @Operation(summary = "Api to create or update application form",
responses = { responses = {
@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { @ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {

View File

@@ -23,7 +23,7 @@ public interface FaqApi {
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = "application/json", examples = @ExampleObject(value = "{ \"error\": \"Not Found\" }"))) @ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = "application/json", examples = @ExampleObject(value = "{ \"error\": \"Not Found\" }")))
}) })
@PostMapping(value = "/call/{callId}", consumes = "application/json", produces = "application/json") @PostMapping(value = "/call/{callId}", consumes = "application/json", produces = "application/json")
ResponseEntity<Response<FaqResponseBean>> createFaq(HttpServletRequest request, @Parameter(description = "evaluation criteria id", required = true) ResponseEntity<Response<FaqResponseBean>> createFaq(HttpServletRequest request, @Parameter(description = "call id", required = true)
@PathVariable("callId") Long callId, @Valid @RequestBody FaqReq faqRequest); @PathVariable("callId") Long callId, @Valid @RequestBody FaqReq faqRequest);
@Operation(summary = "API to get FAQ by id", @Operation(summary = "API to get FAQ by id",

View File

@@ -139,6 +139,7 @@ flow.created.successfully=Flow created successfully.
flow.fetched.successfully=Flow fetched successfully. flow.fetched.successfully=Flow fetched successfully.
flow.already.exists= Flow already exist for this call. flow.already.exists= Flow already exist for this call.
flow.request.not.complete=Flow request is not complete. flow.request.not.complete=Flow request is not complete.
initial.and.final.form.cannot.null=Initial and final form cannot be null.
# Application related messages # Application related messages
application.created.success=Application successfully created. application.created.success=Application successfully created.
@@ -149,6 +150,7 @@ application.not.found=Application not found with the given ID.
application.form.field.not.found=Application form field not found. application.form.field.not.found=Application form field not found.
Form.not.matches.to.call.initial.form=Form id does not matches to initial form id of call. Form.not.matches.to.call.initial.form=Form id does not matches to initial form id of call.
application.already.exists=Application already exists for this call. application.already.exists=Application already exists for this call.
application.already.submitted=Application is already submitted.
#Validation related messages #Validation related messages
validation.field.required=Field {0} is required. validation.field.required=Field {0} is required.
@@ -162,3 +164,4 @@ current.form.incomplete=Current form is not filled.
flow.not.found=Flow not found. flow.not.found=Flow not found.
validation.message=Validation messages. validation.message=Validation messages.
action.required=Action field required. action.required=Action field required.
call.not.published=Call is not published.

View File

@@ -135,6 +135,7 @@ flow.created.successfully=Flusso creato con successo.
flow.fetched.successfully=Flusso recuperato con successo. flow.fetched.successfully=Flusso recuperato con successo.
flow.already.exists= Il flusso esiste gi� per questa chiamata. flow.already.exists= Il flusso esiste gi� per questa chiamata.
flow.request.not.complete=La richiesta di flusso non � completa. flow.request.not.complete=La richiesta di flusso non � completa.
initial.and.final.form.cannot.null=La forma iniziale e finale non possono essere nulle.
# Application related messages # Application related messages
application.created.success=Applicazione creata con successo. application.created.success=Applicazione creata con successo.
@@ -145,6 +146,7 @@ application.not.found=Applicazione non trovata con l'ID fornito.
application.form.field.not.found=Campo del modulo di domanda non trovato. application.form.field.not.found=Campo del modulo di domanda non trovato.
Form.not.matches.to.call.initial.form=L'ID del modulo non corrisponde all'ID del modulo iniziale della chiamata. Form.not.matches.to.call.initial.form=L'ID del modulo non corrisponde all'ID del modulo iniziale della chiamata.
application.already.exists=L'applicazione esiste gi� per questa chiamata. application.already.exists=L'applicazione esiste gi� per questa chiamata.
application.already.submitted=La domanda è già stata inviata.
#Validation related messages #Validation related messages
validation.field.required=Il campo {0} � obbligatorio. validation.field.required=Il campo {0} � obbligatorio.
@@ -157,3 +159,4 @@ current.form.incomplete=il modulo corrente non <20> compilato
flow.not.found=Flow not found. flow.not.found=Flow not found.
validation.message=Messaggi di convalida. validation.message=Messaggi di convalida.
action.required=Campo azione obbligatorio. action.required=Campo azione obbligatorio.
call.not.published=La chiamata non è stata pubblicata.