Search in sources :

Example 46 with ContentDTO

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

the class ProductTranslator method populate.

/**
 * {@inheritDoc}
 */
@Override
public ProductDTO populate(ModelTranslator modelTranslator, Product source, ProductDTO destination) {
    destination = super.populate(modelTranslator, source, destination);
    destination.setUuid(source.getUuid());
    destination.setId(source.getId());
    destination.setName(source.getName());
    destination.setMultiplier(source.getMultiplier());
    destination.setHref(source.getHref());
    destination.setLocked(source.isLocked());
    destination.setAttributes(source.getAttributes());
    destination.setDependentProductIds(source.getDependentProductIds());
    if (modelTranslator != null) {
        Collection<ProductContent> productContent = source.getProductContent();
        destination.setProductContent(Collections.<ProductContentDTO>emptyList());
        if (productContent != null) {
            ObjectTranslator<Content, ContentDTO> contentTranslator = modelTranslator.findTranslatorByClass(Content.class, ContentDTO.class);
            for (ProductContent pc : productContent) {
                if (pc != null) {
                    ContentDTO dto = contentTranslator.translate(modelTranslator, pc.getContent());
                    if (dto != null) {
                        destination.addContent(dto, pc.isEnabled());
                    }
                }
            }
        }
    } else {
        destination.setProductContent(Collections.<ProductContentDTO>emptyList());
    }
    return destination;
}
Also used : ProductContentDTO(org.candlepin.dto.api.v1.ProductDTO.ProductContentDTO) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) ProductContent(org.candlepin.model.ProductContent)

Example 47 with ContentDTO

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

the class OwnerProductResourceTest method testCreateProductWithContent.

@Test
public void testCreateProductWithContent() {
    Owner owner = this.createOwner("Example-Corporation");
    Content content = this.createContent("content-1", "content-1", owner);
    ProductDTO pdto = this.buildTestProductDTO();
    ContentDTO cdto = this.modelTranslator.translate(content, ContentDTO.class);
    pdto.addContent(cdto, true);
    assertNull(this.ownerProductCurator.getProductById(owner.getKey(), pdto.getId()));
    ProductDTO result = this.ownerProductResource.createProduct(owner.getKey(), pdto);
    Product entity = this.ownerProductCurator.getProductById(owner, pdto.getId());
    ProductDTO expected = this.modelTranslator.translate(entity, ProductDTO.class);
    assertNotNull(result);
    assertNotNull(entity);
    assertEquals(expected, result);
    assertNotNull(result.getProductContent());
    assertEquals(1, result.getProductContent().size());
    assertEquals(cdto, result.getProductContent().iterator().next().getContent());
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) Content(org.candlepin.model.Content) Product(org.candlepin.model.Product) ProductDTO(org.candlepin.dto.api.v1.ProductDTO) Test(org.junit.Test)

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