Search in sources :

Example 1 with Entitlement

use of org.candlepin.model.Entitlement in project candlepin by candlepin.

the class Exporter method exportEntitlements.

private void exportEntitlements(File baseDir, Consumer consumer) throws IOException, ExportCreationException {
    File entCertDir = new File(baseDir.getCanonicalPath(), "entitlements");
    entCertDir.mkdir();
    for (Entitlement ent : entitlementCurator.listByConsumer(consumer)) {
        if (ent.isDirty()) {
            log.error("Entitlement " + ent.getId() + " is marked as dirty.");
            throw new ExportCreationException("Attempted to export dirty entitlements");
        }
        if (!this.exportRules.canExport(ent)) {
            if (log.isDebugEnabled()) {
                log.debug("Skipping export of entitlement with product: {}", ent.getPool().getProductId());
            }
            continue;
        }
        if (log.isDebugEnabled()) {
            log.debug("Exporting entitlement for product" + ent.getPool().getProductId());
        }
        FileWriter writer = null;
        try {
            File file = new File(entCertDir.getCanonicalPath(), ent.getId() + ".json");
            writer = new FileWriter(file);
            entExporter.export(mapper, writer, ent);
        } finally {
            if (writer != null) {
                writer.close();
            }
        }
    }
}
Also used : FileWriter(java.io.FileWriter) Entitlement(org.candlepin.model.Entitlement) File(java.io.File)

Example 2 with Entitlement

use of org.candlepin.model.Entitlement in project candlepin by candlepin.

the class Exporter method exportProducts.

private void exportProducts(File baseDir, Consumer consumer) throws IOException {
    File productDir = new File(baseDir.getCanonicalPath(), "products");
    productDir.mkdir();
    Map<String, Product> products = new HashMap<>();
    for (Entitlement entitlement : consumer.getEntitlements()) {
        Pool pool = entitlement.getPool();
        for (Product providedProduct : productCurator.getPoolProvidedProductsCached(pool)) {
            products.put(providedProduct.getId(), providedProduct);
        }
        // Don't forget the 'main' product!
        Product product = pool.getProduct();
        products.put(product.getId(), product);
        // Also need to check for sub products
        Product derivedProduct = pool.getDerivedProduct();
        if (derivedProduct != null) {
            products.put(derivedProduct.getId(), derivedProduct);
        }
        for (Product derivedProvidedProduct : productCurator.getPoolDerivedProvidedProductsCached(pool)) {
            products.put(derivedProvidedProduct.getId(), derivedProvidedProduct);
        }
    }
    for (Product product : products.values()) {
        // Clear the owner and UUID so they can be re-generated/assigned on import
        // product.setUuid(null);
        // product.setOwner(null);
        String path = productDir.getCanonicalPath();
        String productId = product.getId();
        File file = new File(path, productId + ".json");
        FileWriter writer = null;
        try {
            writer = new FileWriter(file);
            productExporter.export(mapper, writer, product);
        } finally {
            if (writer != null) {
                writer.close();
            }
        }
        // Real products have a numeric id.
        if (StringUtils.isNumeric(product.getId())) {
            Owner owner = ownerCurator.findOwnerById(consumer.getOwnerId());
            ProductCertificate cert = productAdapter.getProductCertificate(owner, product.getId());
            // XXX: need to decide if the cert should always be in the export, or never.
            if (cert != null) {
                file = new File(productDir.getCanonicalPath(), product.getId() + ".pem");
                writer = new FileWriter(file);
                productCertExporter.export(writer, cert);
                writer.close();
            }
        }
    }
}
Also used : Owner(org.candlepin.model.Owner) HashMap(java.util.HashMap) FileWriter(java.io.FileWriter) ProductCertificate(org.candlepin.model.ProductCertificate) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) File(java.io.File)

Example 3 with Entitlement

use of org.candlepin.model.Entitlement in project candlepin by candlepin.

the class DefaultContentAccessCertServiceAdapter method createContentAccessDataPayload.

