updated code for company delegation

This commit is contained in:
nisha
2024-12-05 21:12:30 +05:30
parent 87b2d4aaaf
commit 1790bbf52b
8 changed files with 43 additions and 13 deletions

View File

@@ -305,5 +305,6 @@ public class GepafinConstant {
public static final String USER_ID = "userId";
public static final String LOGIN_ATTEMPT_ID = "loginAttemptId";
public static final String USER_ACTION_ID = "userActionId";
public static final String ATLEAST_ONE_ID_REQUIRED="atleast.one.id.required";
}

View File

@@ -5,13 +5,14 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import net.gepafin.tendermanagement.entities.*;
import net.gepafin.tendermanagement.enums.DocOtherSourceTypeEnum;
import net.gepafin.tendermanagement.repositories.ApplicationEvaluationRepository;
import net.gepafin.tendermanagement.repositories.UserWithCompanyRepository;
import net.gepafin.tendermanagement.service.ApplicationService;
import net.gepafin.tendermanagement.service.CompanyService;
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
@@ -82,6 +83,12 @@ public class DelegationDao {
@Autowired
private HttpServletRequest request;
@Autowired
private ApplicationService applicationService;
@Autowired
private ApplicationEvaluationRepository applicationEvaluationRepository;
public ByteArrayOutputStream generateDocument(Map<String, String> placeholders, String templateName) {
try {
String s3Folder = s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.TEMPLATE, 0L, 0L,0L);
@@ -257,10 +264,28 @@ public class DelegationDao {
}
}
public CompanyDelegationResponse getCompanyDelegation(UserEntity userEntity, Long companyId) {
UserWithCompanyEntity userWithCompanyEntity=companyService.getUserWithCompany(userEntity.getId(),companyId);
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);
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
.findByUserIdAndUserWithCompanyIdAndStatus(userEntity.getId(), userWithCompanyEntity.getId(),
.findByUserIdAndUserWithCompanyIdAndStatus(userId, userWithCompanyEntity.getId(),
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
companyDao.getUserWithCompany(userEntity.getId(), companyId);
if(userCompanyDelegationEntity == null) {

View File

@@ -38,7 +38,7 @@ public interface CompanyService {
CompanyDelegationResponse uploadCompanyDelegation(HttpServletRequest request, Long companyId, MultipartFile file);
CompanyDelegationResponse getCompanyDelegation(HttpServletRequest request, Long companyId);
CompanyDelegationResponse getCompanyDelegation(HttpServletRequest request, Long companyId,Long applicationId);
void deleteCompanyDelegation(HttpServletRequest request, Long companyId);
UserWithCompanyEntity getUserWithCompanyEntity(Long userId,Long companyId);

View File

@@ -110,9 +110,8 @@ public class CompanyServiceImpl implements CompanyService {
@Override
@Transactional
public CompanyDelegationResponse getCompanyDelegation(HttpServletRequest request, Long companyId) {
UserEntity userEntity =validator.validateUser(request);
return delegationDao.getCompanyDelegation(userEntity, companyId);
public CompanyDelegationResponse getCompanyDelegation(HttpServletRequest request, Long companyId,Long applicationId) {
return delegationDao.getCompanyDelegation(request, companyId,applicationId);
}
@Override
@Transactional(rollbackFor = Exception.class)

View File

@@ -128,9 +128,10 @@ public interface CompanyApi {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
@GetMapping(value = "{companyId}/delegation", produces = { "application/json" })
@GetMapping(value = "delegation", produces = { "application/json" })
ResponseEntity<Response<CompanyDelegationResponse>> getCompanyDelegation(HttpServletRequest request,
@Parameter(description = "The company id", required = true) @PathVariable("companyId") Long companyId);
@Parameter(description = "The company ID") @RequestParam(value = "companyId", required = false) Long companyId,
@Parameter(description = "The application ID") @RequestParam(value = "applicationId", required = false) Long applicationId);
@Operation(summary = "Api to delete company delegation", responses = { @ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {

View File

@@ -8,6 +8,7 @@ import net.gepafin.tendermanagement.enums.UserActionContextEnum;
import net.gepafin.tendermanagement.enums.UserActionLogsEnum;
import net.gepafin.tendermanagement.model.request.UserActionRequest;
import net.gepafin.tendermanagement.util.LoggingUtil;
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -152,13 +153,13 @@ public class CompanyApiController implements CompanyApi{
@Override
public ResponseEntity<Response<CompanyDelegationResponse>> getCompanyDelegation(HttpServletRequest request,
Long companyId) {
Long companyId,Long applicationId) {
log.info("get company delegation with companyId: {}", companyId);
/** This code is responsible for creating user action logs for the "Get company delegation" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.GET_COMPANY_DELEGATION).build());
CompanyDelegationResponse companyDelegationResponse = companyService.getCompanyDelegation(request, companyId);
CompanyDelegationResponse companyDelegationResponse = companyService.getCompanyDelegation(request, companyId,applicationId);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(companyDelegationResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.DELEGATION_FETCH_SUCCESS)));
}