ActivationKeyResource { @ApiOperation(notes = "Updates an Activation Key", value = "Update Activation Key") @ApiResponses({ @ApiResponse(code = 400, message = "") }) @PUT @Path("{activation_key_id}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public ActivationKeyDTO updateActivationKey( @PathParam("activation_key_id") @Verify(ActivationKey.class) String activationKeyId, @ApiParam(name = "update", required = true) ActivationKeyDTO update) { ActivationKey toUpdate = this.fetchActivationKey(activationKeyId); if (update.getName() != null) { Matcher keyMatcher = AK_CHAR_FILTER.matcher(update.getName()); if (!keyMatcher.matches()) { throw new BadRequestException( i18n.tr("The activation key name \"{0}\" must be alphanumeric or " + "include the characters \"-\" or \"_\"", update.getName())); } toUpdate.setName(update.getName()); } String serviceLevel = update.getServiceLevel(); if (serviceLevel != null) { serviceLevelValidator.validate(toUpdate.getOwner().getId(), serviceLevel); toUpdate.setServiceLevel(serviceLevel); } if (update.getReleaseVersion() != null) { toUpdate.setReleaseVer(new Release(update.getReleaseVersion())); } if (update.getDescription() != null) { toUpdate.setDescription(update.getDescription()); } if (update.getUsage() != null) { toUpdate.setUsage(update.getUsage()); } if (update.getRole() != null) { toUpdate.setRole(update.getRole()); } if (update.getAddOns() != null) { Set<String> addOns = new HashSet<>(); addOns.addAll(update.getAddOns()); toUpdate.setAddOns(addOns); } if (update.isAutoAttach() != null) { toUpdate.setAutoAttach(update.isAutoAttach()); } toUpdate = activationKeyCurator.merge(toUpdate); return this.translator.translate(toUpdate, ActivationKeyDTO.class); } @Inject  ActivationKeyResource(ActivationKeyCurator activationKeyCurator, I18n i18n,
        PoolManager poolManager, ServiceLevelValidator serviceLevelValidator,
        ActivationKeyRules activationKeyRules, OwnerProductCurator ownerProductCurator,
        ProductCachedSerializationModule productCachedModule, ModelTranslator translator); @ApiOperation(notes = "Retrieves a single Activation Key", value = "Get Activation Key") @ApiResponses({ @ApiResponse(code = 400, message = "") }) @GET @Path("{activation_key_id}") @Produces(MediaType.APPLICATION_JSON) ActivationKeyDTO getActivationKey(
        @PathParam("activation_key_id")
        @Verify(ActivationKey.class) String activationKeyId); @ApiOperation(notes = "Retrieves a list of Pools based on the Activation Key", value = "Get Activation Key Pools", response = PoolDTO.class, responseContainer = "list") @ApiResponses({ @ApiResponse(code = 400, message = "")}) @GET @Path("{activation_key_id}/pools") @Produces(MediaType.APPLICATION_JSON) Iterator<PoolDTO> getActivationKeyPools(
        @PathParam("activation_key_id") @Verify(ActivationKey.class) String activationKeyId); @ApiOperation(notes = "Updates an Activation Key", value = "Update Activation Key") @ApiResponses({ @ApiResponse(code = 400, message = "") }) @PUT @Path("{activation_key_id}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) ActivationKeyDTO updateActivationKey(
        @PathParam("activation_key_id") @Verify(ActivationKey.class) String activationKeyId,
        @ApiParam(name = "update", required = true) ActivationKeyDTO update); @ApiOperation(notes = "Adds a Pool to an Activation Key", value = "Add Pool to Key") @ApiResponses({ @ApiResponse(code = 400, message = "")}) @POST @Path("{activation_key_id}/pools/{pool_id}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.WILDCARD) ActivationKeyDTO addPoolToKey(
        @PathParam("activation_key_id") @Verify(ActivationKey.class) String activationKeyId,
        @PathParam("pool_id") @Verify(Pool.class) String poolId,
        @QueryParam("quantity") Long quantity); @ApiOperation(notes = "Removes a Pool from an Activation Key", value = "Remove Pool From Key") @ApiResponses({ @ApiResponse(code = 400, message = "")}) @DELETE @Path("{activation_key_id}/pools/{pool_id}") @Produces(MediaType.APPLICATION_JSON) ActivationKeyDTO removePoolFromKey(
        @PathParam("activation_key_id") @Verify(ActivationKey.class) String activationKeyId,
        @PathParam("pool_id")
        @Verify(Pool.class) String poolId); @ApiOperation(notes = "Adds an Product ID to an Activation Key", value = "Add Product ID to key") @ApiResponses({ @ApiResponse(code = 400, message = "")}) @POST @Path("{activation_key_id}/product/{product_id}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.WILDCARD) ActivationKeyDTO addProductIdToKey(
        @PathParam("activation_key_id") @Verify(ActivationKey.class) String activationKeyId,
        @PathParam("product_id") String productId); @ApiOperation(notes = "Removes a Product ID from an Activation Key", value = "Remove Product Id from Key") @ApiResponses({ @ApiResponse(code = 400, message = "") }) @DELETE @Path("{activation_key_id}/product/{product_id}") @Produces(MediaType.APPLICATION_JSON) ActivationKeyDTO removeProductIdFromKey(
        @PathParam("activation_key_id") @Verify(ActivationKey.class) String activationKeyId,
        @PathParam("product_id") String productId); @ApiOperation(notes = "Retrieves a list of Activation Keys", value = "findActivationKey", response = ActivationKeyDTO.class, responseContainer = "list") @GET @Produces(MediaType.APPLICATION_JSON) CandlepinQuery<ActivationKeyDTO> findActivationKey(); @ApiOperation(notes = "Removes an Activation Key", value = "deleteActivationKey") @ApiResponses({ @ApiResponse(code = 400, message = "") }) @DELETE @Path("{activation_key_id}") @Produces(MediaType.APPLICATION_JSON) void deleteActivationKey(
        @PathParam("activation_key_id")
        @Verify(ActivationKey.class) String activationKeyId);  }
@Test public void testUpdateTooLongRelease() { ActivationKey key = new ActivationKey(); OwnerDTO ownerDto = new OwnerDTO(); key.setOwner(owner); key.setName("dd"); key.setServiceLevel("level1"); key.setReleaseVer(new Release("release1")); activationKeyCurator.create(key); ActivationKeyDTO update = new ActivationKeyDTO(); update.setOwner(ownerDto); update.setName("dd"); update.setServiceLevel("level1"); update.setReleaseVersion(TestUtil.getStringOfSize(256)); assertThrows(BadRequestException.class, () -> activationKeyResource.updateActivationKey(key.getId(), update) ); }