PoolCurator extends AbstractHibernateCurator<Pool> { public Set<String> retrieveServiceLevelsForOwner(Owner owner, boolean exempt) { return retrieveServiceLevelsForOwner(owner.getId(), exempt); } @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 testListServiceLevelForOwnersWithExpiredPool() { Product product1 = TestUtil.createProduct(); product1.setAttribute(Product.Attributes.SUPPORT_LEVEL, "expired"); product1 = this.createProduct(product1, owner); Product product2 = TestUtil.createProduct(); product2.setAttribute(Product.Attributes.SUPPORT_LEVEL, "fresh"); product2 = this.createProduct(product2, owner); int year = Calendar.getInstance().get(Calendar.YEAR); Date pastDate = TestUtil.createDate(year - 2, 3, 2); Date expiredDate = TestUtil.createDate(year - 1, 3, 2); Date futureDate = TestUtil.createDate(year + 10, 3, 2); Pool pool1 = createPool(owner, product1, 100L, pastDate, expiredDate); poolCurator.create(pool1); Pool pool2 = createPool(owner, product2, 100L, pastDate, futureDate); poolCurator.create(pool2); Set<String> levels = poolCurator.retrieveServiceLevelsForOwner(owner, false); assertEquals(1, levels.size()); }
@Test public void testListServiceLevelForOwnersWithExpiredPoolAndEndDateOverride() { Product product1 = TestUtil.createProduct(); product1.setAttribute(Product.Attributes.SUPPORT_LEVEL, "expired"); product1 = this.createProduct(product1, owner); Product product2 = TestUtil.createProduct(); product2.setAttribute(Product.Attributes.SUPPORT_LEVEL, "fresh"); product2 = this.createProduct(product2, owner); int year = Calendar.getInstance().get(Calendar.YEAR); Date pastDate = TestUtil.createDate(year - 2, 3, 2); Date expiredDate = TestUtil.createDate(year - 1, 3, 2); Date futureDate = TestUtil.createDate(year + 10, 3, 2); Pool pool1 = createPool(owner, product1, 100L, pastDate, expiredDate); poolCurator.create(pool1); Pool pool2 = createPool(owner, product2, 100L, pastDate, futureDate); poolCurator.create(pool2); Entitlement e = new Entitlement(pool1, consumer, owner, 1); e.setId(Util.generateDbUUID()); e.setEndDateOverride(futureDate); entitlementCurator.create(e); Set<String> levels = poolCurator.retrieveServiceLevelsForOwner(owner, false); assertEquals(2, levels.size()); }
@Test public void testExempt() { Product product1 = TestUtil.createProduct(); product1.setAttribute(Product.Attributes.SUPPORT_LEVEL, "premium"); product1.setAttribute(Product.Attributes.SUPPORT_LEVEL_EXEMPT, "true"); product1 = this.createProduct(product1, owner); Product product2 = TestUtil.createProduct(); product2.setAttribute(Product.Attributes.SUPPORT_LEVEL, "Premium"); product2 = this.createProduct(product2, owner); Product product3 = TestUtil.createProduct(); product3.setAttribute(Product.Attributes.SUPPORT_LEVEL, "super"); product3 = this.createProduct(product3, owner); Product product4 = TestUtil.createProduct(); product4.setAttribute(Product.Attributes.SUPPORT_LEVEL, "high"); product4.setAttribute(Product.Attributes.SUPPORT_LEVEL_EXEMPT, "false"); product4 = this.createProduct(product4, owner); Product product5 = TestUtil.createProduct(); product5.setAttribute(Product.Attributes.SUPPORT_LEVEL, "HIGH"); product5 = this.createProduct(product5, owner); Pool pool1 = createPool(owner, product1, 100L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2055, 3, 2)); poolCurator.create(pool1); Pool pool2 = createPool(owner, product2, 100L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2055, 3, 2)); poolCurator.create(pool2); Pool pool3 = createPool(owner, product3, 100L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2055, 3, 2)); poolCurator.create(pool3); Pool pool4 = createPool(owner, product4, 100L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2055, 3, 2)); poolCurator.create(pool4); Pool pool5 = createPool(owner, product5, 100L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2055, 3, 2)); poolCurator.create(pool5); Set<String> levels = poolCurator.retrieveServiceLevelsForOwner(owner, false); assertEquals(2, levels.size()); levels = poolCurator.retrieveServiceLevelsForOwner(owner, true); assertEquals(1, levels.size()); assertEquals("premium", levels.toArray()[0]); }
@Test public void testSupportCasing() { Product product1 = TestUtil.createProduct(); product1.setAttribute(Product.Attributes.SUPPORT_LEVEL, "premium"); product1 = this.createProduct(product1, owner); Product product2 = TestUtil.createProduct(); product2.setAttribute(Product.Attributes.SUPPORT_LEVEL, "Premium"); product2 = this.createProduct(product2, owner); Product product3 = TestUtil.createProduct(); product3.setAttribute(Product.Attributes.SUPPORT_LEVEL, "Premiums"); product3 = this.createProduct(product3, owner); Pool pool1 = createPool(owner, product1, 100L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2055, 3, 2)); poolCurator.create(pool1); Pool pool2 = createPool(owner, product2, 100L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2055, 3, 2)); poolCurator.create(pool2); Pool pool3 = createPool(owner, product3, 100L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2055, 3, 2)); poolCurator.create(pool3); Set<String> levels = poolCurator.retrieveServiceLevelsForOwner(owner, false); assertEquals(2, levels.size()); }