PoolCurator extends AbstractHibernateCurator<Pool> { public Map<String, Set<String>> getConsumerStackDerivedPoolIdMap(Iterable<String> stackIds) { Map<String, Set<String>> consumerPoolMap = new HashMap<>(); if (stackIds != null && stackIds.iterator().hasNext()) { String jpql = "SELECT DISTINCT ss.sourceConsumer.id, ss.derivedPool.id FROM SourceStack ss " + "WHERE ss.sourceStackId IN (:stackids)"; TypedQuery<Object[]> query = this.getEntityManager().createQuery(jpql, Object[].class); for (List<String> block : this.partition(stackIds)) { query.setParameter("stackids", block); for (Object[] row : query.getResultList()) { String consumerId = (String) row[0]; String poolId = (String) row[1]; Set<String> poolIds = consumerPoolMap.get(consumerId); if (poolIds == null) { poolIds = new HashSet<>(); consumerPoolMap.put(consumerId, poolIds); } poolIds.add(poolId); } } } return consumerPoolMap; } @Inject  PoolCurator(ConsumerCurator consumerCurator, ConsumerTypeCurator consumerTypeCurator); @Transactional CandlepinQuery<Pool> listByOwner(Owner owner); @Transactional CandlepinQuery<Pool> listByOwner(Owner owner, Date activeOn); @Transactional CandlepinQuery<Pool> listByOwnerAndType(Owner owner, PoolType type); CandlepinQuery<Pool> listBySourceEntitlement(Entitlement e); Set<Pool> listBySourceEntitlements(Iterable<Entitlement> ents); @Transactional List<Pool> listByConsumer(Consumer c); @Transactional List<Pool> listByOwnerAndProduct(Owner owner, String productId); List<Pool> listExpiredPools(); @Transactional @SuppressWarnings("checkstyle:indentation") List<Pool> listExpiredPools(int blockSize); @SuppressWarnings("unchecked") @Transactional List<Pool> listAvailableEntitlementPools(Consumer c, Owner o, String productId, Date activeOn); @SuppressWarnings("unchecked") @Transactional List<Pool> listAvailableEntitlementPools(Consumer c, Owner o, Collection<String> productIds,
        Date activeOn); @SuppressWarnings("unchecked") @Transactional List<Pool> listAvailableEntitlementPools(Consumer c, String ownerId, Collection<String> productIds,
        Date activeOn); @Transactional List<Pool> listByFilter(PoolFilterBuilder filters); @Transactional Page<List<Pool>> listAvailableEntitlementPools(Consumer c, String ownerId, String productId,
        String subscriptionId, Date activeOn, PoolFilterBuilder filters,
        PageRequest pageRequest, boolean postFilter, boolean addFuture, boolean onlyFuture, Date after); @Transactional Page<List<Pool>> listAvailableEntitlementPools(Consumer c, Owner o, String productId,
        String subscriptionId, Date activeOn, PoolFilterBuilder filters,
        PageRequest pageRequest, boolean postFilter, boolean addFuture, boolean onlyFuture, Date after); @Transactional List<String> listEntitledConsumerUuids(String poolId); @Transactional @SuppressWarnings({"unchecked", "checkstyle:indentation", "checkstyle:methodlength"}) // TODO: Remove the methodlength suppression once this method is cleaned up Page<List<Pool>> listAvailableEntitlementPools(Consumer consumer, String ownerId,
        Collection<String> productIds, String subscriptionId, Date activeOn, PoolFilterBuilder filters,
        PageRequest pageRequest, boolean postFilter, boolean addFuture, boolean onlyFuture, Date after); @SuppressWarnings("unchecked") @Transactional boolean hasActiveEntitlementPools(String ownerId, Date date); @Transactional List<Pool> listPoolsRestrictedToUser(String username); @SuppressWarnings("unchecked") List<Entitlement> retrieveOrderedEntitlementsOf(Collection<Pool> existingPools); @SuppressWarnings("unchecked") List<String> retrieveOrderedEntitlementIdsOf(Collection<Pool> pools); void deactivatePool(Pool pool); @Transactional @SuppressWarnings("unchecked") List<Entitlement> entitlementsIn(Pool entitlementPool); @SuppressWarnings("unchecked") List<Pool> getBySubscriptionId(Owner owner, String subId); @SuppressWarnings("unchecked") List<Pool> getBySubscriptionIds(Owner owner, Collection<String> subIds); @SuppressWarnings("unchecked") List<Pool> getBySubscriptionIds(String ownerId, Collection<String> subIds); @SuppressWarnings("unchecked") List<Pool> getOversubscribedBySubscriptionIds(String ownerId, Map<String, Entitlement> subIdMap); @Transactional Pool replicate(Pool pool); @SuppressWarnings("checkstyle:indentation") int getNoOfDependentEntitlements(String entitlementId); @SuppressWarnings("unchecked") List<EntitlementCertificate> retrieveEntCertsOfPoolsWithSourceEntitlement(String entId); Filter disableConsumerFilter(); List<ActivationKey> getActivationKeysForPool(Pool p); Set<String> retrieveServiceLevelsForOwner(Owner owner, boolean exempt); Set<String> retrieveServiceLevelsForOwner(String ownerId, boolean exempt); @Transactional void delete(Pool entity); void batchDelete(Collection<Pool> pools, Collection<String> alreadyDeletedPools); @SuppressWarnings("checkstyle:indentation") List<Pool> getSubPoolForStackIds(Consumer consumer, Collection stackIds); @SuppressWarnings("unchecked") List<Pool> getOwnerSubPoolsForStackId(Owner owner, String stackId); @SuppressWarnings("unchecked") List<Pool> getPoolsFromBadSubs(Owner owner, Collection<String> expectedSubIds); @SuppressWarnings("unchecked") Set<String> getDerivedPoolIdsForPools(Iterable<String> poolIds); @SuppressWarnings("unchecked") Collection<String> getEntitlementIdsForPools(Collection<String> poolIds); @SuppressWarnings("unchecked") Collection<String> getPoolIdsForSourceEntitlements(Collection<String> entIds); @SuppressWarnings("unchecked") Collection<String> getPoolIdsForEntitlements(Collection<String> entIds); @SuppressWarnings("unchecked") CandlepinQuery<Pool> getPoolsBySubscriptionId(String subId); @SuppressWarnings("unchecked") CandlepinQuery<Pool> getPoolsBySubscriptionIds(Collection<String> subIds); @SuppressWarnings("unchecked") List<Pool> getOwnersFloatingPools(Owner owner); CandlepinQuery<Pool> getMasterPools(); CandlepinQuery<Pool> getMasterPoolsForOwner(Owner owner); CandlepinQuery<Pool> getMasterPoolsForOwnerExcludingSubs(Owner owner,
        Collection<String> excludedSubIds); @SuppressWarnings("unchecked") Set<String> getAllKnownProductIds(); @SuppressWarnings("unchecked") Set<String> getAllKnownProductIdsForOwner(Owner owner); @SuppressWarnings("checkstyle:indentation") Pool findDevPool(Consumer consumer); boolean exists(Pool pool); void calculateConsumedForOwnersPools(Owner owner); void calculateExportedForOwnersPools(Owner owner); void markCertificatesDirtyForPoolsWithProducts(Owner owner, Collection<String> productIds); Boolean provides(Pool pool, String providedProductId); Boolean providesDerived(Pool pool, String derivedProvidedProductId); Map<String, Set<String>> getProvidedProductIds(Collection<Pool> pools); Map<String, Set<String>> getProvidedProductIdsByPoolIds(Collection<String> poolIds); Map<String, Set<String>> getDerivedProvidedProductIds(Collection<Pool> pools); Map<String, Set<String>> getDerivedProvidedProductIdsByPoolIds(Collection<String> poolIds); @Transactional void removeCdn(Cdn cdn); void clearPoolSourceEntitlementRefs(Iterable<String> poolIds); Set<String> getExistingPoolIdsByIds(Iterable<String> poolIds); Map<String, Set<String>> getConsumerStackDerivedPoolIdMap(Iterable<String> stackIds); Set<String> getUnentitledStackDerivedPoolIds(Iterable<String> entitlementIds); static final int EXPIRED_POOL_BLOCK_SIZE; }
