Resolved conflict
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.gepafin.tendermanagement.entities.*;
|
||||
import net.gepafin.tendermanagement.model.request.*;
|
||||
import net.gepafin.tendermanagement.model.response.ContentResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.FormResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.VatNumberResponseBean;
|
||||
import net.gepafin.tendermanagement.repositories.*;
|
||||
import net.gepafin.tendermanagement.service.CallService;
|
||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||
@@ -16,6 +17,7 @@ import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundExceptio
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -45,6 +47,9 @@ public class FormDao {
|
||||
@Autowired
|
||||
private FlowEdgesRepository flowEdgesRepository;
|
||||
|
||||
@Autowired
|
||||
private VatCheckDao vatCheckDao;
|
||||
|
||||
@Autowired
|
||||
private CallRepository callRepository;
|
||||
|
||||
@@ -190,7 +195,7 @@ public class FormDao {
|
||||
}
|
||||
|
||||
public void validateFormField(List<ApplicationFormFieldRequestBean> applicationFormFieldRequestList, ApplicationEntity applicationEntity, FormEntity formEntity) {
|
||||
Map<String, String> formFieldMap = new LinkedHashMap<String, String>();
|
||||
Map<String, Object> formFieldMap = new LinkedHashMap<String, Object>();
|
||||
for(ApplicationFormFieldRequestBean applicationFormFieldRequestBean:applicationFormFieldRequestList) {
|
||||
formFieldMap.put(applicationFormFieldRequestBean.getFieldId(),applicationFormFieldRequestBean.getFieldValue());
|
||||
}
|
||||
@@ -201,20 +206,25 @@ public class FormDao {
|
||||
FieldValidator validator = FieldValidator.create();
|
||||
formResponseBean.getContent().forEach(contentResponseBean -> {
|
||||
String fieldId = contentResponseBean.getId();
|
||||
String value = formFieldMap.get(fieldId);
|
||||
String value = String.valueOf(formFieldMap.get(fieldId));
|
||||
|
||||
if(value == null && isApplicationFormExist) {
|
||||
return;
|
||||
}
|
||||
FieldValidatorBean fieldValidatorBean = Utils.convertSourceObjectToDestinationObject(contentResponseBean, FieldValidatorBean.class);
|
||||
FieldValidatorBean fieldValidatorBean = Utils.convertSourceObjectToDestinationObject(contentResponseBean.getValidators(), FieldValidatorBean.class);
|
||||
validator
|
||||
.notNull(value, fieldId)
|
||||
.isRequired(value,fieldValidatorBean.getIsRequired(),fieldId)
|
||||
.minLength(value, fieldValidatorBean.getMinLength(), fieldId) // Only applies if minLength is not null
|
||||
.maxLength(value, fieldValidatorBean.getMaxLength(), fieldId) // Only applies if maxLength is not null
|
||||
.matchesPattern(value, fieldValidatorBean.getPattern(), fieldId); // Only applies if pattern is present
|
||||
.matchesPattern(value, fieldValidatorBean.getPattern(), fieldId) // Only applies if pattern is present
|
||||
.validateCustom(value, fieldValidatorBean.getCustom(), fieldId); // Add the custom validation here
|
||||
if (fieldValidatorBean.getCustom() != null && fieldValidatorBean.getCustom().equals(GepafinConstant.IS_PIVA)) {
|
||||
String error = validateVatNumber(value, fieldValidatorBean.getCustom(), fieldId);
|
||||
validator.addError(error);
|
||||
}
|
||||
});
|
||||
|
||||
validator.validate();
|
||||
|
||||
}
|
||||
|
||||
private Boolean getApplicationFormExist(ApplicationFormEntity applicationFormEntity) {
|
||||
@@ -223,4 +233,20 @@ public class FormDao {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String validateVatNumber(String value,String customRule,String fieldId){
|
||||
String error=null;
|
||||
if (value.matches("^\\d{1,11}$")) {
|
||||
Map<String, Object> customData=null;
|
||||
try {
|
||||
Map<String, Object> vatCheckResponse = vatCheckDao.checkVatNumberApi(value);
|
||||
if (Boolean.FALSE.equals(CollectionUtils.isEmpty(vatCheckResponse))) {
|
||||
customData = vatCheckResponse;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
error=(MessageFormat.format(Translator.toLocale(GepafinConstant.VALIDATION_VALID_PIVA), fieldId));
|
||||
}
|
||||
}
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import feign.FeignException;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.service.feignClient.VatCheckService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class VatCheckDao {
|
||||
|
||||
@Autowired
|
||||
private VatCheckService vatCheckService;
|
||||
|
||||
@Value("${vatCheckNewToken}")
|
||||
public String vatCheckNewToken;
|
||||
|
||||
@Value("${isVatCheckGloballyDisabled}")
|
||||
public String isVatCheckGloballyDisabled;
|
||||
|
||||
public final Logger log = LoggerFactory.getLogger(VatCheckDao.class);
|
||||
|
||||
|
||||
|
||||
public Map<String, Object> checkVatNumberApi(String vatNumber) {
|
||||
if (Boolean.TRUE.equals(Boolean.parseBoolean(isVatCheckGloballyDisabled))) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
Map<String, Object> responseBody = new HashMap<>();
|
||||
try {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.set(GepafinConstant.AUTHORIZATION, "Bearer " + vatCheckNewToken);
|
||||
headers.add(org.apache.http.HttpHeaders.USER_AGENT,
|
||||
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0");
|
||||
|
||||
URI baseUrl = URI.create(GepafinConstant.CHECK_VATNUMBER_V2_NEW_URL);
|
||||
ResponseEntity<Map<String, Object>> response = vatCheckService.checkVatNumber(baseUrl,vatNumber, headers);
|
||||
|
||||
if (response.getStatusCode() == HttpStatus.OK && response.hasBody()) {
|
||||
log.info("Successfully checked vat number");
|
||||
Map<String, Object> responseMap = response.getBody();
|
||||
if (responseMap != null && responseMap.containsKey("data")) {
|
||||
responseBody = (Map<String, Object>) responseMap.get("data");
|
||||
responseBody.remove("timestamp_creation");
|
||||
responseBody.remove("timestamp_last_update");
|
||||
responseBody.remove("data_iscrizione");
|
||||
responseBody.remove("id");
|
||||
Map<String, Object> data = new LinkedHashMap<>();
|
||||
data.put("data", responseBody);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
} catch (FeignException ex) {
|
||||
log.error("Exception occurred while checking vat number: {0}", ex);
|
||||
throw ex;
|
||||
}
|
||||
return responseBody;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user