Search in sources :

Example 31 with DateRange

use of com.google.api.ads.admanager.axis.v202205.DateRange in project candlepin by candlepin.

the class InstalledProductStatusCalculatorTest method validRangeWhenGuestLimitOverridden.

@Test
public void validRangeWhenGuestLimitOverridden() {
    Date now = new Date();
    Owner owner = TestUtil.createOwner();
    owner.setContentAccessMode("entitlement");
    Product product = TestUtil.createProduct("p1", "product1");
    product.setAttribute(Product.Attributes.GUEST_LIMIT, "2");
    Product product2 = TestUtil.createProduct("p2", "product2");
    product2.setAttribute(Product.Attributes.GUEST_LIMIT, "-1");
    Product product3 = TestUtil.createProduct("p3", "product3");
    Consumer consumer = this.mockConsumer(owner, product);
    for (int i = 0; i < 5; i++) {
        consumer.addGuestId(new GuestId(String.valueOf(i), consumer, this.getActiveGuestAttrs()));
    }
    DateRange range1 = this.rangeRelativeToDate(now, -4, 4);
    DateRange range2 = this.rangeRelativeToDate(now, -2, 2);
    consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 10, range1, product));
    consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_2", product2, 10, range2, product3));
    this.mockConsumerEntitlements(consumer, consumer.getEntitlements());
    this.mockOwnerProducts(owner, Arrays.asList(product, product2, product3));
    this.consumerEnricher.enrich(consumer);
    ConsumerInstalledProduct cip = this.getInstalledProduct(consumer, product);
    assertEquals(Util.toDate(range2.getStartDate()), cip.getStartDate());
    assertEquals(Util.toDate(range2.getEndDate()), cip.getEndDate());
}
Also used : Owner(org.candlepin.model.Owner) DateRange(org.candlepin.dto.api.v1.DateRange) Consumer(org.candlepin.model.Consumer) GuestId(org.candlepin.model.GuestId) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 32 with DateRange

use of com.google.api.ads.admanager.axis.v202205.DateRange in project candlepin by candlepin.

the class InstalledProductStatusCalculatorTest method multiEntGreenNowInnerDatesYellowFutureWithOverlap.

@Test
public void multiEntGreenNowInnerDatesYellowFutureWithOverlap() {
    Date now = new Date();
    Owner owner = TestUtil.createOwner();
    owner.setContentAccessMode("entitlement");
    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(Util.toDate(range2.getStartDate()), cip.getStartDate());
    assertEquals(Util.toDate(range2.getEndDate()), cip.getEndDate());
}
Also used : Owner(org.candlepin.model.Owner) DateRange(org.candlepin.dto.api.v1.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.jupiter.api.Test)

Example 33 with DateRange

