EntitlementCurator extends AbstractHibernateCurator<Entitlement> { @SuppressWarnings("unchecked") public CandlepinQuery<Entitlement> findByPoolAttribute(Consumer consumer, String attributeName, String value) { DetachedCriteria criteria = DetachedCriteria.forClass(Entitlement.class) .createAlias("pool", "ent_pool") .createAlias("ent_pool.attributes", "attrs") .add(Restrictions.eq("attrs.indices", attributeName)) .add(Restrictions.eq("attrs.elements", value)); if (consumer != null) { criteria.add(Restrictions.eq("consumer", consumer)); } return this.cpQueryFactory.<Entitlement>buildQuery(this.currentSession(), criteria); } @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 findEntitlementsByPoolAttributes() { Owner owner1 = createOwner(); ownerCurator.create(owner1); Owner owner2 = createOwner(); ownerCurator.create(owner2); Product product1 = this.createProduct(owner1); Product product2 = this.createProduct(owner2); Pool p1Attributes = TestUtil.createPool(owner1, product1); Pool p1NoAttributes = TestUtil.createPool(owner1, product1); Pool p2Attributes = TestUtil.createPool(owner2, product2); Pool p2NoAttributes = TestUtil.createPool(owner2, product2); Pool p2BadAttributes = TestUtil.createPool(owner2, product2); p1Attributes.setAttribute("x", "true"); p2Attributes.setAttribute("x", "true"); p2BadAttributes.setAttribute("x", "false"); poolCurator.create(p1Attributes); poolCurator.create(p1NoAttributes); poolCurator.create(p2Attributes); poolCurator.create(p2NoAttributes); poolCurator.create(p2BadAttributes); Entitlement e1 = createEntitlement(owner, consumer, p1Attributes, createEntitlementCertificate("key", "certificate")); entitlementCurator.create(e1); Entitlement e2 = createEntitlement(owner, consumer, p2Attributes, createEntitlementCertificate("key", "certificate")); entitlementCurator.create(e2); Entitlement eBadAttributes = createEntitlement(owner, consumer, p2NoAttributes, createEntitlementCertificate("key", "certificate")); entitlementCurator.create(eBadAttributes); Entitlement eNoAttributes = createEntitlement(owner, consumer, p2BadAttributes, createEntitlementCertificate("key", "certificate")); entitlementCurator.create(eNoAttributes); List<Entitlement> results = entitlementCurator.findByPoolAttribute("x", "true").list(); assertThat(results, Matchers.hasItems(e1, e2)); }