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