resolved conflict

This commit is contained in:
nisha
2024-10-09 13:27:14 +05:30
37 changed files with 832 additions and 73 deletions

View File

@@ -21,6 +21,8 @@ import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationExceptio
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
@Component
public class CompanyDao {
@@ -33,24 +35,26 @@ public class CompanyDao {
@Autowired
private UserWithCompanyRepository userWithCompanyRepository;
public CompanyResponse createCompany(UserEntity userEntity, CompanyRequest companyRequest) {
CompanyEntity existingCompany = companyRepository.findByVatNumber(companyRequest.getVatNumber());
UserWithCompanyEntity userWithCompanyEntity = null;
if (existingCompany != null) {
UserWithCompanyEntity existingRelation = userWithCompanyRepository.findByUserIdAndCompanyId(userEntity.getId(), existingCompany.getId())
.orElse(null);
if (existingRelation == null) {
createUserWithCompanyRelation(userEntity, existingCompany);
userWithCompanyEntity = createUserWithCompanyRelation(userEntity, existingCompany, companyRequest.getIsLegalRepresentant());
} else {
throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.USER_ALREADY_CONNECTED_TO_COMPANY));
}
return convertCompanyEntityToCompanyResponse(existingCompany);
return convertCompanyEntityToCompanyResponse(existingCompany, userWithCompanyEntity);
} else {
validateCompany(companyRequest);
CompanyEntity companyEntity = convertCompanyRequestToCompanyEntity(companyRequest);
companyRepository.save(companyEntity);
createUserWithCompanyRelation(userEntity, companyEntity);
return convertCompanyEntityToCompanyResponse(companyEntity);
userWithCompanyEntity = createUserWithCompanyRelation(userEntity, companyEntity, companyRequest.getIsLegalRepresentant());
return convertCompanyEntityToCompanyResponse(companyEntity, userWithCompanyEntity);
}
}
@@ -72,13 +76,14 @@ public class CompanyDao {
}
}
private UserWithCompanyEntity createUserWithCompanyRelation(UserEntity userEntity, CompanyEntity companyEntity) {
private UserWithCompanyEntity createUserWithCompanyRelation(UserEntity userEntity, CompanyEntity companyEntity, Boolean isLegalRepresentant) {
UserWithCompanyEntity userWithCompanyEntity = new UserWithCompanyEntity();
if (userEntity.getBeneficiary() != null) {
userWithCompanyEntity.setBeneficiaryId(userEntity.getBeneficiary().getId());
}
userWithCompanyEntity.setCompanyId(companyEntity.getId());
userWithCompanyEntity.setUserId(userEntity.getId());
userWithCompanyEntity.setIsLegalRepresentant(isLegalRepresentant);
return userWithCompanyRepository.save(userWithCompanyEntity);
}
@@ -97,10 +102,12 @@ public class CompanyDao {
entity.setEmail(request.getEmail());
entity.setNumberOfEmployees(request.getNumberOfEmployees());
entity.setAnnualRevenue(request.getAnnualRevenue());
entity.setContactName(request.getContactName());
entity.setContactEmail(request.getContactEmail());
return entity;
}
private CompanyResponse convertCompanyEntityToCompanyResponse(CompanyEntity entity) {
private CompanyResponse convertCompanyEntityToCompanyResponse(CompanyEntity entity, UserWithCompanyEntity userWithCompanyEntity) {
CompanyResponse response = new CompanyResponse();
response.setId(entity.getId());
response.setCompanyName(entity.getCompanyName());
@@ -116,33 +123,44 @@ public class CompanyDao {
response.setEmail(entity.getEmail());
response.setNumberOfEmployees(entity.getNumberOfEmployees());
response.setAnnualRevenue(entity.getAnnualRevenue());
if(userWithCompanyEntity!=null) {
response.setIsLegalRepresentant(userWithCompanyEntity.getIsLegalRepresentant());
}
response.setCreatedDate(entity.getCreatedDate());
response.setUpdatedDate(entity.getUpdatedDate());
response.setContactName(entity.getContactName());
response.setContactEmail(entity.getContactEmail());
return response;
}
public CompanyResponse updateCompany(UserEntity userEntity, Long companyId, CompanyRequest companyRequest) {
CompanyEntity companyEntity = validateCompany(companyId);
Utils.setIfUpdated(companyEntity::getCompanyName, companyEntity::setCompanyName,
setIfUpdated(companyEntity::getCompanyName, companyEntity::setCompanyName,
companyRequest.getCompanyName());
Utils.setIfUpdated(companyEntity::getVatNumber, companyEntity::setVatNumber, companyRequest.getVatNumber());
Utils.setIfUpdated(companyEntity::getCodiceFiscale, companyEntity::setCodiceFiscale,
setIfUpdated(companyEntity::getVatNumber, companyEntity::setVatNumber, companyRequest.getVatNumber());
setIfUpdated(companyEntity::getCodiceFiscale, companyEntity::setCodiceFiscale,
companyRequest.getCodiceFiscale());
Utils.setIfUpdated(companyEntity::getAddress, companyEntity::setAddress, companyRequest.getAddress());
Utils.setIfUpdated(companyEntity::getPhoneNumber, companyEntity::setPhoneNumber,
setIfUpdated(companyEntity::getAddress, companyEntity::setAddress, companyRequest.getAddress());
setIfUpdated(companyEntity::getPhoneNumber, companyEntity::setPhoneNumber,
companyRequest.getPhoneNumber());
Utils.setIfUpdated(companyEntity::getCity, companyEntity::setCity, companyRequest.getCity());
Utils.setIfUpdated(companyEntity::getProvince, companyEntity::setProvince, companyRequest.getProvince());
Utils.setIfUpdated(companyEntity::getCap, companyEntity::setCap, companyRequest.getCap());
Utils.setIfUpdated(companyEntity::getCountry, companyEntity::setCountry, companyRequest.getCountry());
Utils.setIfUpdated(companyEntity::getPec, companyEntity::setPec, companyRequest.getPec());
Utils.setIfUpdated(companyEntity::getEmail, companyEntity::setEmail, companyRequest.getEmail());
Utils.setIfUpdated(companyEntity::getNumberOfEmployees, companyEntity::setNumberOfEmployees,
setIfUpdated(companyEntity::getCity, companyEntity::setCity, companyRequest.getCity());
setIfUpdated(companyEntity::getProvince, companyEntity::setProvince, companyRequest.getProvince());
setIfUpdated(companyEntity::getCap, companyEntity::setCap, companyRequest.getCap());
setIfUpdated(companyEntity::getCountry, companyEntity::setCountry, companyRequest.getCountry());
setIfUpdated(companyEntity::getPec, companyEntity::setPec, companyRequest.getPec());
setIfUpdated(companyEntity::getEmail, companyEntity::setEmail, companyRequest.getEmail());
setIfUpdated(companyEntity::getNumberOfEmployees, companyEntity::setNumberOfEmployees,
companyRequest.getNumberOfEmployees());
Utils.setIfUpdated(companyEntity::getAnnualRevenue, companyEntity::setAnnualRevenue,
setIfUpdated(companyEntity::getAnnualRevenue, companyEntity::setAnnualRevenue,
companyRequest.getAnnualRevenue());
setIfUpdated(companyEntity::getContactName,companyEntity::setContactName,companyRequest.getContactName());
setIfUpdated(companyEntity::getContactEmail,companyEntity::setContactEmail,companyRequest.getContactEmail());
companyRepository.save(companyEntity);
return convertCompanyEntityToCompanyResponse(companyEntity);
UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyId);
Utils.setIfUpdated(userWithCompanyEntity::getIsLegalRepresentant, userWithCompanyEntity::setIsLegalRepresentant,
companyRequest.getIsLegalRepresentant());
userWithCompanyRepository.save(userWithCompanyEntity);
return convertCompanyEntityToCompanyResponse(companyEntity, userWithCompanyEntity);
}
public CompanyEntity validateCompany(Long companyId) {
@@ -151,7 +169,8 @@ public class CompanyDao {
}
public CompanyResponse getCompany(UserEntity userEntity, Long companyId) {
return convertCompanyEntityToCompanyResponse(validateCompany(companyId));
UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyId);
return convertCompanyEntityToCompanyResponse(validateCompany(companyId), userWithCompanyEntity);
}
public void deleteCompany(UserEntity userEntity, Long companyId) {
@@ -164,12 +183,20 @@ public class CompanyDao {
UserEntity userEntity = userService.validateUser(userId);
List<Long> companyIds = userWithCompanyRepository.findCompanyIdByUserId(userEntity.getId());
List<CompanyEntity> list = companyRepository.findByIdIn(companyIds);
return list.stream().map(this::convertCompanyEntityToCompanyResponse).toList();
return list.stream().map(companyEntity->{
UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyEntity.getId());
return convertCompanyEntityToCompanyResponse(companyEntity, userWithCompanyEntity);
}).toList();
}
public UserWithCompanyEntity validateUserWithCompny(Long userId, Long companyId) {
return userWithCompanyRepository.findByUserIdAndCompanyId(userId, companyId).orElseThrow(() -> new CustomValidationException(Status.UNAUTHORIZED,
Translator.toLocale(GepafinConstant.UNAUTHORIZED)));
}
public UserWithCompanyEntity getUserWithCompany(Long userId, Long compnayId) {
return userWithCompanyRepository.findByUserIdAndCompanyId(userId, compnayId).orElseThrow(
() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_COMPANY_RELATION_NOT_FOUND)));
}
}

View File

@@ -0,0 +1,256 @@
package net.gepafin.tendermanagement.dao;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.CompanyEntity;
import net.gepafin.tendermanagement.entities.DocumentEntity;
import net.gepafin.tendermanagement.entities.UserCompanyDelegationEntity;
import net.gepafin.tendermanagement.entities.UserEntity;
import net.gepafin.tendermanagement.enums.UserCompanyDelegationStatusEnum;
import net.gepafin.tendermanagement.model.request.CompanyDelegationRequest;
import net.gepafin.tendermanagement.model.response.CompanyDelegationResponse;
import net.gepafin.tendermanagement.model.response.UserResponseBean;
import net.gepafin.tendermanagement.repositories.DocumentRepository;
import net.gepafin.tendermanagement.repositories.UserCompanyDelegationRepository;
import net.gepafin.tendermanagement.service.AmazonS3Service;
import net.gepafin.tendermanagement.service.UserService;
import net.gepafin.tendermanagement.util.DateTimeUtil;
import net.gepafin.tendermanagement.util.Utils;
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
@Component
public class DelegationDao {
private static final String DEFAULT_PLACEHOLDER = "____________________";
@Autowired
private UserService userService;
@Autowired
private CompanyDao companyDao;
@Autowired
private AmazonS3Service amazonS3Service;
@Autowired
private DocumentRepository documentRepository;
@Value("${aws.s3.url.folder.delegation}")
private String s3Folder;
@Autowired
private UserCompanyDelegationRepository userCompanyDelegationRepository;
public ByteArrayOutputStream generateDocument(Map<String, String> placeholders, String templateName) {
try {
InputStream templateStream = amazonS3Service.getFile(s3Folder ,templateName);
XWPFDocument doc = loadTemplate(templateStream);
replacePlaceholders(doc, placeholders);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
doc.write(byteArrayOutputStream);
return byteArrayOutputStream;
} catch (Exception e) {
throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.DELEGATION_TEMPLATE_GENERATION_ERROR));
}
}
public void replacePlaceholders(XWPFDocument doc, Map<String, String> placeholders) {
doc.getParagraphs().forEach(paragraph -> {
placeholders.forEach((placeholder, value) -> {
if (paragraph.getText().contains(placeholder)) {
String updatedText = paragraph.getText().replace(placeholder, value);
paragraph.getRuns().forEach(run -> run.setText("", 0)); // Clear the existing text
paragraph.createRun().setText(updatedText); // Insert updated text
}
});
});
}
public XWPFDocument loadTemplate(InputStream templateStream) throws IOException {
return new XWPFDocument(templateStream);
}
public ByteArrayOutputStream downloadCompanyDelegation(UserEntity userEntity, Long companyId, CompanyDelegationRequest companyDelegationRequest) {
Map<String, String> placeholders = getDefaultPlaceholders();
UserResponseBean user = userService.getUserById(userEntity.getId());
CompanyEntity companyEntity = companyDao.validateCompany(companyId);
companyDao.getUserWithCompany(userEntity.getId(), companyId);
updatePlaceholdersForDelegation(user, companyEntity, placeholders, companyDelegationRequest);
DocumentEntity documentEntity = documentRepository.findBySource(GepafinConstant.DELEGATION_TEMPLATE).get(0);
return generateDocument(placeholders, documentEntity.getFileName());
}
private Map<String, String> updatePlaceholdersForDelegation(UserResponseBean user, CompanyEntity companyEntity,
Map<String, String> placeholders, CompanyDelegationRequest companyDelegationRequest) {
validateMandatoryFields(companyDelegationRequest);
addIfNotEmpty(placeholders, "{{company_first_name}}", companyDelegationRequest.getFirstName());
addIfNotEmpty(placeholders, "{{company_last_name}}", companyDelegationRequest.getLastName());
addIfNotEmpty(placeholders, "{{company_codice_fiscale}}", companyDelegationRequest.getCodiceFiscale());
addIfNotEmpty(placeholders, "{{company_name}}", companyEntity.getCompanyName());
addIfNotEmpty(placeholders, "{{company_city}}", companyEntity.getCity());
addIfNotEmpty(placeholders, "{{company_address}}", companyEntity.getAddress());
addIfNotEmpty(placeholders, "{{company_province}}", companyEntity.getProvince());
addIfNotEmpty(placeholders, "{{company_cap}}", companyEntity.getCap());
addIfNotEmpty(placeholders, "{{company_vat_number}}", companyEntity.getVatNumber());
addIfNotEmpty(placeholders, "{{user_first_name}}", user.getFirstName());
addIfNotEmpty(placeholders, "{{user_last_name}}", user.getLastName());
addIfNotNull(placeholders, "{{user_date_of_birth}}", user.getDateOfBirth(),
date -> DateTimeUtil.formatLocalDateTime(date, GepafinConstant.YYYY_MM_DD_SLASH));
addIfNotEmpty(placeholders, "{{user_codice_fiscale}}", user.getCodiceFiscale());
return placeholders;
}
private Map<String, String> getDefaultPlaceholders() {
Map<String, String> placeholders = new HashMap<>();
placeholders.put("{{company_first_name}}", "");
placeholders.put("{{company_last_name}}", "");
placeholders.put("{{company_codice_fiscale}}", "");
placeholders.put("{{company_name}}", "");
placeholders.put("{{company_city}}", DEFAULT_PLACEHOLDER);
placeholders.put("{{company_address}}", DEFAULT_PLACEHOLDER);
placeholders.put("{{company_province}}", DEFAULT_PLACEHOLDER);
placeholders.put("{{company_cap}}", DEFAULT_PLACEHOLDER);
placeholders.put("{{company_vat_number}}", "");
placeholders.put("{{user_first_name}}", "");
placeholders.put("{{user_last_name}}", "");
placeholders.put("{{user_date_of_birth}}", DEFAULT_PLACEHOLDER);
placeholders.put("{{user_codice_fiscale}}", "");
return placeholders;
}
private void validateMandatoryFields(CompanyDelegationRequest companyDelegationRequest) {
if (StringUtils.isAllEmpty(companyDelegationRequest.getFirstName())) {
throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.VALIDATION_ERROR_MISSING_FIRSTNAME));
}
if (StringUtils.isAllEmpty(companyDelegationRequest.getLastName())) {
throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.VALIDATION_ERROR_MISSING_LASTNAME));
}
if (StringUtils.isAllEmpty(companyDelegationRequest.getCodiceFiscale())) {
throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.VALIDATION_ERROR_MISSING_CODICEFISCALE));
}
}
private void addIfNotEmpty(Map<String, String> placeholders, String key, String value) {
if (Boolean.FALSE.equals(StringUtils.isAllEmpty(value))) {
placeholders.put(key, value);
}
}
private <T> void addIfNotNull(Map<String, String> placeholders, String key, T value, Function<T, String> formatter) {
if (value != null) {
placeholders.put(key, formatter.apply(value));
}
}
public CompanyDelegationResponse uploadCompanyDelegation(UserEntity userEntity, Long companyId, MultipartFile file) {
companyDao.validateCompany(companyId);
companyDao.getUserWithCompany(userEntity.getId(), companyId);
validateFileType(file);
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
.findByUserIdAndCompanyIdAndStatus(userEntity.getId(), companyId,
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
if (userCompanyDelegationEntity != null) {
userCompanyDelegationEntity.setStatus(UserCompanyDelegationStatusEnum.INACTIVE.getValue());
userCompanyDelegationRepository.save(userCompanyDelegationEntity);
}
UploadFileOnAmazonS3 uploadFileOnAmazonS3 = uploadFileOnAmazonS3(file);
userCompanyDelegationEntity = new UserCompanyDelegationEntity();
userCompanyDelegationEntity.setCompanyId(companyId);
userCompanyDelegationEntity.setUserId(userEntity.getId());
if (userEntity.getBeneficiary() != null) {
userCompanyDelegationEntity.setBeneficiaryId(userEntity.getBeneficiary().getId());
}
userCompanyDelegationEntity.setStatus(UserCompanyDelegationStatusEnum.ACTIVE.getValue());
userCompanyDelegationEntity.setFileName(uploadFileOnAmazonS3.fileName());
userCompanyDelegationEntity.setFilePath(uploadFileOnAmazonS3.filepath());
userCompanyDelegationRepository.save(userCompanyDelegationEntity);
return convertUserCompanyDelegationToCompanyDelegationResponse(userCompanyDelegationEntity);
}
private CompanyDelegationResponse convertUserCompanyDelegationToCompanyDelegationResponse(
UserCompanyDelegationEntity userCompanyDelegationEntity) {
return Utils.convertSourceObjectToDestinationObject(userCompanyDelegationEntity, CompanyDelegationResponse.class);
}
private UploadFileOnAmazonS3 uploadFileOnAmazonS3(MultipartFile file){
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
String fileName = org.springframework.util.StringUtils.cleanPath(file.getOriginalFilename());
String firstNameContain = fileName.substring(0, fileName.lastIndexOf('.'));
firstNameContain+=Utils.randomKey(5);
fileName = (firstNameContain + "." + extension);
try {
String filepath = amazonS3Service.upload(fileName, s3Folder, file);
return new UploadFileOnAmazonS3(fileName, filepath);
} catch (Exception e) {
throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.UPLOAD_ERROR_S3));
}
}
private record UploadFileOnAmazonS3(String fileName, String filepath) {
}
private void validateFileType(MultipartFile file) {
if (file.isEmpty()) {
throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.VALIDATION_ERROR_FILE_EMPTY));
}
String filename = file.getOriginalFilename();
if (filename == null || !filename.endsWith(".p7m")) {
throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.VALIDATION_ERROR_FILE_INVALIDTYPE));
}
}
public CompanyDelegationResponse getCompanyDelegation(UserEntity userEntity, Long companyId) {
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
.findByUserIdAndCompanyIdAndStatus(userEntity.getId(), companyId,
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
companyDao.getUserWithCompany(userEntity.getId(), companyId);
if(userCompanyDelegationEntity == null) {
throw new ResourceNotFoundException(Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.DELEGATION_NOT_FOUND));
}
return convertUserCompanyDelegationToCompanyDelegationResponse(userCompanyDelegationEntity);
}
public void deleteCompanyDelegation(UserEntity userEntity, Long companyId) {
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
.findByUserIdAndCompanyIdAndStatus(userEntity.getId(), companyId,
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
companyDao.getUserWithCompany(userEntity.getId(), companyId);
if(userCompanyDelegationEntity == null) {
throw new ResourceNotFoundException(Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.DELEGATION_NOT_FOUND));
}
userCompanyDelegationEntity.setStatus(UserCompanyDelegationStatusEnum.INACTIVE.getValue());
userCompanyDelegationRepository.save(userCompanyDelegationEntity);
}
}

