Resolved conflicts

This commit is contained in:
rajesh
2025-03-24 19:21:50 +05:30
6 changed files with 181 additions and 72 deletions

View File

@@ -137,6 +137,7 @@ public class GepafinConstant {
public static final String APPLICATION_IS_INCOMPLETE_MSG = "application.is.incomplete"; public static final String APPLICATION_IS_INCOMPLETE_MSG = "application.is.incomplete";
public static final String AUTHORIZATION = "Authorization"; public static final String AUTHORIZATION = "Authorization";
public static final String CHECK_VATNUMBER_V2_NEW_URL = "https://imprese.openapi.it/advance"; public static final String CHECK_VATNUMBER_V2_NEW_URL = "https://imprese.openapi.it/advance";
public static final String CHECK_VATNUMBER_V2_NEW_URL_IT_ADVANCE = "https://company.openapi.com/IT-advanced";
public static final String VALIDATION_FIELD_CUSTOM = "validation.field.custom"; public static final String VALIDATION_FIELD_CUSTOM = "validation.field.custom";
public static final String VALIDATION_CODICE_FISCALE = "validation.codice.fiscale"; public static final String VALIDATION_CODICE_FISCALE = "validation.codice.fiscale";
public static final String VALIDATION_CAP = "validation.cap"; public static final String VALIDATION_CAP = "validation.cap";

View File

@@ -148,22 +148,7 @@ public class CompanyDao {
companyEntity.setJson(Utils.convertMapIntoJsonString(companyRequest.getVatCheckResponse())); companyEntity.setJson(Utils.convertMapIntoJsonString(companyRequest.getVatCheckResponse()));
Map<String, Object> vatCheckResponse = companyRequest.getVatCheckResponse(); Map<String, Object> vatCheckResponse = companyRequest.getVatCheckResponse();
Map<String, Object> data = (Map<String, Object>) vatCheckResponse.get("data"); Map<String, Object> data = (Map<String, Object>) vatCheckResponse.get("data");
if (data != null) { updateCodiceAtecoFieldWithNewJson(companyEntity);
if (data.containsKey("dettaglio")) {
Map<String, Object> dettaglio = (Map<String, Object>) data.get("dettaglio");
if (dettaglio != null) {
if (dettaglio.containsKey("codice_ateco")) {
Object codiceAtecoObj = dettaglio.get("codice_ateco");
String codiceAteco = (codiceAtecoObj != null) ? codiceAtecoObj.toString() : null;
if (codiceAteco != null) {
companyEntity.setCodiceAteco(codiceAteco);
}
}
}
}
}
companyEntity = companyRepository.save(companyEntity); companyEntity = companyRepository.save(companyEntity);
/** This code is responsible for adding a version history log for "updating company json field" operation. **/ /** This code is responsible for adding a version history log for "updating company json field" operation. **/
@@ -193,25 +178,8 @@ public class CompanyDao {
entity.setAnnualRevenue(request.getAnnualRevenue()); entity.setAnnualRevenue(request.getAnnualRevenue());
entity.setHub(userEntity.getHub()); entity.setHub(userEntity.getHub());
entity.setJson(Utils.convertMapIntoJsonString(request.getVatCheckResponse())); entity.setJson(Utils.convertMapIntoJsonString(request.getVatCheckResponse()));
if (request.getVatCheckResponse() != null) { updateCodiceAtecoFieldWithNewJson(entity);
Map<String, Object> vatCheckResponse = request.getVatCheckResponse();
Map<String, Object> data = (Map<String, Object>) vatCheckResponse.get("data");
if (data != null) {
if (data.containsKey("dettaglio")) {
Map<String, Object> dettaglio = (Map<String, Object>) data.get("dettaglio");
if (dettaglio != null) {
if (dettaglio.containsKey("codice_ateco")) {
Object codiceAtecoObj = dettaglio.get("codice_ateco");
String codiceAteco = (codiceAtecoObj != null) ? codiceAtecoObj.toString() : null;
if (codiceAteco != null) {
entity.setCodiceAteco(codiceAteco);
}
}
}
}
}
}
return entity; return entity;
} }
@@ -469,7 +437,8 @@ public class CompanyDao {
log.info("Company ID {}: JSON field updated successfully.", company.getId()); log.info("Company ID {}: JSON field updated successfully.", company.getId());
// Extract and set codiceAteco field // Extract and set codiceAteco field
updateCodiceAtecoField(company); // updateCodiceAtecoField(company);
updateCodiceAtecoFieldWithNewJson(company);
successfulUpdates++; successfulUpdates++;
} else { } else {
@@ -547,5 +516,46 @@ public class CompanyDao {
log.warn("Company ID {}: 'data' section missing in the JSON response.", company.getId()); log.warn("Company ID {}: 'data' section missing in the JSON response.", company.getId());
} }
} }
private void updateCodiceAtecoFieldWithNewJson(CompanyEntity company) {
if (company == null || company.getJson() == null || company.getJson().isEmpty()) {
log.warn("Company is null or JSON data is empty.");
return;
}
Map<String, Object> companyDataMap = Utils.convertJsonStringToMap(company.getJson());
if (companyDataMap == null) {
log.warn("Company ID {}: Failed to parse JSON data.", company.getId());
return;
}
// Extract 'data' section
Map<String, Object> dataMap = Utils.extractMap(companyDataMap, "data");
if (dataMap == null) {
log.warn("Company ID {}: 'data' section is missing or invalid in the JSON.", company.getId());
return;
}
// Extract 'atecoClassification' section
Map<String, Object> atecoClassificationMap = Utils.extractMap(dataMap, "atecoClassification");
if (atecoClassificationMap == null) {
log.warn("Company ID {}: 'atecoClassification' section is missing or invalid.", company.getId());
return;
}
// Extract 'ateco' section
Map<String, Object> atecoMap = Utils.extractMap(atecoClassificationMap, "ateco");
if (atecoMap == null) {
log.warn("Company ID {}: 'ateco' section is missing or invalid.", company.getId());
return;
}
// Extract and set 'code'
String atecoCode = Utils.extractString(atecoMap, "code");
if (atecoCode != null && !atecoCode.isEmpty()) {
company.setCodiceAteco(atecoCode);
log.info("Company ID {}: codiceAteco updated to {}", company.getId(), atecoCode);
} else {
log.warn("Company ID {}: 'code' inside 'ateco' is empty or missing.", company.getId());
}
}
} }

