Search in sources :

Example 26 with DateRange

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());
}
Also used : Owner(org.candlepin.model.Owner) DateRange(org.candlepin.policy.js.compliance.DateRange) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Date(java.util.Date) Test(org.junit.Test)

Example 27 with DateRange

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());
}
Also used : Owner(org.candlepin.model.Owner) DateRange(org.candlepin.policy.js.compliance.DateRange) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Entitlement(org.candlepin.model.Entitlement) Date(java.util.Date) Test(org.junit.Test)

Example 28 with DateRange

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));
            }
        }
    }
}
Also used : DateRange(org.candlepin.policy.js.compliance.DateRange) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) HashMap(java.util.HashMap) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) HashSet(java.util.HashSet)

Aggregations

DateRange (org.candlepin.policy.js.compliance.DateRange)28 Date (java.util.Date)27 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)27 Product (org.candlepin.model.Product)27 Consumer (org.candlepin.model.Consumer)26 Owner (org.candlepin.model.Owner)26 Test (org.junit.Test)26 Entitlement (org.candlepin.model.Entitlement)4 ComplianceStatus (org.candlepin.policy.js.compliance.ComplianceStatus)2 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 GuestId (org.candlepin.model.GuestId)1