Done ticket GEPAFINBE-219

This commit is contained in:
rajesh
2025-05-26 17:17:41 +05:30
parent dbf7a8d564
commit 1123faa710
15 changed files with 467 additions and 23 deletions

View File

@@ -369,6 +369,7 @@ public class ApplicationAmendmentRequestDao {
ProtocolEntity protocolEntity = protocolDao.createProtocolEntity(
applicationEvaluationEntity.getAssignedApplicationsEntity().getApplication(), protocolNumber,
userEntity.getHub().getId(),false);
protocolDao.saveProtocolEntity(protocolEntity);
applicationAmendmentRequestEntity.setProtocol(protocolEntity);
ApplicationAmendmentRequestEntity applicationAmendment = saveApplicationAmendmentRequestEntity(applicationAmendmentRequestEntity, null, VersionActionTypeEnum.INSERT);
String evaluationStatusType = applicationEvaluationEntity.getStatus();

View File

@@ -136,6 +136,9 @@ public class ApplicationDao {
@Value("${call.id}")
private String callId;
@Value("${sviluppumbriaUuid}")
private String sviluppumbriaUuid;
@Autowired
private AmazonS3Service amazonS3Service;
@@ -943,7 +946,7 @@ public class ApplicationDao {
log.info("Call end date verified successfully | callId: {}", applicationEntity.getCall().getId());
//cloned entity for old application data
ApplicationEntity oldApplicationEntity = Utils.getClonedEntityForData(applicationEntity);
HubEntity hub=hubService.valdateHub(applicationEntity.getHubId());
UserEntity userEntity = userService.validateUser(applicationEntity.getUserId());
validator.validateUserWithCompany(request, applicationEntity.getCompanyId());
if (ApplicationStatusTypeEnum.SUBMIT.getValue().equals(applicationEntity.getStatus())) {
@@ -954,10 +957,15 @@ public class ApplicationDao {
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_IN_PREVIOUS_STATUS));
}
if (status.equals(ApplicationStatusTypeEnum.SUBMIT) && Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.READY.getValue()))) {
// callService.validatePublishedCall(applicationEntity.getCall().getId(), userEntity.getHub().getId());
CompanyEntity company=companyService.validateCompany(applicationEntity.getCompanyId());
Long protocolNumber = protocolDao.getProtocolNumber(userEntity.getHub());
ProtocolEntity protocolEntity = protocolDao.createProtocolEntity(applicationEntity, protocolNumber, userEntity.getHub().getId(),true);
protocolDao.saveProtocolEntity(protocolEntity);
applicationEntity.setProtocol(protocolEntity);
if(Boolean.TRUE.equals(hub.getUniqueUuid().equals(sviluppumbriaUuid))) {
protocolEntity = protocolDao.createExternalProtocol(applicationEntity, company, protocolEntity);
}
applicationEntity.setStatus(ApplicationStatusTypeEnum.SUBMIT.getValue());
applicationEntity.setSubmissionDate(protocolEntity.getCreatedDate());
applicationEntity = applicationRepository.save(applicationEntity);
@@ -968,7 +976,7 @@ public class ApplicationDao {
loggingUtil.addVersionHistory(
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationEntity).newData(applicationEntity).build());
sendMailToUserAndCompany(userEntity, applicationEntity);
sendMailToUserAndCompany(userEntity, applicationEntity,company);
sendMailTodefaultSystemAndGepafin(userEntity, applicationEntity);
applicationEntity.setStatus(status.getValue());
log.info("Status updated to SUBMIT for applicationId: " + applicationId);
@@ -1079,9 +1087,8 @@ public class ApplicationDao {
}
}
private void sendMailToUserAndCompany(UserEntity userEntity, ApplicationEntity applicationEntity) {
private void sendMailToUserAndCompany(UserEntity userEntity, ApplicationEntity applicationEntity,CompanyEntity company) {
CallEntity call =applicationEntity.getCall();
CompanyEntity company=companyService.validateCompany(applicationEntity.getCompanyId());
UserWithCompanyEntity userWithCompany=companyService.getUserWithCompany(userEntity.getId(),company.getId());
ProtocolEntity protocol= applicationEntity.getProtocol();
HubEntity hub = hubService.valdateHub(applicationEntity.getHubId());
@@ -1184,12 +1191,19 @@ public class ApplicationDao {
if (applicationSignedDocument != null) {
deleteSignedDocumentFromS3(applicationSignedDocument);
}
String hash ="";
try {
hash = FileHashUtil.calculateSHA256(file.getInputStream());
} catch (IOException e) {
throw new RuntimeException(e);
}
UploadFileOnAmazonS3Response uploadFileOnAmazonS3 = uploadFileOnAmazonS3ForUserSignedDocument(file, applicationEntity.getCall().getId(), applicationId);
applicationSignedDocument = new ApplicationSignedDocumentEntity();
applicationSignedDocument.setApplication(applicationEntity);
applicationSignedDocument.setFileName(uploadFileOnAmazonS3.getFileName());
applicationSignedDocument.setFilePath(uploadFileOnAmazonS3.getFilePath());
applicationSignedDocument.setStatus(ApplicationSignedDocumentStatusEnum.ACTIVE.getValue());
applicationSignedDocument.setFileHash(hash);
applicationSignedDocument = applicationSignedDocumentRepository.save(applicationSignedDocument);
/** This code is responsible for adding a version history log for the "assign application document" operation. **/
@@ -1255,6 +1269,7 @@ public class ApplicationDao {
.setStatus(ApplicationSignedDocumentStatusEnum.valueOf(applicationSignedDocument.getStatus()));
applicationSignedDocumentResponse.setCreatedDate(applicationSignedDocument.getCreatedDate());
applicationSignedDocumentResponse.setUpdatedDate(applicationSignedDocument.getUpdatedDate());
applicationSignedDocumentResponse.setFileHash(applicationSignedDocument.getFileHash());
return applicationSignedDocumentResponse;
}

View File

@@ -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());
}
}
}
}
}

