private ActivationKey findKey(String activationKeyId) { ActivationKey key = activationKeyCurator.find(activationKeyId); if (key == null) { throw new BadRequestException( i18n.tr("ActivationKey with id {0} could not be found.", activationKeyId)); } return key; }
/** * @httpcode 400 * @httpcode 200 */ @DELETE @Path("{activation_key_id}") @Produces(MediaType.APPLICATION_JSON) public void deleteActivationKey( @PathParam("activation_key_id") @Verify(ActivationKey.class) String activationKeyId) { ActivationKey key = findKey(activationKeyId); log.debug("Deleting info " + activationKeyId); activationKeyCurator.delete(key); }
/** * @return an ActivationKey * @httpcode 400 * @httpcode 200 */ @PUT @Path("{activation_key_id}") @Produces(MediaType.APPLICATION_JSON) public ActivationKey updateActivationKey( @PathParam("activation_key_id") @Verify(ActivationKey.class) String activationKeyId, ActivationKey key) { ActivationKey toUpdate = findKey(activationKeyId); toUpdate.setName(key.getName()); activationKeyCurator.merge(toUpdate); return toUpdate; }
/** * @return a Pool * @httpcode 400 * @httpcode 200 */ @DELETE @Path("{activation_key_id}/pools/{pool_id}") @Produces(MediaType.APPLICATION_JSON) public Pool removePoolFromKey( @PathParam("activation_key_id") @Verify(ActivationKey.class) String activationKeyId, @PathParam("pool_id") @Verify(value = Pool.class, require = Access.READ_POOLS) String poolId) { ActivationKey key = findKey(activationKeyId); Pool pool = findPool(poolId); key.removePool(pool); activationKeyCurator.update(key); return pool; }
/** * @return a Pool * @httpcode 400 * @httpcode 200 */ @POST @Path("{activation_key_id}/pools/{pool_id}") @Produces(MediaType.APPLICATION_JSON) public Pool addPoolToKey( @PathParam("activation_key_id") @Verify(ActivationKey.class) String activationKeyId, @PathParam("pool_id") @Verify(value = Pool.class, require = Access.READ_POOLS) String poolId, @QueryParam("quantity") @DefaultValue("1") long quantity) { if (quantity < 1) { throw new BadRequestException(i18n.tr("The quantity must be greater than 0")); } ActivationKey key = findKey(activationKeyId); Pool pool = findPool(poolId); if (pool.getAttributeValue("requires_consumer_type") != null && pool.getAttributeValue("requires_consumer_type").equals("person") || pool.getProductAttribute("requires_consumer_type") != null && pool.getProductAttribute("requires_consumer_type").getValue().equals("person")) { throw new BadRequestException( i18n.tr( "Cannot add pools restricted to " + "consumer type 'person' to activation keys.")); } if (quantity > 1) { ProductPoolAttribute ppa = pool.getProductAttribute("multi-entitlement"); if (ppa == null || !ppa.getValue().equalsIgnoreCase("yes")) { throw new BadRequestException( i18n.tr( "Error: Only pools with multi-entitlement product" + " subscriptions can be added to the activation key with" + " a quantity greater than one.")); } } if ((!pool.isUnlimited()) && (quantity > pool.getQuantity())) { throw new BadRequestException( i18n.tr("The quantity must not be greater than the total " + "allowed for the pool")); } key.addPool(pool, quantity); activationKeyCurator.update(key); return pool; }
/** * @return a list of ActivationKey objects * @httpcode 200 */ @GET @Produces(MediaType.APPLICATION_JSON) public List<ActivationKey> findActivationKey() { List<ActivationKey> keyList = activationKeyCurator.listAll(); return keyList; }