Merge pull request #100 from Kitzanos/get-only-preferred-call-filter

Added an optional parameter onlyPreferredCall
This commit is contained in:
rbonazzo-KZ
2024-11-20 14:31:50 +01:00
committed by GitHub
9 changed files with 31 additions and 9 deletions

View File

@@ -292,5 +292,7 @@ public class GepafinConstant {
public static final String ENCRYPT_KEY = "U2VjdXJlRW5jcnlwdEtleQ=="; public static final String ENCRYPT_KEY = "U2VjdXJlRW5jcnlwdEtleQ==";
public static final String APPLICATION_DOCUMENTS_NOT_FOUND_MSG = "application.documents.not.found"; public static final String APPLICATION_DOCUMENTS_NOT_FOUND_MSG = "application.documents.not.found";
public static final String DUPLICATE_BENEFICIARY_CALL = "beneficiary.call.duplicate"; public static final String DUPLICATE_BENEFICIARY_CALL = "beneficiary.call.duplicate";
public static final String COMPANY_ID_REQUIRED_FOR_PREFERRED_CALL = "company.id.required.for.preferred.call";
} }

View File

@@ -656,13 +656,29 @@ public class CallDao {
return createCallResponseBean; return createCallResponseBean;
} }
public List<CallDetailsResponseBean> getAllCalls(HttpServletRequest request,UserEntity user, Long companyId) { public List<CallDetailsResponseBean> getAllCalls(HttpServletRequest request,UserEntity user, Long companyId,Boolean onlyPreferredCall) {
String type = user.getRoleEntity().getRoleType(); String type = user.getRoleEntity().getRoleType();
List<String> callStatusList = CallStatusEnum.getStatusValues(); List<String> callStatusList = CallStatusEnum.getStatusValues();
if (Boolean.FALSE.equals(ROLE_SUPER_ADMIN.getValue().equals(type))) { if (Boolean.FALSE.equals(ROLE_SUPER_ADMIN.getValue().equals(type))) {
callStatusList = List.of(CallStatusEnum.PUBLISH.getValue()); callStatusList = List.of(CallStatusEnum.PUBLISH.getValue());
} }
List<CallEntity> calls = callRepository.findByStatusInAndHubId(callStatusList, user.getHub().getId()); List<CallEntity> calls;
if (Boolean.TRUE.equals(onlyPreferredCall) && companyId == null) {
throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.COMPANY_ID_REQUIRED_FOR_PREFERRED_CALL));
}
if (Boolean.TRUE.equals(onlyPreferredCall)) {
validator.validateUserWithCompany(request, companyId);
List<BeneficiaryPreferredCallEntity> preferredCalls = beneficiaryPreferredCallRepository
.findByUserIdAndCompanyIdAndIsDeletedFalse(user.getId(), companyId);
List<Long> preferredCallIds = preferredCalls.stream()
.map(BeneficiaryPreferredCallEntity::getCallId)
.collect(Collectors.toList());
calls = callRepository.findByIdInAndStatusIn(preferredCallIds, callStatusList);
} else {
calls = callRepository.findByStatusInAndHubId(callStatusList, user.getHub().getId());
}
List<Long> callIds = calls.stream().map(CallEntity::getId).collect(Collectors.toList()); List<Long> callIds = calls.stream().map(CallEntity::getId).collect(Collectors.toList());
Map<String, BeneficiaryPreferredCallEntity> preferredCallsMap = Map<String, BeneficiaryPreferredCallEntity> preferredCallsMap =
getBeneficiaryPreferredCallsForUser(request,user, callIds, companyId); getBeneficiaryPreferredCallsForUser(request,user, callIds, companyId);

View File

@@ -45,4 +45,6 @@ public interface CallRepository extends JpaRepository<CallEntity, Long> {
@Query("SELECT COALESCE(SUM(c.amount), 0) FROM CallEntity c WHERE c.status = 'PUBLISH' And c.hub.id = :hubId") @Query("SELECT COALESCE(SUM(c.amount), 0) FROM CallEntity c WHERE c.status = 'PUBLISH' And c.hub.id = :hubId")
BigDecimal findTotalAmountOfPublishedCallsAndHubId(@Param("hubId") Long hubId); BigDecimal findTotalAmountOfPublishedCallsAndHubId(@Param("hubId") Long hubId);
@Query("SELECT c FROM CallEntity c WHERE c.id IN :ids AND c.status IN :status")
List<CallEntity> findByIdInAndStatusIn(@Param("ids") List<Long> ids, @Param("status") List<String> status);
} }

