Search in sources :

Example 36 with ContentDTO

use of org.candlepin.dto.api.v1.ContentDTO in project candlepin by candlepin.

the class TestUtil method createProduct.

public static Product createProduct(ProductDTO dto) {
    Product product = null;
    if (dto != null) {
        product = new Product(dto.getId(), dto.getName());
        product.setUuid(dto.getUuid());
        product.setMultiplier(dto.getMultiplier());
        product.setAttributes(dto.getAttributes());
        if (dto.getProductContent() != null) {
            for (ProductContentDTO pcd : dto.getProductContent()) {
                if (pcd != null) {
                    Content content = createContent((ContentDTO) pcd.getContent());
                    if (content != null) {
                        product.addContent(content, pcd.isEnabled() != null ? pcd.isEnabled() : true);
                    }
                }
            }
        }
        product.setDependentProductIds(dto.getDependentProductIds());
        product.setLocked(dto.isLocked() != null ? dto.isLocked() : false);
    }
    return product;
}
Also used : Content(org.candlepin.model.Content) Product(org.candlepin.model.Product) ProductContentDTO(org.candlepin.dto.api.v1.ProductDTO.ProductContentDTO)

Example 37 with ContentDTO

use of org.candlepin.dto.api.v1.ContentDTO in project candlepin by candlepin.

the class ProductTranslatorTest method verifyOutput.

@Override
protected void verifyOutput(Product source, ProductDTO dto, boolean childrenGenerated) {
    if (source != null) {
        assertEquals(source.getUuid(), dto.getUuid());
        assertEquals(source.getId(), dto.getId());
        assertEquals(source.getName(), dto.getName());
        assertEquals(source.getMultiplier(), dto.getMultiplier());
        assertEquals(source.getAttributes(), dto.getAttributes());
        assertEquals(source.getDependentProductIds(), dto.getDependentProductIds());
        assertEquals(source.isLocked(), dto.isLocked());
        assertEquals(source.getHref(), dto.getHref());
        assertNotNull(dto.getProductContent());
        if (childrenGenerated) {
            for (ProductContent pc : source.getProductContent()) {
                for (ProductContentDTO pcdto : dto.getProductContent()) {
                    Content content = pc.getContent();
                    ContentDTO cdto = pcdto.getContent();
                    assertNotNull(cdto);
                    assertNotNull(cdto.getUuid());
                    if (cdto.getUuid().equals(content.getUuid())) {
                        assertEquals(pc.isEnabled(), pcdto.isEnabled());
                        // Pass the content off to the ContentTranslatorTest to verify it
                        this.contentTranslatorTest.verifyOutput(content, cdto, childrenGenerated);
                    }
                }
            }
        } else {
            assertTrue(dto.getProductContent().isEmpty());
        }
    } else {
        assertNull(dto);
    }
}
Also used : ProductContentDTO(org.candlepin.dto.api.v1.ProductDTO.ProductContentDTO) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) ProductContentDTO(org.candlepin.dto.api.v1.ProductDTO.ProductContentDTO) ProductContent(org.candlepin.model.ProductContent)

Example 38 with ContentDTO

use of org.candlepin.dto.api.v1.ContentDTO in project candlepin by candlepin.

the class ProductManagerTest method testAddContentToSharedProduct.

@Test
@Parameters({ "false", "true" })
public void testAddContentToSharedProduct(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", "prod1", owner1);
    Content content = this.createContent("c1", "content1", owner1);
    this.ownerProductCurator.mapProductToOwners(product, owner1, owner2);
    ProductDTO pdto = this.modelTranslator.translate(product, ProductDTO.class);
    ContentDTO cdto = this.modelTranslator.translate(content, ContentDTO.class);
    pdto.addContent(cdto, true);
    Product output = this.productManager.updateProduct(pdto, owner1, regenCerts);
    assertNotEquals(product, output);
    assertFalse(product.hasContent(content.getId()));
    assertTrue(output.hasContent(content.getId()));
    assertFalse(this.ownerProductCurator.isProductMappedToOwner(product, owner1));
    assertTrue(this.ownerProductCurator.isProductMappedToOwner(product, owner2));
    assertTrue(this.ownerProductCurator.isProductMappedToOwner(output, owner1));
    assertFalse(this.ownerProductCurator.isProductMappedToOwner(output, 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) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) Product(org.candlepin.model.Product) ProductDTO(org.candlepin.dto.api.v1.ProductDTO) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 39 with ContentDTO

use of org.candlepin.dto.api.v1.ContentDTO in project candlepin by candlepin.

the class ProductDTOTranslator method populate.

/**
 * {@inheritDoc}
 *
 * <p>Note: the 'locked' field is always set to false and the 'href' field is not translated,
 * since these fields are not currently being exported.</p>
 */
@Override
public ProductData populate(ModelTranslator modelTranslator, ProductDTO source, ProductData 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());
    // We manually set this to false since it is not included in the exported data.
    dest.setLocked(false);
    Collection<ProductDTO.ProductContentDTO> productContentDTOs = source.getProductContent();
    dest.setProductContent(Collections.emptyList());
    if (modelTranslator != null && productContentDTOs != null) {
        ObjectTranslator<ContentDTO, ContentData> contentDTOTranslator = modelTranslator.findTranslatorByClass(ContentDTO.class, ContentData.class);
        for (ProductDTO.ProductContentDTO pcdto : productContentDTOs) {
            if (pcdto != null && pcdto.getContent() != null) {
                ContentData contentData = contentDTOTranslator.translate(modelTranslator, pcdto.getContent());
                dest.addContent(contentData, pcdto.isEnabled());
            }
        }
    }
    return dest;
}
Also used : ContentDTO(org.candlepin.dto.manifest.v1.ContentDTO) ContentData(org.candlepin.model.dto.ContentData) ProductDTO(org.candlepin.dto.manifest.v1.ProductDTO)

Example 40 with ContentDTO

use of org.candlepin.dto.api.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)

Aggregations

ContentDTO (org.candlepin.dto.api.v1.ContentDTO)35 Content (org.candlepin.model.Content)30 Test (org.junit.Test)28 Owner (org.candlepin.model.Owner)26 Product (org.candlepin.model.Product)14 ProductContent (org.candlepin.model.ProductContent)9 ProductContentDTO (org.candlepin.dto.api.v1.ProductDTO.ProductContentDTO)8 ProductDTO (org.candlepin.dto.api.v1.ProductDTO)7 ContentDTO (org.candlepin.dto.manifest.v1.ContentDTO)7 LinkedList (java.util.LinkedList)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