Search in sources :

Example 1 with CertVersionConflictException

use of org.candlepin.version.CertVersionConflictException 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

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ForbiddenException (org.candlepin.common.exceptions.ForbiddenException)1 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)1 Entitlement (org.candlepin.model.Entitlement)1 Owner (org.candlepin.model.Owner)1 Product (org.candlepin.model.Product)1 ActivationKeyPool (org.candlepin.model.activationkeys.ActivationKeyPool)1 AutobindData (org.candlepin.resource.dto.AutobindData)1 CertVersionConflictException (org.candlepin.version.CertVersionConflictException)1