Search in sources :

Example 1 with PoolQuantityDTO

use of org.candlepin.dto.api.v1.PoolQuantityDTO in project candlepin by candlepin.

the class ConsumerResource method dryBind.

@ApiOperation(notes = "Retrieves a list of Pools and quantities that would be the " + "result of an auto-bind. This is a dry run of an autobind. It allows the client " + "to see what would be the result of an autobind without executing it. It can only" + " do this for the prevously established list of installed products for the consumer" + " If a service level is included in the request, then that level will override " + "the one stored on the consumer. If no service level is included then the existing " + "one will be used. The Response has a list of PoolQuantity objects", value = "dryBind")
@ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 403, message = ""), @ApiResponse(code = 404, message = "") })
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/{consumer_uuid}/entitlements/dry-run")
public List<PoolQuantityDTO> dryBind(@PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid, @QueryParam("service_level") String serviceLevel) {
    // Verify consumer exists:
    Consumer consumer = consumerCurator.verifyAndLookupConsumer(consumerUuid);
    Owner owner = ownerCurator.findOwnerById(consumer.getOwnerId());
    if (owner.isAutobindDisabled()) {
        throw new BadRequestException(i18n.tr("Owner has autobind disabled."));
    }
    List<PoolQuantity> dryRunPools = new ArrayList<>();
    try {
        consumerBindUtil.validateServiceLevel(consumer.getOwnerId(), serviceLevel);
        dryRunPools = entitler.getDryRun(consumer, owner, serviceLevel);
    } catch (ForbiddenException fe) {
        return Collections.<PoolQuantityDTO>emptyList();
    } catch (BadRequestException bre) {
        throw bre;
    } catch (RuntimeException re) {
        return Collections.<PoolQuantityDTO>emptyList();
    }
    if (dryRunPools != null) {
        List<PoolQuantityDTO> dryRunPoolDtos = new ArrayList<>();
        for (PoolQuantity pq : dryRunPools) {
            dryRunPoolDtos.add(this.translator.translate(pq, PoolQuantityDTO.class));
        }
        return dryRunPoolDtos;
    } else {
        return Collections.<PoolQuantityDTO>emptyList();
    }
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Owner(org.candlepin.model.Owner) ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) DeletedConsumer(org.candlepin.model.DeletedConsumer) Consumer(org.candlepin.model.Consumer) ArrayList(java.util.ArrayList) BadRequestException(org.candlepin.common.exceptions.BadRequestException) PoolQuantityDTO(org.candlepin.dto.api.v1.PoolQuantityDTO) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 ArrayList (java.util.ArrayList)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 BadRequestException (org.candlepin.common.exceptions.BadRequestException)1 ForbiddenException (org.candlepin.common.exceptions.ForbiddenException)1 PoolQuantityDTO (org.candlepin.dto.api.v1.PoolQuantityDTO)1 Consumer (org.candlepin.model.Consumer)1 DeletedConsumer (org.candlepin.model.DeletedConsumer)1 Owner (org.candlepin.model.Owner)1 PoolQuantity (org.candlepin.model.PoolQuantity)1