Search in sources :

Example 1 with Environment

use of org.candlepin.model.Environment 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 Environment

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

the class DefaultEntitlementCertServiceAdapter method getContentPrefix.

/**
 * @param consumer
 * @param useContentPrefix
 * @return
 * @throws IOException
 */
private String getContentPrefix(Consumer consumer, Owner owner, boolean useContentPrefix) throws IOException {
    String contentPrefix = null;
    if (useContentPrefix) {
        contentPrefix = owner.getContentPrefix();
        Environment env = this.environmentCurator.getConsumerEnvironment(consumer);
        if (contentPrefix != null && !contentPrefix.equals("")) {
            if (env != null) {
                contentPrefix = contentPrefix.replaceAll("\\$env", env.getName());
            }
            contentPrefix = this.cleanUpPrefix(contentPrefix);
        }
    }
    return contentPrefix;
}
Also used : Environment(org.candlepin.model.Environment)

Example 3 with Environment

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

the class DefaultContentAccessCertServiceAdapter method hasCertChangedSince.

public boolean hasCertChangedSince(Consumer consumer, Date date) {
    if (date == null) {
        return true;
    }
    Environment env = this.environmentCurator.getConsumerEnvironment(consumer);
    OwnerEnvContentAccess oeca = ownerEnvContentAccessCurator.getContentAccess(consumer.getOwnerId(), env == null ? null : env.getId());
    return oeca == null || consumer.getContentAccessCert() == null || oeca.getUpdated().getTime() > date.getTime();
}
Also used : Environment(org.candlepin.model.Environment) OwnerEnvContentAccess(org.candlepin.model.OwnerEnvContentAccess)

Example 4 with Environment

use of org.candlepin.model.Environment 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 Environment

use of org.candlepin.model.Environment 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

Environment (org.candlepin.model.Environment)29 EnvironmentContent (org.candlepin.model.EnvironmentContent)10 Test (org.junit.Test)9 HashSet (java.util.HashSet)8 Owner (org.candlepin.model.Owner)7 ApiOperation (io.swagger.annotations.ApiOperation)6 HashMap (java.util.HashMap)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 Content (org.candlepin.model.Content)6 ApiResponses (io.swagger.annotations.ApiResponses)5 Date (java.util.Date)5 Consumer (org.candlepin.model.Consumer)5 NotFoundException (org.candlepin.common.exceptions.NotFoundException)4 ConsumerCapability (org.candlepin.model.ConsumerCapability)4 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)4 ConsumerType (org.candlepin.model.ConsumerType)4 Release (org.candlepin.model.Release)4 Matchers.anyString (org.mockito.Matchers.anyString)4 KeyPair (java.security.KeyPair)3