Done ticket GEPAFINBE-223 & GEPAFINBE-224

This commit is contained in:
rajesh
2025-06-18 20:23:12 +05:30
parent ab549a0d80
commit 6d66037adb
20 changed files with 344 additions and 47 deletions

View File

@@ -2,6 +2,7 @@ package net.gepafin.tendermanagement.dao;
import org.springframework.data.domain.Pageable; // Correct package
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -413,7 +414,7 @@ public class CompanyDao {
Translator.toLocale(GepafinConstant.INVALID_LIMIT));
}
int successfulUpdates = 0;
int successfulUpdates = 0;
int failedUpdates = 0;
int invalidVatNumbers = 0;
@@ -531,7 +532,11 @@ public class CompanyDao {
Map<String, Object> dataMap = Utils.extractMap(companyDataMap, "data");
Object dataObj = companyDataMap.get("data");
if (dataMap == null) {
if (dataObj instanceof Map<?, ?> singleMap) {
dataMap = (Map<String, Object>) singleMap;
} else if (dataObj instanceof List<?> list && !list.isEmpty() && list.get(0) instanceof Map<?, ?> firstMap) {
dataMap = (Map<String, Object>) firstMap;
} else {
log.warn("Company ID {}: 'data' section is missing or invalid in the JSON.", company.getId());
return;
}
@@ -540,11 +545,11 @@ public class CompanyDao {
updateCodiceAtecoField(company);
} else {
Object pecEmail = Utils.extractMap(dataMap, "pec");
Object pecEmail = dataMap.get("pec");
if (pecEmail == null) {
log.warn("Company ID {}: 'pec' section is missing or invalid.", company.getId());
company.setPec((String) pecEmail);
}
company.setPec((String) pecEmail);
// Extract 'atecoClassification' section
Map<String, Object> atecoClassificationMap = Utils.extractMap(dataMap, "atecoClassification");
@@ -577,49 +582,79 @@ public class CompanyDao {
}
public void getCompanyEntity() {
List<CompanyEntity> companyEntities=companyRepository.findAll();
List<CompanyEntity> companyEntities=companyRepository.findByJsonIsNotNullAndPecIsNull();
List<CompanyEntity> companyEntityList=new ArrayList<>();
for (CompanyEntity company:companyEntities){
if(company.getJson()!=null){
if(company.getJson()!=null && company.getPec()==null){
if (company == null || company.getJson() == null || company.getJson().isEmpty()) {
log.warn("Company is null or JSON data is empty.");
return;
continue;
}
Map<String, Object> vatCheckResponse = Utils.convertJsonStringToMap(company.getJson());
if (vatCheckResponse == null) {
log.warn("Company ID {}: Invalid JSON response.", company.getId());
return;
continue;
}
Map<String, Object> companyDataMap = Utils.convertJsonStringToMap(company.getJson());
if (companyDataMap == null) {
log.warn("Company ID {}: Failed to parse JSON data.", company.getId());
return;
continue;
}
Object dataObj = vatCheckResponse.get("data");
if (!(dataObj instanceof Map<?, ?> dataMap)) {
log.warn("Company ID {}: 'data' is missing or not a valid object.", company.getId());
return;
Map<String, Object> dataMap=null;
// if (!(dataObj instanceof Map<?, ?> dataMap)) {
// log.warn("Company ID {}: 'data' is missing or not a valid object.", company.getId());
// continue;
// }
if (dataObj instanceof Map<?, ?> singleMap) {
dataMap = (Map<String, Object>) singleMap;
} else if (dataObj instanceof List<?> list && !list.isEmpty() && list.get(0) instanceof Map<?, ?> firstMap) {
dataMap = (Map<String, Object>) firstMap;
} else {
log.warn("Company ID {}: 'data' section is missing or invalid in the JSON.", company.getId());
continue;
}
if (dataMap.containsKey("pec")) {
Object pecEmailObj = dataMap.get("pec");
if (pecEmailObj instanceof String pec && !pec.isEmpty()) {
company.setPec(pec); // Only set if valid string
companyEntityList.add(company);
} else {
log.warn("Company ID {}: 'pec' is missing, empty, or not a string.", company.getId());
continue;
}
}
if (!dataMap.containsKey("dettaglio")) {
log.warn("Company ID {}: 'dettaglio' not present inside 'data'. Skipping codiceAteco update.", company.getId());
return;
continue;
}
Object dettaglioObj = dataMap.get("dettaglio");
if (!(dettaglioObj instanceof Map<?, ?> dettaglio)) {
log.warn("Company ID {}: 'dettaglio' is not a valid object.", company.getId());
return;
continue;
}
Object pecEmailObj = dettaglio.get("pec");
if (pecEmailObj instanceof String pec && !pec.isEmpty()) {
company.setPec(pec); // Only set if valid string
if(pec!=null) {
company.setPec(pec); // Only set if valid string
companyEntityList.add(company);
}
} else {
log.warn("Company ID {}: 'pec' is missing, empty, or not a string.", company.getId());
continue;
}
}
}
companyRepository.saveAll(companyEntityList);
}
}