Search in sources :

Example 6 with ContentData

use of org.candlepin.model.dto.ContentData in project candlepin by candlepin.

the class ContentDataTranslatorTest method initSourceObject.

@Override
protected ContentData initSourceObject() {
    ContentData source = new ContentData();
    source.setUuid("test_value");
    source.setId("test_value");
    source.setType("test_value");
    source.setLabel("test_value");
    source.setName("test_value");
    source.setVendor("test_value");
    source.setContentUrl("test_value");
    source.setRequiredTags("test_value");
    source.setReleaseVersion("test_value");
    source.setGpgUrl("test_value");
    source.setMetadataExpire(1234L);
    source.setModifiedProductIds(Arrays.asList("1", "2", "3"));
    source.setArches("test_value");
    source.setLocked(Boolean.TRUE);
    return source;
}
Also used : ContentData(org.candlepin.model.dto.ContentData)

Example 7 with ContentData

use of org.candlepin.model.dto.ContentData in project candlepin by candlepin.

the class ProductDataTranslatorTest method verifyOutput.

@Override
protected void verifyOutput(ProductData source, ProductDTO dto, boolean childrenGenerated) {
    if (source != null) {
        assertEquals(source.getUuid(), dto.getUuid());
        assertEquals(source.getId(), dto.getId());
        assertEquals(source.getName(), dto.getName());
        assertEquals(source.getMultiplier(), dto.getMultiplier());
        assertEquals(source.getAttributes(), dto.getAttributes());
        assertEquals(source.getDependentProductIds(), dto.getDependentProductIds());
        assertEquals(source.isLocked(), dto.isLocked());
        assertEquals(source.getHref(), dto.getHref());
        if (childrenGenerated) {
            assertNotNull(dto.getProductContent());
            for (ProductContentData pc : source.getProductContent()) {
                for (ProductContentDTO pcdto : dto.getProductContent()) {
                    ContentData content = pc.getContent();
                    ContentDTO cdto = pcdto.getContent();
                    assertNotNull(cdto);
                    assertNotNull(cdto.getUuid());
                    if (cdto.getUuid().equals(content.getUuid())) {
                        assertEquals(pc.isEnabled(), pcdto.isEnabled());
                        // Pass the content off to the ContentTranslatorTest to verify it
                        this.contentDataTranslatorTest.verifyOutput(content, cdto, childrenGenerated);
                    }
                }
            }
        } else {
            assertNull(dto.getProductContent());
        }
    } else {
        assertNull(dto);
    }
}
Also used : ProductContentDTO(org.candlepin.dto.api.v1.ProductDTO.ProductContentDTO) ContentDTO(org.candlepin.dto.api.v1.ContentDTO) ContentData(org.candlepin.model.dto.ContentData) ProductContentData(org.candlepin.model.dto.ProductContentData) ProductContentDTO(org.candlepin.dto.api.v1.ProductDTO.ProductContentDTO) ProductContentData(org.candlepin.model.dto.ProductContentData)

Example 8 with ContentData

use of org.candlepin.model.dto.ContentData in project candlepin by candlepin.

the class ProductDTOTranslator method populate.

/**
 * {@inheritDoc}
 *
 * <p>Note: the 'locked' field is always set to false and the 'href' field is not translated,
 * since these fields are not currently being exported.</p>
 */
@Override
public ProductData populate(ModelTranslator modelTranslator, ProductDTO source, ProductData 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());
    // We manually set this to false since it is not included in the exported data.
    dest.setLocked(false);
    Collection<ProductDTO.ProductContentDTO> productContentDTOs = source.getProductContent();
    dest.setProductContent(Collections.emptyList());
    if (modelTranslator != null && productContentDTOs != null) {
        ObjectTranslator<ContentDTO, ContentData> contentDTOTranslator = modelTranslator.findTranslatorByClass(ContentDTO.class, ContentData.class);
        for (ProductDTO.ProductContentDTO pcdto : productContentDTOs) {
            if (pcdto != null && pcdto.getContent() != null) {
                ContentData contentData = contentDTOTranslator.translate(modelTranslator, pcdto.getContent());
                dest.addContent(contentData, pcdto.isEnabled());
            }
        }
    }
    return dest;
}
Also used : ContentDTO(org.candlepin.dto.manifest.v1.ContentDTO) ContentData(org.candlepin.model.dto.ContentData) ProductDTO(org.candlepin.dto.manifest.v1.ProductDTO)

