diff --git a/src/main/java/net/gepafin/tendermanagement/config/MessageSourceConfig.java b/src/main/java/net/gepafin/tendermanagement/config/MessageSourceConfig.java
index 79ef4d11..1159a0aa 100644
--- a/src/main/java/net/gepafin/tendermanagement/config/MessageSourceConfig.java
+++ b/src/main/java/net/gepafin/tendermanagement/config/MessageSourceConfig.java
@@ -14,7 +14,7 @@ public class MessageSourceConfig {
public ResourceBundleMessageSource messageSource() {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasenames("message");
- messageSource.setDefaultEncoding("UTF-8");
+ messageSource.setDefaultEncoding("ISO-8859-1");
messageSource.setUseCodeAsDefaultMessage(true);
return messageSource;
}
diff --git a/src/main/java/net/gepafin/tendermanagement/config/WebSocketConfig.java b/src/main/java/net/gepafin/tendermanagement/config/WebSocketConfig.java
index 0212f720..1b9a9e36 100644
--- a/src/main/java/net/gepafin/tendermanagement/config/WebSocketConfig.java
+++ b/src/main/java/net/gepafin/tendermanagement/config/WebSocketConfig.java
@@ -23,10 +23,22 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Value("${spring.rabbitmq.password}")
private String clientPassword;
+ @Value("${rabbitmq.enabled:false}")
+ private boolean rabbitmqEnabled;
+
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
-
- config.enableStompBrokerRelay("/topic").setRelayHost(relayHost).setRelayPort(relayPort).setClientLogin(clientUserName).setClientPasscode(clientPassword);
+ if (rabbitmqEnabled) {
+ // Use external RabbitMQ broker
+ config.enableStompBrokerRelay("/topic")
+ .setRelayHost(relayHost)
+ .setRelayPort(relayPort)
+ .setClientLogin(clientUserName)
+ .setClientPasscode(clientPassword);
+ } else {
+ // Use in-memory simple broker
+ config.enableSimpleBroker("/topic");
+ }
config.setApplicationDestinationPrefixes("/app");
}
diff --git a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java
index d312f062..46a8eb23 100644
--- a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java
+++ b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java
@@ -199,6 +199,7 @@ public class GepafinConstant {
public static final String VALIDATION_ERROR_FILE_EMPTY = "validation.error.file.empty";
public static final String VALIDATION_ERROR_FILE_INVALIDTYPE = "validation.error.file.invalidType";
public static final String UPLOAD_ERROR_S3 = "upload.error.s3";
+ public static final String VAT_OR_TAX_CODE_REQUIRED = "vat.or.tax.code.required";
public static final String CALL_NOT_STARTED_YET = "call.not.started.yet";
public static final String CALL_ALREADY_ENDED = "call.already.ended";
@@ -638,7 +639,7 @@ public class GepafinConstant {
public static final String UPLOAD_COMPANY_DOCUMENT_TO_APPLICATION_MSG="upload.company.document.to.application";
public static final String COMPANY_DOCUMENT_NOT_FOUND_WITH_IDS="company.document.not.found.with.ids";
public static final String REQUIRED_AMOUNT_FIELD_NOT_PROVIDED = "amount.field.not.provided";
-
+ public static final String PLEASE_PROVIDE_VALID_VAT_NUMBER="provide.valid.vat.number";
}
diff --git a/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java b/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java
index 069d823d..0e25e8d4 100644
--- a/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java
+++ b/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java
@@ -163,6 +163,9 @@ public class AppointmentDao {
NdgResponse ndgResponse = new NdgResponse();
CompanyEntity company = companyService.validateCompany(application.getCompanyId());
+ if(Boolean.FALSE.equals(company.getValidVat())){
+ throw new CustomValidationException(Status.VALIDATION_ERROR,Translator.toLocale(GepafinConstant.PLEASE_PROVIDE_VALID_VAT_NUMBER));
+ }
NdganagEntity ndganagEntity = ndganagRepository.findByVatNumber(company.getVatNumber());
if (ndganagEntity != null && ndganagEntity.getNdg() != null) {
ndgResponse.setNdg(ndganagEntity.getNdg());
diff --git a/src/main/java/net/gepafin/tendermanagement/dao/CompanyDao.java b/src/main/java/net/gepafin/tendermanagement/dao/CompanyDao.java
index 8b59eebe..8c6a8b1b 100644
--- a/src/main/java/net/gepafin/tendermanagement/dao/CompanyDao.java
+++ b/src/main/java/net/gepafin/tendermanagement/dao/CompanyDao.java
@@ -69,13 +69,26 @@ public class CompanyDao {
@Autowired
private HttpServletRequest request;
+ @Autowired
+ private VatCheckDao vatCheckDao;
+
private static final String NOT_FOUND_JSON = "{\"data\": \"not found\"}";
public CompanyResponse createCompany(UserEntity userEntity, CompanyRequest companyRequest) {
log.info("Initiating company creation by userId: {}", userEntity.getId());
- CompanyEntity existingCompany = companyRepository.findByVatNumberAndHubId(companyRequest.getVatNumber(), userEntity.getHub().getId());
+ Boolean validVat=Boolean.FALSE;
+ if(companyRequest.getVatNumber()!=null){
+ VatCheckResponseBean vatCheckResponseBean=vatCheckDao.checkVatNumber(companyRequest.getVatNumber(), userEntity.getHub().getId());
+ if(vatCheckResponseBean!=null && Boolean.TRUE.equals(vatCheckResponseBean.getValid())){
+ validVat=Boolean.TRUE;
+ }
+ }
+ CompanyEntity existingCompany = null;
+ if (!StringUtils.isEmpty(companyRequest.getVatNumber())) {
+ existingCompany = companyRepository.findByVatNumberAndHubId(companyRequest.getVatNumber(), userEntity.getHub().getId());
+ }
UserWithCompanyEntity userWithCompanyEntity = null;
if (existingCompany != null) {
UserWithCompanyEntity existingRelation = userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userEntity.getId(), existingCompany.getId()).orElse(null);
@@ -93,6 +106,7 @@ public class CompanyDao {
} else {
validateCompany(userEntity, companyRequest);
CompanyEntity companyEntity = convertCompanyRequestToCompanyEntity(userEntity, companyRequest);
+ companyEntity.setValidVat(validVat);
CompanyEntity companyData = companyRepository.save(companyEntity);
/** This code is responsible for adding a version history log for "creating company" operation. **/
@@ -112,12 +126,16 @@ public class CompanyDao {
throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.INVALID_EMAIL));
}
- if (StringUtils.isEmpty(companyRequest.getVatNumber())) {
+ // At least one identifier required
+ if (StringUtils.isEmpty(companyRequest.getVatNumber())
+ && StringUtils.isEmpty(companyRequest.getCodiceFiscale())) {
throw new CustomValidationException(Status.VALIDATION_ERROR,
- Translator.toLocale(GepafinConstant.VATNUMBER_MANDATORY));
+ Translator.toLocale(GepafinConstant.VAT_OR_TAX_CODE_REQUIRED));
}
- if (companyRepository.existsByVatNumberAndHubId(companyRequest.getVatNumber(), userEntity.getHub().getId())) {
- throw new CustomValidationException(Status.VALIDATION_ERROR,
+ // Only check VAT uniqueness if VAT provided
+ if (!StringUtils.isEmpty(companyRequest.getVatNumber())
+ && companyRepository.existsByVatNumberAndHubId(companyRequest.getVatNumber(), userEntity.getHub().getId())) {
+ throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.VATNUMBER_ALREADY_EXISTS));
}
}
@@ -140,7 +158,7 @@ public class CompanyDao {
UserWithCompanyEntity userWithCompany = userWithCompanyRepository.save(userWithCompanyEntity);
/** This code is responsible for adding a version history log for the "adding user with company" operation. **/
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null).newData(userWithCompany).build());
- if (StringUtils.isEmpty(companyEntity.getJson())) {
+ if (StringUtils.isEmpty(companyEntity.getJson()) && companyRequest.getVatCheckResponse() != null) {
companyEntity.setJson(Utils.convertMapIntoJsonString(companyRequest.getVatCheckResponse()));
updateCodiceAtecoFieldWithNewJson(companyEntity);
companyEntity = companyRepository.save(companyEntity);
@@ -161,7 +179,11 @@ public class CompanyDao {
private CompanyEntity convertCompanyRequestToCompanyEntity(UserEntity userEntity, CompanyRequest request) {
CompanyEntity entity = new CompanyEntity();
entity.setCompanyName(request.getCompanyName());
- entity.setVatNumber(request.getVatNumber());
+ if(request.getVatNumber()==null){
+ entity.setVatNumber(request.getCodiceFiscale());
+ }else {
+ entity.setVatNumber(request.getVatNumber());
+ }
entity.setCodiceFiscale(request.getCodiceFiscale());
entity.setAddress(request.getAddress());
entity.setPhoneNumber(request.getPhoneNumber());
@@ -182,7 +204,11 @@ public class CompanyDao {
CompanyResponse response = new CompanyResponse();
response.setId(entity.getId());
response.setCompanyName(entity.getCompanyName());
- response.setVatNumber(entity.getVatNumber());
+ if(entity.getVatNumber()==null){
+ response.setVatNumber(entity.getCodiceFiscale());
+ }else {
+ response.setVatNumber(entity.getVatNumber());
+ }
response.setCodiceFiscale(entity.getCodiceFiscale());
response.setAddress(entity.getAddress());
response.setPhoneNumber(entity.getPhoneNumber());
@@ -231,6 +257,29 @@ public class CompanyDao {
// companyEntity.setVatNumber(companyRequest.getVatNumber());
//
// }
+
+ //allow adding VAT later
+ if(StringUtils.isNotBlank(companyRequest.getVatNumber())
+ && StringUtils.isBlank(companyEntity.getVatNumber())) {
+ CompanyEntity existingCompany = companyRepository.findByVatNumberAndHubId(companyRequest.getVatNumber(), userEntity.getHub().getId());
+ if(existingCompany!=null){
+ throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.VATNUMBER_ALREADY_EXISTS));
+ }
+ Boolean validVat=Boolean.FALSE;
+ if(companyRequest.getVatNumber()!=null){
+ VatCheckResponseBean vatCheckResponseBean=vatCheckDao.checkVatNumber(companyRequest.getVatNumber(), userEntity.getHub().getId());
+ if(vatCheckResponseBean!=null && Boolean.TRUE.equals(vatCheckResponseBean.getValid())){
+ validVat=Boolean.TRUE;
+ }
+ }
+ companyEntity.setVatNumber(companyRequest.getVatNumber());
+ companyEntity.setValidVat(validVat);
+ if(companyRequest.getVatCheckResponse() != null) {
+ String responseJson = Utils.convertMapIntoJsonString(companyRequest.getVatCheckResponse());
+ companyEntity.setJson(responseJson);
+ updateCodiceAtecoFieldWithNewJson(companyEntity);
+ }
+ }
companyRepository.save(companyEntity);
log.info("Company updated and saved. companyId: {}", companyEntity.getId());
diff --git a/src/main/java/net/gepafin/tendermanagement/entities/CompanyEntity.java b/src/main/java/net/gepafin/tendermanagement/entities/CompanyEntity.java
index 8a6c94e1..0f47d5d9 100644
--- a/src/main/java/net/gepafin/tendermanagement/entities/CompanyEntity.java
+++ b/src/main/java/net/gepafin/tendermanagement/entities/CompanyEntity.java
@@ -64,4 +64,7 @@ public class CompanyEntity extends BaseEntity{
@Column(name = "PEC")
private String pec;
+
+ @Column(name = "VALID_VAT")
+ private Boolean validVat;
}
diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties
index 356735fb..6db0a637 100644
--- a/src/main/resources/application-dev.properties
+++ b/src/main/resources/application-dev.properties
@@ -29,4 +29,6 @@ spring.rabbitmq.host=172.18.0.7
spring.rabbitmq.port=61613
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
-spring.rabbitmq.virtual-host=/
\ No newline at end of file
+spring.rabbitmq.virtual-host=/
+
+rabbitmq.enabled=false
\ No newline at end of file
diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties
index b61da230..e1abc344 100644
--- a/src/main/resources/application-local.properties
+++ b/src/main/resources/application-local.properties
@@ -26,4 +26,5 @@ spring.rabbitmq.host=localhost
spring.rabbitmq.port=61613
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
-spring.rabbitmq.virtual-host=/
\ No newline at end of file
+spring.rabbitmq.virtual-host=/
+rabbitmq.enabled=false
\ No newline at end of file
diff --git a/src/main/resources/application-production.properties b/src/main/resources/application-production.properties
index a38014af..bfb4a6c3 100644
--- a/src/main/resources/application-production.properties
+++ b/src/main/resources/application-production.properties
@@ -38,4 +38,6 @@ spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
spring.rabbitmq.virtual-host=/
-isSviluppumbriaProtocolEnabled = false
\ No newline at end of file
+isSviluppumbriaProtocolEnabled = false
+
+rabbitmq.enabled=true
\ No newline at end of file
diff --git a/src/main/resources/application-testing.properties b/src/main/resources/application-testing.properties
index 532deb3f..912727b9 100644
--- a/src/main/resources/application-testing.properties
+++ b/src/main/resources/application-testing.properties
@@ -24,4 +24,5 @@ spring.rabbitmq.host=rabbitmq.bflows.ai
spring.rabbitmq.port=61613
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
-spring.rabbitmq.virtual-host=/
\ No newline at end of file
+spring.rabbitmq.virtual-host=/
+rabbitmq.enabled=false
\ No newline at end of file
diff --git a/src/main/resources/db/changelog/db.changelog-1.0.0.xml b/src/main/resources/db/changelog/db.changelog-1.0.0.xml
index 32c8690d..36e1c630 100644
--- a/src/main/resources/db/changelog/db.changelog-1.0.0.xml
+++ b/src/main/resources/db/changelog/db.changelog-1.0.0.xml
@@ -3193,5 +3193,10 @@
+
+
+
+
+
diff --git a/src/main/resources/message_en.properties b/src/main/resources/message_en.properties
index b26ec2c2..64331f3d 100644
--- a/src/main/resources/message_en.properties
+++ b/src/main/resources/message_en.properties
@@ -431,6 +431,8 @@ amendment.appropiate.status=Application amendment is not in appropiate status fo
upload.company.document.to.application=Uploaded company document to application successfully.
company.document.not.found.with.ids=Company document not found. Missing IDs: {0}.
amount.field.not.provided= Please provide the required amount fields.
+vat.or.tax.code.required=VAT Number or Tax Code is required.
+provide.valid.vat.number=Please provide a valid vat number to proceed NDG.
diff --git a/src/main/resources/message_it.properties b/src/main/resources/message_it.properties
index 041e08a2..5265325f 100644
--- a/src/main/resources/message_it.properties
+++ b/src/main/resources/message_it.properties
@@ -71,7 +71,7 @@ email.already.exists=Esiste gi? un utente con questa email.
invalid_user=Validazione utente fallita. Controlla le informazioni, lo stato dell'account e la scadenza del token.
#Global messages
-common_message=qualcosa � andato storto. Per favore riprova
+common_message=Qualcosa è andato storto. Riprova.
invalid_signature=Gettone non valido.
invalid_login=Nome utente o password errati
req_validation_er=Errore di convalida
@@ -422,3 +422,5 @@ amendment.appropiate.status=L'emendamento dell'applicazione non � in stato app
upload.company.document.to.application=Documento aziendale caricato correttamente nell'applicazione.
company.document.not.found.with.ids=Documento aziendale non trovato. ID mancanti: {0}
amount.field.not.provided= Si prega di fornire i campi obbligatori per l'importo.
+vat.or.tax.code.required=È obbligatorio il numero di partita IVA o il codice fiscale.
+provide.valid.vat.number=Inserisci un numero di partita IVA valido per procedere con NDG.
\ No newline at end of file