@Test public void testGetConsumerStackDerivedPoolIdMap() { Owner owner1 = this.createOwner("owner-1"); Owner owner2 = this.createOwner("owner-2"); Consumer consumer1 = this.createConsumer(owner1); Consumer consumer2 = this.createConsumer(owner1); Consumer consumer3 = this.createConsumer(owner2); Date startDate = TestUtil.createDate(2010, 3, 2); Date endDate = TestUtil.createDate(Calendar.getInstance().get(Calendar.YEAR) + 1, 3, 2); String stackId1 = "123"; Product stackingProduct1 = TestUtil.createProduct(); stackingProduct1.setAttribute(Product.Attributes.VIRT_LIMIT, "3"); stackingProduct1.setAttribute(Product.Attributes.STACKING_ID, stackId1); stackingProduct1 = this.createProduct(stackingProduct1, owner); String stackId2 = "456"; Product stackingProduct2 = TestUtil.createProduct(); stackingProduct2.setAttribute(Product.Attributes.VIRT_LIMIT, "3"); stackingProduct2.setAttribute(Product.Attributes.STACKING_ID, stackId2); stackingProduct2 = this.createProduct(stackingProduct2, owner); String stackId3 = "789"; Product stackingProduct3 = TestUtil.createProduct(); stackingProduct3.setAttribute(Product.Attributes.VIRT_LIMIT, "3"); stackingProduct3.setAttribute(Product.Attributes.STACKING_ID, stackId3); stackingProduct3 = this.createProduct(stackingProduct3, owner); Pool pool1 = createPool(owner, stackingProduct1, 20L, startDate, endDate); pool1.setSourceStack(new SourceStack(consumer1, stackId1)); pool1.setAttribute(Pool.Attributes.REQUIRES_HOST, consumer1.getUuid()); poolCurator.create(pool1); Pool pool2 = createPool(owner, stackingProduct2, 20L, startDate, endDate); pool2.setSourceStack(new SourceStack(consumer1, stackId2)); pool2.setAttribute(Pool.Attributes.REQUIRES_HOST, consumer1.getUuid()); poolCurator.create(pool2); Pool pool3 = createPool(owner, stackingProduct3, 20L, startDate, endDate); pool3.setSourceStack(new SourceStack(consumer2, stackId3)); pool3.setAttribute(Pool.Attributes.REQUIRES_HOST, consumer2.getUuid()); poolCurator.create(pool3); Pool pool4 = createPool(owner, stackingProduct1, 20L, startDate, endDate); pool4.setSourceStack(new SourceStack(consumer2, stackId1)); pool4.setAttribute(Pool.Attributes.REQUIRES_HOST, consumer2.getUuid()); poolCurator.create(pool4); Pool pool5 = createPool(owner, stackingProduct2, 20L, startDate, endDate); pool5.setSourceStack(new SourceStack(consumer2, stackId2)); pool5.setAttribute(Pool.Attributes.REQUIRES_HOST, consumer2.getUuid()); poolCurator.create(pool5); Pool pool6 = createPool(owner, stackingProduct3, 20L, startDate, endDate); pool6.setSourceStack(new SourceStack(consumer3, stackId3)); pool6.setAttribute(Pool.Attributes.REQUIRES_HOST, consumer3.getUuid()); poolCurator.create(pool6); Map<String, Set<String>> output; output = this.poolCurator.getConsumerStackDerivedPoolIdMap( Arrays.asList(stackId1, stackId2, stackId3)); assertNotNull(output); assertEquals(3, output.size()); assertTrue(output.containsKey(consumer1.getId())); assertTrue(output.containsKey(consumer2.getId())); assertTrue(output.containsKey(consumer3.getId())); assertEquals(output.get(consumer1.getId()), Util.asSet(pool1.getId(), pool2.getId())); assertEquals(output.get(consumer2.getId()), Util.asSet(pool3.getId(), pool4.getId(), pool5.getId())); assertEquals(output.get(consumer3.getId()), Util.asSet(pool6.getId())); output = this.poolCurator.getConsumerStackDerivedPoolIdMap(Arrays.asList(stackId1, stackId2)); assertNotNull(output); assertEquals(2, output.size()); assertTrue(output.containsKey(consumer1.getId())); assertTrue(output.containsKey(consumer2.getId())); assertFalse(output.containsKey(consumer3.getId())); assertEquals(output.get(consumer1.getId()), Util.asSet(pool1.getId(), pool2.getId())); assertEquals(output.get(consumer2.getId()), Util.asSet(pool4.getId(), pool5.getId())); output = this.poolCurator.getConsumerStackDerivedPoolIdMap(Arrays.asList(stackId1)); assertNotNull(output); assertEquals(2, output.size()); assertTrue(output.containsKey(consumer1.getId())); assertTrue(output.containsKey(consumer2.getId())); assertFalse(output.containsKey(consumer3.getId())); assertEquals(output.get(consumer1.getId()), Util.asSet(pool1.getId())); assertEquals(output.get(consumer2.getId()), Util.asSet(pool4.getId())); output = this.poolCurator.getConsumerStackDerivedPoolIdMap(Collections.<String>emptyList()); assertNotNull(output); assertEquals(0, output.size()); output = this.poolCurator.getConsumerStackDerivedPoolIdMap(null); assertNotNull(output); assertEquals(0, output.size()); }