Done ticket GEPAFINBE-219
This commit is contained in:
@@ -52,13 +52,13 @@ public class CompanyDao {
|
||||
private ApplicationRepository applicationRepository;
|
||||
@Autowired
|
||||
private FaqRepository faqRepository;
|
||||
|
||||
|
||||
@Autowired
|
||||
private BeneficiaryPreferredCallRepository beneficiaryPreferredCallRepository;
|
||||
|
||||
@Autowired
|
||||
private UserCompanyDelegationRepository userCompanyDelegationRepository;
|
||||
|
||||
|
||||
@Autowired
|
||||
private CompanyService companyService;
|
||||
|
||||
@@ -103,7 +103,7 @@ public class CompanyDao {
|
||||
|
||||
|
||||
private void validateCompany(UserEntity userEntity, CompanyRequest companyRequest) {
|
||||
|
||||
|
||||
if (Boolean.FALSE.equals(StringUtils.isEmpty(companyRequest.getEmail()))
|
||||
&& Boolean.FALSE.equals(Utils.isValidEmail(companyRequest.getEmail()))) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
@@ -169,7 +169,7 @@ public class CompanyDao {
|
||||
entity.setHub(userEntity.getHub());
|
||||
entity.setJson(Utils.convertMapIntoJsonString(request.getVatCheckResponse()));
|
||||
updateCodiceAtecoFieldWithNewJson(entity);
|
||||
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
@@ -483,12 +483,19 @@ public class CompanyDao {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Object pecEmailObj = dettaglio.get("pec");
|
||||
if (pecEmailObj instanceof String pec && !pec.isEmpty()) {
|
||||
company.setPec(pec); // Only set if valid string
|
||||
} else {
|
||||
log.warn("Company ID {}: 'pec' is missing, empty, or not a string.", company.getId());
|
||||
}
|
||||
|
||||
Object codiceAtecoObj = dettaglio.get("codice_ateco");
|
||||
if (!(codiceAtecoObj instanceof String codiceAteco) || codiceAteco.isEmpty()) {
|
||||
log.warn("Company ID {}: 'codice_ateco' is missing, empty, or not a string.", company.getId());
|
||||
return;
|
||||
}
|
||||
|
||||
company.setCodiceAteco(codiceAteco);
|
||||
logCodiceAtecoUpdate(company, codiceAteco);
|
||||
}
|
||||
@@ -517,6 +524,13 @@ public class CompanyDao {
|
||||
// if data is a single object
|
||||
updateCodiceAtecoField(company);
|
||||
} else {
|
||||
|
||||
Object pecEmail = Utils.extractMap(dataMap, "pec");
|
||||
if (pecEmail == null) {
|
||||
log.warn("Company ID {}: 'pec' section is missing or invalid.", company.getId());
|
||||
company.setPec((String) pecEmail);
|
||||
}
|
||||
|
||||
// Extract 'atecoClassification' section
|
||||
Map<String, Object> atecoClassificationMap = Utils.extractMap(dataMap, "atecoClassification");
|
||||
if (atecoClassificationMap == null) {
|
||||
@@ -546,4 +560,51 @@ public class CompanyDao {
|
||||
|
||||
log.info("Company ID {}: codiceAteco updated to {}", company.getId(), atecoCode);
|
||||
}
|
||||
|
||||
public void getCompanyEntity() {
|
||||
List<CompanyEntity> companyEntities=companyRepository.findAll();
|
||||
for (CompanyEntity company:companyEntities){
|
||||
if(company.getJson()!=null){
|
||||
if (company == null || company.getJson() == null || company.getJson().isEmpty()) {
|
||||
log.warn("Company is null or JSON data is empty.");
|
||||
return;
|
||||
}
|
||||
Map<String, Object> vatCheckResponse = Utils.convertJsonStringToMap(company.getJson());
|
||||
|
||||
if (vatCheckResponse == null) {
|
||||
log.warn("Company ID {}: Invalid JSON response.", company.getId());
|
||||
return;
|
||||
}
|
||||
Map<String, Object> companyDataMap = Utils.convertJsonStringToMap(company.getJson());
|
||||
if (companyDataMap == null) {
|
||||
log.warn("Company ID {}: Failed to parse JSON data.", company.getId());
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (!dataMap.containsKey("dettaglio")) {
|
||||
log.warn("Company ID {}: 'dettaglio' not present inside 'data'. Skipping codiceAteco update.", company.getId());
|
||||
return;
|
||||
}
|
||||
|
||||
Object dettaglioObj = dataMap.get("dettaglio");
|
||||
if (!(dettaglioObj instanceof Map<?, ?> dettaglio)) {
|
||||
log.warn("Company ID {}: 'dettaglio' is not a valid object.", company.getId());
|
||||
return;
|
||||
}
|
||||
|
||||
Object pecEmailObj = dettaglio.get("pec");
|
||||
if (pecEmailObj instanceof String pec && !pec.isEmpty()) {
|
||||
company.setPec(pec); // Only set if valid string
|
||||
} else {
|
||||
log.warn("Company ID {}: 'pec' is missing, empty, or not a string.", company.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user