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();
}
}
Aggregations