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

@@ -549,6 +549,28 @@ public class GepafinConstant {
public static final String CAUSE_STRING = "cause" ;
public static final String ERROR_DESCRIPTION_STRING = "errorDescription" ;
public static final String ERROR_STRING = "errors";
public static final String PROTOCOL_SERVICE_URL="http://65.108.55.96:8080";
public static final String PROTOCOL_SERVICE_BEARER_TOKEN="/auth/login";
public static final String PROTOCOL_SERVICE_CREATE_PROTOCOL="/documenti/protocollaUD";
public static final String PROTOCOL_CALL_NAME="BANDO";
public static final String PROTOCOL_DOC_URL="DOC_URL";
public static final String PROTOCOL_COMPANY_NAME_VAT_NUMBER="OGGETTO_PG";
public static final String PROTOCOL_DOC_HASH="URL_CONTENT_HASH";
public static final String PROTOCOL_TIPO_PROTOCOLLAZIONE="TIPO_PROTOCOLLAZIONE";
public static final String PROTOCOL_TIPO_CORRISPONDENTE_COMPANY="tipoCorrispondente";
public static final String PROTOCOL_COMPANY_NAME="denominazione";
public static final String PROTOCOL_MEZZO="mezzo";
public static final String PROTOCOL_INDIRIZZO_PEC="indirizzoPec";
public static final String PROTOCOL_COMPANY_VAT_NUMBER="identificativo";
public static final String PROTOCOL_CODICE_UO="codiceUo";
public static final String PROTOCOL_COMPETENTE="competente";
public static final String PROTOCOL_TIPO_CORRISPONDENTE="tipoCorrispondente";
public static final String PROTOCOL_MITTENTE="mittente";
public static final String PROTOCOL_DESTINATARI="destinatari";
public static final String PROTOCOL_EXTERNAL_YEAR="ANNO_PG";
public static final String PROTOCOL_EXTERNAL_NUMBER="";
public static final String PROTOCOL_EXTERNAL_DATE="";
}

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;
}
}

View File

@@ -25,4 +25,6 @@ public class ApplicationSignedDocumentEntity extends BaseEntity {
@Column(name="STATUS")
private String status;
@Column(name="FILE_HASH")
private String fileHash;
}

View File

@@ -51,9 +51,6 @@ public class CompanyEntity extends BaseEntity{
@JoinColumn(name = "HUB_ID")
private HubEntity hub;
// @Column(name = "JSON")
// private String json;
@Column(name = "NDG")
private String ndg;
@@ -62,4 +59,7 @@ public class CompanyEntity extends BaseEntity{
@Column(name = "JSON")
private String json;
@Column(name = "PEC")
private String pec;
}

View File

@@ -4,6 +4,7 @@ import jakarta.persistence.*;
import lombok.Data;
import net.gepafin.tendermanagement.config.LocalTimeAttributeConverter;
import java.time.LocalDateTime;
import java.time.LocalTime;
@Entity
@@ -33,4 +34,14 @@ public class ProtocolEntity extends BaseEntity {
@Column(name = "type")
private String type;
@Column(name = "external_protocol_year")
private Integer externalProtocolYear;
@Column(name = "external_protocol_date")
private LocalDateTime externalProtocolDate;
@Column(name = "external_protocol_number")
private String externalProtocolNumber;
}

View File

@@ -11,4 +11,5 @@ public class ApplicationSignedDocumentResponse extends BaseBean{
private String fileName;
private String filePath;
private ApplicationSignedDocumentStatusEnum status;
private String fileHash;
}

View File

@@ -0,0 +1,32 @@
package net.gepafin.tendermanagement.service.feignClient;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import java.net.URI;
import java.util.List;
import java.util.Map;
@FeignClient(value = "protocol-service" ,url = GepafinConstant.PROTOCOL_SERVICE_URL)
public interface ProtocolService {
@PostMapping(GepafinConstant.PROTOCOL_SERVICE_BEARER_TOKEN)
ResponseEntity<String> getBearerToken(@RequestHeader HttpHeaders headers,@RequestParam("codAoo") String codAoo,@RequestParam("username") String username,@RequestParam("password") String password
);
@PutMapping(GepafinConstant.PROTOCOL_SERVICE_CREATE_PROTOCOL)
ResponseEntity<Object> createProtocol(@RequestHeader HttpHeaders headers, @RequestParam("CLASSIFICA") String classifica, @RequestParam("ANNO_FASCICOLO") String year, @RequestParam("PROGR_FASCICOLO") String applicationId,
@RequestParam("DES_FASCICOLO") String companyName, @RequestParam("PARENT_PROGR_FASCICOLO") String callName, @RequestParam("PARENT_DES_FASCICOLO") String callId, @RequestBody List<Map<String,Object>> requestBody
);
}

View File

@@ -98,11 +98,19 @@ public class DateTimeUtil {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
return LocalDateTime.parse(dateTimeStr, formatter);
}
public static LocalDateTime parseStringToLocalDateTime(String timestampStr) {
// Use ISO_LOCAL_DATE_TIME to parse the input string
return LocalDateTime.parse(timestampStr, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
public static LocalDateTime parseStringToLocalDateTime(String dateStr) {
if (dateStr == null || dateStr.isEmpty()) return null;
try {
return LocalDateTime.parse(dateStr, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
} catch (Exception e) {
try {
return LocalDateTime.parse(dateStr, DateTimeFormatter.ISO_DATE_TIME); // fallback
} catch (Exception ignored) {
}
}
return null;
}
public static String parseLocalTimeToString(LocalTime time, String format) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
return time.format(formatter);

View File

@@ -0,0 +1,40 @@
package net.gepafin.tendermanagement.util;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.io.InputStream;
import java.security.DigestInputStream;
import java.security.MessageDigest;
@Component
public class FileHashUtil {
public static String calculateSHA256(InputStream inputStream) throws IOException {
try {
MessageDigest md = MessageDigest.getInstance("SHA-256");
try (DigestInputStream dis = new DigestInputStream(inputStream, md)) {
byte[] buffer = new byte[8192];
while (dis.read(buffer) != -1) {
// reading to compute hash
}
}
byte[] digest = md.digest();
return bytesToHex(digest);
} catch (Exception e) {
throw new RuntimeException("Could not generate hash", e);
}
}
private static String bytesToHex(byte[] bytes) {
StringBuilder hexString = new StringBuilder();
for (byte b : bytes) {
String hex = Integer.toHexString(0xff & b);
if (hex.length() == 1) hexString.append('0');
hexString.append(hex);
}
return hexString.toString();
}
}

View File

@@ -48,6 +48,7 @@ import net.objecthunter.exp4j.ExpressionBuilder;
import org.apache.commons.collections4.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -60,6 +61,7 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import feign.FeignException;
import io.micrometer.common.util.StringUtils;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
@@ -1043,5 +1045,12 @@ public class Utils {
return new ArrayList<>(responseMap.values());
}
public static HttpHeaders getHeaders(){
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add(org.apache.http.HttpHeaders.USER_AGENT, "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0");
return headers;
}
}