use of org.candlepin.model.Content in project candlepin by candlepin.
the class OwnerContentResourceTest method deleteLockedContent.
@Test(expected = ForbiddenException.class)
public void deleteLockedContent() {
Owner owner = this.createOwner("test_owner");
Content content = this.createContent("test_content", "test_content", owner);
content.setLocked(true);
this.contentCurator.merge(content);
Environment environment = this.createEnvironment(owner, "test_env", "test_env", null, null, Arrays.asList(content));
assertNotNull(this.ownerContentCurator.getContentById(owner, content.getId()));
try {
this.ownerContentResource.remove(owner.getKey(), content.getId());
} catch (ForbiddenException e) {
assertNotNull(this.ownerContentCurator.getContentById(owner, content.getId()));
this.environmentCurator.evict(environment);
environment = this.environmentCurator.find(environment.getId());
assertEquals(1, environment.getEnvironmentContent().size());
throw e;
}
}
use of org.candlepin.model.Content in project candlepin by candlepin.
the class OwnerContentResourceTest method deleteContent.
@Test
public void deleteContent() {
Owner owner = this.createOwner("test_owner");
Content content = this.createContent("test_content", "test_content", owner);
Environment environment = this.createEnvironment(owner, "test_env", "test_env", null, null, Arrays.asList(content));
assertNotNull(this.ownerContentCurator.getContentById(owner, content.getId()));
this.ownerContentResource.remove(owner.getKey(), content.getId());
assertNull(this.ownerContentCurator.getContentById(owner, content.getId()));
this.environmentCurator.evict(environment);
environment = this.environmentCurator.find(environment.getId());
assertEquals(0, environment.getEnvironmentContent().size());
}
use of org.candlepin.model.Content in project candlepin by candlepin.
the class AutobindRulesTest method createV3OnlyPool.
/*
* Create a pool with too much content for a V1 certificate, consumer must be V3
* capable.
*/
public Pool createV3OnlyPool() {
Product mktProduct = TestUtil.createProduct(productId, "A test product");
Product engProduct = TestUtil.createProduct(Integer.toString(TestUtil.randomInt()), "An ENG product");
engProduct.setProductContent(null);
for (int i = 0; i < X509ExtensionUtil.V1_CONTENT_LIMIT + 1; i++) {
Content content = TestUtil.createContent("fake" + i);
content.setLabel("fake" + i);
content.setType("yum");
content.setVendor("vendor");
content.setContentUrl("");
content.setGpgUrl("");
content.setArches("");
engProduct.addContent(content, true);
}
Pool pool = TestUtil.createPool(owner, mktProduct);
pool.setId("DEAD-BEEFX");
pool.addProvidedProduct(engProduct);
when(mockProductCurator.getPoolProvidedProductsCached(pool.getId())).thenReturn(Collections.singleton(engProduct));
return pool;
}
use of org.candlepin.model.Content in project candlepin by candlepin.
the class OwnerProductResource method addBatchContent.
@ApiOperation(notes = "Adds one or more Content entities to a Product", value = "addBatchContent")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/{product_id}/batch_content")
@Transactional
public ProductDTO addBatchContent(@PathParam("owner_key") String ownerKey, @PathParam("product_id") String productId, @ApiParam(name = "contentMap", required = true) Map<String, Boolean> contentMap) {
Owner owner = this.getOwnerByKey(ownerKey);
Product product = this.fetchProduct(owner, productId);
Collection<ProductContent> productContent = new LinkedList<>();
if (product.isLocked()) {
throw new ForbiddenException(i18n.tr("product \"{0}\" is locked", product.getId()));
}
this.productCurator.lock(product);
ProductDTO pdto = this.translator.translate(product, ProductDTO.class);
// Impl note:
// This is a wholely inefficient way of doing this. When we return to using ID-based linking
// and we're not linking the universe with our model, we can just attach the IDs directly
// without needing all this DTO conversion back and forth.
// Alternatively, we can shut off Hibernate's auto-commit junk and get in the habit of
// calling commit methods as necessary so we don't have to work with DTOs internally.
boolean changed = false;
for (Entry<String, Boolean> entry : contentMap.entrySet()) {
Content content = this.fetchContent(owner, entry.getKey());
boolean enabled = entry.getValue() != null ? entry.getValue() : ProductContent.DEFAULT_ENABLED_STATE;
ContentDTO cdto = this.translator.translate(content, ContentDTO.class);
changed |= pdto.addContent(cdto, enabled);
}
if (changed) {
product = this.productManager.updateProduct(pdto, owner, true);
}
return this.translator.translate(product, ProductDTO.class);
}
use of org.candlepin.model.Content in project candlepin by candlepin.
the class OwnerContentResource method createContentImpl.
/**
* Creates or merges the given Content object.
*
* @param owner
* The owner for which to create the new content
*
* @param content
* The content to create or merge
*
* @return
* the newly created and/or merged Content object.
*/
private Content createContentImpl(Owner owner, ContentDTO content) {
// TODO: check if arches have changed ??
Content entity = null;
if (content.getId() == null || content.getId().trim().length() == 0) {
content.setId(this.idGenerator.generateId());
entity = this.contentManager.createContent(content, owner);
} else {
Content existing = this.ownerContentCurator.getContentById(owner, content.getId());
if (existing != null) {
if (existing.isLocked()) {
throw new ForbiddenException(i18n.tr("content \"{0}\" is locked", existing.getId()));
}
entity = this.contentManager.updateContent(content, owner, true);
} else {
entity = this.contentManager.createContent(content, owner);
}
}
return entity;
}
Aggregations