use of org.candlepin.dto.manifest.v1.ContentDTO in project candlepin by candlepin.
the class ProductDataTranslator method populate.
/**
* {@inheritDoc}
*/
@Override
public ProductDTO populate(ModelTranslator modelTranslator, ProductData source, ProductDTO dest) {
if (source == null) {
throw new IllegalArgumentException("source is null");
}
if (dest == null) {
throw new IllegalArgumentException("dest is null");
}
dest.setCreated(source.getCreated());
dest.setUpdated(source.getUpdated());
dest.setUuid(source.getUuid());
dest.setId(source.getId());
dest.setName(source.getName());
dest.setMultiplier(source.getMultiplier());
dest.setAttributes(source.getAttributes());
dest.setDependentProductIds(source.getDependentProductIds());
dest.setHref(source.getHref());
dest.setLocked(source.isLocked());
Collection<ProductContentData> productContentData = source.getProductContent();
dest.setProductContent(null);
if (modelTranslator != null && productContentData != null) {
ObjectTranslator<ContentData, ContentDTO> contentTranslator = modelTranslator.findTranslatorByClass(ContentData.class, ContentDTO.class);
for (ProductContentData pcd : productContentData) {
if (pcd != null && pcd.getContent() != null) {
ContentDTO dto = contentTranslator.translate(modelTranslator, pcd.getContent());
dest.addContent(dto, pcd.isEnabled());
}
}
}
return dest;
}
use of org.candlepin.dto.manifest.v1.ContentDTO in project candlepin by candlepin.
the class ContentManagerTest method testUpdateContent.
@Test
@Parameters({ "false", "true" })
public void testUpdateContent(boolean regenCerts) {
Owner owner = this.createOwner("test-owner", "Test Owner");
Product product = this.createProduct("p1", "product-1", owner);
Content content = this.createContent("c1", "content-1", owner);
ContentDTO update = TestUtil.createContentDTO("c1", "new content name");
product.addContent(content, true);
product = this.productCurator.merge(product);
Content output = this.contentManager.updateContent(update, owner, regenCerts);
assertNotEquals(output.getUuid(), content.getUuid());
assertEquals(output.getName(), update.getName());
// We expect the original to be kept around as an orphan until the orphan removal job
// gets around to removing them
assertNotNull(this.contentCurator.find(content.getUuid()));
assertEquals(0, this.ownerContentCurator.getOwnerCount(content));
assertNotNull(this.ownerContentCurator.getContentById(owner, content.getId()));
// The product should have also changed in the same way as a result of the content change
assertNotNull(this.productCurator.find(product.getUuid()));
assertEquals(0, this.ownerProductCurator.getOwnerCount(product));
assertNotNull(this.ownerProductCurator.getProductById(owner, product.getId()));
if (regenCerts) {
verify(this.mockEntCertGenerator, times(1)).regenerateCertificatesOf(eq(Arrays.asList(owner)), anyCollectionOf(Product.class), anyBoolean());
} else {
verifyZeroInteractions(this.mockEntCertGenerator);
}
}
use of org.candlepin.dto.manifest.v1.ContentDTO in project candlepin by candlepin.
the class ContentManagerTest method testUpdateContentConvergeWithExisting.
@Test
@Parameters({ "false", "true" })
public void testUpdateContentConvergeWithExisting(boolean regenCerts) {
Owner owner1 = this.createOwner("test-owner-1", "Test Owner 1");
Owner owner2 = this.createOwner("test-owner-2", "Test Owner 2");
Product product = this.createProduct("p1", "product-1", owner1);
Content content1 = this.createContent("c1", "content-1", owner1);
Content content2 = this.createContent("c1", "updated content", owner2);
ContentDTO update = TestUtil.createContentDTO("c1", "updated content");
product.addContent(content1, true);
product = this.productCurator.merge(product);
assertTrue(this.ownerContentCurator.isContentMappedToOwner(content1, owner1));
assertFalse(this.ownerContentCurator.isContentMappedToOwner(content2, owner1));
assertFalse(this.ownerContentCurator.isContentMappedToOwner(content1, owner2));
assertTrue(this.ownerContentCurator.isContentMappedToOwner(content2, owner2));
Content output = this.contentManager.updateContent(update, owner1, regenCerts);
assertEquals(content2.getUuid(), output.getUuid());
assertFalse(this.ownerContentCurator.isContentMappedToOwner(content1, owner1));
assertTrue(this.ownerContentCurator.isContentMappedToOwner(content2, owner1));
assertFalse(this.ownerContentCurator.isContentMappedToOwner(content1, owner2));
assertTrue(this.ownerContentCurator.isContentMappedToOwner(content2, owner2));
if (regenCerts) {
verify(this.mockEntCertGenerator, times(1)).regenerateCertificatesOf(eq(Arrays.asList(owner1)), anyCollectionOf(Product.class), anyBoolean());
} else {
verifyZeroInteractions(this.mockEntCertGenerator);
}
}
use of org.candlepin.dto.manifest.v1.ContentDTO in project candlepin by candlepin.
the class ContentManagerTest method testUpdateContentThatDoesntExist.
@Test(expected = IllegalStateException.class)
public void testUpdateContentThatDoesntExist() {
Owner owner = this.createOwner("test-owner", "Test Owner");
Content content = TestUtil.createContent("c1", "content-1");
ContentDTO update = TestUtil.createContentDTO("c1", "new_name");
assertFalse(this.ownerContentCurator.isContentMappedToOwner(content, owner));
this.contentManager.updateContent(update, owner, false);
}
use of org.candlepin.dto.manifest.v1.ContentDTO in project candlepin by candlepin.
the class OwnerContentResource method createBatchContent.
@ApiOperation(notes = "Creates Contents in bulk", value = "createBatchContent")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/batch")
@Transactional
public Collection<ContentDTO> createBatchContent(@PathParam("owner_key") String ownerKey, @ApiParam(name = "contents", required = true) List<ContentDTO> contents) {
Collection<ContentDTO> result = new LinkedList<>();
Owner owner = this.getOwnerByKey(ownerKey);
for (ContentDTO content : contents) {
Content entity = this.createContentImpl(owner, content);
result.add(this.translator.translate(entity, ContentDTO.class));
}
ownerManager.refreshOwnerForContentAccess(owner);
return result;
}
Aggregations