Search in sources :

Example 1 with EnvironmentContent

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

the class DefaultEntitlementCertServiceAdapter method getPromotedContent.

/**
 * @param consumer
 * @return
 */
private Map<String, EnvironmentContent> getPromotedContent(Consumer consumer) {
    // Build a set of all content IDs promoted to the consumer's environment so
    // we can determine if anything needs to be skipped:
    Map<String, EnvironmentContent> promotedContent = new HashMap<>();
    if (consumer.getEnvironmentId() != null) {
        Environment environment = this.environmentCurator.getConsumerEnvironment(consumer);
        log.debug("Consumer has an environment; checking for promoted content in: {}", environment);
        for (EnvironmentContent envContent : environment.getEnvironmentContent()) {
            log.debug("  promoted content: {}", envContent.getContent());
            promotedContent.put(envContent.getContent().getId(), envContent);
        }
    }
    return promotedContent;
}
Also used : HashMap(java.util.HashMap) Environment(org.candlepin.model.Environment) EnvironmentContent(org.candlepin.model.EnvironmentContent)

Example 2 with EnvironmentContent

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

the class DefaultContentAccessCertServiceAdapter method createContentAccessDataPayload.

private byte[] createContentAccessDataPayload(Owner owner, Environment environment) throws IOException {
    // fake a product dto as a container for the org content
    Set<Product> containerSet = new HashSet<>();
    CandlepinQuery<Content> ownerContent = ownerContentCurator.getContentByOwner(owner);
    Set<String> entitledProductIds = new HashSet<>();
    List<org.candlepin.model.dto.Product> productModels = new ArrayList<>();
    Map<String, EnvironmentContent> promotedContent = getPromotedContent(environment);
    String contentPrefix = getContentPrefix(owner, environment);
    Product container = new Product();
    Entitlement emptyEnt = new Entitlement();
    Pool emptyPool = new Pool();
    Product skuProduct = new Product();
    Consumer emptyConsumer = new Consumer();
    containerSet.add(container);
    container.setId("content_access");
    container.setName(" Content Access");
    for (Content c : ownerContent) {
        container.addContent(c, false);
    }
    emptyConsumer.setEnvironment(environment);
    emptyEnt.setPool(emptyPool);
    emptyEnt.setConsumer(emptyConsumer);
    emptyPool.setProduct(skuProduct);
    emptyPool.setStartDate(new Date());
    emptyPool.setEndDate(new Date());
    skuProduct.setName("Content Access");
    skuProduct.setId("content_access");
    entitledProductIds.add("content-access");
    org.candlepin.model.dto.Product productModel = v3extensionUtil.mapProduct(container, skuProduct, contentPrefix, promotedContent, emptyConsumer, emptyPool, entitledProductIds);
    productModels.add(productModel);
    return v3extensionUtil.createEntitlementDataPayload(productModels, emptyConsumer, emptyPool, null);
}
Also used : ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) EnvironmentContent(org.candlepin.model.EnvironmentContent) Date(java.util.Date) Consumer(org.candlepin.model.Consumer) Content(org.candlepin.model.Content) EnvironmentContent(org.candlepin.model.EnvironmentContent) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) HashSet(java.util.HashSet)

Example 3 with EnvironmentContent

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

the class DefaultContentAccessCertServiceAdapter method getPromotedContent.

private Map<String, EnvironmentContent> getPromotedContent(Environment environment) {
    // Build a set of all content IDs promoted to the consumer's environment so
    // we can determine if anything needs to be skipped:
    Map<String, EnvironmentContent> promotedContent = new HashMap<>();
    if (environment != null) {
        log.debug("Consumer has an environment, checking for promoted content in: {}", environment);
        for (EnvironmentContent envContent : environment.getEnvironmentContent()) {
            log.debug("  promoted content: {}", envContent.getContent().getId());
            promotedContent.put(envContent.getContent().getId(), envContent);
        }
    }
    return promotedContent;
}
Also used : HashMap(java.util.HashMap) EnvironmentContent(org.candlepin.model.EnvironmentContent)

Example 4 with EnvironmentContent

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

the class DefaultEntitlementCertServiceAdapterTest method testFilterProductContent.

