Merge pull request #29 from Kitzanos/create-beneficiary-and-company-crud
Created beneficiary table and company crud Operations
This commit is contained in:
@@ -17,15 +17,18 @@ import net.gepafin.tendermanagement.service.FormService;
|
||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||
import net.gepafin.tendermanagement.util.FieldValidator;
|
||||
import net.gepafin.tendermanagement.util.Utils;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
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;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
@@ -65,14 +68,17 @@ public class ApplicationDao {
|
||||
|
||||
@Autowired
|
||||
private FlowDataRepository flowDataRepository;
|
||||
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
|
||||
|
||||
public ApplicationResponseBean createApplication(ApplicationRequestBean applicationRequestBean, UserEntity userEntity, Long formId,Long applicationId) {
|
||||
public ApplicationResponseBean createApplication(ApplicationRequestBean applicationRequestBean, UserEntity userEntity, Long formId, Long applicationId) {
|
||||
FormEntity formEntity = formService.validateForm(formId);
|
||||
CallEntity call = callService.validatePublishedCall(formEntity.getCall().getId());
|
||||
callService.validatePublishedCall(formEntity.getCall().getId());
|
||||
validateFormFields(applicationRequestBean,formEntity);
|
||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||
if(Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.SUBMIT.getValue()))){
|
||||
if(Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.SUBMIT.getValue()))) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_SUBMITTED));
|
||||
}
|
||||
formService.validateFormField(applicationRequestBean.getFormFields(),applicationEntity,formEntity);
|
||||
@@ -94,9 +100,10 @@ public class ApplicationDao {
|
||||
return applicationFormEntity;
|
||||
}
|
||||
|
||||
public ApplicationEntity createApplicationEntity(UserEntity user, CallEntity call) {
|
||||
public ApplicationEntity createApplicationEntity(UserEntity user, CallEntity call, CompanyEntity companyEntity) {
|
||||
ApplicationEntity entity = new ApplicationEntity();
|
||||
entity.setUser(user);
|
||||
entity.setUserId(user.getId());
|
||||
entity.setCompany(companyEntity);
|
||||
entity.setCall(call);
|
||||
entity.setIsDeleted(false);
|
||||
entity.setStatus(ApplicationStatusTypeEnum.DRAFT.getValue());
|
||||
@@ -109,7 +116,6 @@ public class ApplicationDao {
|
||||
ApplicationEntity applicationEntity = validateApplication(id);
|
||||
ApplicationFormEntity applicationFormEntity = applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(),formId);
|
||||
List<ApplicationFormFieldResponseBean> applicationFormFieldResponseBeans=new ArrayList<>();
|
||||
ApplicationFormFieldResponseBean applicationFormFieldResponseBeans1=null;
|
||||
List<ApplicationFormFieldEntity> applicationFormFieldEntities = applicationFormFieldRepository.findByApplicationFormId(applicationFormEntity.getId());
|
||||
applicationFormFieldResponseBeans=createApplicationFormFieldResponse(applicationFormFieldEntities, applicationFormEntity, applicationFormFieldResponseBeans);
|
||||
ApplicationResponseBean applicationResponseBean= convertApplicationEntityToApplicationResponseBean(applicationEntity);
|
||||
@@ -170,44 +176,74 @@ public class ApplicationDao {
|
||||
log.info("Application deleted with ID: {}", id);
|
||||
}
|
||||
|
||||
public List<ApplicationResponse> getAllApplications(UserEntity userEntity, Long callId) {
|
||||
boolean isBeneficiary = isBeneficiary(userEntity);
|
||||
|
||||
// public List<ApplicationResponse> getAllApplications(UserEntity userEntity, Long callId, CompanyEntity companyEntity) {
|
||||
// boolean isBeneficiary = validator.checkIsBeneficiary();
|
||||
//
|
||||
// log.info("Fetching applications for RoleType: {}", userEntity.getRoleEntity().getRoleType());
|
||||
// List<ApplicationResponse> applicationResponses = new ArrayList<>();
|
||||
//
|
||||
// if (callId != null) {
|
||||
// // Fetch based on callId and user if role is BENEFICIARY, otherwise fetch all for the call
|
||||
// log.info("Fetching applications for callId: {}", callId);
|
||||
// CallEntity call = callService.validateCall(callId);
|
||||
//
|
||||
// // Use a single method to handle both conditions for consistency
|
||||
// List<ApplicationEntity> applicationEntities = isBeneficiary
|
||||
// ? applicationRepository.findByUserIdAndCallIdAndIsDeletedFalse(userEntity.getId(), call.getId())
|
||||
// .map(List::of) // Convert Optional<ApplicationEntity> to a List of one element
|
||||
// .orElse(List.of()) // If not present, return an empty list
|
||||
// : applicationRepository.findByCallIdAndIsDeletedFalse(call.getId());
|
||||
//
|
||||
// applicationResponses = applicationEntities.stream()
|
||||
// .map(this::getApplicationResponse)
|
||||
// .collect(Collectors.toList());
|
||||
//
|
||||
// } else {
|
||||
// // Fetch all applications for the user if BENEFICIARY, or fetch all applications in general
|
||||
// List<ApplicationEntity> applicationEntities = isBeneficiary
|
||||
// ? applicationRepository.findByUserIdAndIsDeletedFalse(companyEntity.getId())
|
||||
// : applicationRepository.findByIsDeletedFalse();
|
||||
//
|
||||
// applicationResponses = applicationEntities.stream()
|
||||
// .map(this::getApplicationResponse)
|
||||
// .collect(Collectors.toList());
|
||||
// }
|
||||
//
|
||||
// return applicationResponses;
|
||||
// }
|
||||
|
||||
public List<ApplicationResponse> getAllApplications(UserEntity userEntity, Long callId, Long companyId) {
|
||||
|
||||
log.info("Fetching applications for RoleType: {}", userEntity.getRoleEntity().getRoleType());
|
||||
List<ApplicationResponse> applicationResponses = new ArrayList<>();
|
||||
|
||||
if (callId != null) {
|
||||
// Fetch based on callId and user if role is BENEFICIARY, otherwise fetch all for the call
|
||||
log.info("Fetching applications for callId: {}", callId);
|
||||
CallEntity call = callService.validateCall(callId);
|
||||
Specification<ApplicationEntity> spec = search(userEntity.getId(), callId, companyId);
|
||||
|
||||
// Use a single method to handle both conditions for consistency
|
||||
List<ApplicationEntity> applicationEntities = isBeneficiary
|
||||
? applicationRepository.findByUserIdAndCallIdAndIsDeletedFalse(userEntity.getId(), call.getId())
|
||||
.map(List::of) // Convert Optional<ApplicationEntity> to a List of one element
|
||||
.orElse(List.of()) // If not present, return an empty list
|
||||
: applicationRepository.findByCallIdAndIsDeletedFalse(call.getId());
|
||||
List<ApplicationEntity> applicationEntities = applicationRepository.findAll(spec);
|
||||
|
||||
applicationResponses = applicationEntities.stream()
|
||||
.map(this::getApplicationResponse)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
} else {
|
||||
// Fetch all applications for the user if BENEFICIARY, or fetch all applications in general
|
||||
List<ApplicationEntity> applicationEntities = isBeneficiary
|
||||
? applicationRepository.findByUserIdAndIsDeletedFalse(userEntity.getId())
|
||||
: applicationRepository.findByIsDeletedFalse();
|
||||
|
||||
applicationResponses = applicationEntities.stream()
|
||||
.map(this::getApplicationResponse)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return applicationResponses;
|
||||
return applicationEntities.stream()
|
||||
.map(this::getApplicationResponse)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
private ApplicationResponse getApplicationResponse(ApplicationEntity applicationEntity) {
|
||||
private Specification<ApplicationEntity> search(Long userId, Long callId, Long companyId) {
|
||||
return (root, query, builder) -> {
|
||||
Boolean isBeneficiary = validator.checkIsBeneficiary();
|
||||
Predicate predicate = builder.isFalse(root.get("isDeleted"));
|
||||
if (isBeneficiary) {
|
||||
predicate = builder.and(predicate, builder.equal(root.get("userId"), userId));
|
||||
}
|
||||
if (callId != null) {
|
||||
predicate = builder.and(predicate, builder.equal(root.get("call").get("id"), callId));
|
||||
}
|
||||
if (companyId != null) {
|
||||
predicate = builder.and(predicate, builder.equal(root.get("company").get("id"), companyId));
|
||||
}
|
||||
return predicate;
|
||||
};
|
||||
}
|
||||
|
||||
private ApplicationResponse getApplicationResponse(ApplicationEntity applicationEntity) {
|
||||
ApplicationResponse responseBean = new ApplicationResponse();
|
||||
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
|
||||
Long totalFormSteps = flowFormDao.calculateTotalSteps(flowEdgesList);
|
||||
@@ -222,13 +258,17 @@ public class ApplicationDao {
|
||||
responseBean.setSubmissionDate(applicationEntity.getSubmissionDate());
|
||||
responseBean.setStatus(applicationEntity.getStatus());
|
||||
responseBean.setComments(applicationEntity.getComments());
|
||||
responseBean.setCompanyId(applicationEntity.getCompany().getId());
|
||||
responseBean.setCompanyName(applicationEntity.getCompany().getCompanyName());
|
||||
return responseBean;
|
||||
}
|
||||
|
||||
public ApplicationEntity validateApplication(Long id) {
|
||||
ApplicationEntity applicationEntity= applicationRepository.findById(id).orElseThrow(() ->new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.APPLICATION_NOT_FOUND_MSG)));
|
||||
return applicationEntity;
|
||||
}
|
||||
public ApplicationEntity validateApplication(Long id) {
|
||||
ApplicationEntity applicationEntity = applicationRepository.findById(id)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.APPLICATION_NOT_FOUND_MSG)));
|
||||
return applicationEntity;
|
||||
}
|
||||
|
||||
private ApplicationResponseBean convertApplicationEntityToApplicationResponseBean(ApplicationEntity entity) {
|
||||
ApplicationResponseBean response = new ApplicationResponseBean();
|
||||
@@ -348,20 +388,19 @@ public class ApplicationDao {
|
||||
return applicationEntity;
|
||||
}
|
||||
|
||||
public ApplicationGetResponseBean getApplicationByFormId( Long applicationId,Long formId, UserEntity userEntity) {
|
||||
public ApplicationGetResponseBean getApplicationByFormId( Long applicationId, Long formId, UserEntity userEntity) {
|
||||
List<FormApplicationResponse> formApplicationResponses = new ArrayList<>();
|
||||
List<FormEntity> formEntities = new ArrayList<>();
|
||||
boolean isBeneficiary = isBeneficiary(userEntity);
|
||||
ApplicationEntity applicationEntity = isBeneficiary
|
||||
? applicationRepository.findByIdAndUserIdAndIsDeletedFalse(applicationId,userEntity.getId())
|
||||
? applicationRepository.findByIdAndUserIdAndIsDeletedFalse(applicationId, userEntity.getId())
|
||||
.orElseThrow(() -> new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_NOT_FOUND_MSG)))
|
||||
: applicationRepository.findById(applicationId)
|
||||
.stream().findFirst()
|
||||
.orElseThrow(() -> new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_NOT_FOUND_MSG)));
|
||||
|
||||
if (formId != null) {
|
||||
FormEntity formEntity = formService.validateForm(formId);
|
||||
Optional<ApplicationEntity> application = applicationRepository.findByUserIdAndCallIdAndIsDeletedFalse(userEntity.getId(),
|
||||
Optional<ApplicationEntity> application = applicationRepository.findByIdAndUserIdAndCallIdAndIsDeletedFalse(applicationId, userEntity.getId(),
|
||||
formEntity.getCall().getId());
|
||||
applicationEntity=application.get();
|
||||
formEntities.add(formEntity);
|
||||
@@ -421,6 +460,8 @@ public class ApplicationDao {
|
||||
applicationGetResponseBean.setSubmissionDate(applicationEntity.getSubmissionDate());
|
||||
applicationGetResponseBean.setCallId(applicationEntity.getCall().getId());
|
||||
applicationGetResponseBean.setCallTitle(applicationEntity.getCall().getName());
|
||||
applicationGetResponseBean.setCompanyId(applicationEntity.getCompany().getId());
|
||||
applicationGetResponseBean.setCompanyName(applicationEntity.getCompany().getCompanyName());
|
||||
return applicationGetResponseBean;
|
||||
}
|
||||
|
||||
@@ -433,36 +474,29 @@ public class ApplicationDao {
|
||||
return formApplicationResponse;
|
||||
}
|
||||
|
||||
public ApplicationResponse createApplicationByCallId(ApplicationRequest applicationRequest,Long callId,UserEntity userEntity){
|
||||
CallEntity call=callService.validateCall(callId);
|
||||
call = callService.validatePublishedCall(call.getId());
|
||||
checkIfApplicationExists(call,userEntity);
|
||||
ApplicationEntity applicationEntity=createApplicationEntity(userEntity,call);
|
||||
applicationEntity.setComments(applicationRequest.getComments());
|
||||
applicationEntity=saveApplicationEntity(applicationEntity);
|
||||
ApplicationResponse applicationResponse=getApplicationResponse(applicationEntity);
|
||||
return applicationResponse;
|
||||
}
|
||||
public void checkIfApplicationExists(CallEntity call,UserEntity userEntity){
|
||||
Optional<ApplicationEntity> applicationEntity=applicationRepository.findByUserIdAndCallIdAndIsDeletedFalse(userEntity.getId(),call.getId());
|
||||
public ApplicationResponse createApplicationByCallId(CompanyEntity companyEntity,
|
||||
ApplicationRequest applicationRequest, Long callId, UserEntity userEntity) {
|
||||
CallEntity call = callService.validateCall(callId);
|
||||
call = callService.validatePublishedCall(call.getId());
|
||||
checkIfApplicationExists(call, companyEntity);
|
||||
ApplicationEntity applicationEntity = createApplicationEntity(userEntity, call, companyEntity);
|
||||
applicationEntity.setComments(applicationRequest.getComments());
|
||||
applicationEntity = saveApplicationEntity(applicationEntity);
|
||||
ApplicationResponse applicationResponse = getApplicationResponse(applicationEntity);
|
||||
return applicationResponse;
|
||||
}
|
||||
public void checkIfApplicationExists(CallEntity call, CompanyEntity companyEntity){
|
||||
Optional<ApplicationEntity> applicationEntity=applicationRepository.findByCompanyIdAndCallIdAndIsDeletedFalse(companyEntity.getId(),call.getId());
|
||||
if(applicationEntity.isPresent()){
|
||||
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_EXISTS));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ApplicationEntity getApplicationByCallAndUser(CallEntity call, UserEntity userEntity) {
|
||||
return applicationRepository.findByUserIdAndCallIdAndIsDeletedFalse(userEntity.getId(), call.getId())
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.APPLICATION_NOT_FOUND_MSG)));
|
||||
|
||||
}
|
||||
|
||||
public void updateApplicationStatus(Long applicationId, ApplicationStatusTypeEnum status) {
|
||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||
|
||||
if (status.equals(ApplicationStatusTypeEnum.SUBMIT)) {
|
||||
CallEntity callEntity = applicationEntity.getCall();
|
||||
// CallEntity callEntity = applicationEntity.getCall();
|
||||
// Long initialFormId = callEntity.getInitialForm();
|
||||
// Long finalFormId = callEntity.getFinalForm();
|
||||
//// if (initialFormId == null || finalFormId == null) {
|
||||
@@ -500,7 +534,7 @@ public class ApplicationDao {
|
||||
return (int) Math.round(progress);
|
||||
}
|
||||
public void validateFormFields(ApplicationRequestBean request, FormEntity formEntity) {
|
||||
List<String> errors=new ArrayList<>();
|
||||
|
||||
List<ContentResponseBean> contentResponseBeans=Utils.convertJsonStringToList(formEntity.getContent(),ContentResponseBean.class);
|
||||
|
||||
List<ApplicationFormFieldRequestBean> requestFields = request.getFormFields();
|
||||
|
||||
161
src/main/java/net/gepafin/tendermanagement/dao/CompanyDao.java
Normal file
161
src/main/java/net/gepafin/tendermanagement/dao/CompanyDao.java
Normal file
@@ -0,0 +1,161 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.CompanyEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserWithCompanyEntity;
|
||||
import net.gepafin.tendermanagement.model.request.CompanyRequest;
|
||||
import net.gepafin.tendermanagement.model.response.CompanyResponse;
|
||||
import net.gepafin.tendermanagement.repositories.CompanyRepository;
|
||||
import net.gepafin.tendermanagement.repositories.UserWithCompanyRepository;
|
||||
import net.gepafin.tendermanagement.service.UserService;
|
||||
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 CompanyDao {
|
||||
|
||||
@Autowired
|
||||
private CompanyRepository companyRepository;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private UserWithCompanyRepository userWithCompanyRepository;
|
||||
|
||||
public CompanyResponse createCompany(UserEntity userEntity, CompanyRequest companyRequest) {
|
||||
validateCompany(companyRequest);
|
||||
CompanyEntity companyEntity = convertCompanyRequestToCompanyEntity(companyRequest);
|
||||
companyRepository.save(companyEntity);
|
||||
createUserWithCompanyRelation(userEntity, companyEntity);
|
||||
return convertCompanyEntityToCompanyResponse(companyEntity);
|
||||
}
|
||||
|
||||
private void validateCompany(CompanyRequest companyRequest) {
|
||||
|
||||
if (Boolean.FALSE.equals(StringUtils.isEmpty(companyRequest.getEmail()))
|
||||
&& Boolean.FALSE.equals(Utils.isValidEmail(companyRequest.getEmail()))) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.INVALID_EMAIL));
|
||||
}
|
||||
if (StringUtils.isEmpty(companyRequest.getVatNumber())) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.VATNUMBER_MANDATORY));
|
||||
}
|
||||
if (companyRepository.existsByVatNumber(companyRequest.getVatNumber())) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.VATNUMBER_ALREADY_EXISTS));
|
||||
}
|
||||
}
|
||||
|
||||
private UserWithCompanyEntity createUserWithCompanyRelation(UserEntity userEntity, CompanyEntity companyEntity) {
|
||||
UserWithCompanyEntity userWithCompanyEntity = new UserWithCompanyEntity();
|
||||
if (userEntity.getBeneficiary() != null) {
|
||||
userWithCompanyEntity.setBeneficiaryId(userEntity.getBeneficiary().getId());
|
||||
}
|
||||
userWithCompanyEntity.setCompanyId(companyEntity.getId());
|
||||
userWithCompanyEntity.setUserId(userEntity.getId());
|
||||
return userWithCompanyRepository.save(userWithCompanyEntity);
|
||||
}
|
||||
|
||||
private CompanyEntity convertCompanyRequestToCompanyEntity(CompanyRequest request) {
|
||||
CompanyEntity entity = new CompanyEntity();
|
||||
entity.setCompanyName(request.getCompanyName());
|
||||
entity.setVatNumber(request.getVatNumber());
|
||||
entity.setCodiceFiscale(request.getCodiceFiscale());
|
||||
entity.setAddress(request.getAddress());
|
||||
entity.setPhoneNumber(request.getPhoneNumber());
|
||||
entity.setCity(request.getCity());
|
||||
entity.setProvince(request.getProvince());
|
||||
entity.setCap(request.getCap());
|
||||
entity.setCountry(request.getCountry());
|
||||
entity.setPec(request.getPec());
|
||||
entity.setEmail(request.getEmail());
|
||||
entity.setNumberOfEmployees(request.getNumberOfEmployees());
|
||||
entity.setAnnualRevenue(request.getAnnualRevenue());
|
||||
return entity;
|
||||
}
|
||||
|
||||
private CompanyResponse convertCompanyEntityToCompanyResponse(CompanyEntity entity) {
|
||||
CompanyResponse response = new CompanyResponse();
|
||||
response.setId(entity.getId());
|
||||
response.setCompanyName(entity.getCompanyName());
|
||||
response.setVatNumber(entity.getVatNumber());
|
||||
response.setCodiceFiscale(entity.getCodiceFiscale());
|
||||
response.setAddress(entity.getAddress());
|
||||
response.setPhoneNumber(entity.getPhoneNumber());
|
||||
response.setCity(entity.getCity());
|
||||
response.setProvince(entity.getProvince());
|
||||
response.setCap(entity.getCap());
|
||||
response.setCountry(entity.getCountry());
|
||||
response.setPec(entity.getPec());
|
||||
response.setEmail(entity.getEmail());
|
||||
response.setNumberOfEmployees(entity.getNumberOfEmployees());
|
||||
response.setAnnualRevenue(entity.getAnnualRevenue());
|
||||
response.setCreatedDate(entity.getCreatedDate());
|
||||
response.setUpdatedDate(entity.getUpdatedDate());
|
||||
return response;
|
||||
}
|
||||
|
||||
public CompanyResponse updateCompany(UserEntity userEntity, Long companyId, CompanyRequest companyRequest) {
|
||||
CompanyEntity companyEntity = validateCompany(companyId);
|
||||
Utils.setIfUpdated(companyEntity::getCompanyName, companyEntity::setCompanyName,
|
||||
companyRequest.getCompanyName());
|
||||
Utils.setIfUpdated(companyEntity::getVatNumber, companyEntity::setVatNumber, companyRequest.getVatNumber());
|
||||
Utils.setIfUpdated(companyEntity::getCodiceFiscale, companyEntity::setCodiceFiscale,
|
||||
companyRequest.getCodiceFiscale());
|
||||
Utils.setIfUpdated(companyEntity::getAddress, companyEntity::setAddress, companyRequest.getAddress());
|
||||
Utils.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,
|
||||
companyRequest.getNumberOfEmployees());
|
||||
Utils.setIfUpdated(companyEntity::getAnnualRevenue, companyEntity::setAnnualRevenue,
|
||||
companyRequest.getAnnualRevenue());
|
||||
companyRepository.save(companyEntity);
|
||||
return convertCompanyEntityToCompanyResponse(companyEntity);
|
||||
}
|
||||
|
||||
public CompanyEntity validateCompany(Long 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) {
|
||||
return convertCompanyEntityToCompanyResponse(validateCompany(companyId));
|
||||
}
|
||||
|
||||
public void deleteCompany(UserEntity userEntity, Long companyId) {
|
||||
CompanyEntity companyEntity = validateCompany(companyId);
|
||||
companyRepository.delete(companyEntity);
|
||||
userWithCompanyRepository.deleteByCompanyId(companyId);
|
||||
}
|
||||
|
||||
public List<CompanyResponse> getCompanyByUserId(Long userId) {
|
||||
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();
|
||||
}
|
||||
|
||||
public UserWithCompanyEntity validateUserWithCompny(Long userId, Long companyId) {
|
||||
return userWithCompanyRepository.findByUserIdAndCompanyId(userId, companyId).orElseThrow(() -> new CustomValidationException(Status.UNAUTHORIZED,
|
||||
Translator.toLocale(GepafinConstant.UNAUTHORIZED)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,8 +12,11 @@ import net.gepafin.tendermanagement.model.request.FaqReq;
|
||||
import net.gepafin.tendermanagement.model.response.FaqResponseBean;
|
||||
import net.gepafin.tendermanagement.repositories.FaqRepository;
|
||||
import net.gepafin.tendermanagement.service.CallService;
|
||||
import net.gepafin.tendermanagement.service.CompanyService;
|
||||
import net.gepafin.tendermanagement.service.LookUpDataService;
|
||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
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;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -35,12 +38,25 @@ public class FaqDao {
|
||||
|
||||
@Autowired
|
||||
private LookUpDataService lookUpDataService;
|
||||
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
|
||||
@Autowired
|
||||
private CompanyService companyService;
|
||||
|
||||
public FaqResponseBean createFaq(FaqReq faqRequest, UserEntity userEntity, Long callId) {
|
||||
FaqEntity entity = new FaqEntity();
|
||||
public FaqResponseBean createFaq(FaqReq faqRequest, UserEntity userEntity, Long callId, Long companyId) {
|
||||
CallEntity callEntity = callService.validateCall(callId);
|
||||
entity = createOrUpdateFaqEntity(faqRequest, callEntity, userEntity,
|
||||
FaqEntity entity = createOrUpdateFaqEntity(faqRequest, callEntity, userEntity,
|
||||
LookUpDataEntity.LookUpDataTypeEnum.FAQ);
|
||||
if (validator.checkIsBeneficiary() && companyId == null) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.COMPANY_ID_MANDATORY));
|
||||
}
|
||||
if(companyId!=null) {
|
||||
companyService.validateCompany(companyId);
|
||||
entity.setCompanyId(companyId);
|
||||
}
|
||||
faqRepository.save(entity);
|
||||
return convertToFaqResponseBean(entity);
|
||||
}
|
||||
|
||||
@@ -4,20 +4,16 @@ import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.CallEntity;
|
||||
import net.gepafin.tendermanagement.entities.FlowDataEntity;
|
||||
import net.gepafin.tendermanagement.entities.FlowDataEntity;
|
||||
import net.gepafin.tendermanagement.entities.FlowEdgesEntity;
|
||||
import net.gepafin.tendermanagement.enums.CallStatusEnum;
|
||||
import net.gepafin.tendermanagement.model.request.FlowDataRequestBean;
|
||||
import net.gepafin.tendermanagement.model.request.FlowEdgesRequestBean;
|
||||
import net.gepafin.tendermanagement.model.request.FlowRequestBean;
|
||||
import net.gepafin.tendermanagement.model.response.EvaluationCriteriaResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.FlowDataResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.FlowEdgesResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.FlowResponseBean;
|
||||
import net.gepafin.tendermanagement.repositories.CallRepository;
|
||||
import net.gepafin.tendermanagement.repositories.FlowDataRepository;
|
||||
import net.gepafin.tendermanagement.repositories.FlowDataRepository;
|
||||
import net.gepafin.tendermanagement.repositories.FlowEdgesRepository;
|
||||
import net.gepafin.tendermanagement.repositories.FlowEdgesRepository;
|
||||
import net.gepafin.tendermanagement.service.CallService;
|
||||
import net.gepafin.tendermanagement.service.FormService;
|
||||
@@ -29,7 +25,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.repositories.*;
|
||||
@@ -20,7 +19,6 @@ import net.gepafin.tendermanagement.enums.FormActionEnum;
|
||||
import net.gepafin.tendermanagement.model.response.NextOrPreviousFormResponse;
|
||||
import net.gepafin.tendermanagement.service.FormService;
|
||||
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
|
||||
@@ -296,6 +294,8 @@ public class FlowFormDao {
|
||||
applicationDao.processForm(formEntity, applicationEntity));
|
||||
nextOrPreviousFormResponse.setCallId(applicationEntity.getCall().getId());
|
||||
nextOrPreviousFormResponse.setCallTitle(applicationEntity.getCall().getName());
|
||||
nextOrPreviousFormResponse.setCompanyId(applicationEntity.getCompany().getId());
|
||||
nextOrPreviousFormResponse.setCompanyName(applicationEntity.getCompany().getCompanyName());
|
||||
|
||||
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
|
||||
Long totalFormSteps = calculateTotalSteps(flowEdgesList);
|
||||
|
||||
@@ -4,6 +4,7 @@ import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.BeneficiaryEntity;
|
||||
import net.gepafin.tendermanagement.entities.RoleEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||
@@ -13,6 +14,7 @@ import net.gepafin.tendermanagement.model.response.RoleResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.UserSamlResponse;
|
||||
import net.gepafin.tendermanagement.model.response.UserResponseBean;
|
||||
import net.gepafin.tendermanagement.model.util.JWTToken;
|
||||
import net.gepafin.tendermanagement.repositories.BeneficiaryRepository;
|
||||
import net.gepafin.tendermanagement.repositories.UserRepository;
|
||||
import net.gepafin.tendermanagement.service.impl.AuthenticationService;
|
||||
import net.gepafin.tendermanagement.util.Utils;
|
||||
@@ -29,8 +31,6 @@ import org.springframework.stereotype.Repository;
|
||||
|
||||
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Repository
|
||||
public class UserDao {
|
||||
|
||||
@@ -47,10 +47,42 @@ public class UserDao {
|
||||
|
||||
@Autowired
|
||||
private RoleDao roleDao;
|
||||
|
||||
@Autowired
|
||||
private BeneficiaryRepository beneficiaryRepository;
|
||||
|
||||
|
||||
public JWTToken createUser(HttpServletRequest request, String tempToken, UserReq userReq) {
|
||||
|
||||
if (Boolean.FALSE.equals(isValidEmail(userReq.getEmail()))) {
|
||||
validateUserRequest(tempToken, userReq);
|
||||
validatePassword(userReq.getPassword(), userReq.getConfPassword(), tempToken);
|
||||
|
||||
RoleEntity roleEntity = getRoleEntity(userReq.getRoleId());
|
||||
BeneficiaryEntity beneficiary = createBeneficiary(roleEntity, userReq);
|
||||
UserEntity userEntity = convertUserRequestToUserEntity(beneficiary, roleEntity, userReq);
|
||||
log.info("User created with ID: {}", userEntity.getId());
|
||||
return authService.getJWTTokenBean(userEntity, Boolean.TRUE);
|
||||
}
|
||||
|
||||
private BeneficiaryEntity createBeneficiary(RoleEntity roleEntity, UserReq userReq) {
|
||||
BeneficiaryEntity beneficiaryEntity = null;
|
||||
if (RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(roleEntity.getRoleType())) {
|
||||
beneficiaryEntity = new BeneficiaryEntity();
|
||||
beneficiaryEntity.setAddress(userReq.getAddress());
|
||||
beneficiaryEntity.setCity(userReq.getCity());
|
||||
beneficiaryEntity.setCodiceFiscale(userReq.getCodiceFiscale());
|
||||
beneficiaryEntity.setCountry(userReq.getCountry());
|
||||
beneficiaryEntity.setDateOfBirth(userReq.getDateOfBirth());
|
||||
beneficiaryEntity.setEmail(userReq.getEmail());
|
||||
beneficiaryEntity.setFirstName(userReq.getFirstName());
|
||||
beneficiaryEntity.setLastName(userReq.getLastName());
|
||||
beneficiaryEntity.setOrganization(userReq.getOrganization());
|
||||
beneficiaryEntity.setPhoneNumber(userReq.getPhoneNumber());
|
||||
}
|
||||
return beneficiaryRepository.save(beneficiaryEntity);
|
||||
}
|
||||
|
||||
private void validateUserRequest(String tempToken, UserReq userReq) {
|
||||
if (Boolean.FALSE.equals(Utils.isValidEmail(userReq.getEmail()))) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.VALIDATE_EMAIL));
|
||||
}
|
||||
@@ -61,27 +93,21 @@ public class UserDao {
|
||||
Translator.toLocale(GepafinConstant.EMAIL_ALREADY_EXISTS));
|
||||
}
|
||||
if (Boolean.FALSE.equals(StringUtils.isEmpty(userReq.getCodiceFiscale()))
|
||||
&& userRepository.existsByCodiceFiscale(userReq.getCodiceFiscale())) {
|
||||
&& userRepository.existsByBeneficiaryCodiceFiscale(userReq.getCodiceFiscale())) {
|
||||
log.error("User creation failed: CodiceFiscale {} already exists", userReq.getCodiceFiscale());
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.CODICE_FISCALE_EXISTS));
|
||||
}
|
||||
if (tempToken == null && userReq.getRoleId() == null) {
|
||||
throw new ResourceNotFoundException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.ROLE_ID_MANDATORY));
|
||||
throw new ResourceNotFoundException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.ROLE_ID_MANDATORY));
|
||||
}
|
||||
if(tempToken != null) {
|
||||
userReq.setRoleId(null);
|
||||
if (tempToken != null) {
|
||||
userReq.setRoleId(null);
|
||||
}
|
||||
validatePassword(userReq.getPassword(), userReq.getConfPassword(), tempToken);
|
||||
|
||||
UserEntity userEntity = convertUserRequestToUserEntity(userReq);
|
||||
userEntity = userRepository.save(userEntity);
|
||||
log.info("User created with ID: {}", userEntity.getId());
|
||||
return authService.getJWTTokenBean(userEntity, Boolean.TRUE);
|
||||
}
|
||||
|
||||
private void validatePassword(String password, String confirmPassword, String tempToken) {
|
||||
}
|
||||
|
||||
private void validatePassword(String password, String confirmPassword, String tempToken) {
|
||||
if (StringUtils.isEmpty(password) || StringUtils.isEmpty(confirmPassword)) {
|
||||
if(tempToken == null) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.VALIDATE_PASSWORD));
|
||||
@@ -124,22 +150,24 @@ public class UserDao {
|
||||
return convertUserEntityToUserResponse(userEntity);
|
||||
}
|
||||
|
||||
private UserEntity convertUserRequestToUserEntity(UserReq userReq) {
|
||||
private UserEntity convertUserRequestToUserEntity(BeneficiaryEntity beneficiary, RoleEntity roleEntity, UserReq userReq) {
|
||||
UserEntity userEntity = new UserEntity();
|
||||
if(Boolean.FALSE.equals(StringUtils.isEmpty(userReq.getPassword()))) {
|
||||
userEntity.setPassword(passwordEncoder.encode(userReq.getPassword()));
|
||||
}
|
||||
userEntity.setRoleEntity(roleEntity);
|
||||
userEntity.setEmail(userReq.getEmail());
|
||||
userEntity.setFirstName(userReq.getFirstName());
|
||||
userEntity.setStatus(UserStatusEnum.ACTIVE.getValue());
|
||||
userEntity.setLastName(userReq.getLastName());
|
||||
userEntity.setOrganization(userReq.getOrganization());
|
||||
userEntity.setAddress(userReq.getAddress());
|
||||
userEntity.setPhoneNumber(userReq.getPhoneNumber());
|
||||
userEntity.setRoleEntity(getRoleEntity(userReq.getRoleId()));
|
||||
userEntity.setCodiceFiscale(userReq.getCodiceFiscale());
|
||||
userEntity.setDateOfBirth(userReq.getDateOfBirth());
|
||||
return userEntity;
|
||||
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());
|
||||
userEntity.setAddress(userReq.getAddress());
|
||||
userEntity.setPhoneNumber(userReq.getPhoneNumber());
|
||||
userEntity.setDateOfBirth(userReq.getDateOfBirth());
|
||||
}
|
||||
return userRepository.save(userEntity);
|
||||
}
|
||||
|
||||
private RoleEntity getRoleEntity(Long roleId) {
|
||||
@@ -151,37 +179,48 @@ public class UserDao {
|
||||
}
|
||||
|
||||
private UserResponseBean convertUserEntityToUserResponse(UserEntity userEntity) {
|
||||
UserResponseBean userResponseBean = new UserResponseBean();
|
||||
userResponseBean.setId(userEntity.getId());
|
||||
userResponseBean.setCreatedDate(userEntity.getCreatedDate());
|
||||
userResponseBean.setUpdatedDate(userEntity.getUpdatedDate());
|
||||
userResponseBean.setEmail(userEntity.getEmail());
|
||||
userResponseBean.setFirstName(userEntity.getFirstName());
|
||||
userResponseBean.setLastName(userEntity.getLastName());
|
||||
userResponseBean.setPhoneNumber(userEntity.getPhoneNumber());
|
||||
userResponseBean.setOrganization(userEntity.getOrganization());
|
||||
userResponseBean.setAddress(userEntity.getAddress());
|
||||
userResponseBean.setCity(userEntity.getCity());
|
||||
userResponseBean.setCountry(userEntity.getCountry());
|
||||
userResponseBean.setStatus(UserStatusEnum.valueOf(userEntity.getStatus()));
|
||||
RoleResponseBean roleResponseBean = roleDao.convertRoleEntityToRoleResponse(userEntity.getRoleEntity());
|
||||
userResponseBean.setRole(roleResponseBean);
|
||||
userResponseBean.setLastLogin(userEntity.getLastLogin());
|
||||
userResponseBean.setCodiceFiscale(userEntity.getCodiceFiscale());
|
||||
userResponseBean.setDateOfBirth(userEntity.getDateOfBirth());
|
||||
return userResponseBean;
|
||||
}
|
||||
UserResponseBean userResponseBean = new UserResponseBean();
|
||||
userResponseBean.setId(userEntity.getId());
|
||||
userResponseBean.setCreatedDate(userEntity.getCreatedDate());
|
||||
userResponseBean.setUpdatedDate(userEntity.getUpdatedDate());
|
||||
userResponseBean.setEmail(userEntity.getEmail());
|
||||
userResponseBean.setStatus(UserStatusEnum.valueOf(userEntity.getStatus()));
|
||||
RoleResponseBean roleResponseBean = roleDao.convertRoleEntityToRoleResponse(userEntity.getRoleEntity());
|
||||
userResponseBean.setRole(roleResponseBean);
|
||||
userResponseBean.setLastLogin(userEntity.getLastLogin());
|
||||
if (userEntity.getBeneficiary() == null) {
|
||||
userResponseBean.setFirstName(userEntity.getFirstName());
|
||||
userResponseBean.setLastName(userEntity.getLastName());
|
||||
userResponseBean.setPhoneNumber(userEntity.getPhoneNumber());
|
||||
userResponseBean.setOrganization(userEntity.getOrganization());
|
||||
userResponseBean.setAddress(userEntity.getAddress());
|
||||
userResponseBean.setCity(userEntity.getCity());
|
||||
userResponseBean.setCountry(userEntity.getCountry());
|
||||
userResponseBean.setDateOfBirth(userEntity.getDateOfBirth());
|
||||
} else {
|
||||
userResponseBean.setFirstName(userEntity.getBeneficiary().getFirstName());
|
||||
userResponseBean.setLastName(userEntity.getBeneficiary().getLastName());
|
||||
userResponseBean.setPhoneNumber(userEntity.getBeneficiary().getPhoneNumber());
|
||||
userResponseBean.setOrganization(userEntity.getBeneficiary().getOrganization());
|
||||
userResponseBean.setAddress(userEntity.getBeneficiary().getAddress());
|
||||
userResponseBean.setCity(userEntity.getBeneficiary().getCity());
|
||||
userResponseBean.setCountry(userEntity.getBeneficiary().getCountry());
|
||||
userResponseBean.setCodiceFiscale(userEntity.getBeneficiary().getCodiceFiscale());
|
||||
userResponseBean.setDateOfBirth(userEntity.getBeneficiary().getDateOfBirth());
|
||||
}
|
||||
return userResponseBean;
|
||||
}
|
||||
|
||||
public UserResponseBean getUserById(Long id) {
|
||||
log.info("Fetching user with ID: {}", id);
|
||||
UserEntity userEntity=validateUser(id);
|
||||
public UserResponseBean getUserById(Long id) {
|
||||
log.info("Fetching user with ID: {}", id);
|
||||
UserEntity userEntity = validateUser(id);
|
||||
// if (!UserStatusEnum.ACTIVE.getValue().equals(userEntity.getStatus())) {
|
||||
// log.info("User with ID: {} is not active", id);
|
||||
// throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG));
|
||||
// }
|
||||
log.info("User found: {}", userEntity);
|
||||
return convertUserEntityToUserResponse(userEntity);
|
||||
}
|
||||
log.info("User found: {}", userEntity);
|
||||
return convertUserEntityToUserResponse(userEntity);
|
||||
}
|
||||
|
||||
public void deleteUser(Long id) {
|
||||
log.info("Deleting user with ID: {}", id);
|
||||
@@ -261,16 +300,6 @@ public class UserDao {
|
||||
authService.logout(request, response);
|
||||
log.info("User successfully logged out.");
|
||||
}
|
||||
|
||||
|
||||
public static Boolean isValidEmail(String email) {
|
||||
String EMAIL_REGEX = "^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+$";
|
||||
if (email == null || email.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
Pattern pattern = Pattern.compile(EMAIL_REGEX);
|
||||
return pattern.matcher(email).matches();
|
||||
}
|
||||
|
||||
public UserResponseBean updateUserStatus(Long userId, UserStatusEnum statusReq) {
|
||||
log.info("Updating status for user with ID: {}", userId);
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import feign.FeignException;
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.service.feignClient.VatCheckService;
|
||||
import net.gepafin.tendermanagement.util.Utils;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -67,8 +72,17 @@ public class VatCheckDao {
|
||||
}
|
||||
} catch (FeignException ex) {
|
||||
log.error("Exception occurred while checking vat number: {0}", ex);
|
||||
throw ex;
|
||||
Utils.callException(ex.status(), ex);
|
||||
}
|
||||
return responseBody;
|
||||
}
|
||||
|
||||
public Map<String, Object> checkVatNumber(String vatNumber) {
|
||||
try {
|
||||
return checkVatNumberApi(vatNumber);
|
||||
} catch (Exception e) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user