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