View File

@@ -23,6 +23,7 @@ import java.net.URI;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
@Component @Component
@@ -45,7 +46,97 @@ public class VatCheckDao {
@Autowired @Autowired
private HttpServletRequest request; private HttpServletRequest request;
// public VatCheckResponseBean checkVatNumberApi(String vatNumber) {
// VatCheckResponseBean vatCheckResponseBean = new VatCheckResponseBean();
// vatCheckResponseBean.setValid(false);
// vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
// if (Boolean.TRUE.equals(Boolean.parseBoolean(isVatCheckGloballyDisabled))) {
// vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
// return vatCheckResponseBean;
// }
// 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();
// processValidResponse(responseMap, vatCheckResponseBean);
// }
// } catch (FeignException ex) {
// if (ex.status() == 406) {
// try {
// Map<String, Object> errorResponse = Utils.parseErrorResponse(ex.contentUTF8());
// processValidResponse(errorResponse, vatCheckResponseBean);
// } catch (Exception parseEx) {
// log.error("Failed to parse 406 error response: {0}", parseEx);
// }
// } else {
// log.error("Exception occurred while checking vat number: {0}", ex);
// Utils.callException(ex.status(), ex);
// }
// }
// return vatCheckResponseBean;
// }
// public static void processValidResponse(Map<String, Object> responseMap, VatCheckResponseBean vatCheckResponseBean) {
// if (responseMap != null && responseMap.containsKey("data")) {
// Map<String, Object> responseBody = (Map<String, Object>) responseMap.get("data");
//
// if (responseBody != null) {
// 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);
//
// vatCheckResponseBean.setValid(true);
// vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.VALID_VATNUMBER_MSG));
// vatCheckResponseBean.setVatCheckResponse(data);
// } else {
// vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
// }
// } else {
// vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
// }
// }
//
// public VatCheckResponseBean checkVatNumber(String vatNumber) {
// try {
// return checkVatNumberApi(vatNumber);
// } catch (Exception e) {
// log.error("Error in checkVatNumber: {}", e.getMessage());
// VatCheckResponseBean vatCheckResponseBean = new VatCheckResponseBean();
// vatCheckResponseBean.setValid(false);
// vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
// return vatCheckResponseBean;
// }
// }
public VatCheckResponseBean checkVatNumber(String vatNumber) {
try {
return checkVatNumberApi(vatNumber);
} catch (Exception e) {
log.error("Error in checkVatNumber: {}", e.getMessage());
VatCheckResponseBean vatCheckResponseBean = new VatCheckResponseBean();
vatCheckResponseBean.setValid(false);
vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
return vatCheckResponseBean;
}
}
public VatCheckResponseBean checkVatNumberApi(String vatNumber) { public VatCheckResponseBean checkVatNumberApi(String vatNumber) {
VatCheckResponseBean vatCheckResponseBean = new VatCheckResponseBean(); VatCheckResponseBean vatCheckResponseBean = new VatCheckResponseBean();
vatCheckResponseBean.setValid(false); vatCheckResponseBean.setValid(false);
vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER)); vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
@@ -53,18 +144,14 @@ public class VatCheckDao {
vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER)); vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
return vatCheckResponseBean; return vatCheckResponseBean;
} }
Map<String, Object> responseBody = new HashMap<>();
try { try {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set(GepafinConstant.AUTHORIZATION, "Bearer " + vatCheckNewToken); 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); URI baseUrl = URI.create(GepafinConstant.CHECK_VATNUMBER_V2_NEW_URL_IT_ADVANCE);
ResponseEntity<Map<String, Object>> response = vatCheckService.checkVatNumber(baseUrl, vatNumber, headers); ResponseEntity<Map<String, Object>> response = vatCheckService.checkVatNumber(baseUrl, vatNumber, headers);
if (response.getStatusCode() == HttpStatus.OK && response.hasBody()) { if (response.getStatusCode() == HttpStatus.OK && response.hasBody()) {
log.info("Successfully checked vat number"); log.info("Successfully checked vat number");
Map<String, Object> responseMap = response.getBody(); Map<String, Object> responseMap = response.getBody();
@@ -86,13 +173,19 @@ public class VatCheckDao {
return vatCheckResponseBean; return vatCheckResponseBean;
} }
public static void processValidResponse(Map<String, Object> responseMap, VatCheckResponseBean vatCheckResponseBean) { public static void processValidResponse(Map<String, Object> responseMap, VatCheckResponseBean vatCheckResponseBean) {
if (responseMap != null && responseMap.containsKey("data")) {
Map<String, Object> responseBody = (Map<String, Object>) responseMap.get("data");
if (responseBody != null) { if (responseMap != null && responseMap.containsKey("data")) {
responseBody.remove("timestamp_creation"); Object dataObject = responseMap.get("data");
responseBody.remove("timestamp_last_update");
responseBody.remove("data_iscrizione"); if (dataObject instanceof List && !((List<?>) dataObject).isEmpty()) {
dataObject = ((List<?>) dataObject).get(0);
}
if (dataObject instanceof Map) {
Map<String, Object> responseBody = (Map<String, Object>) dataObject;
responseBody.remove("creationTimestamp");
responseBody.remove("lastUpdateTimestamp");
responseBody.remove("id"); responseBody.remove("id");
Map<String, Object> data = new LinkedHashMap<>(); Map<String, Object> data = new LinkedHashMap<>();
@@ -108,17 +201,4 @@ public class VatCheckDao {
vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER)); vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
} }
} }
public VatCheckResponseBean checkVatNumber(String vatNumber) {
try {
return checkVatNumberApi(vatNumber);
} catch (Exception e) {
log.error("Error in checkVatNumber: {}", e.getMessage());
VatCheckResponseBean vatCheckResponseBean = new VatCheckResponseBean();
vatCheckResponseBean.setValid(false);
vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
return vatCheckResponseBean;
}
}
} }

View File

@@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RequestHeader;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
@FeignClient(value = "vat-check-service", url = GepafinConstant.CHECK_VATNUMBER_V2_NEW_URL) @FeignClient(value = "vat-check-service", url = GepafinConstant.CHECK_VATNUMBER_V2_NEW_URL_IT_ADVANCE)
public interface VatCheckService { public interface VatCheckService {

View File

@@ -886,4 +886,22 @@ public class Utils {
} }
/**
* Extracts a Map from a parent Map safely.
*/
public static Map<String, Object> extractMap(Map<String, Object> parentMap, String key) {
Object obj = parentMap.get(key);
if (obj instanceof Map<?, ?> map) {
return (Map<String, Object>) map;
}
return null;
}
/**
* Extracts a String from a Map safely.
*/
public static String extractString(Map<String, Object> parentMap, String key) {
Object obj = parentMap.get(key);
return (obj instanceof String str) ? str : null;
}
} }

View File

@@ -47,7 +47,7 @@ fe.base.url=https://bandi-staging.memento.credit
spring.main.allow-circular-references=true spring.main.allow-circular-references=true
isVatCheckGloballyDisabled = true isVatCheckGloballyDisabled = true
vatCheckNewToken: 66026bd891a51044e90e08c4 vatCheckNewToken: 671916c76c6e822f660774d4
#SPID configuration #SPID configuration
spid.ipd.base.url=https://federatest.umbriadigitale.it spid.ipd.base.url=https://federatest.umbriadigitale.it