use of org.candlepin.dto.api.v1.ContentTranslator in project candlepin by candlepin.
the class EnvironmentTranslator method populate.
/**
* {@inheritDoc}
*/
@Override
public EnvironmentDTO populate(ModelTranslator translator, Environment source, EnvironmentDTO dest) {
dest = super.populate(translator, source, dest);
dest.setId(source.getId());
dest.setName(source.getName());
dest.setDescription(source.getDescription());
if (translator != null) {
dest.setOwner(translator.translate(source.getOwner(), OwnerDTO.class));
Set<EnvironmentContent> envContents = source.getEnvironmentContent();
if (envContents != null) {
Collection<EnvironmentContent> envContent = source.getEnvironmentContent();
dest.setEnvironmentContent(Collections.<EnvironmentContentDTO>emptyList());
if (envContent != null) {
ObjectTranslator<Content, ContentDTO> contentTranslator = translator.findTranslatorByClass(Content.class, ContentDTO.class);
for (EnvironmentContent ec : envContent) {
if (ec != null) {
ContentDTO dto = contentTranslator.translate(translator, ec.getContent());
if (dto != null) {
dest.addContent(dto, ec.getEnabled());
}
}
}
}
}
} else {
dest.setOwner(null);
dest.setEnvironmentContent(null);
}
return dest;
}
use of org.candlepin.dto.api.v1.ContentTranslator in project candlepin by candlepin.
the class ContentResourceTest method init.
@Before
public void init() {
i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
cc = mock(ContentCurator.class);
envContentCurator = mock(EnvironmentContentCurator.class);
poolManager = mock(PoolManager.class);
oc = mock(OwnerCurator.class);
productCurator = mock(ProductCurator.class);
this.modelTranslator = new SimpleModelTranslator();
this.modelTranslator.registerTranslator(new ContentTranslator(), Content.class, ContentDTO.class);
cr = new ContentResource(cc, i18n, new DefaultUniqueIdGenerator(), envContentCurator, poolManager, productCurator, oc, this.modelTranslator);
}
use of org.candlepin.dto.api.v1.ContentTranslator 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;
}
use of org.candlepin.dto.api.v1.ContentTranslator 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;
}
Aggregations