Done ticket GEPAFINBE-76
This commit is contained in:
@@ -781,30 +781,21 @@ public class CallDao {
|
||||
return createCallResponseBean;
|
||||
}
|
||||
|
||||
public List<CallDetailsResponseBean> getAllCalls(HttpServletRequest request,UserEntity user, Long companyId,Boolean onlyPreferredCall) {
|
||||
public List<CallDetailsResponseBean> getAllCalls(HttpServletRequest request,UserEntity user, Long companyId,Boolean onlyPreferredCall,Boolean onlyConfidiCall) {
|
||||
String type = user.getRoleEntity().getRoleType();
|
||||
List<String> callStatusList = CallStatusEnum.getStatusValues();
|
||||
if (Boolean.FALSE.equals(ROLE_SUPER_ADMIN.getValue().equals(type))) {
|
||||
callStatusList = List.of(CallStatusEnum.PUBLISH.getValue());
|
||||
}
|
||||
List<CallEntity> calls;
|
||||
// List<CallEntity> calls = List.of();
|
||||
if (Boolean.TRUE.equals(onlyPreferredCall) && companyId == null) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.COMPANY_ID_REQUIRED_FOR_PREFERRED_CALL));
|
||||
}
|
||||
Specification<CallEntity> spec = buildCallSpecification(request, user, companyId, onlyPreferredCall, onlyConfidiCall, callStatusList);
|
||||
|
||||
List<CallEntity> calls = callRepository.findAll(spec);
|
||||
|
||||
if (Boolean.TRUE.equals(onlyPreferredCall)) {
|
||||
validator.validateUserWithCompany(request, companyId);
|
||||
UserWithCompanyEntity userWithCompanyEntity=companyService.getUserWithCompany(user.getId(),companyId);
|
||||
List<BeneficiaryPreferredCallEntity> preferredCalls = beneficiaryPreferredCallRepository
|
||||
.findByUserIdAndUserWithCompanyIdAndIsDeletedFalse(user.getId(), userWithCompanyEntity.getId());
|
||||
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());
|
||||
Map<String, BeneficiaryPreferredCallEntity> preferredCallsMap =
|
||||
getBeneficiaryPreferredCallsForUser(request,user, callIds, companyId);
|
||||
@@ -825,7 +816,7 @@ public class CallDao {
|
||||
public Map<String, BeneficiaryPreferredCallEntity> getBeneficiaryPreferredCallsForUser(HttpServletRequest request, UserEntity user, List<Long> callIds, Long companyId) {
|
||||
List<BeneficiaryPreferredCallEntity> beneficiaryPreferredCalls;
|
||||
|
||||
if (companyId != null && Boolean.TRUE.equals(validator.checkIsBeneficiary())) {
|
||||
if (companyId != null && (Boolean.TRUE.equals(validator.checkIsBeneficiary()) || Boolean.TRUE.equals(validator.checkIsConfidi()))) {
|
||||
validator.validateUserWithCompany(request, companyId);
|
||||
UserWithCompanyEntity userWithCompanyEntity=companyService.getUserWithCompany(user.getId(),companyId);
|
||||
beneficiaryPreferredCalls = beneficiaryPreferredCallRepository
|
||||
@@ -994,7 +985,10 @@ public class CallDao {
|
||||
|
||||
// Add preferredCallIds filtering to the specification
|
||||
spec = spec.and((root, query, criteriaBuilder) ->
|
||||
root.get(GepafinConstant.ID).in(preferredCallIds)
|
||||
criteriaBuilder.and(
|
||||
root.get(GepafinConstant.ID).in(preferredCallIds),
|
||||
criteriaBuilder.isTrue(root.get("confidi"))
|
||||
)
|
||||
);
|
||||
}
|
||||
entityPage = callRepository.findAll(spec, PageRequest.of(pageNo - 1, pageLimit));
|
||||
@@ -1110,6 +1104,28 @@ public class CallDao {
|
||||
predicates.add(root.get(GepafinConstant.STATUS).in(statusValues));
|
||||
}
|
||||
applyFilters(root, criteriaBuilder, predicates, filters);
|
||||
Boolean isConfidi = callPageableRequestBean.getConfidi();
|
||||
|
||||
if (validator.checkIsConfidi()) {
|
||||
|
||||
if (isConfidi == null || isConfidi.equals(Boolean.FALSE)) {
|
||||
// Ensure no records are returned
|
||||
return List.of(criteriaBuilder.disjunction());
|
||||
}
|
||||
|
||||
if (isConfidi.equals(Boolean.TRUE)) {
|
||||
predicates.add(criteriaBuilder.isTrue(root.get("confidi")));
|
||||
}
|
||||
}
|
||||
else if( Boolean.FALSE.equals(validator.checkIsConfidi()) && isConfidi!=null){
|
||||
if (isConfidi.equals(Boolean.TRUE)) {
|
||||
predicates.add(criteriaBuilder.isTrue(root.get("confidi")));
|
||||
}
|
||||
if (isConfidi.equals(Boolean.FALSE)) {
|
||||
predicates.add(criteriaBuilder.isFalse(root.get("confidi")));
|
||||
}
|
||||
}
|
||||
|
||||
predicates.add(criteriaBuilder.equal(root.get(GepafinConstant.HUB).get(GepafinConstant.ID), userEntity.getHub().getId()));
|
||||
|
||||
|
||||
@@ -1251,4 +1267,45 @@ public class CallDao {
|
||||
createCallResponseBean.setCurrentStep(GepafinConstant.EVALUATION_V2_STEP_2);
|
||||
return createCallResponseBean;
|
||||
}
|
||||
private Specification<CallEntity> buildCallSpecification(HttpServletRequest request, UserEntity user, Long companyId, Boolean onlyPreferredCall, Boolean onlyConfidiCall, List<String> callStatusList) {
|
||||
return (root, query, criteriaBuilder) -> {
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
predicates.add(root.get("status").in(callStatusList));
|
||||
|
||||
if (Boolean.TRUE.equals(onlyPreferredCall)) {
|
||||
validator.validateUserWithCompany(request, companyId);
|
||||
UserWithCompanyEntity userWithCompanyEntity = companyService.getUserWithCompany(user.getId(), companyId);
|
||||
List<BeneficiaryPreferredCallEntity> preferredCalls = beneficiaryPreferredCallRepository
|
||||
.findByUserIdAndUserWithCompanyIdAndIsDeletedFalse(user.getId(), userWithCompanyEntity.getId());
|
||||
List<Long> preferredCallIds = preferredCalls.stream()
|
||||
.map(BeneficiaryPreferredCallEntity::getCallId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
predicates.add(root.get("id").in(preferredCallIds));
|
||||
} else {
|
||||
predicates.add(criteriaBuilder.equal(root.get("hub").get("id"), user.getHub().getId()));
|
||||
}
|
||||
|
||||
if (validator.checkIsConfidi()) {
|
||||
if (onlyConfidiCall==null || Boolean.FALSE.equals(onlyConfidiCall)) {
|
||||
return criteriaBuilder.conjunction();
|
||||
}
|
||||
|
||||
if (onlyConfidiCall!=null && Boolean.TRUE.equals(onlyConfidiCall)) {
|
||||
predicates.add(criteriaBuilder.isTrue(root.get("confidi")));
|
||||
}
|
||||
}else {
|
||||
if(onlyConfidiCall!=null) {
|
||||
if (Boolean.TRUE.equals(onlyConfidiCall)) {
|
||||
predicates.add(criteriaBuilder.isTrue(root.get("confidi")));
|
||||
}
|
||||
if (Boolean.FALSE.equals(onlyConfidiCall)) {
|
||||
predicates.add(criteriaBuilder.isFalse(root.get("confidi")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user