updated code for get company delegation
This commit is contained in:
@@ -34,6 +34,7 @@ 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.ApplicationEvaluationService;
|
||||
import net.gepafin.tendermanagement.service.UserService;
|
||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||
import net.gepafin.tendermanagement.util.Utils;
|
||||
@@ -87,7 +88,7 @@ public class DelegationDao {
|
||||
private ApplicationService applicationService;
|
||||
|
||||
@Autowired
|
||||
private ApplicationEvaluationRepository applicationEvaluationRepository;
|
||||
private ApplicationEvaluationService applicationEvaluationService;
|
||||
|
||||
public ByteArrayOutputStream generateDocument(Map<String, String> placeholders, String templateName) {
|
||||
try {
|
||||
@@ -265,29 +266,11 @@ public class DelegationDao {
|
||||
}
|
||||
|
||||
public CompanyDelegationResponse getCompanyDelegation(HttpServletRequest request, Long companyId, Long applicationId) {
|
||||
if(companyId==null && applicationId==null){
|
||||
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.ATLEAST_ONE_ID_REQUIRED));
|
||||
}
|
||||
if(validator.checkIsPreInstructor()) {
|
||||
ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationRepository.findByApplicationIdAndIsDeletedFalse(applicationId).orElseThrow(()->
|
||||
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.APPLICATION_EVALUATION_NOT_FOUND, companyId));
|
||||
|
||||
validator.validateUserWithCompany();
|
||||
} else {
|
||||
validator.validateUserWithCompany();
|
||||
}
|
||||
|
||||
Long userId=userEntity.getId();
|
||||
if(applicationId != null) {
|
||||
ApplicationEntity application = applicationService.validateApplication(applicationId);
|
||||
userId=application.getUserId();
|
||||
companyId=application.getCompanyId();
|
||||
}
|
||||
UserWithCompanyEntity userWithCompanyEntity=companyService.getUserWithCompany(userId,companyId);
|
||||
UserWithCompanyEntity userWithCompanyEntity= validateUserAndGetUserWithCompany(request, companyId, applicationId);
|
||||
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
|
||||
.findByUserIdAndUserWithCompanyIdAndStatus(userId, userWithCompanyEntity.getId(),
|
||||
.findByUserIdAndUserWithCompanyIdAndStatus(userWithCompanyEntity.getUserId(), userWithCompanyEntity.getId(),
|
||||
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
|
||||
companyDao.getUserWithCompany(userEntity.getId(), companyId);
|
||||
if(userCompanyDelegationEntity == null) {
|
||||
throw new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.DELEGATION_NOT_FOUND));
|
||||
@@ -295,6 +278,27 @@ public class DelegationDao {
|
||||
return convertUserCompanyDelegationToCompanyDelegationResponse(userCompanyDelegationEntity);
|
||||
}
|
||||
|
||||
private UserWithCompanyEntity validateUserAndGetUserWithCompany(HttpServletRequest request, Long companyId,
|
||||
Long applicationId) {
|
||||
Long userId = null;
|
||||
if (companyId == null && applicationId == null) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST,
|
||||
Translator.toLocale(GepafinConstant.ATLEAST_ONE_ID_REQUIRED));
|
||||
}
|
||||
if (applicationId != null) {
|
||||
ApplicationEntity application = applicationService.validateApplication(applicationId);
|
||||
userId = application.getUserId();
|
||||
companyId = application.getCompanyId();
|
||||
}
|
||||
if (validator.checkIsPreInstructor()) {
|
||||
ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluationByApplicationId(applicationId);
|
||||
validator.validatePreInstructor(request, applicationEvaluationEntity.getUserId());
|
||||
} else if (validator.checkIsBeneficiary()) {
|
||||
userId = validator.validateUser(request).getId();
|
||||
}
|
||||
return companyService.getUserWithCompany(userId, companyId);
|
||||
}
|
||||
|
||||
public void deleteCompanyDelegation(UserEntity userEntity, Long companyId) {
|
||||
UserWithCompanyEntity userWithCompanyEntity=companyService.getUserWithCompany(userEntity.getId(),companyId);
|
||||
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
|
||||
|
||||
Reference in New Issue
Block a user