use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.
the class ActivationKeyResource method addPoolToKey.
@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)
public ActivationKeyDTO addPoolToKey(@PathParam("activation_key_id") @Verify(ActivationKey.class) String activationKeyId, @PathParam("pool_id") @Verify(Pool.class) String poolId, @QueryParam("quantity") Long quantity) {
ActivationKey key = activationKeyCurator.verifyAndLookupKey(activationKeyId);
Pool pool = findPool(poolId);
// Throws a BadRequestException if adding pool to key is a bad idea
activationKeyRules.validatePoolForActKey(key, pool, quantity);
// Make sure we don't try to register the pool twice.
if (key.hasPool(pool)) {
throw new BadRequestException(i18n.tr("Pool ID \"{0}\" has already been registered with this activation key", poolId));
}
key.addPool(pool, quantity);
activationKeyCurator.update(key);
return this.translator.translate(key, ActivationKeyDTO.class);
}
use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.
the class ActivationKeyResource method deleteActivationKey.
@ApiOperation(notes = "Removes an Activation Key", value = "deleteActivationKey")
@ApiResponses({ @ApiResponse(code = 400, message = "") })
@DELETE
@Path("{activation_key_id}")
@Produces(MediaType.APPLICATION_JSON)
public void deleteActivationKey(@PathParam("activation_key_id") @Verify(ActivationKey.class) String activationKeyId) {
ActivationKey key = activationKeyCurator.verifyAndLookupKey(activationKeyId);
log.debug("Deleting activation key: {}", activationKeyId);
activationKeyCurator.delete(key);
}
use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.
the class ActivationKeyResource method removePoolFromKey.
@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)
public ActivationKeyDTO removePoolFromKey(@PathParam("activation_key_id") @Verify(ActivationKey.class) String activationKeyId, @PathParam("pool_id") @Verify(Pool.class) String poolId) {
ActivationKey key = activationKeyCurator.verifyAndLookupKey(activationKeyId);
Pool pool = findPool(poolId);
key.removePool(pool);
activationKeyCurator.update(key);
return this.translator.translate(key, ActivationKeyDTO.class);
}
use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.
the class ActivationKeyResourceTest method testAddingRemovingProductIDs.
@Test
public void testAddingRemovingProductIDs() {
ActivationKey key = new ActivationKey();
Owner owner = createOwner();
Product product = this.createProduct(owner);
key.setOwner(owner);
key.setName("dd");
key = activationKeyCurator.create(key);
assertNotNull(key.getId());
activationKeyResource.addProductIdToKey(key.getId(), product.getId());
assertTrue(key.getProducts().size() == 1);
activationKeyResource.removeProductIdFromKey(key.getId(), product.getId());
assertEquals(0, key.getProducts().size());
}
use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.
the class ActivationKeyResourceTest method testActivationKeyWithDiffHostReqPools.
@Test
public void testActivationKeyWithDiffHostReqPools() {
ActivationKey ak = genActivationKey();
ActivationKeyCurator akc = mock(ActivationKeyCurator.class);
PoolManager poolManager = mock(PoolManager.class);
Pool p1 = genPool();
p1.setAttribute(Pool.Attributes.REQUIRES_HOST, "host1");
Pool p2 = genPool();
p2.setAttribute(Pool.Attributes.REQUIRES_HOST, "host2");
ak.addPool(p2, 1L);
when(akc.verifyAndLookupKey(eq("testKey"))).thenReturn(ak);
when(poolManager.find(eq("testPool1"))).thenReturn(p1);
ActivationKeyResource akr = new ActivationKeyResource(akc, i18n, poolManager, serviceLevelValidator, activationKeyRules, null, new ProductCachedSerializationModule(productCurator), this.modelTranslator);
akr.addPoolToKey("testKey", "testPool1", 1L);
}
Aggregations