Esempio n. 1
0
 /**
  * @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;
 }
Esempio n. 2
0
  /**
   * @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;
  }