Resolved conflicts
This commit is contained in:
@@ -155,4 +155,5 @@ public class GepafinConstant {
|
||||
public static final String IS_CODICE_FISCALE="isCodiceFiscale";
|
||||
public static final String IS_PIVA="isPIVA";
|
||||
|
||||
public static final String FAILED_RETAIN_FIELD="failed.retain.field";
|
||||
}
|
||||
|
||||
@@ -3,12 +3,14 @@ package net.gepafin.tendermanagement.dao;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.response.*;
|
||||
import net.gepafin.tendermanagement.service.*;
|
||||
import net.gepafin.tendermanagement.util.Utils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -424,8 +426,14 @@ public class CallDao {
|
||||
|
||||
public CallResponse updateCallStep1(Long callId, UpdateCallRequestStep1 updateCallRequest, Long userId) {
|
||||
CallEntity callEntity = validateCall(callId);
|
||||
validateUpdate(callEntity);
|
||||
UserEntity userEntity = userService.validateUser(userId);
|
||||
if(Boolean.TRUE.equals(callEntity.getStatus().equals(CallStatusEnum.PUBLISH.getValue()))) {
|
||||
try {
|
||||
Utils.retainOnlySpecificFields(updateCallRequest, Collections.singletonList("faq"));
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.FAILED_RETAIN_FIELD));
|
||||
}
|
||||
}
|
||||
UserEntity userEntity = userService.validateUser(userId);
|
||||
isValidDateRange(updateCallRequest, callEntity);
|
||||
setIfUpdated(callEntity::getName, callEntity::setName, updateCallRequest.getName());
|
||||
setIfUpdated(callEntity::getDescriptionShort, callEntity::setDescriptionShort,
|
||||
|
||||
@@ -95,55 +95,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 convertFormEntityToFormResponseBean(formEntity);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.apache.commons.collections4.MapUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
@@ -147,4 +148,17 @@ public class Utils {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static <T> void retainOnlySpecificFields(T requestObject, List<T> retainFields) throws IllegalAccessException {
|
||||
// Get all declared fields of the request object's class
|
||||
Field[] fields = requestObject.getClass().getDeclaredFields();
|
||||
|
||||
for (Field field : fields) {
|
||||
field.setAccessible(true); // To allow access to private fields
|
||||
|
||||
// Check if the field is in the retainFields list
|
||||
if (!retainFields.contains(field.getName())) {
|
||||
field.set(requestObject, null); // Set the field to null if not in the retain list
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user