Managed company creation
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
@@ -64,4 +64,7 @@ public class CompanyEntity extends BaseEntity{
|
||||
|
||||
@Column(name = "PEC")
|
||||
private String pec;
|
||||
|
||||
@Column(name = "VALID_VAT")
|
||||
private Boolean validVat;
|
||||
}
|
||||
|
||||
@@ -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=/
|
||||
spring.rabbitmq.virtual-host=/
|
||||
|
||||
rabbitmq.enabled=false
|
||||
@@ -26,4 +26,5 @@ spring.rabbitmq.host=localhost
|
||||
spring.rabbitmq.port=61613
|
||||
spring.rabbitmq.username=guest
|
||||
spring.rabbitmq.password=guest
|
||||
spring.rabbitmq.virtual-host=/
|
||||
spring.rabbitmq.virtual-host=/
|
||||
rabbitmq.enabled=false
|
||||
@@ -38,4 +38,6 @@ spring.rabbitmq.username=guest
|
||||
spring.rabbitmq.password=guest
|
||||
spring.rabbitmq.virtual-host=/
|
||||
|
||||
isSviluppumbriaProtocolEnabled = false
|
||||
isSviluppumbriaProtocolEnabled = false
|
||||
|
||||
rabbitmq.enabled=true
|
||||
@@ -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=/
|
||||
spring.rabbitmq.virtual-host=/
|
||||
rabbitmq.enabled=false
|
||||
@@ -3193,5 +3193,10 @@
|
||||
<column name="blue_tongue_field_2" type="numeric"/>
|
||||
</addColumn>
|
||||
</changeSet>
|
||||
<changeSet id="10-03-2026_RK_133852" author="Rajesh Khore">
|
||||
<addColumn tableName="company">
|
||||
<column name="valid_vat" type="BOOLEAN"/>
|
||||
</addColumn>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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 <EFBFBD> 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 <20> 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.
|
||||
Reference in New Issue
Block a user