Skip to content

Commit

Permalink
update filters to add missing and update wrong ones (#743)
Browse files Browse the repository at this point in the history
* update filters to add missing and update wrong ones

* update how we group-by on active pools filtering
  • Loading branch information
ricardofreitasrocha authored and Ben-Edwards-cgi committed Aug 23, 2024
1 parent 14af453 commit 33c9785
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import uk.gov.hmcts.juror.api.moj.domain.QJurorPool;
import uk.gov.hmcts.juror.api.moj.domain.QPoolRequest;
import uk.gov.hmcts.juror.api.moj.domain.SortMethod;
import uk.gov.hmcts.juror.api.moj.repository.ActivePoolsRepositoryImpl;
import uk.gov.hmcts.juror.api.moj.service.IsPageable;
import uk.gov.hmcts.juror.api.validation.CourtLocationCode;

Expand Down Expand Up @@ -44,9 +45,11 @@ public enum SortField implements SortMethod.HasComparableExpression {
POOL_NUMBER(QPoolRequest.poolRequest.poolNumber),
TOTAL_NUMBER_REQUESTED(QPoolRequest.poolRequest.totalNoRequired),
JURORS_IN_POOL(QJurorPool.jurorPool.isActive.count()),
COURT_NAME(QPoolRequest.poolRequest.poolType.poolType),
COURT_NAME(QPoolRequest.poolRequest.courtLocation.name),
SERVICE_START_DATE(QPoolRequest.poolRequest.returnDate),
POOL_TYPE(QPoolRequest.poolRequest.poolType.description);
POOL_TYPE(QPoolRequest.poolRequest.poolType.poolType),
POOL_CAPACITY(QPoolRequest.poolRequest.totalNoRequired),
JURORS_CONFIRMED(ActivePoolsRepositoryImpl.CONFIRMED_FROM_BUREAU);

private final Expression<? extends Comparable<?>> comparableExpression;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public class ActivePoolsRepositoryImpl implements IActivePoolsRepository {
private static final String COURT_TAB = "court";
private static final int ACTIVE_POOL_DAYS_LIMIT = 28;

public static NumberExpression<Integer> CONFIRMED_FROM_BUREAU = new CaseBuilder()
.when(JUROR_POOL.owner.eq(SecurityUtil.BUREAU_OWNER)
.and(JUROR_POOL.status.status.eq(IJurorStatus.RESPONDED)))
.then(1)
.otherwise(0).sum();

@PersistenceContext
EntityManager entityManager;

Expand All @@ -63,20 +69,14 @@ public PaginatedList<PoolRequestActiveDataDto> getActivePoolRequests(ActivePoolF
private PaginatedList<PoolRequestActiveDataDto> getActiveBureauTabRequests(ActivePoolFilterQuery filterQuery) {
JPAQueryFactory queryFactory = new JPAQueryFactory(entityManager);

NumberExpression<Integer> confirmedFromBureau = new CaseBuilder()
.when(JUROR_POOL.owner.eq(SecurityUtil.BUREAU_OWNER)
.and(JUROR_POOL.status.status.eq(IJurorStatus.RESPONDED)))
.then(1)
.otherwise(0).sum();

JPAQuery<Tuple> query = queryFactory.select(POOL_REQUEST, confirmedFromBureau)
JPAQuery<Tuple> query = queryFactory.select(POOL_REQUEST, CONFIRMED_FROM_BUREAU)
.from(POOL_REQUEST)
.leftJoin(JUROR_POOL).on(POOL_REQUEST.eq(JUROR_POOL.pool))
.where(POOL_REQUEST.owner.eq(SecurityUtil.BUREAU_OWNER))
.where(POOL_REQUEST.newRequest.eq('N'))
.where(POOL_REQUEST.numberRequested.ne(0))
.where(POOL_REQUEST.poolType.description.in(PoolRequestUtils.POOL_TYPES_DESC_LIST))
.groupBy(POOL_REQUEST);
.groupBy(POOL_REQUEST, POOL_REQUEST.courtLocation.name);

if (StringUtils.isNotBlank(filterQuery.getLocCode())) {
query.where(POOL_REQUEST.courtLocation.locCode.eq(filterQuery.getLocCode()));
Expand All @@ -95,7 +95,7 @@ private PaginatedList<PoolRequestActiveDataDto> getActiveBureauTabRequests(Activ
return PoolRequestActiveDataDto.builder()
.poolNumber(poolRequest.getPoolNumber())
.requestedFromBureau(poolRequest.getNumberRequested())
.confirmedFromBureau(data.get(confirmedFromBureau))
.confirmedFromBureau(data.get(CONFIRMED_FROM_BUREAU))
.courtName(poolRequest.getCourtLocation().getName())
.poolType(poolRequest.getPoolType().getDescription())
.attendanceDate(poolRequest.getReturnDate())
Expand Down

0 comments on commit 33c9785

Please sign in to comment.