Example 9 with ContentData

use of org.candlepin.model.dto.ContentData 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 10 with ContentData

use of org.candlepin.model.dto.ContentData in project candlepin by candlepin.

the class ProductManager method applyProductChanges.

/**
 * Applies the changes from the given DTO to the specified entity
 *
 * @param entity
 *  The entity to modify
 *
 * @param update
 *  The DTO containing the modifications to apply
 *
 * @param content
 *  A mapping of Red Hat content ID to content entities to use for content resolution
 *
 * @throws IllegalArgumentException
 *  if entity, update or owner is null
 *
 * @return
 *  The updated product entity
 */
private Product applyProductChanges(Product entity, ProductData update, Map<String, Content> contentMap) {
    if (entity == null) {
        throw new IllegalArgumentException("entity is null");
    }
    if (update == null) {
        throw new IllegalArgumentException("update is null");
    }
    if (contentMap == null) {
        throw new IllegalArgumentException("contentMap is null");
    }
    if (update.getName() != null) {
        entity.setName(update.getName());
    }
    if (update.getMultiplier() != null) {
        entity.setMultiplier(update.getMultiplier());
    }
    if (update.getAttributes() != null) {
        entity.setAttributes(update.getAttributes());
    }
    if (update.getProductContent() != null) {
        Collection<ProductContent> productContent = new LinkedList<>();
        // Sort the existing ProductContent so we aren't iterating on it several times.
        // TODO: Remove this if/when product content is stored as a map on products.
        Map<String, ProductContent> existingLinks = new HashMap<>();
        for (ProductContent pc : entity.getProductContent()) {
            existingLinks.put(pc.getContent().getId(), pc);
        }
        // Actually process our list of content...
        for (ProductContentData pcd : update.getProductContent()) {
            if (pcd == null) {
                throw new IllegalStateException("Product data contains a null product-content mapping: " + update);
            }
            ContentData cdto = pcd.getContent();
            if (cdto == null || cdto.getId() == null) {
                // adding it to our link object. This is very bad.
                throw new IllegalStateException("Product data contains an incomplete product-content " + "mapping: " + update);
            }
            ProductContent existingLink = existingLinks.get(cdto.getId());
            Content content = contentMap.get(cdto.getId());
            if (content == null) {
                // Content doesn't exist yet -- it should have been created already
                throw new IllegalStateException("product references content which does not exist: " + cdto);
            }
            if (existingLink == null) {
                existingLink = new ProductContent(entity, content, pcd.isEnabled() != null ? pcd.isEnabled() : false);
            } else {
                existingLink.setContent(content);
                if (pcd.isEnabled() != null) {
                    existingLink.setEnabled(pcd.isEnabled());
                }
            }
            productContent.add(existingLink);
        }
        entity.setProductContent(productContent);
    }
    if (update.getDependentProductIds() != null) {
        entity.setDependentProductIds(update.getDependentProductIds());
    }
    if (update.isLocked() != null) {
        entity.setLocked(update.isLocked());
    }
    return entity;
}
Also used : ContentData(org.candlepin.model.dto.ContentData) ProductContentData(org.candlepin.model.dto.ProductContentData) HashMap(java.util.HashMap) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) ProductContentData(org.candlepin.model.dto.ProductContentData) ProductContent(org.candlepin.model.ProductContent) LinkedList(java.util.LinkedList)

Aggregations

ContentData (org.candlepin.model.dto.ContentData)11 ProductContentData (org.candlepin.model.dto.ProductContentData)9 Content (org.candlepin.model.Content)6 HashMap (java.util.HashMap)5 Product (org.candlepin.model.Product)4 ProductContent (org.candlepin.model.ProductContent)4 ProductData (org.candlepin.model.dto.ProductData)4 LinkedList (java.util.LinkedList)3 Transactional (com.google.inject.persist.Transactional)2 ArrayList (java.util.ArrayList)2 ContentDTO (org.candlepin.dto.api.v1.ContentDTO)2 ContentDTO (org.candlepin.dto.manifest.v1.ContentDTO)2 OwnerContent (org.candlepin.model.OwnerContent)2 Traceable (org.candlepin.util.Traceable)2 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1