View File

@@ -6,6 +6,7 @@ import java.util.stream.Collectors;
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
@@ -40,6 +41,9 @@ public class DocumentDao {
@Autowired
private CallService callService;
@Value("${aws.s3.url.folder}")
private String s3Folder;
public List<DocumentResponseBean> uploadFiles(List<MultipartFile> files, Long sourceId, DocumentSourceTypeEnum sourceType, DocumentTypeEnum fileType) {
List<DocumentEntity> documentEntities = new ArrayList<>();
@@ -81,7 +85,7 @@ public class DocumentDao {
String fileName = StringUtils.cleanPath(file.getOriginalFilename());
String firstNameContain = fileName.substring(0, fileName.lastIndexOf('.'));
fileName = (firstNameContain + "." + extension);
String filepath = amazonS3Service.upload(fileName, file);
String filepath = amazonS3Service.upload(fileName, s3Folder, file);
uploadFileOnAmazonS3 result = new uploadFileOnAmazonS3(fileName, filepath);
return result;
}
@@ -99,7 +103,7 @@ public class DocumentDao {
private DocumentEntity deleteFileOnAmazonS3(String fileName) {
try {
amazonS3Service.delete(fileName);
amazonS3Service.delete(s3Folder, fileName);
} catch (Exception e) {
}
return null;

View File

@@ -83,6 +83,12 @@ public class UserDao {
beneficiaryEntity.setLastName(userReq.getLastName());
beneficiaryEntity.setOrganization(userReq.getOrganization());
beneficiaryEntity.setPhoneNumber(userReq.getPhoneNumber());
beneficiaryEntity.setPrivacy(userReq.getPrivacy());
beneficiaryEntity.setTerms(userReq.getTerms());
beneficiaryEntity.setOffers(userReq.getOffers());
beneficiaryEntity.setMarketing(userReq.getMarketing());
beneficiaryEntity.setThirdParty(userReq.getThirdParty());
beneficiaryEntity.setEmailPec(userReq.getEmailPec());
beneficiaryEntity =beneficiaryRepository.save(beneficiaryEntity);
}
return beneficiaryEntity;
@@ -148,10 +154,16 @@ public class UserDao {
setIfUpdated(userEntity::getOrganization, userEntity::setOrganization, userReq.getOrganization());
setIfUpdated(userEntity::getAddress, userEntity::setAddress, userReq.getAddress());
setIfUpdated(userEntity::getPhoneNumber, userEntity::setPhoneNumber, userReq.getPhoneNumber());
setIfUpdated(userEntity::getDateOfBirth, userEntity::setDateOfBirth, userReq.getDateOfBirth());
setIfUpdated(userEntity.getBeneficiary()::getCodiceFiscale, userEntity.getBeneficiary()::setCodiceFiscale, userReq.getCodiceFiscale());
setIfUpdated(userEntity.getBeneficiary()::getMarketing, userEntity.getBeneficiary()::setMarketing, userReq.getMarketing());
setIfUpdated(userEntity.getBeneficiary()::getOffers, userEntity.getBeneficiary()::setOffers, userReq.getOffers());
setIfUpdated(userEntity.getBeneficiary()::getThirdParty, userEntity.getBeneficiary()::setThirdParty, userReq.getThirdParty());
if (userReq.getRoleId() != null) {
RoleEntity roleEntity = roleDao.validateRole(userReq.getRoleId());
setIfUpdated(userEntity::getRoleEntity, userEntity::setRoleEntity, roleEntity);
}
setIfUpdated(userEntity.getBeneficiary()::getEmailPec, userEntity.getBeneficiary()::setEmailPec, userReq.getEmailPec());
userEntity = userRepository.save(userEntity);
log.info("User updated with ID: {}", userEntity.getId());
return convertUserEntityToUserResponse(userEntity);
@@ -167,6 +179,7 @@ public class UserDao {
userEntity.setStatus(UserStatusEnum.ACTIVE.getValue());
userEntity.setBeneficiary(beneficiary);
if (Boolean.FALSE.equals(RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(roleEntity.getRoleType()))) {
userEntity.setFirstName(userReq.getFirstName());
userEntity.setLastName(userReq.getLastName());
userEntity.setOrganization(userReq.getOrganization());
@@ -216,6 +229,12 @@ public class UserDao {
userResponseBean.setCountry(userEntity.getBeneficiary().getCountry());
userResponseBean.setCodiceFiscale(userEntity.getBeneficiary().getCodiceFiscale());
userResponseBean.setDateOfBirth(userEntity.getBeneficiary().getDateOfBirth());
userResponseBean.setPrivacy(userEntity.getBeneficiary().getPrivacy());
userResponseBean.setTerms(userEntity.getBeneficiary().getTerms());
userResponseBean.setOffers(userEntity.getBeneficiary().getOffers());
userResponseBean.setMarketing(userEntity.getBeneficiary().getMarketing());
userResponseBean.setThirdParty(userEntity.getBeneficiary().getThirdParty());
userResponseBean.setEmailPec(userEntity.getBeneficiary().getEmailPec());
}
return userResponseBean;
}