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