Fixed form issue
This commit is contained in:
@@ -90,55 +90,65 @@ public class FormDao {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.REQUIRED_PARAMETER_NOT_FOUND_FOR_FORM));
|
||||
}
|
||||
}
|
||||
public FormResponseBean updateForm(Long formId, FormRequest formRequest,Boolean forceDeleteFlow){
|
||||
public FormResponseBean updateForm(Long formId, FormRequest formRequest,Boolean forceDeleteFlow){
|
||||
ContentRequestBean contentRequestBean2=null;
|
||||
String choosenField=null;
|
||||
FormEntity formEntity = validateForm(formId);
|
||||
callDao.validateUpdate(formEntity.getCall());
|
||||
FlowDataEntity flowDataEntity=flowDataRepository.findByFormIdAndCallId(formEntity.getId(),formEntity.getCall().getId());
|
||||
String choosenField=flowDataEntity.getChoosenField();
|
||||
List<ContentRequestBean> contentRequestBean=Utils.convertJsonStringToList(formEntity.getContent(),ContentRequestBean.class);
|
||||
for (ContentRequestBean contentRequestBean1:contentRequestBean){
|
||||
if(Boolean.TRUE.equals(contentRequestBean1.getId().equals(choosenField))){
|
||||
contentRequestBean2=contentRequestBean1;
|
||||
break;
|
||||
callDao.validateUpdate(formEntity.getCall());
|
||||
List<ContentRequestBean> contentRequestBean = Utils.convertJsonStringToList(formEntity.getContent(), ContentRequestBean.class);
|
||||
for (ContentRequestBean contentRequestBean1 : contentRequestBean) {
|
||||
FlowDataEntity flowDataEntity = flowDataRepository.findByFormIdAndChoosenField(formEntity.getId(), contentRequestBean1.getId());
|
||||
if (flowDataEntity != null) {
|
||||
choosenField = flowDataEntity.getChoosenField();
|
||||
if (Boolean.TRUE.equals(contentRequestBean1.getId().equals(choosenField))) {
|
||||
contentRequestBean2 = contentRequestBean1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (contentRequestBean2 != null) {
|
||||
List<SettingRequestBean> settingRequestBeansDB = contentRequestBean2.getSettings();
|
||||
for (ContentRequestBean contentRequestBeanRequest : formRequest.getContent()) {
|
||||
if (contentRequestBeanRequest.getId().equals(contentRequestBean2.getId())) {
|
||||
for (SettingRequestBean settingRequestBeanRequest : contentRequestBeanRequest.getSettings()) {
|
||||
for (SettingRequestBean settingRequestBeanDB : settingRequestBeansDB) {
|
||||
if (settingRequestBeanRequest.getName().equals(settingRequestBeanDB.getName())) {
|
||||
if (!settingRequestBeanRequest.getValue().equals(settingRequestBeanDB.getValue())) {
|
||||
if(Boolean.TRUE.equals(forceDeleteFlow)) {
|
||||
Utils.setIfUpdated(formEntity::getLabel,formEntity::setLabel,formRequest.getLabel());
|
||||
Utils.setIfUpdated(formEntity::getContent,formEntity::setContent,setContentResponseBean(formRequest.getContent()));
|
||||
formEntity.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||
formEntity=saveFormEntity(formEntity);
|
||||
List<FlowDataEntity> flowDataEntities=flowDataRepository.findByCallId(formEntity.getCall().getId());
|
||||
List<FlowEdgesEntity> flowEdgesEntities=flowEdgesRepository.findByCallId(formEntity.getCall().getId());
|
||||
flowDataRepository.deleteAll(flowDataEntities);
|
||||
flowEdgesRepository.deleteAll(flowEdgesEntities);
|
||||
CallEntity callEntity=formEntity.getCall();
|
||||
callEntity.setInitialForm(null);
|
||||
callEntity.setFinalForm(null);
|
||||
callRepository.save(callEntity);
|
||||
return convertFormEntityToFormResponseBean(formEntity);
|
||||
}else {
|
||||
throw new CustomValidationException(
|
||||
Status.BAD_REQUEST,
|
||||
Translator.toLocale(GepafinConstant.UPDATING_FORM_VALUE_IMPACT_ON_FLOW, choosenField)
|
||||
);
|
||||
}
|
||||
if (contentRequestBean2 != null) {
|
||||
List<SettingRequestBean> settingRequestBeansDB = contentRequestBean2.getSettings();
|
||||
for (ContentRequestBean contentRequestBeanRequest : formRequest.getContent()) {
|
||||
if (contentRequestBeanRequest.getId().equals(contentRequestBean2.getId())) {
|
||||
for (SettingRequestBean settingRequestBeanRequest : contentRequestBeanRequest.getSettings()) {
|
||||
for (SettingRequestBean settingRequestBeanDB : settingRequestBeansDB) {
|
||||
if (settingRequestBeanRequest.getName().equals(settingRequestBeanDB.getName())) {
|
||||
if (!settingRequestBeanRequest.getValue().equals(settingRequestBeanDB.getValue())) {
|
||||
if (Boolean.TRUE.equals(forceDeleteFlow)) {
|
||||
Utils.setIfUpdated(formEntity::getLabel, formEntity::setLabel, formRequest.getLabel());
|
||||
Utils.setIfUpdated(formEntity::getContent, formEntity::setContent, setContentResponseBean(formRequest.getContent()));
|
||||
formEntity.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||
formEntity = saveFormEntity(formEntity);
|
||||
List<FlowDataEntity> flowDataEntities = flowDataRepository.findByCallId(formEntity.getCall().getId());
|
||||
List<FlowEdgesEntity> flowEdgesEntities = flowEdgesRepository.findByCallId(formEntity.getCall().getId());
|
||||
flowDataRepository.deleteAll(flowDataEntities);
|
||||
flowEdgesRepository.deleteAll(flowEdgesEntities);
|
||||
CallEntity callEntity = formEntity.getCall();
|
||||
callEntity.setInitialForm(null);
|
||||
callEntity.setFinalForm(null);
|
||||
callRepository.save(callEntity);
|
||||
return convertFormEntityToFormResponseBean(formEntity);
|
||||
} else {
|
||||
throw new CustomValidationException(
|
||||
Status.BAD_REQUEST,
|
||||
Translator.toLocale(GepafinConstant.UPDATING_FORM_VALUE_IMPACT_ON_FLOW, choosenField)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
Utils.setIfUpdated(formEntity::getLabel, formEntity::setLabel, formRequest.getLabel());
|
||||
Utils.setIfUpdated(formEntity::getContent, formEntity::setContent, setContentResponseBean(formRequest.getContent()));
|
||||
formEntity.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||
formEntity = saveFormEntity(formEntity);
|
||||
return convertFormEntityToFormResponseBean(formEntity);
|
||||
}
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
public FormEntity validateForm(Long formId) {
|
||||
|
||||
@@ -17,4 +17,7 @@ public interface FlowDataRepository extends JpaRepository<FlowDataEntity,Long> {
|
||||
public Optional<FlowDataEntity> findByChoosenValueAndFormIdIn(String fieldValue, List<Long> nextFormIds);
|
||||
|
||||
public List<FlowDataEntity> findByFormIdInAndCallId(List<Long> previousFormIds, Long callId);
|
||||
|
||||
public FlowDataEntity findByFormIdAndChoosenField(Long formId, String choosenField);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user