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

@@ -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()));