Search in sources :

Example 6 with ActivationKeyPool

use of org.candlepin.model.activationkeys.ActivationKeyPool in project candlepin by candlepin.

the class PoolCurator method getActivationKeysForPool.

public List<ActivationKey> getActivationKeysForPool(Pool p) {
    List<ActivationKey> activationKeys = new ArrayList<>();
    List<ActivationKeyPool> activationKeyPools = currentSession().createCriteria(ActivationKeyPool.class).add(Restrictions.eq("pool", p)).list();
    for (ActivationKeyPool akp : activationKeyPools) {
        activationKeys.add(akp.getKey());
    }
    return activationKeys;
}
Also used : ArrayList(java.util.ArrayList) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) ActivationKey(org.candlepin.model.activationkeys.ActivationKey)

Example 7 with ActivationKeyPool

use of org.candlepin.model.activationkeys.ActivationKeyPool in project candlepin by candlepin.

the class ConsumerBindUtil method handleActivationKeyAutoBind.

private void handleActivationKeyAutoBind(Consumer consumer, ActivationKey key) throws AutobindDisabledForOwnerException {
    try {
        Set<String> productIds = new HashSet<>();
        List<String> poolIds = new ArrayList<>();
        for (Product akp : key.getProducts()) {
            productIds.add(akp.getId());
        }
        for (ConsumerInstalledProduct cip : consumer.getInstalledProducts()) {
            productIds.add(cip.getProductId());
        }
        for (ActivationKeyPool p : key.getPools()) {
            poolIds.add(p.getPool().getId());
        }
        Owner owner = ownerCurator.findOwnerById(consumer.getOwnerId());
        AutobindData autobindData = AutobindData.create(consumer, owner).forProducts(productIds.toArray(new String[0])).withPools(poolIds);
        List<Entitlement> ents = entitler.bindByProducts(autobindData);
        entitler.sendEvents(ents);
    } catch (ForbiddenException fe) {
        throw fe;
    } catch (CertVersionConflictException cvce) {
        throw cvce;
    } catch (RuntimeException re) {
        log.warn("Unable to attach a subscription for a product that " + "has no pool: " + re.getMessage());
    }
}
Also used : Owner(org.candlepin.model.Owner) ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) CertVersionConflictException(org.candlepin.version.CertVersionConflictException) AutobindData(org.candlepin.resource.dto.AutobindData) Entitlement(org.candlepin.model.Entitlement) HashSet(java.util.HashSet)

Aggregations

ActivationKeyPool (org.candlepin.model.activationkeys.ActivationKeyPool)7 HashSet (java.util.HashSet)3 Product (org.candlepin.model.Product)3 ActivationKey (org.candlepin.model.activationkeys.ActivationKey)3 ArrayList (java.util.ArrayList)2 ForbiddenException (org.candlepin.common.exceptions.ForbiddenException)2 Owner (org.candlepin.model.Owner)2 Pool (org.candlepin.model.Pool)2 Release (org.candlepin.model.Release)2 ActivationKeyContentOverride (org.candlepin.model.activationkeys.ActivationKeyContentOverride)2 LinkedList (java.util.LinkedList)1 PoolManager (org.candlepin.controller.PoolManager)1 ProductCachedSerializationModule (org.candlepin.jackson.ProductCachedSerializationModule)1 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)1 Entitlement (org.candlepin.model.Entitlement)1 ActivationKeyCurator (org.candlepin.model.activationkeys.ActivationKeyCurator)1 AutobindData (org.candlepin.resource.dto.AutobindData)1 CertVersionConflictException (org.candlepin.version.CertVersionConflictException)1 Test (org.junit.Test)1