use of org.candlepin.model.EntitlementFilterBuilder in project candlepin by candlepin.
the class EntitlementFinderUtilTest method nullFilterTest.
@Test
public void nullFilterTest() {
EntitlementFilterBuilder filters = EntitlementFinderUtil.createFilter(null, null);
assertEquals(false, filters.hasMatchFilters());
}
use of org.candlepin.model.EntitlementFilterBuilder in project candlepin by candlepin.
the class EntitlementFinderUtilTest method matchesFilterTest.
@Test
public void matchesFilterTest() {
EntitlementFilterBuilder filters = EntitlementFinderUtil.createFilter("matchesFilterTest", null);
assertEquals(true, filters.hasMatchFilters());
}
use of org.candlepin.model.EntitlementFilterBuilder in project candlepin by candlepin.
the class OwnerResource method ownerEntitlements.
/**
* Retrieves the list of Entitlements for an Owner
*
* @param ownerKey id of the owner whose entitlements are sought.
* @return a list of Entitlement objects
* @httpcode 404
* @httpcode 200
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{owner_key}/entitlements")
@ApiOperation(notes = "Retrieves the list of Entitlements for an Owner", value = "List Owner Entitlements")
@ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") })
public List<EntitlementDTO> ownerEntitlements(@PathParam("owner_key") @Verify(Owner.class) String ownerKey, @QueryParam("product") String productId, @QueryParam("matches") String matches, @QueryParam("attribute") @CandlepinParam(type = KeyValueParameter.class) List<KeyValueParameter> attrFilters, @Context PageRequest pageRequest) {
Owner owner = findOwnerByKey(ownerKey);
EntitlementFilterBuilder filters = EntitlementFinderUtil.createFilter(matches, attrFilters);
Page<List<Entitlement>> entitlementsPage = entitlementCurator.listByOwner(owner, productId, filters, pageRequest);
// Store the page for the LinkHeaderPostInterceptor
ResteasyProviderFactory.pushContext(Page.class, entitlementsPage);
List<EntitlementDTO> entitlementDTOs = new ArrayList<>();
for (Entitlement entitlement : entitlementsPage.getPageData()) {
entitlementDTOs.add(this.translator.translate(entitlement, EntitlementDTO.class));
}
return entitlementDTOs;
}
use of org.candlepin.model.EntitlementFilterBuilder in project candlepin by candlepin.
the class ConsumerResource method listEntitlements.
@ApiOperation(notes = "Retrives a list of Entitlements", value = "listEntitlements")
@ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 404, message = "") })
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{consumer_uuid}/entitlements")
public List<EntitlementDTO> listEntitlements(@PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid, @QueryParam("product") String productId, @QueryParam("regen") @DefaultValue("true") Boolean regen, @QueryParam("matches") String matches, @QueryParam("attribute") @CandlepinParam(type = KeyValueParameter.class) List<KeyValueParameter> attrFilters, @Context PageRequest pageRequest) {
Consumer consumer = consumerCurator.verifyAndLookupConsumer(consumerUuid);
if (regen) {
revokeOnGuestMigration(consumer);
}
EntitlementFilterBuilder filters = EntitlementFinderUtil.createFilter(matches, attrFilters);
Page<List<Entitlement>> entitlementsPage = entitlementCurator.listByConsumer(consumer, productId, filters, pageRequest);
// Store the page for the LinkHeaderPostInterceptor
ResteasyProviderFactory.pushContext(Page.class, entitlementsPage);
if (regen) {
poolManager.regenerateDirtyEntitlements(entitlementsPage.getPageData());
} else {
log.debug("Skipping certificate regeneration.");
}
// the method in this class does not do quantity
if (entitlementsPage.getPageData() != null) {
for (Entitlement ent : entitlementsPage.getPageData()) {
addCalculatedAttributes(ent);
}
}
List<EntitlementDTO> entitlementDTOs = new ArrayList<>();
for (Entitlement entitlement : entitlementsPage.getPageData()) {
entitlementDTOs.add(this.translator.translate(entitlement, EntitlementDTO.class));
}
return entitlementDTOs;
}
use of org.candlepin.model.EntitlementFilterBuilder in project candlepin by candlepin.
the class EntitlementResource method listAllForConsumer.
@ApiOperation(notes = "Retrieves list of Entitlements", value = "listAllForConsumer")
@ApiResponses({ @ApiResponse(code = 400, message = "") })
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<EntitlementDTO> listAllForConsumer(@QueryParam("consumer") String consumerUuid, @QueryParam("matches") String matches, @QueryParam("attribute") @CandlepinParam(type = KeyValueParameter.class) List<KeyValueParameter> attrFilters, @Context PageRequest pageRequest) {
EntitlementFilterBuilder filters = EntitlementFinderUtil.createFilter(matches, attrFilters);
Page<List<Entitlement>> p;
if (consumerUuid != null) {
Consumer consumer = consumerCurator.findByUuid(consumerUuid);
if (consumer == null) {
throw new BadRequestException(i18n.tr("Unit with ID \"{0}\" could not be found.", consumerUuid));
}
p = entitlementCurator.listByConsumer(consumer, null, filters, pageRequest);
} else {
p = entitlementCurator.listAll(filters, pageRequest);
}
// Store the page for the LinkHeaderResponseFilter
ResteasyProviderFactory.pushContext(Page.class, p);
List<EntitlementDTO> entitlementDTOs = new ArrayList<>();
for (Entitlement entitlement : p.getPageData()) {
entitlementDTOs.add(this.translator.translate(entitlement, EntitlementDTO.class));
}
return entitlementDTOs;
}
Aggregations