OwnerCurator extends AbstractHibernateCurator<Owner> { @SuppressWarnings("checkstyle:indentation") public CandlepinQuery<Owner> getOwnersWithProducts(Collection<String> productIds) { if (productIds != null && !productIds.isEmpty()) { Session session = this.currentSession(); Criteria idCriteria = session.createCriteria(Owner.class, "Owner") .setProjection(Projections.distinct(Projections.id())) .createAlias("Owner.pools", "Pool") .createAlias("Pool.product", "Prod", JoinType.LEFT_OUTER_JOIN) .createAlias("Pool.derivedProduct", "DProd", JoinType.LEFT_OUTER_JOIN) .createAlias("Pool.providedProducts", "PProd", JoinType.LEFT_OUTER_JOIN) .createAlias("Pool.derivedProvidedProducts", "DPProd", JoinType.LEFT_OUTER_JOIN) .add(Restrictions.or( CPRestrictions.in("Prod.id", productIds), CPRestrictions.in("DProd.id", productIds), CPRestrictions.in("PProd.id", productIds), CPRestrictions.in("DPProd.id", productIds) )); List<String> ownerIds = idCriteria.list(); if (ownerIds != null && !ownerIds.isEmpty()) { DetachedCriteria criteria = DetachedCriteria.forClass(Owner.class) .add(CPRestrictions.in("id", ownerIds)); return this.cpQueryFactory.<Owner>buildQuery(session, criteria); } } return this.cpQueryFactory.<Owner>buildQuery(); } OwnerCurator(); Owner findOwnerById(String ownerId); @Transactional Owner replicate(Owner owner); @Transactional @Override Owner create(Owner entity); @Transactional Owner getByKeySecure(String key); Owner lockAndLoadByKey(String key); @Transactional Owner getByKey(String key); @Transactional CandlepinQuery<Owner> getByKeys(Collection<String> keys); Owner getByUpstreamUuid(String upstreamUuid); CandlepinQuery<Owner> getOwnersByActiveProduct(Collection<String> productIds); @SuppressWarnings("checkstyle:indentation") CandlepinQuery<Owner> getOwnersWithProducts(Collection<String> productIds); CandlepinQuery<String> getConsumerIds(Owner owner); @SuppressWarnings("unchecked") CandlepinQuery<String> getConsumerIds(String ownerId); CandlepinQuery<String> getConsumerUuids(Owner owner); @SuppressWarnings("unchecked") CandlepinQuery<String> getConsumerUuids(String ownerId);  }
@Test public void testGetOwnersWithProducts() { List<Owner> owners = this.setupDBForLookupOwnersForProductTests(); Owner owner1 = owners.get(0); Owner owner2 = owners.get(1); Owner owner3 = owners.get(2); owners = this.ownerCurator.getOwnersWithProducts(Arrays.asList("p4")).list(); assertEquals(Arrays.asList(owner1), owners); owners = this.ownerCurator.getOwnersWithProducts(Arrays.asList("p5d")).list(); assertEquals(Arrays.asList(owner2), owners); owners = this.ownerCurator.getOwnersWithProducts(Arrays.asList("p1")).list(); assertEquals(Arrays.asList(owner1, owner2, owner3), owners); owners = this.ownerCurator.getOwnersWithProducts(Arrays.asList("p3")).list(); assertEquals(Arrays.asList(owner2, owner3), owners); owners = this.ownerCurator.getOwnersWithProducts(Arrays.asList("p4", "p6")).list(); assertEquals(Arrays.asList(owner1, owner3), owners); owners = this.ownerCurator.getOwnersWithProducts(Arrays.asList("nope")).list(); assertEquals(0, owners.size()); }