Search in sources :

Example 1 with ContentTranslator

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;
}
Also used : EnvironmentContentDTO(org.candlepin.dto.api.v1.EnvironmentDTO.EnvironmentContentDTO) EnvironmentContent(org.candlepin.model.EnvironmentContent) Content(org.candlepin.model.Content) EnvironmentContent(org.candlepin.model.EnvironmentContent)

Example 2 with ContentTranslator

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);
}
Also used : OwnerCurator(org.candlepin.model.OwnerCurator) ContentTranslator(org.candlepin.dto.api.v1.ContentTranslator) SimpleModelTranslator(org.candlepin.dto.SimpleModelTranslator) EnvironmentContentCurator(org.candlepin.model.EnvironmentContentCurator) ContentCurator(org.candlepin.model.ContentCurator) ProductCurator(org.candlepin.model.ProductCurator) DefaultUniqueIdGenerator(org.candlepin.service.impl.DefaultUniqueIdGenerator) EnvironmentContentCurator(org.candlepin.model.EnvironmentContentCurator) PoolManager(org.candlepin.controller.PoolManager) Before(org.junit.Before)

Example 3 with ContentTranslator

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;
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) ContentData(org.candlepin.model.dto.ContentData) ProductContentData(org.candlepin.model.dto.ProductContentData) ProductContentData(org.candlepin.model.dto.ProductContentData)

Example 4 with ContentTranslator

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

Aggregations

Content (org.candlepin.model.Content)2 PoolManager (org.candlepin.controller.PoolManager)1 SimpleModelTranslator (org.candlepin.dto.SimpleModelTranslator)1 ContentDTO (org.candlepin.dto.api.v1.ContentDTO)1 ContentTranslator (org.candlepin.dto.api.v1.ContentTranslator)1 EnvironmentContentDTO (org.candlepin.dto.api.v1.EnvironmentDTO.EnvironmentContentDTO)1 ProductContentDTO (org.candlepin.dto.api.v1.ProductDTO.ProductContentDTO)1 ContentCurator (org.candlepin.model.ContentCurator)1 EnvironmentContent (org.candlepin.model.EnvironmentContent)1 EnvironmentContentCurator (org.candlepin.model.EnvironmentContentCurator)1 OwnerCurator (org.candlepin.model.OwnerCurator)1 ProductContent (org.candlepin.model.ProductContent)1 ProductCurator (org.candlepin.model.ProductCurator)1 ContentData (org.candlepin.model.dto.ContentData)1 ProductContentData (org.candlepin.model.dto.ProductContentData)1 DefaultUniqueIdGenerator (org.candlepin.service.impl.DefaultUniqueIdGenerator)1 Before (org.junit.Before)1