EntitlementResource { @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") 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); } ResteasyContext.pushContext(Page.class, p); List<EntitlementDTO> entitlementDTOs = new ArrayList<>(); for (Entitlement entitlement : p.getPageData()) { entitlementDTOs.add(this.translator.translate(entitlement, EntitlementDTO.class)); } return entitlementDTOs; } @Inject  EntitlementResource(EntitlementCurator entitlementCurator,
        ConsumerCurator consumerCurator,
        ConsumerTypeCurator consumerTypeCurator,
        PoolManager poolManager,
        I18n i18n,
        Entitler entitler,
        Enforcer enforcer,
        EntitlementRulesTranslator messageTranslator,
        JobManager jobManager,
        ModelTranslator translator); @ApiOperation(notes = "Checks Consumer for Product Entitlement", value = "hasEntitlement") @ApiResponses({ @ApiResponse(code = 404, message = "") }) @GET @Produces(MediaType.APPLICATION_JSON) @Path("consumer/{consumer_uuid}/product/{product_id}") EntitlementDTO hasEntitlement(@PathParam("consumer_uuid") String consumerUuid,
        @PathParam("product_id") String productId); @ApiOperation(notes = "Retrieves list of Entitlements", value = "listAllForConsumer") @ApiResponses({ @ApiResponse(code = 400, message = "") }) @GET @Produces(MediaType.APPLICATION_JSON) List<EntitlementDTO> listAllForConsumer(
        @QueryParam("consumer") String consumerUuid,
        @QueryParam("matches") String matches,
        @QueryParam("attribute") List<KeyValueParameter> attrFilters,
        @Context PageRequest pageRequest); @ApiOperation(notes = "Retrieves a single Entitlement", value = "getEntitlement") @ApiResponses({ @ApiResponse(code = 404, message = "") }) @GET @Produces(MediaType.APPLICATION_JSON) @Path("{entitlement_id}") EntitlementDTO getEntitlement(
        @PathParam("entitlement_id") @Verify(Entitlement.class) String entitlementId); @ApiOperation(notes = "Updates an Entitlement. This only works for the quantity.", value = "updateEntitlement") @ApiResponses({ @ApiResponse(code = 404, message = "") }) @PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("{entitlement_id}") void updateEntitlement(
        @PathParam("entitlement_id") @Verify(Entitlement.class) String id,
        @ApiParam(name = "update", required = true) EntitlementDTO update); @ApiOperation(notes = "Retrieves a Subscription Certificate. We can't return CdnInfo " + "at this time, but when the time comes this is the implementation we want to start" + " from. It will require changes to thumbslug. will also" + " @Produces(MediaType.APPLICATION_JSON)", value = "getUpstreamCert") @ApiResponses({ @ApiResponse(code = 404, message = "") }) @GET @Produces(MediaType.TEXT_PLAIN) @Path("{dbid}/upstream_cert") String getUpstreamCert(
        @PathParam("dbid") String entitlementId); @ApiOperation(notes = "Deletes an Entitlement", value = "unbind") @ApiResponses({ @ApiResponse(code = 403, message = ""), @ApiResponse(code = 404, message = "") }) @DELETE @Produces(MediaType.WILDCARD) @Path("/{dbid}") void unbind(@PathParam("dbid") String dbid); @ApiOperation(notes = "Regenerates the Entitlement Certificates for a Product", value = "regenerateEntitlementCertificatesForProduct") @ApiResponses({ @ApiResponse(code = 202, message = "") }) @PUT @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.WILDCARD) @Path("product/{product_id}") AsyncJobStatusDTO regenerateEntitlementCertificatesForProduct(
        @PathParam("product_id") String productId,
        @QueryParam("lazy_regen") @DefaultValue("true") boolean lazyRegen); @ApiOperation(notes = "Migrate entitlements from one distributor consumer to another." + " Can specify full or partial quantity. No specified quantity " + "will lead to full migration of the entitlement.", value = "migrateEntitlement") @ApiResponses({ @ApiResponse(code = 404, message = "") }) @PUT @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.WILDCARD) @Path("{entitlement_id}/migrate") @Transactional Response migrateEntitlement(
        @PathParam("entitlement_id") @Verify(Entitlement.class) String id,
        @QueryParam("to_consumer") @Verify(Consumer.class) String uuid,
        @QueryParam("quantity") Integer quantity);  }
@Test public void getAllEntitlements() { PageRequest req = new PageRequest(); req.setPage(1); req.setPerPage(10); Entitlement e = TestUtil.createEntitlement(); e.setId("getEntitlementList"); List<Entitlement> entitlements = new ArrayList<>(); entitlements.add(e); Page<List<Entitlement>> page = new Page<>(); page.setPageData(entitlements); EntitlementDTO entitlementDTO = new EntitlementDTO(); entitlementDTO.setId("getEntitlementList"); when(entitlementCurator.listAll(isA(EntitlementFilterBuilder.class), isA(PageRequest.class))) .thenReturn(page); when(modelTranslator.translate(isA(Entitlement.class), eq(EntitlementDTO.class))).thenReturn(entitlementDTO); List<EntitlementDTO> result = entResource.listAllForConsumer(null, null, null, req); assertEquals(1, result.size()); assertEquals("getEntitlementList", result.get(0).getId()); }
@Test public void getAllEntitlementsForConsumer() { PageRequest req = new PageRequest(); req.setPage(1); req.setPerPage(10); Owner owner = TestUtil.createOwner(); Consumer consumer = TestUtil.createConsumer(owner); Pool pool = TestUtil.createPool(owner, TestUtil.createProduct()); Entitlement e = TestUtil.createEntitlement(owner, consumer, pool, null); e.setId("getAllEntitlementsForConsumer"); List<Entitlement> entitlements = new ArrayList<>(); entitlements.add(e); Page<List<Entitlement>> page = new Page<>(); page.setPageData(entitlements); EntitlementDTO entitlementDTO = new EntitlementDTO(); entitlementDTO.setId("getAllEntitlementsForConsumer"); when(consumerCurator.findByUuid(eq(consumer.getUuid()))).thenReturn(consumer); when(entitlementCurator.listByConsumer(any(Consumer.class), nullable(String.class), any(EntitlementFilterBuilder.class), any(PageRequest.class))).thenReturn(page); when(modelTranslator.translate(any(Entitlement.class), eq(EntitlementDTO.class))).thenReturn(entitlementDTO); List<EntitlementDTO> result = entResource.listAllForConsumer(consumer.getUuid(), null, null, req); assertEquals(1, result.size()); assertEquals("getAllEntitlementsForConsumer", result.get(0).getId()); }