updated code for get company delegation

This commit is contained in:
rajesh
2024-12-05 22:12:24 +05:30
parent 1790bbf52b
commit cbaf25801f
5 changed files with 49 additions and 23 deletions

View File

@@ -14,6 +14,7 @@ import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
import net.gepafin.tendermanagement.model.response.*; import net.gepafin.tendermanagement.model.response.*;
import net.gepafin.tendermanagement.repositories.*; import net.gepafin.tendermanagement.repositories.*;
import net.gepafin.tendermanagement.service.AmazonS3Service; import net.gepafin.tendermanagement.service.AmazonS3Service;
import net.gepafin.tendermanagement.service.ApplicationEvaluationService;
import net.gepafin.tendermanagement.service.CallService; import net.gepafin.tendermanagement.service.CallService;
import net.gepafin.tendermanagement.service.CompanyService; import net.gepafin.tendermanagement.service.CompanyService;
import net.gepafin.tendermanagement.service.DocumentService; import net.gepafin.tendermanagement.service.DocumentService;
@@ -159,7 +160,7 @@ public class ApplicationDao {
private HttpServletRequest request; private HttpServletRequest request;
@Autowired @Autowired
private TokenProvider tokenProvider; private ApplicationEvaluationService applicationEvaluationService;
public ApplicationResponseBean createApplication(HttpServletRequest request, ApplicationRequestBean applicationRequestBean, Long formId, Long applicationId) { public ApplicationResponseBean createApplication(HttpServletRequest request, ApplicationRequestBean applicationRequestBean, Long formId, Long applicationId) {
FormEntity formEntity = formService.validateForm(formId); FormEntity formEntity = formService.validateForm(formId);
@@ -1110,7 +1111,14 @@ public class ApplicationDao {
public ApplicationSignedDocumentResponse getSignedDocument(HttpServletRequest request, Long applicationId) { public ApplicationSignedDocumentResponse getSignedDocument(HttpServletRequest request, Long applicationId) {
ApplicationEntity applicationEntity = validateApplication(applicationId); ApplicationEntity applicationEntity = validateApplication(applicationId);
validator.validateUserWithCompany(request, applicationEntity.getCompanyId()); // validator.validateUserWithCompany(request, applicationEntity.getCompanyId());
if (validator.checkIsPreInstructor()) {
ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluationByApplicationId(applicationId);
validator.validatePreInstructor(request, applicationEvaluationEntity.getUserId());
} else {
validator.validateUserId(request, applicationEntity.getUserId());
}
ApplicationSignedDocumentEntity applicationSignedDocument = applicationSignedDocumentRepository ApplicationSignedDocumentEntity applicationSignedDocument = applicationSignedDocumentRepository
.findByApplicationIdAndStatus(applicationId, ApplicationSignedDocumentStatusEnum.ACTIVE.getValue()); .findByApplicationIdAndStatus(applicationId, ApplicationSignedDocumentStatusEnum.ACTIVE.getValue());

View File

@@ -1396,5 +1396,12 @@ public class ApplicationEvaluationDao {
} }
return null; return null;
} }
public ApplicationEvaluationEntity validateApplicationEvaluationByApplicationId(Long applicationId) {
return applicationEvaluationRepository
.findByApplicationIdAndIsDeletedFalse(applicationId)
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.APPLICATION_EVALUATION_NOT_FOUND)));
}
} }

View File