private byte[] createContentAccessDataPayload(Owner owner, Environment environment) throws IOException {
    // fake a product dto as a container for the org content
    Set<Product> containerSet = new HashSet<>();
    CandlepinQuery<Content> ownerContent = ownerContentCurator.getContentByOwner(owner);
    Set<String> entitledProductIds = new HashSet<>();
    List<org.candlepin.model.dto.Product> productModels = new ArrayList<>();
    Map<String, EnvironmentContent> promotedContent = getPromotedContent(environment);
    String contentPrefix = getContentPrefix(owner, environment);
    Product container = new Product();
    Entitlement emptyEnt = new Entitlement();
    Pool emptyPool = new Pool();
    Product skuProduct = new Product();
    Consumer emptyConsumer = new Consumer();
    containerSet.add(container);
    container.setId("content_access");
    container.setName(" Content Access");
    for (Content c : ownerContent) {
        container.addContent(c, false);
    }
    emptyConsumer.setEnvironment(environment);
    emptyEnt.setPool(emptyPool);
    emptyEnt.setConsumer(emptyConsumer);
    emptyPool.setProduct(skuProduct);
    emptyPool.setStartDate(new Date());
    emptyPool.setEndDate(new Date());
    skuProduct.setName("Content Access");
    skuProduct.setId("content_access");
    entitledProductIds.add("content-access");
    org.candlepin.model.dto.Product productModel = v3extensionUtil.mapProduct(container, skuProduct, contentPrefix, promotedContent, emptyConsumer, emptyPool, entitledProductIds);
    productModels.add(productModel);
    return v3extensionUtil.createEntitlementDataPayload(productModels, emptyConsumer, emptyPool, null);
}
Also used : ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) EnvironmentContent(org.candlepin.model.EnvironmentContent) Date(java.util.Date) Consumer(org.candlepin.model.Consumer) Content(org.candlepin.model.Content) EnvironmentContent(org.candlepin.model.EnvironmentContent) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) HashSet(java.util.HashSet)

Example 4 with Entitlement

use of org.candlepin.model.Entitlement in project candlepin by candlepin.

the class HandleCertificatesOp method execute.

/**
 * we can now associate and persist the certs.
 * @param context
 */
@Override
public boolean execute(BindContext context) {
    if (!context.getConsumerType().isType(ConsumerTypeEnum.SHARE)) {
        Map<String, Entitlement> ents = context.getEntitlementMap();
        for (Entitlement ent : ents.values()) {
            EntitlementCertificate cert = certs.get(ent.getPool().getId());
            ent.getCertificates().add(cert);
            cert.setEntitlement(ent);
        }
        ecCurator.saveAll(certs.values(), false, false);
        eCurator.saveOrUpdateAll(ents.values(), false, false);
        this.ecGenerator.regenerateCertificatesByEntitlementIds(modifyingEnts, true);
    }
    return true;
}
Also used : EntitlementCertificate(org.candlepin.model.EntitlementCertificate) Entitlement(org.candlepin.model.Entitlement)

Example 5 with Entitlement

use of org.candlepin.model.Entitlement in project candlepin by candlepin.

the class PostBindBonusPoolsOp method execute.

@Override
public boolean execute(BindContext context) {
    Consumer consumer = context.getLockedConsumer();
    Map<String, Entitlement> entitlements = context.getEntitlementMap();
    Map<String, PoolQuantity> poolQuantities = context.getPoolQuantities();
    poolManager.handlePostEntitlement(poolManager, consumer, context.getOwner(), entitlements, poolQuantities);
    // we might have changed the bonus pool quantities, lets revoke ents if needed.
    poolManager.checkBonusPoolQuantities(consumer.getOwnerId(), entitlements);
    return true;
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Consumer(org.candlepin.model.Consumer) Entitlement(org.candlepin.model.Entitlement)

Aggregations

Entitlement (org.candlepin.model.Entitlement)301 Test (org.junit.Test)201 Consumer (org.candlepin.model.Consumer)164 Pool (org.candlepin.model.Pool)125 LinkedList (java.util.LinkedList)84 Product (org.candlepin.model.Product)68 Date (java.util.Date)62 ArrayList (java.util.ArrayList)61 HashSet (java.util.HashSet)59 HashMap (java.util.HashMap)55 Owner (org.candlepin.model.Owner)44 PoolQuantity (org.candlepin.model.PoolQuantity)35 ConsumerType (org.candlepin.model.ConsumerType)34 List (java.util.List)30 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)24 Matchers.anyString (org.mockito.Matchers.anyString)17 Set (java.util.Set)16 Subscription (org.candlepin.model.dto.Subscription)16 ApiOperation (io.swagger.annotations.ApiOperation)15 ApiResponses (io.swagger.annotations.ApiResponses)15