Search in sources :

Example 1 with PoolUpdate

use of org.candlepin.policy.js.pool.PoolUpdate in project candlepin by candlepin.

the class CandlepinPoolManager method updateFloatingPools.

/**
 * Update pools which have no subscription attached, if applicable.
 *
 * @param floatingPools
 * @return
 */
@Transactional
void updateFloatingPools(List<Pool> floatingPools, boolean lazy, Map<String, Product> changedProducts) {
    /*
         * Rules need to determine which pools have changed, but the Java must
         * send out the events. Create an event for each pool that could change,
         * even if we won't use them all.
         */
    Map<String, EventBuilder> poolEvents = new HashMap<>();
    for (Pool existing : floatingPools) {
        EventBuilder eventBuilder = eventFactory.getEventBuilder(Target.POOL, Type.MODIFIED).setEventData(existing);
        poolEvents.put(existing.getId(), eventBuilder);
    }
    // Hand off to rules to determine which pools need updating
    List<PoolUpdate> updatedPools = poolRules.updatePools(floatingPools, changedProducts);
    regenerateCertificatesByEntIds(processPoolUpdates(poolEvents, updatedPools), lazy);
}
Also used : EventBuilder(org.candlepin.audit.EventBuilder) HashMap(java.util.HashMap) Pool(org.candlepin.model.Pool) PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) Transactional(com.google.inject.persist.Transactional)

Example 2 with PoolUpdate

use of org.candlepin.policy.js.pool.PoolUpdate in project candlepin by candlepin.

the class PoolManagerTest method refreshPoolsCleanupPoolThatLostVirtLimit.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void refreshPoolsCleanupPoolThatLostVirtLimit() {
    List<Subscription> subscriptions = new ArrayList<>();
    List<Pool> pools = new ArrayList<>();
    Owner owner = getOwner();
    Product product = TestUtil.createProduct();
    product.setLocked(true);
    Subscription s = TestUtil.createSubscription(owner, product);
    s.setId("01923");
    subscriptions.add(s);
    Pool p = TestUtil.createPool(product);
    p.setSourceSubscription(new SourceSubscription(s.getId(), "master"));
    p.setMarkedForDelete(true);
    p.setOwner(owner);
    pools.add(p);
    mockSubsList(subscriptions);
    mockPoolsList(pools);
    List<PoolUpdate> updates = new LinkedList();
    PoolUpdate u = new PoolUpdate(p);
    u.setQuantityChanged(true);
    u.setOrderChanged(true);
    updates.add(u);
    ArgumentCaptor<Pool> argPool = ArgumentCaptor.forClass(Pool.class);
    when(poolRulesMock.updatePools(argPool.capture(), eq(pools), eq(s.getQuantity()), any(Map.class))).thenReturn(updates);
    when(mockOwnerCurator.lookupByKey(owner.getKey())).thenReturn(owner);
    this.mockProducts(owner, product);
    this.mockProductImport(owner, product);
    this.mockContentImport(owner, new Content[] {});
    CandlepinQuery<Pool> cqmock = mock(CandlepinQuery.class);
    when(cqmock.list()).thenReturn(pools);
    when(cqmock.iterator()).thenReturn(pools.iterator());
    when(mockPoolCurator.listByOwnerAndType(eq(owner), any(PoolType.class))).thenReturn(cqmock);
    this.manager.getRefresher(mockSubAdapter, mockOwnerAdapter).add(owner).run();
    verify(poolRulesMock).createAndEnrichPools(argPool.capture(), any(List.class));
    TestUtil.assertPoolsAreEqual(TestUtil.copyFromSub(s), argPool.getValue());
}
Also used : Owner(org.candlepin.model.Owner) PoolType(org.candlepin.model.Pool.PoolType) ArrayList(java.util.ArrayList) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) LinkedList(java.util.LinkedList) SourceSubscription(org.candlepin.model.SourceSubscription) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Matchers.anyList(org.mockito.Matchers.anyList) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 3 with PoolUpdate

use of org.candlepin.policy.js.pool.PoolUpdate in project candlepin by candlepin.

the class PoolRulesStackDerivedTest method addLaterEndDate.

@Test
public void addLaterEndDate() {
    stackedEnts.add(createEntFromPool(pool1));
    stackedEnts.add(createEntFromPool(pool3));
    PoolUpdate update = poolRules.updatePoolFromStack(stackDerivedPool, null);
    assertTrue(update.changed());
    assertTrue(update.getDatesChanged());
    assertEquals(pool1.getStartDate(), stackDerivedPool.getStartDate());
    assertEquals(pool3.getEndDate(), stackDerivedPool.getEndDate());
}
Also used : PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) Test(org.junit.Test)

Example 4 with PoolUpdate

use of org.candlepin.policy.js.pool.PoolUpdate in project candlepin by candlepin.

the class PoolRulesStackDerivedTest method removeEldestEntitlement.

@Test
public void removeEldestEntitlement() {
    stackedEnts.add(createEntFromPool(pool1));
    stackedEnts.add(createEntFromPool(pool3));
    poolRules.updatePoolFromStack(stackDerivedPool, null);
    // Should change a variety of settings on the pool.
    stackedEnts.remove(0);
    PoolUpdate update = poolRules.updatePoolFromStack(stackDerivedPool, null);
    assertTrue(update.changed());
    assertFalse(update.getDatesChanged());
    // Should have changed from pool2 to pool1's info:
    assertEquals(pool1.getProductId(), stackDerivedPool.getProductId());
    assertEquals(pool1.getProductName(), stackDerivedPool.getProductName());
    assertEquals(pool1.getAccountNumber(), stackDerivedPool.getAccountNumber());
    assertEquals(pool1.getContractNumber(), stackDerivedPool.getContractNumber());
    assertEquals(pool1.getOrderNumber(), stackDerivedPool.getOrderNumber());
}
Also used : PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) Test(org.junit.Test)

Example 5 with PoolUpdate

use of org.candlepin.policy.js.pool.PoolUpdate in project candlepin by candlepin.

the class PoolRulesStackDerivedTest method addEarlierStartDate.

@Test
public void addEarlierStartDate() {
    stackedEnts.add(createEntFromPool(pool1));
    PoolUpdate update = poolRules.updatePoolFromStack(stackDerivedPool, null);
    assertTrue(update.changed());
    assertTrue(update.getDatesChanged());
    assertEquals(pool1.getStartDate(), stackDerivedPool.getStartDate());
    assertEquals(pool2.getEndDate(), stackDerivedPool.getEndDate());
}
Also used : PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) Test(org.junit.Test)

Aggregations

PoolUpdate (org.candlepin.policy.js.pool.PoolUpdate)38 Test (org.junit.Test)35 Pool (org.candlepin.model.Pool)28 LinkedList (java.util.LinkedList)10 Product (org.candlepin.model.Product)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 EventBuilder (org.candlepin.audit.EventBuilder)4 Entitlement (org.candlepin.model.Entitlement)4 Subscription (org.candlepin.model.dto.Subscription)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)2 Branding (org.candlepin.model.Branding)2 Transactional (com.google.inject.persist.Transactional)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Event (org.candlepin.audit.Event)1 CandlepinQuery (org.candlepin.model.CandlepinQuery)1 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)1