@@ -34,6 +34,7 @@ import net.gepafin.tendermanagement.model.response.UserResponseBean;
import net.gepafin.tendermanagement.repositories.DocumentRepository; import net.gepafin.tendermanagement.repositories.DocumentRepository;
import net.gepafin.tendermanagement.repositories.UserCompanyDelegationRepository; import net.gepafin.tendermanagement.repositories.UserCompanyDelegationRepository;
import net.gepafin.tendermanagement.service.AmazonS3Service; import net.gepafin.tendermanagement.service.AmazonS3Service;
import net.gepafin.tendermanagement.service.ApplicationEvaluationService;
import net.gepafin.tendermanagement.service.UserService; import net.gepafin.tendermanagement.service.UserService;
import net.gepafin.tendermanagement.util.DateTimeUtil; import net.gepafin.tendermanagement.util.DateTimeUtil;
import net.gepafin.tendermanagement.util.Utils; import net.gepafin.tendermanagement.util.Utils;
@@ -87,7 +88,7 @@ public class DelegationDao {
private ApplicationService applicationService; private ApplicationService applicationService;
@Autowired @Autowired
private ApplicationEvaluationRepository applicationEvaluationRepository; private ApplicationEvaluationService applicationEvaluationService;
public ByteArrayOutputStream generateDocument(Map<String, String> placeholders, String templateName) { public ByteArrayOutputStream generateDocument(Map<String, String> placeholders, String templateName) {
try { try {
@@ -265,29 +266,11 @@ public class DelegationDao {
} }
public CompanyDelegationResponse getCompanyDelegation(HttpServletRequest request, Long companyId, Long applicationId) { 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(); UserWithCompanyEntity userWithCompanyEntity= validateUserAndGetUserWithCompany(request, companyId, applicationId);
} 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);
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
.findByUserIdAndUserWithCompanyIdAndStatus(userId, userWithCompanyEntity.getId(), .findByUserIdAndUserWithCompanyIdAndStatus(userWithCompanyEntity.getUserId(), userWithCompanyEntity.getId(),
UserCompanyDelegationStatusEnum.ACTIVE.getValue()); UserCompanyDelegationStatusEnum.ACTIVE.getValue());
companyDao.getUserWithCompany(userEntity.getId(), companyId);
if(userCompanyDelegationEntity == null) { if(userCompanyDelegationEntity == null) {
throw new ResourceNotFoundException(Status.NOT_FOUND, throw new ResourceNotFoundException(Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.DELEGATION_NOT_FOUND)); Translator.toLocale(GepafinConstant.DELEGATION_NOT_FOUND));
@@ -295,6 +278,27 @@ public class DelegationDao {
return convertUserCompanyDelegationToCompanyDelegationResponse(userCompanyDelegationEntity); 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) { public void deleteCompanyDelegation(UserEntity userEntity, Long companyId) {
UserWithCompanyEntity userWithCompanyEntity=companyService.getUserWithCompany(userEntity.getId(),companyId); UserWithCompanyEntity userWithCompanyEntity=companyService.getUserWithCompany(userEntity.getId(),companyId);
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository

View File

@@ -16,4 +16,6 @@ public interface ApplicationEvaluationService {
ApplicationEvaluationResponse getApplicationEvaluationByApplicationId(HttpServletRequest request,Long applicationId,Long assignedApplicationId); ApplicationEvaluationResponse getApplicationEvaluationByApplicationId(HttpServletRequest request,Long applicationId,Long assignedApplicationId);
ApplicationEvaluationEntity validateApplicationEvaluation(Long applicationEvaluationId); ApplicationEvaluationEntity validateApplicationEvaluation(Long applicationEvaluationId);
ApplicationEvaluationEntity validateApplicationEvaluationByApplicationId(Long applicationId);
} }

View File

@@ -93,4 +93,9 @@ public class ApplicationEvaluationServiceImpl implements ApplicationEvaluationSe
public ApplicationEvaluationEntity validateApplicationEvaluation(Long applicationEvaluationId) { public ApplicationEvaluationEntity validateApplicationEvaluation(Long applicationEvaluationId) {
return applicationEvaluationDao.validateApplicationEvaluation(applicationEvaluationId); return applicationEvaluationDao.validateApplicationEvaluation(applicationEvaluationId);
} }
@Override
public ApplicationEvaluationEntity validateApplicationEvaluationByApplicationId(Long applicationId) {
return applicationEvaluationDao.validateApplicationEvaluationByApplicationId(applicationId);
}
} }