|
|
|
@@ -67,7 +67,7 @@ public class CompanyDao {
|
|
|
|
if (existingCompany != null) {
|
|
|
|
if (existingCompany != null) {
|
|
|
|
UserWithCompanyEntity existingRelation = userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userEntity.getId(), existingCompany.getId()).orElse(null);
|
|
|
|
UserWithCompanyEntity existingRelation = userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userEntity.getId(), existingCompany.getId()).orElse(null);
|
|
|
|
if (existingRelation == null) {
|
|
|
|
if (existingRelation == null) {
|
|
|
|
userWithCompanyEntity = createUserWithCompanyRelation(userEntity, existingCompany, companyRequest.getIsLegalRepresentant());
|
|
|
|
userWithCompanyEntity = createUserWithCompanyRelation(userEntity, existingCompany, companyRequest.getIsLegalRepresentant(),companyRequest.getVatCheckResponse());
|
|
|
|
|
|
|
|
|
|
|
|
/** This code is responsible for adding a version history log for "adding user with company" operation. **/
|
|
|
|
/** This code is responsible for adding a version history log for "adding user with company" operation. **/
|
|
|
|
loggingUtil.addVersionHistory(
|
|
|
|
loggingUtil.addVersionHistory(
|
|
|
|
@@ -79,14 +79,12 @@ public class CompanyDao {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
validateCompany(userEntity, companyRequest);
|
|
|
|
validateCompany(userEntity, companyRequest);
|
|
|
|
CompanyEntity companyEntity = convertCompanyRequestToCompanyEntity(userEntity, companyRequest);
|
|
|
|
CompanyEntity companyEntity = convertCompanyRequestToCompanyEntity(userEntity, companyRequest);
|
|
|
|
companyEntity.setJson(Utils.convertMapIntoJsonString(companyRequest.getVatCheckResponse()) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CompanyEntity companyData = companyRepository.save(companyEntity);
|
|
|
|
CompanyEntity companyData = companyRepository.save(companyEntity);
|
|
|
|
|
|
|
|
|
|
|
|
/** This code is responsible for adding a version history log for "creating company" operation. **/
|
|
|
|
/** This code is responsible for adding a version history log for "creating company" operation. **/
|
|
|
|
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null).newData(companyData).build());
|
|
|
|
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null).newData(companyData).build());
|
|
|
|
|
|
|
|
|
|
|
|
userWithCompanyEntity = createUserWithCompanyRelation(userEntity, companyEntity, companyRequest.getIsLegalRepresentant());
|
|
|
|
userWithCompanyEntity = createUserWithCompanyRelation(userEntity, companyEntity, companyRequest.getIsLegalRepresentant(),companyRequest.getVatCheckResponse());
|
|
|
|
|
|
|
|
|
|
|
|
return convertCompanyEntityToCompanyResponse(companyEntity, userWithCompanyEntity);
|
|
|
|
return convertCompanyEntityToCompanyResponse(companyEntity, userWithCompanyEntity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -110,7 +108,7 @@ public class CompanyDao {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private UserWithCompanyEntity createUserWithCompanyRelation(UserEntity userEntity, CompanyEntity companyEntity, Boolean isLegalRepresentant) {
|
|
|
|
private UserWithCompanyEntity createUserWithCompanyRelation(UserEntity userEntity, CompanyEntity companyEntity, Boolean isLegalRepresentant,Map<String, Object> vatCheckResponse) {
|
|
|
|
|
|
|
|
|
|
|
|
UserWithCompanyEntity userWithCompanyEntity = new UserWithCompanyEntity();
|
|
|
|
UserWithCompanyEntity userWithCompanyEntity = new UserWithCompanyEntity();
|
|
|
|
if (userEntity.getBeneficiary() != null) {
|
|
|
|
if (userEntity.getBeneficiary() != null) {
|
|
|
|
@@ -120,6 +118,11 @@ public class CompanyDao {
|
|
|
|
userWithCompanyEntity.setCompanyId(companyEntity.getId());
|
|
|
|
userWithCompanyEntity.setCompanyId(companyEntity.getId());
|
|
|
|
userWithCompanyEntity.setUserId(userEntity.getId());
|
|
|
|
userWithCompanyEntity.setUserId(userEntity.getId());
|
|
|
|
userWithCompanyEntity.setIsLegalRepresentant(isLegalRepresentant);
|
|
|
|
userWithCompanyEntity.setIsLegalRepresentant(isLegalRepresentant);
|
|
|
|
|
|
|
|
userWithCompanyEntity.setEmail(companyEntity.getEmail());
|
|
|
|
|
|
|
|
userWithCompanyEntity.setPec(companyEntity.getPec());
|
|
|
|
|
|
|
|
userWithCompanyEntity.setContactName(companyEntity.getContactName());
|
|
|
|
|
|
|
|
userWithCompanyEntity.setContactEmail(companyEntity.getContactEmail());
|
|
|
|
|
|
|
|
userWithCompanyEntity.setJson(Utils.convertMapIntoJsonString(vatCheckResponse) );
|
|
|
|
UserWithCompanyEntity userWithCompany = userWithCompanyRepository.save(userWithCompanyEntity);
|
|
|
|
UserWithCompanyEntity userWithCompany = userWithCompanyRepository.save(userWithCompanyEntity);
|
|
|
|
|
|
|
|
|
|
|
|
/** This code is responsible for adding a version history log for the "adding user with company" operation. **/
|
|
|
|
/** This code is responsible for adding a version history log for the "adding user with company" operation. **/
|
|
|
|
@@ -201,8 +204,6 @@ public class CompanyDao {
|
|
|
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.VATNUMBER_ALREADY_EXISTS));
|
|
|
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.VATNUMBER_ALREADY_EXISTS));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
companyEntity.setVatNumber(companyRequest.getVatNumber());
|
|
|
|
companyEntity.setVatNumber(companyRequest.getVatNumber());
|
|
|
|
String responseJson = companyRequest.getVatCheckResponse() != null ? Utils.convertMapIntoJsonString(companyRequest.getVatCheckResponse()) : null;
|
|
|
|
|
|
|
|
setIfUpdated(companyEntity::getJson, companyEntity::setJson, responseJson);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
companyRepository.save(companyEntity);
|
|
|
|
companyRepository.save(companyEntity);
|
|
|
|
@@ -214,8 +215,15 @@ public class CompanyDao {
|
|
|
|
UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyId);
|
|
|
|
UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyId);
|
|
|
|
//cloned entity for old data
|
|
|
|
//cloned entity for old data
|
|
|
|
UserWithCompanyEntity oldUserWithCompanyData = Utils.getClonedEntityForData(userWithCompanyEntity);
|
|
|
|
UserWithCompanyEntity oldUserWithCompanyData = Utils.getClonedEntityForData(userWithCompanyEntity);
|
|
|
|
|
|
|
|
if(StringUtils.isNotBlank(companyRequest.getVatNumber())) {
|
|
|
|
Utils.setIfUpdated(userWithCompanyEntity::getIsLegalRepresentant, userWithCompanyEntity::setIsLegalRepresentant, companyRequest.getIsLegalRepresentant());
|
|
|
|
String responseJson = companyRequest.getVatCheckResponse() != null ? Utils.convertMapIntoJsonString(companyRequest.getVatCheckResponse()) : null;
|
|
|
|
|
|
|
|
setIfUpdated(userWithCompanyEntity::getJson, userWithCompanyEntity::setJson, responseJson);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
setIfUpdated(userWithCompanyEntity::getPec, userWithCompanyEntity::setPec, userWithCompanyEntity.getPec());
|
|
|
|
|
|
|
|
setIfUpdated(userWithCompanyEntity::getEmail, userWithCompanyEntity::setEmail, userWithCompanyEntity.getEmail());
|
|
|
|
|
|
|
|
setIfUpdated(userWithCompanyEntity::getContactName, userWithCompanyEntity::setContactName, companyRequest.getContactName());
|
|
|
|
|
|
|
|
setIfUpdated(userWithCompanyEntity::getContactEmail, userWithCompanyEntity::setContactEmail, companyRequest.getContactEmail());
|
|
|
|
|
|
|
|
setIfUpdated(userWithCompanyEntity::getIsLegalRepresentant, userWithCompanyEntity::setIsLegalRepresentant, companyRequest.getIsLegalRepresentant());
|
|
|
|
userWithCompanyEntity = userWithCompanyRepository.save(userWithCompanyEntity);
|
|
|
|
userWithCompanyEntity = userWithCompanyRepository.save(userWithCompanyEntity);
|
|
|
|
|
|
|
|
|
|
|
|
/** This code is responsible for adding a version history log for the "Update company" operation. **/
|
|
|
|
/** This code is responsible for adding a version history log for the "Update company" operation. **/
|
|
|
|
@@ -290,36 +298,56 @@ public class CompanyDao {
|
|
|
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.CANNOT_DELETE_COMPANY_WITH_APPLICATION_SUBMITT));
|
|
|
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.CANNOT_DELETE_COMPANY_WITH_APPLICATION_SUBMITT));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for(ApplicationEntity application:userApplications){
|
|
|
|
userApplications = userApplications.stream()
|
|
|
|
|
|
|
|
.peek(application -> {
|
|
|
|
ApplicationEntity oldApplication = Utils.getClonedEntityForData(application);
|
|
|
|
ApplicationEntity oldApplication = Utils.getClonedEntityForData(application);
|
|
|
|
application.setIsDeleted(Boolean.TRUE);
|
|
|
|
application.setIsDeleted(Boolean.TRUE);
|
|
|
|
|
|
|
|
|
|
|
|
/** This code is responsible for adding a version history log for the "Soft delete application" operation. **/
|
|
|
|
|
|
|
|
loggingUtil.addVersionHistory(
|
|
|
|
|
|
|
|
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldApplication).newData(application).build());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
applicationRepository.saveAll(userApplications);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(FaqEntity faq:faqs){
|
|
|
|
|
|
|
|
FaqEntity oldFaq = Utils.getClonedEntityForData(faq);
|
|
|
|
|
|
|
|
faq.setIsDeleted(Boolean.TRUE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** This code is responsible for adding a version history log for the "Soft delete Faq" operation. **/
|
|
|
|
/** This code is responsible for adding a version history log for the "Soft delete Faq" operation. **/
|
|
|
|
loggingUtil.addVersionHistory(
|
|
|
|
loggingUtil.addVersionHistory(
|
|
|
|
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldFaq).newData(faq).build());
|
|
|
|
VersionHistoryRequest.builder()
|
|
|
|
}
|
|
|
|
.request(request)
|
|
|
|
|
|
|
|
.actionType(VersionActionTypeEnum.SOFT_DELETE)
|
|
|
|
|
|
|
|
.oldData(oldApplication)
|
|
|
|
|
|
|
|
.newData(application)
|
|
|
|
|
|
|
|
.build()
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
applicationRepository.saveAll(userApplications);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
faqs = faqs.stream()
|
|
|
|
|
|
|
|
.peek(faq -> {
|
|
|
|
|
|
|
|
FaqEntity oldFaq = Utils.getClonedEntityForData(faq);
|
|
|
|
|
|
|
|
faq.setIsDeleted(Boolean.TRUE);
|
|
|
|
|
|
|
|
/** This code is responsible for adding a version history log for the "Soft delete Faq" operation. **/
|
|
|
|
|
|
|
|
loggingUtil.addVersionHistory(
|
|
|
|
|
|
|
|
VersionHistoryRequest.builder()
|
|
|
|
|
|
|
|
.request(request)
|
|
|
|
|
|
|
|
.actionType(VersionActionTypeEnum.SOFT_DELETE)
|
|
|
|
|
|
|
|
.oldData(oldFaq)
|
|
|
|
|
|
|
|
.newData(faq)
|
|
|
|
|
|
|
|
.build()
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.toList();
|
|
|
|
faqRepository.saveAll(faqs);
|
|
|
|
faqRepository.saveAll(faqs);
|
|
|
|
|
|
|
|
|
|
|
|
for(BeneficiaryPreferredCallEntity beneficiaryPreferredCall:preferredCallEntities){
|
|
|
|
preferredCallEntities = preferredCallEntities.stream()
|
|
|
|
|
|
|
|
.peek(beneficiaryPreferredCall -> {
|
|
|
|
BeneficiaryPreferredCallEntity oldPreferredCall = Utils.getClonedEntityForData(beneficiaryPreferredCall);
|
|
|
|
BeneficiaryPreferredCallEntity oldPreferredCall = Utils.getClonedEntityForData(beneficiaryPreferredCall);
|
|
|
|
beneficiaryPreferredCall.setIsDeleted(Boolean.TRUE);
|
|
|
|
beneficiaryPreferredCall.setIsDeleted(Boolean.TRUE);
|
|
|
|
|
|
|
|
|
|
|
|
/** This code is responsible for adding a version history log for the "Soft Delete BeneficiaryPreferredCall" operation. **/
|
|
|
|
/** This code is responsible for adding a version history log for the "Soft Delete BeneficiaryPreferredCall" operation. **/
|
|
|
|
loggingUtil.addVersionHistory(
|
|
|
|
loggingUtil.addVersionHistory(
|
|
|
|
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldPreferredCall).newData(beneficiaryPreferredCall).build());
|
|
|
|
VersionHistoryRequest.builder()
|
|
|
|
|
|
|
|
.request(request)
|
|
|
|
}
|
|
|
|
.actionType(VersionActionTypeEnum.SOFT_DELETE)
|
|
|
|
|
|
|
|
.oldData(oldPreferredCall)
|
|
|
|
|
|
|
|
.newData(beneficiaryPreferredCall)
|
|
|
|
|
|
|
|
.build()
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.toList();
|
|
|
|
beneficiaryPreferredCallRepository.saveAll(preferredCallEntities);
|
|
|
|
beneficiaryPreferredCallRepository.saveAll(preferredCallEntities);
|
|
|
|
|
|
|
|
|
|
|
|
if(userCompanyDelegationEntity!=null){
|
|
|
|
if(userCompanyDelegationEntity!=null){
|
|
|
|
|