use of com.google.api.ads.admanager.axis.v202205.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.isDisabled()) {
            cip.setStatus(GRAY_STATUS);
        }
        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(Util.toDate(range.getStartDate()));
            cip.setEndDate(Util.toDate(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.dto.api.v1.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)

Example 34 with DateRange

use of com.google.api.ads.admanager.axis.v202205.DateRange in project candlepin by candlepin.

the class ComplianceStatusTranslatorTest method initSourceObject.

@Override
protected ComplianceStatus initSourceObject() {
    ComplianceStatus source = new ComplianceStatus();
    Set<ComplianceReason> reasons = new HashSet<>();
    for (int i = 0; i < 3; ++i) {
        ComplianceReason reason = new ComplianceReason();
        reason.setKey("test-key-" + i);
        reason.setMessage("test-msg-" + i);
        Map<String, String> attributes = new HashMap<>();
        attributes.put("a1-" + i, "v1-" + i);
        attributes.put("a2-" + i, "v2-" + i);
        attributes.put("a3-" + i, "v3-" + i);
        reasons.add(reason);
    }
    Map<String, DateRange> ranges = new HashMap<>();
    for (int i = 0; i < 3; ++i) {
        DateRange range = new DateRange();
        Calendar sdc = Calendar.getInstance();
        sdc.add(Calendar.HOUR, i);
        range.setStartDate(Util.toDateTime(sdc.getTime()));
        Calendar edc = Calendar.getInstance();
        edc.add(Calendar.HOUR, i);
        edc.add(Calendar.YEAR, 1);
        range.setEndDate(Util.toDateTime(edc.getTime()));
        ranges.put("test_prod-" + i, range);
    }
    Map<String, Set<Entitlement>> compliantProducts = new HashMap<>();
    Map<String, Set<Entitlement>> partiallyCompliantProducts = new HashMap<>();
    Map<String, Set<Entitlement>> partialStacks = new HashMap<>();
    for (int i = 0; i < 3; ++i) {
        compliantProducts.put("p" + i, this.generateEntitlements(3));
        partiallyCompliantProducts.put("p" + (3 + i), this.generateEntitlements(3));
        partialStacks.put("s" + i, this.generateEntitlements(3));
    }
    source.setDate(new Date());
    source.setCompliantUntil(new Date());
    source.getCompliantProducts().putAll(compliantProducts);
    source.getNonCompliantProducts().addAll(Arrays.asList("p1", "p2", "p3"));
    source.getPartiallyCompliantProducts().putAll(partiallyCompliantProducts);
    source.getPartialStacks().putAll(partialStacks);
    source.getProductComplianceDateRanges().putAll(ranges);
    source.setReasons(reasons);
    return source;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) HashMap(java.util.HashMap) Calendar(java.util.Calendar) Date(java.util.Date) DateRange(org.candlepin.dto.api.v1.DateRange) ComplianceReason(org.candlepin.policy.js.compliance.ComplianceReason) HashSet(java.util.HashSet)

Example 35 with DateRange

use of com.google.api.ads.admanager.axis.v202205.DateRange in project candlepin by candlepin.

the class ComplianceStatusDTO method clone.

/**
 * {@inheritDoc}
 */
@Override
public ComplianceStatusDTO clone() {
    ComplianceStatusDTO copy = super.clone();
    Date date = this.getDate();
    copy.setDate(date != null ? (Date) date.clone() : null);
    date = this.getCompliantUntil();
    copy.setCompliantUntil(date != null ? (Date) date.clone() : null);
    Map<String, Set<EntitlementDTO>> entMap = this.getCompliantProducts();
    copy.setCompliantProducts(null);
    if (entMap != null) {
        copy.setCompliantProducts(entMap);
    }
    Set<String> nonCompliantProducts = this.getNonCompliantProducts();
    copy.setNonCompliantProducts(null);
    if (nonCompliantProducts != null) {
        copy.setNonCompliantProducts(nonCompliantProducts);
    }
    entMap = this.getPartiallyCompliantProducts();
    copy.setPartiallyCompliantProducts(null);
    if (entMap != null) {
        copy.setPartiallyCompliantProducts(entMap);
    }
    entMap = this.getPartialStacks();
    copy.setPartialStacks(null);
    if (entMap != null) {
        copy.setPartialStacks(entMap);
    }
    Map<String, DateRange> ranges = this.getProductComplianceDateRanges();
    copy.setProductComplianceDateRanges(null);
    if (ranges != null) {
        copy.setProductComplianceDateRanges(ranges);
    }
    Set<ComplianceReasonDTO> reasons = this.getReasons();
    copy.setReasons(null);
    if (reasons != null) {
        copy.setReasons(reasons);
    }
    return copy;
}
Also used : DateRange(org.candlepin.dto.api.v1.DateRange) Set(java.util.Set) HashSet(java.util.HashSet) Date(java.util.Date)

Aggregations

DateRange (org.candlepin.dto.api.v1.DateRange)30 Date (java.util.Date)29 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.jupiter.api.Test)26 Random (java.util.Random)4 DateTime (org.joda.time.DateTime)4 Interval (org.joda.time.Interval)4 HashSet (java.util.HashSet)3 Entitlement (org.candlepin.model.Entitlement)3 ComplianceStatus (org.candlepin.policy.js.compliance.ComplianceStatus)3 Date (com.google.api.ads.admanager.axis.v202108.Date)2 DateRange (com.google.api.ads.admanager.axis.v202108.DateRange)2 Date (com.google.api.ads.admanager.axis.v202111.Date)2 DateRange (com.google.api.ads.admanager.axis.v202111.DateRange)2 Date (com.google.api.ads.admanager.axis.v202202.Date)2 DateRange (com.google.api.ads.admanager.axis.v202202.DateRange)2 Date (com.google.api.ads.admanager.axis.v202205.Date)2