Search in sources :

Example 16 with Content

use of org.candlepin.model.Content in project candlepin by candlepin.

the class ProductImporterTest method addNoVendorContentTo.

// Returns the Content object added without vendor
private Content addNoVendorContentTo(Product product) {
    Content content = TestUtil.createContent("100130", "name");
    content.setVendor("");
    content.setMetadataExpire(1000L);
    product.addContent(content, true);
    return content;
}
Also used : Content(org.candlepin.model.Content)

Example 17 with Content

use of org.candlepin.model.Content in project candlepin by candlepin.

the class TestUtil method createContent.

public static Content createContent(ContentData cdata) {
    Content content = null;
    if (cdata != null) {
        content = createContent(cdata.getId(), cdata.getName());
        content.setUuid(cdata.getUuid());
        content.setType(cdata.getType());
        content.setLabel(cdata.getLabel());
        content.setVendor(cdata.getVendor());
        content.setContentUrl(cdata.getContentUrl());
        content.setRequiredTags(cdata.getRequiredTags());
        content.setReleaseVersion(cdata.getReleaseVersion());
        content.setGpgUrl(cdata.getGpgUrl());
        content.setMetadataExpire(cdata.getMetadataExpire());
        content.setModifiedProductIds(cdata.getModifiedProductIds());
        content.setArches(cdata.getArches());
        content.setLocked(cdata.isLocked());
    }
    return content;
}
Also used : Content(org.candlepin.model.Content)

Example 18 with Content

use of org.candlepin.model.Content in project candlepin by candlepin.

the class DatabaseTestFixture method createEnvironment.

protected Environment createEnvironment(Owner owner, String id, String name, String description, Collection<Consumer> consumers, Collection<Content> content) {
    Environment environment = new Environment(id, name, owner);
    environment.setDescription(description);
    if (content != null) {
        for (Content elem : content) {
            EnvironmentContent envContent = new EnvironmentContent(environment, elem, true);
            // Impl note:
            // At the time of writing, this line is redundant. But if we ever fix environment,
            // this will be good to have as a backup.
            environment.getEnvironmentContent().add(envContent);
        }
    }
    environment = this.environmentCurator.create(environment);
    // Update consumers to point to the new environment
    if (consumers != null) {
        for (Consumer consumer : consumers) {
            consumer.setEnvironmentId(environment.getId());
            this.consumerCurator.merge(consumer);
        }
    }
    return environment;
}
Also used : Consumer(org.candlepin.model.Consumer) Content(org.candlepin.model.Content) EnvironmentContent(org.candlepin.model.EnvironmentContent) Environment(org.candlepin.model.Environment) EnvironmentContent(org.candlepin.model.EnvironmentContent)

Example 19 with Content

use of org.candlepin.model.Content 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 20 with Content

use of org.candlepin.model.Content in project candlepin by candlepin.

the class HostedTestSubscriptionResource method addBatchContent.

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/owners/{owner_key}/products/{product_id}/batch_content")
@Transactional
public ProductDTO addBatchContent(@PathParam("owner_key") String ownerKey, @PathParam("product_id") String productId, Map<String, Boolean> contentMap) {
    Owner owner = this.getOwnerByKey(ownerKey);
    Product product = this.fetchProduct(owner, productId);
    Collection<ProductContent> productContent = new LinkedList<>();
    ProductDTO pdto = this.translator.translate(product, ProductDTO.class);
    // Impl note:
    // This is a wholely inefficient way of doing this. When we return to using ID-based linking
    // and we're not linking the universe with our model, we can just attach the IDs directly
    // without needing all this DTO conversion back and forth.
    // Alternatively, we can shut off Hibernate's auto-commit junk and get in the habit of
    // calling commit methods as necessary so we don't have to work with DTOs internally.
    boolean changed = false;
    for (Entry<String, Boolean> entry : contentMap.entrySet()) {
        Content content = this.fetchContent(owner, entry.getKey());
        boolean enabled = entry.getValue() != null ? entry.getValue() : ProductContent.DEFAULT_ENABLED_STATE;
        ContentDTO cdto = this.translator.translate(content, ContentDTO.class);
        changed |= pdto.addContent(cdto, enabled);
        addContentToUpstreamSubscriptions(product, content, enabled);
    }
    if (changed) {
        product = this.productManager.updateProduct(pdto, owner, true);
    }
    return this.translator.translate(product, ProductDTO.class);
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) Product(org.candlepin.model.Product) ProductContent(org.candlepin.model.ProductContent) LinkedList(java.util.LinkedList) ProductDTO(org.candlepin.dto.api.v1.ProductDTO) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Transactional(com.google.inject.persist.Transactional)

Aggregations

Content (org.candlepin.model.Content)97 Test (org.junit.Test)45 ProductContent (org.candlepin.model.ProductContent)41 Product (org.candlepin.model.Product)40 Owner (org.candlepin.model.Owner)39 ContentDTO (org.candlepin.dto.api.v1.ContentDTO)25 HashMap (java.util.HashMap)18 EnvironmentContent (org.candlepin.model.EnvironmentContent)17 HashSet (java.util.HashSet)14 LinkedList (java.util.LinkedList)11 ProductDTO (org.candlepin.dto.api.v1.ProductDTO)10 ArrayList (java.util.ArrayList)9 Matchers.anyString (org.mockito.Matchers.anyString)9 Transactional (com.google.inject.persist.Transactional)8 Produces (javax.ws.rs.Produces)8 Parameters (junitparams.Parameters)8 ApiOperation (io.swagger.annotations.ApiOperation)7 ForbiddenException (org.candlepin.common.exceptions.ForbiddenException)7 Path (javax.ws.rs.Path)6 ProductContentDTO (org.candlepin.dto.api.v1.ProductDTO.ProductContentDTO)6