Search in sources :

Example 1 with EntitlementFilterBuilder

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());
}
Also used : EntitlementFilterBuilder(org.candlepin.model.EntitlementFilterBuilder) Test(org.junit.Test)

Example 2 with EntitlementFilterBuilder

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());
}
Also used : EntitlementFilterBuilder(org.candlepin.model.EntitlementFilterBuilder) Test(org.junit.Test)

Example 3 with EntitlementFilterBuilder

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;
}
Also used : Owner(org.candlepin.model.Owner) EntitlementDTO(org.candlepin.dto.api.v1.EntitlementDTO) EntitlementFilterBuilder(org.candlepin.model.EntitlementFilterBuilder) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Entitlement(org.candlepin.model.Entitlement) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with EntitlementFilterBuilder

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;
}
Also used : EntitlementDTO(org.candlepin.dto.api.v1.EntitlementDTO) DeletedConsumer(org.candlepin.model.DeletedConsumer) Consumer(org.candlepin.model.Consumer) EntitlementFilterBuilder(org.candlepin.model.EntitlementFilterBuilder) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Entitlement(org.candlepin.model.Entitlement) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 5 with EntitlementFilterBuilder

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;
}
Also used : EntitlementDTO(org.candlepin.dto.api.v1.EntitlementDTO) Consumer(org.candlepin.model.Consumer) EntitlementFilterBuilder(org.candlepin.model.EntitlementFilterBuilder) ArrayList(java.util.ArrayList) BadRequestException(org.candlepin.common.exceptions.BadRequestException) List(java.util.List) ArrayList(java.util.ArrayList) Entitlement(org.candlepin.model.Entitlement) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

EntitlementFilterBuilder (org.candlepin.model.EntitlementFilterBuilder)5 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 GET (javax.ws.rs.GET)3 Produces (javax.ws.rs.Produces)3 EntitlementDTO (org.candlepin.dto.api.v1.EntitlementDTO)3 Entitlement (org.candlepin.model.Entitlement)3 LinkedList (java.util.LinkedList)2 Path (javax.ws.rs.Path)2 Consumer (org.candlepin.model.Consumer)2 Test (org.junit.Test)2 BadRequestException (org.candlepin.common.exceptions.BadRequestException)1 DeletedConsumer (org.candlepin.model.DeletedConsumer)1 Owner (org.candlepin.model.Owner)1