@Test
public void testFilterProductContent() {
    Product modProduct = new Product("12345", "a product", "variant", "version", ARCH_LABEL, "SVC");
    // Use this set for successful providing queries:
    Set<Entitlement> successResult = new HashSet<>();
    // just need something in there
    successResult.add(new Entitlement());
    Content normalContent = createContent(CONTENT_NAME, CONTENT_ID, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, CONTENT_URL, CONTENT_GPG_URL, ARCH_LABEL);
    // Change label to prevent an equals match:
    Content modContent = createContent(CONTENT_NAME, CONTENT_ID + "_2", "differentlabel", CONTENT_TYPE, CONTENT_VENDOR, CONTENT_URL, CONTENT_GPG_URL, ARCH_LABEL);
    modContent.setLabel("mod content");
    Set<String> modifiedProductIds = new HashSet<>(Arrays.asList(new String[] { "product1", "product2" }));
    modContent.setModifiedProductIds(modifiedProductIds);
    modProduct.addContent(normalContent, false);
    modProduct.addContent(modContent, false);
    // First check that if we have no entitlements providing the modified
    // products,
    // the content set is filtered out:
    // Mod content should get filtered out because we have no ents providing
    // the product it modifies:
    assertEquals(1, extensionUtil.filterProductContent(modProduct, consumer, new HashMap<>(), false, new HashSet<>()).size());
    // Now mock that we have an entitlement providing one of the modified
    // products,
    // and we should see both content sets included in the cert:
    Set<String> entitledProdIds = new HashSet<>();
    entitledProdIds.add("product2");
    assertEquals(2, extensionUtil.filterProductContent(modProduct, consumer, new HashMap<>(), false, entitledProdIds).size());
    // Make sure that we filter by environment when asked.
    Environment environment = this.mockEnvironment(new Environment());
    consumer.setEnvironment(environment);
    Map<String, EnvironmentContent> promotedContent = new HashMap<>();
    promotedContent.put(normalContent.getId(), new EnvironmentContent(environment, normalContent, true));
    assertEquals(1, extensionUtil.filterProductContent(modProduct, consumer, promotedContent, true, entitledProdIds).size());
}
Also used : HashMap(java.util.HashMap) Product(org.candlepin.model.Product) EnvironmentContent(org.candlepin.model.EnvironmentContent) Matchers.anyString(org.mockito.Matchers.anyString) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) EnvironmentContent(org.candlepin.model.EnvironmentContent) Environment(org.candlepin.model.Environment) Entitlement(org.candlepin.model.Entitlement) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with EnvironmentContent

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

the class DefaultEntitlementCertServiceAdapterTest method testContentExtentionIncludesPromotedContent.

@Test
public void testContentExtentionIncludesPromotedContent() throws CertificateSizeException {
    // Environment, with promoted content:
    Environment e = this.mockEnvironment(new Environment("env1", "Env 1", owner));
    e.getEnvironmentContent().add(new EnvironmentContent(e, content, true));
    this.consumer.setEnvironment(e);
    Map<String, EnvironmentContent> promotedContent = new HashMap<>();
    promotedContent.put(content.getId(), e.getEnvironmentContent().iterator().next());
    Set<X509ExtensionWrapper> contentExtensions = extensionUtil.contentExtensions(product.getProductContent(), null, promotedContent, entitlement.getConsumer(), product);
    Map<String, X509ExtensionWrapper> encodedContent = getEncodedContent(contentExtensions);
    assertTrue(isEncodedContentValid(encodedContent));
    assertTrue(encodedContent.containsKey(content.getLabel()));
}
Also used : HashMap(java.util.HashMap) Environment(org.candlepin.model.Environment) EnvironmentContent(org.candlepin.model.EnvironmentContent) X509ExtensionWrapper(org.candlepin.pki.X509ExtensionWrapper) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

EnvironmentContent (org.candlepin.model.EnvironmentContent)17 HashSet (java.util.HashSet)9 Environment (org.candlepin.model.Environment)9 HashMap (java.util.HashMap)6 Content (org.candlepin.model.Content)6 Date (java.util.Date)4 Test (org.junit.Test)4 Matchers.anyString (org.mockito.Matchers.anyString)4 KeyPair (java.security.KeyPair)3 Entitlement (org.candlepin.model.Entitlement)3 Product (org.candlepin.model.Product)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 BigInteger (java.math.BigInteger)2 X509Certificate (java.security.cert.X509Certificate)2 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 Set (java.util.Set)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2