View File

@@ -1,20 +1,36 @@
package net.gepafin.tendermanagement.dao;
import java.net.URI;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import feign.FeignException;
import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.*;
import net.gepafin.tendermanagement.enums.ApplicationSignedDocumentStatusEnum;
import net.gepafin.tendermanagement.enums.ProtocolTypeEnum;
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
import net.gepafin.tendermanagement.repositories.ApplicationSignedDocumentRepository;
import net.gepafin.tendermanagement.service.feignClient.ProtocolService;
import net.gepafin.tendermanagement.util.LoggingUtil;
import net.gepafin.tendermanagement.util.Utils;
import org.apache.commons.lang3.StringUtils;
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.ResponseEntity;
import org.springframework.stereotype.Component;
import net.gepafin.tendermanagement.entities.ApplicationEntity;
import net.gepafin.tendermanagement.entities.HubEntity;
import net.gepafin.tendermanagement.entities.ProtocolEntity;
import net.gepafin.tendermanagement.repositories.ProtocolRepository;
import net.gepafin.tendermanagement.util.DateTimeUtil;
@@ -33,6 +49,50 @@ public class ProtocolDao {
@Autowired
private HttpServletRequest request;
@Autowired
private ProtocolService protocolService;
@Value("${codAoo}")
private String codAoo;
@Value("${sviluppumbria.username}")
private String username;
@Value("${password}")
private String password;
@Value("${CLASSIFICA}")
private String classifica;
@Value("${TIPO_PROTOCOLLAZIONE}")
private String TIPO_PROTOCOLLAZIONE;
@Value("${tipoCorrispondenteCompany}")
private String tipoCorrispondenteCompany;
@Value("${tipoCorrispondenteWithoutCompany}")
private String tipoCorrispondenteWithoutCompany;
@Value("${mezzo}")
private String mezzo;
@Value("${indirizzoPec}")
private String indirizzoPec;
@Value("${codiceUo}")
private String codiceUo;
@Value("${competente}")
private Boolean competente;
@Value("${tipoCorrispondente}")
private String tipoCorrispondente;
@Autowired
private ApplicationSignedDocumentRepository applicationSignedDocumentRepository;
public final Logger log = LoggerFactory.getLogger(ProtocolDao.class);
public Long getProtocolNumber(HubEntity hubEntity) {
Long maxProtocolNumber = protocolRepository.findMaxProtocolNumberAndHubId(hubEntity.getId());
@@ -58,11 +118,160 @@ public class ProtocolDao {
}else {
protocolEntity.setType(ProtocolTypeEnum.OUTPUT.getValue());
}
return protocolEntity;
}
public void saveProtocolEntity(ProtocolEntity protocolEntity) {
protocolRepository.save(protocolEntity);
/** This code is responsible for adding a version history log for "create protocol" operation. **/
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null).newData(protocolEntity).build());
return protocolEntity;
}
public String getBearerToken(String codAoo, String username, String password) {
log.info("Requesting bearer token for user: {} and codAoo: {}", username, codAoo);
HttpHeaders httpHeaders = Utils.getHeaders();
URI url = URI.create(GepafinConstant.PROTOCOL_SERVICE_BEARER_TOKEN);
try {
ResponseEntity<String> response = protocolService.getBearerToken(httpHeaders, codAoo,username,password);
if (response != null && response.getStatusCode().is2xxSuccessful()) {
log.debug("Bearer token successfully retrieved. HTTP Status: {}", response.getStatusCode());
return response.getBody().toString(); // Use getBody() instead of toString()
} else {
log.warn("Bearer token request failed or returned unexpected status. Response: {}", response);
}
} catch (FeignException ex) {
log.error("FeignException while retrieving bearer token for user {}: {}", username, ex.getMessage(), ex);
Utils.callException(ex.status(), ex);
} catch (Exception ex) {
log.error("Unexpected exception while retrieving bearer token: {}", ex.getMessage(), ex);
}
log.warn("Returning null bearer token for user: {}", username);
return null;
}
public ProtocolEntity createExternalProtocol(ApplicationEntity application, CompanyEntity company, ProtocolEntity protocol) {
log.info("Starting createExternalProtocol for application ID: {}", application.getId());
log.debug("Successfully retrieved bearer token");
ApplicationSignedDocumentEntity applicationSignedDocumentEntity=applicationSignedDocumentRepository.findByApplicationIdAndStatus(application.getId(), ApplicationSignedDocumentStatusEnum.ACTIVE.getValue());
String year = String.valueOf(LocalDateTime.now().getYear());
String applicationId = String.valueOf(application.getId());
String mittenteValue="";
String vatNumber ="";
if(company!=null) {
mittenteValue= tipoCorrispondenteCompany;
vatNumber=company.getVatNumber();
}else {
mittenteValue = tipoCorrispondenteWithoutCompany;
vatNumber = company.getCodiceFiscale();
}
mittenteValue=tipoCorrispondenteWithoutCompany;
String companyName = company.getCompanyName() + " " + vatNumber;
String callName = application.getCall().getName();
String callId = GepafinConstant.PROTOCOL_CALL_NAME+ String.valueOf(application.getCall().getId());
String pecEmail=company.getPec();
String docUrl=applicationSignedDocumentEntity.getFilePath();
Map<String, Object> requestBody = new HashMap<>();
requestBody.put(GepafinConstant.PROTOCOL_DOC_URL,docUrl);
requestBody.put(GepafinConstant.PROTOCOL_COMPANY_NAME,companyName);
requestBody.put(GepafinConstant.PROTOCOL_DOC_HASH,applicationSignedDocumentEntity.getFileHash());
requestBody.put(GepafinConstant.PROTOCOL_TIPO_PROTOCOLLAZIONE,TIPO_PROTOCOLLAZIONE);
Map<String, Object> mittente = new HashMap<>();
mittente.put(GepafinConstant.PROTOCOL_TIPO_CORRISPONDENTE_COMPANY, mittenteValue);
mittente.put(GepafinConstant.PROTOCOL_COMPANY_NAME_VAT_NUMBER,company.getCompanyName());
mittente.put(GepafinConstant.PROTOCOL_MEZZO,mezzo);
mittente.put(GepafinConstant.PROTOCOL_INDIRIZZO_PEC,pecEmail);
mittente.put(GepafinConstant.PROTOCOL_COMPANY_VAT_NUMBER,vatNumber);
List<Map<String,Object>> destinatariObject=new ArrayList<>();
Map<String, Object> destinatari = new HashMap<>();
destinatari.put(GepafinConstant.PROTOCOL_CODICE_UO,codiceUo);
destinatari.put(GepafinConstant.PROTOCOL_COMPETENTE,competente);
destinatari.put(GepafinConstant.PROTOCOL_TIPO_CORRISPONDENTE,tipoCorrispondente);
requestBody.put(GepafinConstant.PROTOCOL_MITTENTE,mittente);
destinatariObject.add(destinatari);
requestBody.put(GepafinConstant.PROTOCOL_DESTINATARI,destinatariObject);
List<Map<String,Object>> listObject=new ArrayList<>();
listObject.add(requestBody);
log.info("Preparing to create protocol with data: year={}, applicationId={}, companyName={}, callName={}, callId={}",
year, applicationId, companyName, callName, callId);
ResponseEntity<Object> response=null;
try {
String bearerToken = getBearerToken(codAoo, username, password);
if (bearerToken == null) {
log.error("Bearer token retrieval failed for user: {}", username);
return protocol;
}
HttpHeaders httpHeaders = Utils.getHeaders();
httpHeaders.set(GepafinConstant.AUTHORIZATION, "Bearer " + bearerToken);
URI url = URI.create(GepafinConstant.PROTOCOL_SERVICE_CREATE_PROTOCOL);
response = protocolService.createProtocol(httpHeaders, classifica, year, applicationId, companyName, callName, callId,listObject
);
log.info("Protocol creation response: status={}, body={}", response.getStatusCode(), response.getBody());
} catch (FeignException ex) {
log.error("FeignException during protocol creation for application ID {}: {}", applicationId, ex.getMessage(), ex);
// Utils.callException(ex.status(), ex);
} catch (Exception ex) {
log.error("Unexpected exception during protocol creation for application ID {}: {}", applicationId, ex.getMessage(), ex);
}
log.info("Finished createExternalProtocol for application ID: {}", application.getId());
if(response!=null && response.getBody()!=null) {
protocol = extractDetailForProtocol((List<Map<String, Object>>) response.getBody(), protocol);
}
return protocol;
}
public ProtocolEntity extractDetailForProtocol(List<Map<String,Object>> responseObject, ProtocolEntity protocol) {
Map<String,Object> responseField= responseObject.get(0);
Object yearObj = responseField.get(GepafinConstant.PROTOCOL_EXTERNAL_YEAR);
Integer externalProtocolYear = null;
if (yearObj instanceof Integer) {
externalProtocolYear = (Integer) yearObj;
} else if (yearObj instanceof String) {
try {
externalProtocolYear = Integer.parseInt((String) yearObj);
} catch (NumberFormatException e) {
// handle invalid format gracefully
externalProtocolYear = null;
}
}
Object dateObj = responseField.get(GepafinConstant.PROTOCOL_EXTERNAL_DATE);
LocalDateTime externalProtocolDate = null;
if (dateObj instanceof LocalDateTime) {
externalProtocolDate = (LocalDateTime) dateObj;
} else if (dateObj instanceof String) {
externalProtocolDate = DateTimeUtil.parseStringToLocalDateTime((String) dateObj);
}
if(externalProtocolDate!=null){
protocol.setExternalProtocolDate(externalProtocolDate);
}
if (externalProtocolYear!=null){
protocol.setExternalProtocolYear(externalProtocolYear);
}
String externalProtocolNumber = (String) responseField.get(GepafinConstant.PROTOCOL_EXTERNAL_NUMBER);
if (Boolean.FALSE.equals(StringUtils.isEmpty(externalProtocolNumber))) {
protocol.setExternalProtocolNumber(externalProtocolNumber);
}
protocolRepository.save(protocol);
return protocol;
}
}