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;
}
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;
}
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;
}
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));
}
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));
}
Aggregations