View File

@@ -21,7 +21,7 @@ public interface CallService {
CallResponse getCallById (HttpServletRequest request, Long callId,Long companyId); CallResponse getCallById (HttpServletRequest request, Long callId,Long companyId);
List<CallDetailsResponseBean> getAllCalls(HttpServletRequest request,Long companyId); List<CallDetailsResponseBean> getAllCalls(HttpServletRequest request,Long companyId,Boolean onlyPreferredCall);
CallResponse validateCallData(HttpServletRequest request, Long callId); CallResponse validateCallData(HttpServletRequest request, Long callId);

View File

@@ -62,9 +62,9 @@ public class CallServiceImpl implements CallService {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public List<CallDetailsResponseBean> getAllCalls(HttpServletRequest request,Long companyId) { public List<CallDetailsResponseBean> getAllCalls(HttpServletRequest request,Long companyId,Boolean onlyPreferredCall) {
UserEntity user = validator.validateUser(request); UserEntity user = validator.validateUser(request);
return callDao.getAllCalls(request,user,companyId); return callDao.getAllCalls(request,user,companyId,onlyPreferredCall);
} }

View File

@@ -100,7 +100,7 @@ public interface CallApi {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) }) @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
@GetMapping(value = "", @GetMapping(value = "",
produces = { "application/json" }) produces = { "application/json" })
ResponseEntity<Response<List<CallDetailsResponseBean>>> getAllCalls(HttpServletRequest request,@RequestParam(value = "companyId", required = false) Long companyId); ResponseEntity<Response<List<CallDetailsResponseBean>>> getAllCalls(HttpServletRequest request,@RequestParam(value = "companyId", required = false) Long companyId , @RequestParam(value = "onlyPreferredCall", required = false, defaultValue = "false") Boolean onlyPreferredCall);
@Operation(summary = "Api to validate call", @Operation(summary = "Api to validate call",

View File

@@ -67,8 +67,8 @@ public class CallApiController implements CallApi {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public ResponseEntity<Response<List<CallDetailsResponseBean>>> getAllCalls(HttpServletRequest request,Long companyId) { public ResponseEntity<Response<List<CallDetailsResponseBean>>> getAllCalls(HttpServletRequest request,Long companyId,Boolean onlyPreferredCall) {
List<CallDetailsResponseBean> calls = callService.getAllCalls(request,companyId); List<CallDetailsResponseBean> calls = callService.getAllCalls(request,companyId,onlyPreferredCall);
return ResponseEntity.status(HttpStatus.OK) return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(calls, Status.SUCCESS, Translator.toLocale(GepafinConstant.CALL_FETCH_SUCCESS_MSG))); .body(new Response<>(calls, Status.SUCCESS, Translator.toLocale(GepafinConstant.CALL_FETCH_SUCCESS_MSG)));

View File

@@ -308,3 +308,4 @@ invalid.amendment.for.comment = Invalid Amendment Request for the Given Comment.
DD_MM_YYYY_HH_MM = dd_MM_yyyy HH:mm DD_MM_YYYY_HH_MM = dd_MM_yyyy HH:mm
application.documents.not.found=No documents found for the application. application.documents.not.found=No documents found for the application.
beneficiary.call.duplicate = A preferred call with this call ID and company ID already exists for this user. beneficiary.call.duplicate = A preferred call with this call ID and company ID already exists for this user.
company.id.required.for.preferred.call=Company ID is required when requesting only preferred calls.

View File

@@ -303,3 +303,4 @@ beneficiary.email.not.found.msg=L'indirizzo email per il beneficiario non <20> st
reminder.email.sent.success.msg=Email di promemoria inviata con successo! reminder.email.sent.success.msg=Email di promemoria inviata con successo!
application.documents.not.found=Nessun documento trovato per la domanda. application.documents.not.found=Nessun documento trovato per la domanda.
beneficiary.call.duplicate = Una chiamata preferita con questo ID di chiamata e ID azienda esiste gi<67> per questo utente. beneficiary.call.duplicate = Una chiamata preferita con questo ID di chiamata e ID azienda esiste gi<67> per questo utente.
company.id.required.for.preferred.call=ID azienda obbligatorio quando si richiedono solo chiamate preferite.