use of org.candlepin.policy.js.compliance.DateRange in project candlepin by candlepin.
the class InstalledProductStatusCalculatorTest method multiEntGreenNowInnerDatesYellowFutureWithOverlap.
@Test
public void multiEntGreenNowInnerDatesYellowFutureWithOverlap() {
Date now = new Date();
Owner owner = TestUtil.createOwner();
Product product = TestUtil.createProduct("p1", "product1");
Consumer consumer = this.mockConsumer(owner, product);
consumer.setCreated(now);
DateRange range1 = this.rangeRelativeToDate(now, -4, 12);
DateRange range2 = this.rangeRelativeToDate(now, -3, 10);
DateRange range3 = this.rangeRelativeToDate(now, 11, 24);
consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range1, product));
consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range2, product));
consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range3, product));
this.mockConsumerEntitlements(consumer, consumer.getEntitlements());
this.mockOwnerProducts(owner, Arrays.asList(product));
this.consumerEnricher.enrich(consumer);
ConsumerInstalledProduct cip = this.getInstalledProduct(consumer, product);
assertEquals(range2.getStartDate(), cip.getStartDate());
assertEquals(range2.getEndDate(), cip.getEndDate());
}
use of org.candlepin.policy.js.compliance.DateRange in project candlepin by candlepin.
the class InstalledProductStatusCalculatorTest method enricherSetsArchVersion.
@Test
public void enricherSetsArchVersion() {
// test that the enricher sets the arch and version when they are null in the CIP
Owner owner = TestUtil.createOwner();
Product product = TestUtil.createProduct("p1", "product1");
Consumer consumer = this.mockConsumer(owner, product);
DateRange range = this.rangeRelativeToDate(new Date(), -1, 4);
Entitlement entitlement = this.mockEntitlement(owner, consumer, product, range, product);
consumer.addEntitlement(entitlement);
this.mockConsumerEntitlements(consumer, consumer.getEntitlements());
ConsumerInstalledProduct cip = new ConsumerInstalledProduct();
cip.setProductId(product.getId());
consumer.addInstalledProduct(cip);
this.mockOwnerProducts(owner, Arrays.asList(product));
product.setAttribute(Product.Attributes.ARCHITECTURE, "candlepin arch");
product.setAttribute(Product.Attributes.VERSION, "candlepin version");
this.consumerEnricher.enrich(consumer);
assertEquals("candlepin arch", cip.getArch());
assertEquals("candlepin version", cip.getVersion());
}
use of org.candlepin.policy.js.compliance.DateRange in project candlepin by candlepin.
the class ConsumerEnricher method enrich.
public void enrich(Consumer consumer) {
if (consumer == null || CollectionUtils.isEmpty(consumer.getInstalledProducts())) {
// No consumer or the consumer doesn't have any installed products -- nothing to do here.
return;
}
ComplianceStatus status = this.complianceRules.getStatus(consumer, null, null, false, true, true, true);
Map<String, DateRange> ranges = status.getProductComplianceDateRanges();
// Compile the product IDs for the products we're going to be enriching
Set<String> productIds = new HashSet<>();
Map<String, Product> productMap = new HashMap<>();
for (ConsumerInstalledProduct cip : consumer.getInstalledProducts()) {
productIds.add(cip.getProductId());
}
for (Product product : this.ownerProductCurator.getProductsByIds(consumer.getOwnerId(), productIds)) {
productMap.put(product.getId(), product);
}
// Perform enrichment of the consumer's installed products
for (ConsumerInstalledProduct cip : consumer.getInstalledProducts()) {
String pid = cip.getProductId();
DateRange range = ranges != null ? ranges.get(pid) : null;
// do those first.
if (status.getCompliantProducts().containsKey(pid)) {
cip.setStatus(GREEN_STATUS);
} else if (status.getPartiallyCompliantProducts().containsKey(pid)) {
cip.setStatus(YELLOW_STATUS);
} else if (status.getNonCompliantProducts().contains(pid)) {
cip.setStatus(RED_STATUS);
}
// Set the compliance date range if we have it
if (range != null) {
cip.setStartDate(range.getStartDate());
cip.setEndDate(range.getEndDate());
}
// Fetch missing product information from the actual product
Product product = productMap.get(pid);
if (product != null) {
if (cip.getVersion() == null) {
cip.setVersion(product.getAttributeValue(Product.Attributes.VERSION));
}
if (cip.getArch() == null) {
cip.setArch(product.getAttributeValue(Product.Attributes.ARCHITECTURE));
}
}
}
}
Aggregations