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

View File

@@ -387,7 +387,7 @@ public class CallDao {
return createCallResponseBean;
}
private void validateUpdate(CallEntity callEntity) {
public void validateUpdate(CallEntity callEntity) {
if(callEntity.getStatus().equals(CallStatusEnum.PUBLISH.getValue())) {
throw new CustomValidationException(Status.VALIDATION_ERROR,
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.FormService;
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.Status;
import org.springframework.beans.factory.annotation.Autowired;
@@ -49,6 +50,9 @@ public class FlowDao {
@Autowired
private FormService formService;
@Autowired
private CallDao callDao;
public FlowResponseBean createOrUpdateFlow(FlowRequestBean flowRequestBean, Long callId) {
validateFlowRequestBean(flowRequestBean);
CallEntity call = callService.validateCall(callId);
@@ -62,12 +66,17 @@ public class FlowDao {
}
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()) {
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.FLOW_REQUEST_NOT_PROPER));
}
}
public void checkIfFlowExits(CallEntity call) {
callDao.validateUpdate(call);
List<FlowDataEntity> flowDataEntities = flowDataRepository.findByCallId(call.getId());
List<FlowEdgesEntity> flowEdgesEntities = flowEdgesRepository.findByCallId(call.getId());
if (Boolean.FALSE.equals(flowDataEntities.isEmpty()) || Boolean.FALSE.equals(flowEdgesEntities.isEmpty())) {

View File

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

View File

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

View File

@@ -11,4 +11,6 @@ public interface CallRepository extends JpaRepository<CallEntity, Long> {
public CallEntity findByIdAndStatusNotIn(Long id, List<String> status);
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 validatePublishedCall(Long callId);
}

View File

@@ -87,4 +87,9 @@ public class CallServiceImpl implements CallService {
public CallEntity validateCall(Long 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);
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
public interface ApplicationApi {
@Operation(summary = "Api to create application form",
@Operation(summary = "Api to create or update application form",
responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@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\" }")))
})
@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);
@Operation(summary = "API to get FAQ by id",