Resolved conflicts
This commit is contained in:
@@ -73,6 +73,7 @@ public class CompanyDao {
|
||||
|
||||
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());
|
||||
UserWithCompanyEntity userWithCompanyEntity = null;
|
||||
if (existingCompany != null) {
|
||||
@@ -84,6 +85,7 @@ public class CompanyDao {
|
||||
loggingUtil.addVersionHistory(
|
||||
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null).newData(userWithCompanyEntity).build());
|
||||
} else {
|
||||
log.warn("User already connected to company. userId: {}, companyId: {}", userEntity.getId(), existingCompany.getId());
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.USER_ALREADY_CONNECTED_TO_COMPANY));
|
||||
}
|
||||
return convertCompanyEntityToCompanyResponse(existingCompany, userWithCompanyEntity);
|
||||
@@ -121,6 +123,7 @@ public class CompanyDao {
|
||||
|
||||
private UserWithCompanyEntity createUserWithCompanyRelation(UserEntity userEntity, CompanyEntity companyEntity, Boolean isLegalRepresentant,CompanyRequest companyRequest) {
|
||||
|
||||
log.info("Creating user-company relation. userId: {}, companyId: {}, isLegalRep: {}", userEntity.getId(), companyEntity.getId(), isLegalRepresentant);
|
||||
UserWithCompanyEntity userWithCompanyEntity = new UserWithCompanyEntity();
|
||||
if (userEntity.getBeneficiary() != null) {
|
||||
userWithCompanyEntity.setBeneficiaryId(userEntity.getBeneficiary().getId());
|
||||
@@ -140,6 +143,7 @@ public class CompanyDao {
|
||||
companyEntity.setJson(Utils.convertMapIntoJsonString(companyRequest.getVatCheckResponse()));
|
||||
updateCodiceAtecoFieldWithNewJson(companyEntity);
|
||||
companyEntity = companyRepository.save(companyEntity);
|
||||
log.info("Updated company JSON field and saved. companyId: {}", companyEntity.getId());
|
||||
|
||||
/** This code is responsible for adding a version history log for "updating company json field" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder()
|
||||
@@ -202,6 +206,7 @@ public class CompanyDao {
|
||||
|
||||
public CompanyResponse updateCompany(UserEntity userEntity, Long companyId, CompanyRequest companyRequest) {
|
||||
|
||||
log.info("Updating company. companyId: {}, userId: {}", companyId, userEntity.getId());
|
||||
CompanyEntity companyEntity = validateCompany(companyId);
|
||||
//cloned entity for old data
|
||||
CompanyEntity oldCompanyData = Utils.getClonedEntityForData(companyEntity);
|
||||
@@ -226,11 +231,14 @@ public class CompanyDao {
|
||||
//
|
||||
// }
|
||||
companyRepository.save(companyEntity);
|
||||
log.info("Company updated and saved. companyId: {}", companyEntity.getId());
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Update company" operation. **/
|
||||
loggingUtil.addVersionHistory(
|
||||
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldCompanyData).newData(companyEntity).build());
|
||||
|
||||
log.info("Logged version history for company update. companyId: {}", companyEntity.getId());
|
||||
|
||||
UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyId);
|
||||
//cloned entity for old data
|
||||
UserWithCompanyEntity oldUserWithCompanyData = Utils.getClonedEntityForData(userWithCompanyEntity);
|
||||
@@ -253,17 +261,19 @@ public class CompanyDao {
|
||||
}
|
||||
|
||||
public CompanyEntity validateCompany(Long companyId) {
|
||||
log.info("Validating company. companyId: {}", companyId);
|
||||
return companyRepository.findById(companyId).orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.COMPANY_NOT_FOUND_MSG)));
|
||||
}
|
||||
|
||||
public CompanyResponse getCompany(UserEntity userEntity, Long companyId) {
|
||||
log.info("Fetching company details. userId: {}, companyId: {}", userEntity.getId(), companyId);
|
||||
UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyId);
|
||||
return convertCompanyEntityToCompanyResponse(validateCompany(companyId), userWithCompanyEntity);
|
||||
}
|
||||
|
||||
public void deleteCompany(UserEntity userEntity, Long companyId) {
|
||||
|
||||
log.info("Deleting company. userId: {}, companyId: {}", userEntity.getId(), companyId);
|
||||
CompanyEntity companyEntity = validateCompany(companyId);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "delete company" operation. **/
|
||||
@@ -281,6 +291,7 @@ public class CompanyDao {
|
||||
}
|
||||
|
||||
public List<CompanyResponse> getCompanyByUserId(Long userId) {
|
||||
log.info("Fetching companies by userId: {}", userId);
|
||||
UserEntity userEntity = userService.validateUser(userId);
|
||||
List<Long> activeCompanyIds = userWithCompanyRepository.findActiveCompanyIdsByUserId(userEntity.getId());
|
||||
List<CompanyEntity> companies = companyRepository.findByIdInAndHubId(activeCompanyIds, userEntity.getHub().getId());
|
||||
@@ -291,15 +302,18 @@ public class CompanyDao {
|
||||
}
|
||||
|
||||
public UserWithCompanyEntity validateUserWithCompny(Long userId, Long companyId) {
|
||||
log.info("Validating user-company access. userId: {}, companyId: {}", userId, companyId);
|
||||
return userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userId, companyId).orElseThrow(() -> new ForbiddenAccessException(Status.FORBIDDEN,
|
||||
Translator.toLocale(GepafinConstant.PERMISSION_DENIED)));
|
||||
}
|
||||
|
||||
public UserWithCompanyEntity getUserWithCompany(Long userId, Long compnayId) {
|
||||
log.info("Fetching user-company relation. userId: {}, companyId: {}", userId, compnayId);
|
||||
return userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userId, compnayId).orElseThrow(
|
||||
() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_COMPANY_RELATION_NOT_FOUND)));
|
||||
}
|
||||
public void removeCompanyFromList(UserEntity userEntity, Long companyId) {
|
||||
log.info("Initiating removal of company from user list. userId: {}, companyId: {}", userEntity.getId(), companyId);
|
||||
CompanyEntity companyEntity = validateCompany(companyId);
|
||||
UserWithCompanyEntity existingRelation=companyService.getUserWithCompany(userEntity.getId(),companyEntity.getId());
|
||||
List<ApplicationEntity> userApplications = applicationRepository.findByUserWithCompanyIdAndUserIdAndIsDeletedFalse(existingRelation.getId(), userEntity.getId());
|
||||
@@ -314,6 +328,7 @@ public class CompanyDao {
|
||||
boolean notAllowedStatus = userApplications.stream()
|
||||
.anyMatch(application -> !applicationStatusAllowed.contains(application.getStatus()));
|
||||
if (notAllowedStatus) {
|
||||
log.warn("Cannot remove company. One or more applications in non-removable status. userId: {}, companyId: {}", userEntity.getId(), companyId);
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.CANNOT_DELETE_COMPANY_WITH_APPLICATION_SUBMITT));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user