Search in sources :

Example 36 with ContentDTO

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;
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) ContentData(org.candlepin.model.dto.ContentData) ProductContentData(org.candlepin.model.dto.ProductContentData) ProductContentData(org.candlepin.model.dto.ProductContentData)

Example 37 with ContentDTO

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);
    }
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) Content(org.candlepin.model.Content) Product(org.candlepin.model.Product) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 38 with ContentDTO

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);
    }
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) Content(org.candlepin.model.Content) Product(org.candlepin.model.Product) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 39 with ContentDTO

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);
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) Content(org.candlepin.model.Content) Test(org.junit.Test)

Example 40 with ContentDTO

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;
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) Content(org.candlepin.model.Content) LinkedList(java.util.LinkedList) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) Transactional(com.google.inject.persist.Transactional)

Aggregations

ContentDTO (org.candlepin.dto.api.v1.ContentDTO)35 Test (org.junit.Test)28 Owner (org.candlepin.model.Owner)26 Content (org.candlepin.model.Content)25 Product (org.candlepin.model.Product)13 ProductDTO (org.candlepin.dto.api.v1.ProductDTO)7 ContentDTO (org.candlepin.dto.manifest.v1.ContentDTO)7 ProductContent (org.candlepin.model.ProductContent)7 LinkedList (java.util.LinkedList)5 ProductContentDTO (org.candlepin.dto.api.v1.ProductDTO.ProductContentDTO)5 ProductDTO (org.candlepin.dto.manifest.v1.ProductDTO)5 Transactional (com.google.inject.persist.Transactional)4 Parameters (junitparams.Parameters)4 ContentData (org.candlepin.model.dto.ContentData)4 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 ForbiddenException (org.candlepin.common.exceptions.ForbiddenException)3 ProductContentData (org.candlepin.model.dto.ProductContentData)3