use of org.candlepin.model.PoolQuantity in project candlepin by candlepin.
the class PreEntitlementRulesCheckOp method preProcess.
/**
* The java script portion of the rules can be run before the locks have been placed.
* if there is a failure, we stop the chain here.
* @param context
*/
@Override
public boolean preProcess(BindContext context) {
/* Whether or not we run pre ent rules check, this first call
* is used to fetch the pools and enrich some context fields.
*/
Map<String, PoolQuantity> poolQuantityMap = context.getPoolQuantities();
if (context.isQuantityRequested()) {
log.debug("Running pre-entitlement rules.");
// XXX preEntitlement is run twice for new entitlement creation
results = enforcer.preEntitlement(context.getConsumer(), poolQuantityMap.values(), callerType);
EntitlementRefusedException exception = checkResults();
if (exception != null) {
context.setException(exception, Thread.currentThread().getStackTrace());
return false;
}
}
return true;
}
use of org.candlepin.model.PoolQuantity in project candlepin by candlepin.
the class PreEntitlementRulesCheckOp method execute.
/**
* The pool's quantity might have changed since we last fetched it,
* so ensure that the pool still has enough quantity left.
* @param context
*/
@Override
public boolean execute(BindContext context) {
if (context.isQuantityRequested()) {
for (PoolQuantity poolQuantity : context.getPoolQuantities().values()) {
Pool pool = poolQuantity.getPool();
enforcer.finishValidation(results.get(pool.getId()), pool, context.getPoolQuantities().get(pool.getId()).getQuantity());
}
EntitlementRefusedException exception = checkResults();
if (exception != null) {
context.setException(exception, Thread.currentThread().getStackTrace());
return false;
}
}
return true;
}
use of org.candlepin.model.PoolQuantity in project candlepin by candlepin.
the class BindContext method getPoolQuantities.
public Map<String, PoolQuantity> getPoolQuantities() {
if (poolQuantities == null) {
poolQuantities = new HashMap<>();
for (Pool pool : poolCurator.listAllByIds(quantities.keySet())) {
Integer quantity = quantities.get(pool.getId());
if (quantity > 0) {
quantityRequested = true;
}
poolQuantities.put(pool.getId(), new PoolQuantity(pool, quantity));
quantities.remove(pool.getId());
}
if (!quantities.isEmpty()) {
throw new IllegalArgumentException(i18n.tr("Subscription pool(s) {0} do not exist.", quantities.keySet()));
}
}
return poolQuantities;
}
use of org.candlepin.model.PoolQuantity in project candlepin by candlepin.
the class BindContext method getEntitlementMap.
public Map<String, Entitlement> getEntitlementMap() {
if (entitlementMap == null) {
entitlementMap = new HashMap<>();
for (PoolQuantity poolQuantity : poolQuantities.values()) {
Pool pool = poolQuantity.getPool();
Entitlement ent = new Entitlement(consumer, getOwner(), poolQuantity.getQuantity());
// we manually generate ids as they are needed before the entitlement
// can be persisted.
ent.setId(Util.generateDbUUID());
ent.setUpdatedOnStart(pool.getStartDate().after(new Date()));
entitlementMap.put(pool.getId(), ent);
}
}
return entitlementMap;
}
use of org.candlepin.model.PoolQuantity in project candlepin by candlepin.
the class StubEntitlementCertServiceAdapter method generateEntitlementCert.
@Override
public EntitlementCertificate generateEntitlementCert(Entitlement entitlement, Product product) throws GeneralSecurityException, IOException {
Map<String, Entitlement> ents = new HashMap<>();
Map<String, PoolQuantity> poolQuantityMap = new HashMap<>();
Map<String, Product> productMap = new HashMap<>();
Pool pool = entitlement.getPool();
ents.put(pool.getId(), entitlement);
poolQuantityMap.put(pool.getId(), new PoolQuantity(pool, entitlement.getQuantity()));
productMap.put(pool.getId(), product);
return generateEntitlementCerts(entitlement.getConsumer(), poolQuantityMap, ents, productMap, true).get(pool.getId());
}
Aggregations