EntitlementCurator extends AbstractHibernateCurator<Entitlement> { public Set<String> listEntitledProductIds(Consumer consumer, Pool pool) { Set<String> entitledProductIds = new HashSet<>(); List<Pool> pools = new LinkedList<>(); for (Entitlement e : consumer.getEntitlements()) { pools.add(e.getPool()); } ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer); pools.add(pool); for (Pool p : pools) { if (!poolOverlapsRange(p, pool.getStartDate(), pool.getEndDate())) { continue; } entitledProductIds.add(p.getProduct().getId()); for (Product pp : productCurator.getPoolProvidedProductsCached(p)) { entitledProductIds.add(pp.getId()); } if (ctype.isManifest() && p.getDerivedProduct() != null) { entitledProductIds.add(p.getDerivedProduct().getId()); for (Product dpp : productCurator.getPoolDerivedProvidedProductsCached(p)) { entitledProductIds.add(dpp.getId()); } } } return entitledProductIds; } @Inject  EntitlementCurator(OwnerProductCurator ownerProductCurator, ProductCurator productCurator,
        ConsumerTypeCurator consumerTypeCurator, CandlepinQueryFactory cpQueryFactory); @Transactional Set<Entitlement> bulkUpdate(Set<Entitlement> entitlements); List<Entitlement> listByConsumer(Consumer consumer); List<Entitlement> listByConsumer(Consumer consumer, EntitlementFilterBuilder filters); List<Entitlement> listByConsumerAndPoolId(Consumer consumer, String poolId); Page<List<Entitlement>> listByConsumer(Consumer consumer, String productId,
        EntitlementFilterBuilder filters, PageRequest pageRequest); Page<List<Entitlement>> listByOwner(Owner owner, String productId,
        EntitlementFilterBuilder filters, PageRequest pageRequest); Page<List<Entitlement>> listAll(EntitlementFilterBuilder filters, PageRequest pageRequest); CandlepinQuery<Entitlement> listByOwner(Owner owner); CandlepinQuery<Entitlement> listByEnvironment(Environment environment); CandlepinQuery<Entitlement> listByEnvironment(String environmentId); CandlepinQuery<Entitlement> listByConsumerAndDate(Consumer consumer, Date activeOn); List<Entitlement> listDirty(Consumer consumer); Set<String> listEntitledProductIds(Consumer consumer, Pool pool); int markDependentEntitlementsDirty(Iterable<String> entitlementIds); Set<String> filterDistributorEntitlementIds(Iterable<String> entsIdsToFilter); @Transactional int markEntitlementsDirty(Iterable<String> entitlementIds); @Deprecated Map<Consumer, List<Entitlement>> getDistinctConsumers(List<Entitlement> entsToRevoke); @Transactional void delete(Entitlement entity); void batchDelete(Collection<Entitlement> entitlements); int batchDeleteByIds(Collection<String> entitlementIds); void unlinkEntitlements(Collection<Entitlement> entitlements); @Transactional Entitlement findByCertificateSerial(Long serial); @Transactional Entitlement replicate(Entitlement ent); @SuppressWarnings("unchecked") CandlepinQuery<Entitlement> findByStackId(Consumer consumer, String stackId); @SuppressWarnings("unchecked") CandlepinQuery<Entitlement> findByStackIds(Consumer consumer, Collection stackIds); @SuppressWarnings("unchecked") CandlepinQuery<Entitlement> findByPoolAttribute(Consumer consumer, String attributeName,
        String value); CandlepinQuery<Entitlement> findByPoolAttribute(String attributeName, String value); Entitlement findUpstreamEntitlementForStack(Consumer consumer, String stackId); Collection<String> getDependentEntitlementIdsForPools(Consumer consumer,
        Iterable<String> poolIds);  }
@Test public void listEntitledProductIds() { Pool pool = setupListProvidingEntitlement().getPool(); Set<String> results = entitlementCurator.listEntitledProductIds(consumer, pool); assertEquals(3, results.size()); assertTrue(results.contains(providedProduct1.getId())); assertTrue(results.contains(providedProduct2.getId())); assertTrue(results.contains(pool.getProduct().getId())); }
@Test public void listEntitledProductIdsStartDateOverlap() { Pool existingEntPool = setupListProvidingEntitlement().getPool(); Pool anotherPool = newPoolUsingProducts(existingEntPool, createDate(2002, 1, 1), createDate(2006, 1, 1)); Set<String> results = entitlementCurator.listEntitledProductIds(consumer, anotherPool); assertEquals(3, results.size()); assertTrue(results.contains(existingEntPool.getProductId())); }
@Test public void listEntitledProductIdsEndDateOverlap() { Pool existingEntPool = setupListProvidingEntitlement().getPool(); Pool anotherPool = newPoolUsingProducts(existingEntPool, pastDate, createDate(2002, 1, 1)); Set<String> results = entitlementCurator.listEntitledProductIds(consumer, anotherPool); assertEquals(3, results.size()); assertTrue(results.contains(existingEntPool.getProductId())); }
@Test public void listEntitledProductIdsTotalOverlap() { Pool existingEntPool = setupListProvidingEntitlement().getPool(); Pool anotherPool = newPoolUsingProducts(existingEntPool, pastDate, futureDate); Set<String> results = entitlementCurator.listEntitledProductIds(consumer, anotherPool); assertEquals(5, results.size()); assertTrue(results.contains(existingEntPool.getProductId())); }
@Test public void listEntitledProductIdsNoOverlap() { Pool existingEntPool = setupListProvidingEntitlement().getPool(); Pool anotherPool = setupListProvidingEntitlement(parentProduct2, pastDate, pastDate).getPool(); Set<String> results = entitlementCurator.listEntitledProductIds(consumer, anotherPool); assertEquals(3, results.size()); assertFalse(results.contains(existingEntPool.getProductId())); }