PoolResource { @ApiOperation(notes = "Retrieves a single Pool", value = "getPool") @ApiResponses({ @ApiResponse(code = 404, message = "if the pool with the specified id is not found"), @ApiResponse(code = 404, message = "") }) @GET @Path("/{pool_id}") @Produces(MediaType.APPLICATION_JSON) public PoolDTO getPool(@PathParam("pool_id") @Verify(Pool.class) String id, @QueryParam("consumer") String consumerUuid, @ApiParam("Uses ISO 8601 format") @QueryParam("activeon") String activeOn, @Context Principal principal) { Pool toReturn = poolManager.get(id); Consumer c = null; if (consumerUuid != null) { c = consumerCurator.findByUuid(consumerUuid); if (c == null) { throw new NotFoundException(i18n.tr("consumer: {0} not found", consumerUuid)); } if (!principal.canAccess(c, SubResource.NONE, Access.READ_ONLY)) { throw new ForbiddenException(i18n.tr("User {0} cannot access consumer {1}", principal.getPrincipalName(), c.getUuid())); } } if (toReturn != null) { Date activeOnDate = new Date(); if (activeOn != null) { activeOnDate = ResourceDateParser.parseDateString(activeOn); } toReturn.setCalculatedAttributes( calculatedAttributesUtil.buildCalculatedAttributes(toReturn, activeOnDate)); calculatedAttributesUtil.setQuantityAttributes(toReturn, c, activeOnDate); return translator.translate(toReturn, PoolDTO.class); } throw new NotFoundException(i18n.tr("Subscription Pool with ID \"{0}\" could not be found.", id)); } @Inject  PoolResource(ConsumerCurator consumerCurator, OwnerCurator ownerCurator,
        I18n i18n, PoolManager poolManager, CalculatedAttributesUtil calculatedAttributesUtil,
        ModelTranslator translator); @ApiOperation( notes = "Retrieves a list of Pools @deprecated Use the method on /owners", value = "") @ApiResponses({ @ApiResponse(code = 400, message = "if both consumer(unit) and owner are given, or if a" + " product id is specified without a consumer(unit) or owner"), @ApiResponse(code = 404, message = "if a specified consumer(unit) or owner is not found"), @ApiResponse(code = 403, message = "") }) @GET @Produces(MediaType.APPLICATION_JSON) @Wrapped(element = "pools") @Deprecated @SecurityHole List<PoolDTO> list(@QueryParam("owner") String ownerId,
        @QueryParam("consumer") String consumerUuid,
        @QueryParam("product") String productId,
        @ApiParam("Use with consumerUuid to list all pools available to the consumer. " +
        "This will include pools which would otherwise be omitted due to a rules" +
        " warning. (i.e. not recommended) Pools that trigger an error however will" +
        " still be omitted. (no entitlements available, consumer type mismatch, etc)")
        @QueryParam("listall") @DefaultValue("false") boolean listAll,
        @ApiParam("Uses ISO 8601 format") @QueryParam("activeon") String activeOn,
        @Context Principal principal,
        @Context PageRequest pageRequest); @ApiOperation(notes = "Retrieves a single Pool", value = "getPool") @ApiResponses({ @ApiResponse(code = 404, message = "if the pool with the specified id is not found"), @ApiResponse(code = 404, message = "") }) @GET @Path("/{pool_id}") @Produces(MediaType.APPLICATION_JSON) PoolDTO getPool(@PathParam("pool_id") @Verify(Pool.class) String id,
        @QueryParam("consumer") String consumerUuid,
        @ApiParam("Uses ISO 8601 format") @QueryParam("activeon") String activeOn,
        @Context Principal principal); @ApiOperation(notes = "Remove a Pool", value = "deletePool") @ApiResponses({ @ApiResponse(code = 404, message = "if the pool with the specified id is not found") }) @DELETE @Path("/{pool_id}") @Produces(MediaType.APPLICATION_JSON) void deletePool(@PathParam("pool_id") String id); @ApiOperation(notes = "Retrieve a CDN for a Pool", value = "getPoolCdn") @ApiResponses({ @ApiResponse(code = 400, message = "") }) @GET @Path("{pool_id}/cdn") @Produces(MediaType.APPLICATION_JSON) CdnDTO getPoolCdn(
        @PathParam("pool_id") @Verify(Pool.class) String id); @ApiOperation( notes = "Retrieve a list of Consumer UUIDs attached to a pool. Available only to superadmins", value = "listEntitledConsumerUuids") @ApiResponses({ @ApiResponse(code = 400, message = "") }) @GET @Path("{pool_id}/entitlements/consumer_uuids") @Produces(MediaType.APPLICATION_JSON) List<String> listEntitledConsumerUuids(@PathParam("pool_id") String id); @ApiOperation(notes = "Retrieve a list of Entitlements for a Pool", value = "getPoolEntitlements") @ApiResponses({ @ApiResponse(code = 400, message = "") }) @GET @Path("{pool_id}/entitlements") @Produces(MediaType.APPLICATION_JSON) List<EntitlementDTO> getPoolEntitlements(@PathParam("pool_id")
        @Verify(value = Pool.class, subResource = SubResource.ENTITLEMENTS) String id,
        @Context Principal principal); @ApiOperation(notes = "Retrieves a Subscription Certificate As a PEM", value = "getSubCertAsPem") @DoNotUseJAXBProvider @GET @Path("{pool_id}/cert") // cpc passes up content-type on all calls, make sure we don't 415 it @Consumes({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON}) @Produces({ MediaType.TEXT_PLAIN }) String getSubCertAsPem(
        @PathParam("pool_id") String poolId); @ApiOperation(notes = "Retrieves a Subscription Certificate", value = "getSubCert") @GET @Path("{pool_id}/cert") @Consumes({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON}) CertificateDTO getSubCert(
        @PathParam("pool_id") String poolId);  }
@Test public void testCalculatedAttributesEmpty() { PoolDTO p = poolResource.getPool(pool1.getId(), null, null, adminPrincipal); assertTrue(p.getCalculatedAttributes().isEmpty()); }
@Test public void testUnauthorizedUserRequestingPool() { Owner owner2 = createOwner(); ownerCurator.create(owner2); assertThrows(NotFoundException.class, () -> poolResource.getPool(pool1.getId(), passConsumer.getUuid(), null, setupPrincipal(owner2, Access.NONE)) ); }
@Test public void testUnknownConsumerRequestingPool() { assertThrows(NotFoundException.class, () -> poolResource.getPool(pool1.getId(), "xyzzy", null, adminPrincipal) ); }