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