Search in sources :

Example 26 with ProductContent

use of org.candlepin.model.ProductContent 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.setMultiplier(source.getMultiplier());
    destination.setId(source.getId());
    destination.setName(source.getName());
    destination.setAttributes(source.getAttributes());
    destination.setDependentProductIds(source.getDependentProductIds());
    if (modelTranslator != null) {
        Collection<ProductContent> productContent = source.getProductContent();
        destination.setProductContent(Collections.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.emptyList());
    }
    return destination;
}
Also used : ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) ProductContent(org.candlepin.model.ProductContent)

Example 27 with ProductContent

use of org.candlepin.model.ProductContent 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 28 with ProductContent

use of org.candlepin.model.ProductContent in project candlepin by candlepin.

the class ProductData method populate.

/**
 * Populates this DTO with data from the given source entity.
 *
 * @param source
 *  The source entity from which to copy data
 *
 * @throws IllegalArgumentException
 *  if source is null
 *
 * @return
 *  a reference to this DTO
 */
public ProductData populate(Product source) {
    if (source == null) {
        throw new IllegalArgumentException("source is null");
    }
    super.populate(source);
    this.uuid = source.getUuid();
    this.id = source.getId();
    this.name = source.getName();
    this.multiplier = source.getMultiplier();
    this.href = source.getHref();
    this.locked = source.isLocked();
    this.setAttributes(source.getAttributes());
    if (source.getProductContent() != null) {
        if (this.content == null) {
            this.content = new HashMap<>();
        } else {
            this.content.clear();
        }
        for (ProductContent entity : source.getProductContent()) {
            this.addProductContent(entity.toDTO());
        }
    } else {
        this.setProductContent(null);
    }
    this.setDependentProductIds(source.getDependentProductIds());
    return this;
}
Also used : ProductContent(org.candlepin.model.ProductContent)

Example 29 with ProductContent

use of org.candlepin.model.ProductContent in project candlepin by candlepin.

the class ProductDataTest method testAddContentByEntity.

@Test
public void testAddContentByEntity() {
    ProductData dto = new ProductData();
    Content[] contentEntities = new Content[] { new Content("c1", "content-1", "test_type", "test_label-1", "test_vendor-1"), new Content("c2", "content-2", "test_type", "test_label-2", "test_vendor-2") };
    ProductContent pcentity1 = new ProductContent(null, contentEntities[0], true);
    ProductContent pcentity2 = new ProductContent(null, contentEntities[1], false);
    ProductContent pcentity3 = new ProductContent(null, contentEntities[1], true);
    ContentData[] content = new ContentData[] { contentEntities[0].toDTO(), contentEntities[1].toDTO() };
    ProductContentData pcdata1 = new ProductContentData(content[0], true);
    ProductContentData pcdata2 = new ProductContentData(content[1], false);
    ProductContentData pcdata3 = new ProductContentData(content[1], true);
    assertNull(dto.getProductContent());
    boolean output = dto.addContent(pcentity1.getContent(), pcentity1.isEnabled());
    Collection<ProductContentData> output2 = dto.getProductContent();
    assertTrue(output);
    assertTrue(Util.collectionsAreEqual(Arrays.asList(pcdata1), output2));
    output = dto.addContent(pcentity1.getContent(), pcentity1.isEnabled());
    output2 = dto.getProductContent();
    assertFalse(output);
    assertTrue(Util.collectionsAreEqual(Arrays.asList(pcdata1), output2));
    output = dto.addContent(pcentity2.getContent(), pcentity2.isEnabled());
    output2 = dto.getProductContent();
    assertTrue(output);
    assertTrue(Util.collectionsAreEqual(Arrays.asList(pcdata1, pcdata2), output2));
    output = dto.addContent(pcentity3.getContent(), pcentity3.isEnabled());
    output2 = dto.getProductContent();
    assertTrue(output);
    assertTrue(Util.collectionsAreEqual(Arrays.asList(pcdata1, pcdata3), output2));
}
Also used : ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) ProductContent(org.candlepin.model.ProductContent) Test(org.junit.Test)

Example 30 with ProductContent

use of org.candlepin.model.ProductContent in project candlepin by candlepin.

the class ProductDataTest method testRemoveProductContentByEntity.

@Test
public void testRemoveProductContentByEntity() {
    ProductData dto = new ProductData();
    ContentData[] content = new ContentData[] { new ContentData("c1", "content-1", "test_type", "test_label-1", "test_vendor-1"), new ContentData("c2", "content-2", "test_type", "test_label-2", "test_vendor-2") };
    ProductContentData pcdata1 = new ProductContentData(content[0], true);
    ProductContentData pcdata2 = new ProductContentData(content[1], false);
    Content[] contentEntities = new Content[] { new Content("c1", "content-1", "test_type", "test_label-1", "test_vendor-1"), new Content("c2", "content-2", "test_type", "test_label-2", "test_vendor-2"), new Content("c2", "content-3", "test_type", "test_label-3", "test_vendor-3") };
    ProductContent pcentity1 = new ProductContent(null, contentEntities[0], true);
    ProductContent pcentity2 = new ProductContent(null, contentEntities[1], false);
    ProductContent pcentity3 = new ProductContent(null, contentEntities[2], true);
    assertNull(dto.getProductContent());
    assertFalse(dto.removeProductContent(pcentity1));
    assertFalse(dto.removeProductContent(pcentity2));
    assertFalse(dto.removeProductContent(pcentity3));
    dto.setProductContent(Arrays.asList(pcdata1, pcdata2));
    boolean output = dto.removeProductContent(pcentity1);
    Collection<ProductContentData> output2 = dto.getProductContent();
    assertTrue(output);
    assertTrue(Util.collectionsAreEqual(Arrays.asList(pcdata2), output2));
    output = dto.removeProductContent(pcentity1);
    output2 = dto.getProductContent();
    assertFalse(output);
    assertTrue(Util.collectionsAreEqual(Arrays.asList(pcdata2), output2));
    // This should work because we remove by content ID, not by exact element match
    // Note that the collection should not be nulled by removing the final element
    output = dto.removeProductContent(pcentity3);
    output2 = dto.getProductContent();
    assertTrue(output);
    assertTrue(Util.collectionsAreEqual(Collections.<ProductContentData>emptyList(), output2));
}
Also used : ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) ProductContent(org.candlepin.model.ProductContent) Test(org.junit.Test)

Aggregations

ProductContent (org.candlepin.model.ProductContent)30 Content (org.candlepin.model.Content)20 Test (org.junit.Test)11 Product (org.candlepin.model.Product)9 HashSet (java.util.HashSet)7 HashMap (java.util.HashMap)5 LinkedList (java.util.LinkedList)5 ContentDTO (org.candlepin.dto.api.v1.ContentDTO)4 ProductContentDTO (org.candlepin.dto.api.v1.ProductDTO.ProductContentDTO)4 Owner (org.candlepin.model.Owner)4 X509ExtensionWrapper (org.candlepin.pki.X509ExtensionWrapper)4 Transactional (com.google.inject.persist.Transactional)3 ArrayList (java.util.ArrayList)3 LinkedHashSet (java.util.LinkedHashSet)3 List (java.util.List)3 ProductDTO (org.candlepin.dto.api.v1.ProductDTO)3 ContentData (org.candlepin.model.dto.ContentData)3 ProductContentData (org.candlepin.model.dto.ProductContentData)3 CertificateSizeException (org.candlepin.util.CertificateSizeException)3 IOException (java.io.IOException)2