PoolCurator extends AbstractHibernateCurator<Pool> { public void clearPoolSourceEntitlementRefs(Iterable<String> poolIds) { if (poolIds != null && poolIds.iterator().hasNext()) { String hql = "UPDATE Pool SET sourceEntitlement = null WHERE id IN (:pids)"; Query query = this.currentSession().createQuery(hql); for (List<String> block : this.partition(poolIds)) { query.setParameterList("pids", block); query.executeUpdate(); } } } @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 testClearPoolSourceEntitlementRefs() { Date startDate = TestUtil.createDate(2010, 3, 2); Date endDate = TestUtil.createDate(Calendar.getInstance().get(Calendar.YEAR) + 1, 3, 2); Pool pool1 = createPool(owner, product, 20L, startDate, endDate); poolCurator.create(pool1); Entitlement e = new Entitlement(pool1, consumer, owner, 5); e.setId("test-entitlement-id-1"); entitlementCurator.create(e); Pool pool2 = createPool(owner, product, 20L, startDate, endDate); pool2.setSourceEntitlement(e); poolCurator.create(pool2); this.poolCurator.clearPoolSourceEntitlementRefs(Arrays.asList(pool2.getId())); this.poolCurator.refresh(pool2); assertNull(pool2.getSourceEntitlement()); }
@Test public void testClearPoolSourceEntitlementRefsDoesntAffectUnspecifiedPools() { Date startDate = TestUtil.createDate(2010, 3, 2); Date endDate = TestUtil.createDate(Calendar.getInstance().get(Calendar.YEAR) + 1, 3, 2); Pool pool1 = createPool(owner, product, 20L, startDate, endDate); poolCurator.create(pool1); Entitlement e = new Entitlement(pool1, consumer, owner, 5); e.setId("test-entitlement-id-1"); entitlementCurator.create(e); Pool pool2 = createPool(owner, product, 20L, startDate, endDate); pool2.setSourceEntitlement(e); poolCurator.create(pool2); this.poolCurator.clearPoolSourceEntitlementRefs(Arrays.asList(pool1.getId())); this.poolCurator.refresh(pool2); assertSame(e, pool2.getSourceEntitlement()); }
@Test public void testClearPoolSourceEntitlementRefsWorksOnMultiplePools() { Date startDate = TestUtil.createDate(2010, 3, 2); Date endDate = TestUtil.createDate(Calendar.getInstance().get(Calendar.YEAR) + 1, 3, 2); Pool pool1 = createPool(owner, product, 20L, startDate, endDate); poolCurator.create(pool1); Entitlement e = new Entitlement(pool1, consumer, owner, 5); e.setId("test-entitlement-id-1"); entitlementCurator.create(e); Pool pool2 = createPool(owner, product, 20L, startDate, endDate); pool2.setSourceEntitlement(e); poolCurator.create(pool2); Pool pool3 = createPool(owner, product, 20L, startDate, endDate); pool3.setSourceEntitlement(e); poolCurator.create(pool3); Pool pool4 = createPool(owner, product, 20L, startDate, endDate); pool4.setSourceEntitlement(e); poolCurator.create(pool4); this.poolCurator.clearPoolSourceEntitlementRefs(Arrays.asList(pool2.getId(), pool3.getId())); this.poolCurator.refresh(pool2); this.poolCurator.refresh(pool3); this.poolCurator.refresh(pool4); assertNull(pool2.getSourceEntitlement()); assertNull(pool3.getSourceEntitlement()); assertSame(e, pool4.getSourceEntitlement()); }