Skip to content

Commit

Permalink
[backend] Add subqueries for atomicTestings
Browse files Browse the repository at this point in the history
  • Loading branch information
savacano28 committed Oct 28, 2024
1 parent 051f959 commit 6b63b67
Showing 1 changed file with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import static io.openbas.helper.StreamHelper.iterableToSet;
import static io.openbas.utils.AtomicTestingUtils.*;
import static io.openbas.utils.JpaUtils.createJoinArrayAggOnId;
import static io.openbas.utils.JpaUtils.createLeftJoin;
import static io.openbas.utils.StringUtils.duplicateString;
import static io.openbas.utils.pagination.PaginationUtils.buildPaginationCriteriaBuilder;
import static io.openbas.utils.pagination.SortUtilsCriteriaBuilder.toSortCriteriaBuilder;
Expand Down Expand Up @@ -292,6 +291,8 @@ public void deleteAtomicTesting(String injectId) {
// -- PAGINATION --

public Page<AtomicTestingOutput> findAllAtomicTestings(@NotNull final SearchPaginationInput searchPaginationInput) {
Map<String, Join<Base, Base>> joinMap = new HashMap<>();

Specification<Inject> customSpec = Specification.where((root, query, cb) -> {
Predicate predicate = cb.conjunction();
predicate = cb.and(predicate, cb.isNull(root.get("scenario")));
Expand All @@ -302,23 +303,26 @@ public Page<AtomicTestingOutput> findAllAtomicTestings(@NotNull final SearchPagi
(Specification<Inject> specification, Specification<Inject> specificationCount, Pageable pageable) -> this.atomicTestings(
customSpec.and(specification),
customSpec.and(specificationCount),
pageable
pageable,
joinMap
),
searchPaginationInput,
Inject.class
Inject.class,
joinMap
);
}


public Page<AtomicTestingOutput> atomicTestings(
Specification<Inject> specification,
Specification<Inject> specificationCount,
Pageable pageable) {
Pageable pageable,
Map<String, Join<Base, Base>> joinMap) {
CriteriaBuilder cb = this.entityManager.getCriteriaBuilder();

CriteriaQuery<Tuple> cq = cb.createTupleQuery();
Root<Inject> injectRoot = cq.from(Inject.class);
selectForAtomicTesting(cb, cq, injectRoot);
selectForAtomicTesting(cb, cq, injectRoot, joinMap);

// -- Text Search and Filters --
if (specification != null) {
Expand Down Expand Up @@ -389,10 +393,13 @@ public Page<AtomicTestingOutput> atomicTestings(
return new PageImpl<>(injects, pageable, total);
}

private void selectForAtomicTesting(CriteriaBuilder cb, CriteriaQuery<Tuple> cq, Root<Inject> injectRoot) {
private void selectForAtomicTesting(CriteriaBuilder cb, CriteriaQuery<Tuple> cq, Root<Inject> injectRoot, Map<String, Join<Base, Base>> joinMap) {
// Joins
Join<Inject, InjectorContract> injectorContractJoin = createLeftJoin(injectRoot, "injectorContract");
Join<InjectorContract, Injector> injectorJoin = injectorContractJoin.join("injector", JoinType.LEFT);
Join<Base, Base> injectorContractJoin = injectRoot.join("injectorContract", JoinType.LEFT);
joinMap.put("injectorContract", injectorContractJoin);

Join<Base, Base> injectorJoin = injectorContractJoin.join("injector", JoinType.LEFT);
joinMap.put("injector", injectorJoin);

// Subquery for InjectStatus
Subquery<Tuple> statusSubquery = cq.subquery(Tuple.class);
Expand Down

0 comments on commit 6b63b67

Please sign in to comment.