Search in sources :

Example 21 with Branding

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

the class X509V3ExtensionUtil method mapProduct.

public org.candlepin.model.dto.Product mapProduct(Product engProduct, Product sku, String contentPrefix, Map<String, EnvironmentContent> promotedContent, Consumer consumer, Pool pool, Set<String> entitledProductIds) {
    org.candlepin.model.dto.Product toReturn = new org.candlepin.model.dto.Product();
    toReturn.setId(engProduct.getId());
    toReturn.setName(engProduct.getName());
    String version = engProduct.getAttributeValue(Product.Attributes.VERSION);
    toReturn.setVersion(version != null ? version : "");
    Branding brand = getBranding(pool, engProduct.getId());
    toReturn.setBrandType(brand.getType());
    toReturn.setBrandName(brand.getName());
    String productArches = engProduct.getAttributeValue(Product.Attributes.ARCHITECTURE);
    Set<String> productArchSet = Arch.parseArches(productArches);
    // FIXME: getParsedArches might make more sense to just return a list
    List<String> archList = new ArrayList<>();
    for (String arch : productArchSet) {
        archList.add(arch);
    }
    toReturn.setArchitectures(archList);
    toReturn.setContent(createContent(filterProductContent(engProduct, entitledProductIds), sku, contentPrefix, promotedContent, consumer, engProduct));
    return toReturn;
}
Also used : ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) Branding(org.candlepin.model.Branding)

Example 22 with Branding

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

the class PoolTranslator method populate.

/**
 * {@inheritDoc}
 */
@Override
public PoolDTO populate(ModelTranslator modelTranslator, Pool source, PoolDTO dest) {
    if (source == null) {
        throw new IllegalArgumentException("source is null");
    }
    if (dest == null) {
        throw new IllegalArgumentException("destination is null");
    }
    dest.setId(source.getId());
    dest.setType(source.getType().toString());
    dest.setActiveSubscription(source.getActiveSubscription());
    dest.setCreatedByShare(source.isCreatedByShare());
    dest.setHasSharedAncestor(source.hasSharedAncestor());
    dest.setQuantity(source.getQuantity());
    dest.setStartDate(source.getStartDate());
    dest.setEndDate(source.getEndDate());
    dest.setAttributes(source.getAttributes());
    dest.setRestrictedToUsername(source.getRestrictedToUsername());
    dest.setContractNumber(source.getContractNumber());
    dest.setAccountNumber(source.getAccountNumber());
    dest.setOrderNumber(source.getOrderNumber());
    dest.setConsumed(source.getConsumed());
    dest.setExported(source.getExported());
    dest.setShared(source.getShared());
    dest.setCalculatedAttributes(source.getCalculatedAttributes());
    dest.setUpstreamPoolId(source.getUpstreamPoolId());
    dest.setUpstreamEntitlementId(source.getUpstreamEntitlementId());
    dest.setUpstreamConsumerId(source.getUpstreamConsumerId());
    dest.setProductName(source.getProductName());
    dest.setProductId(source.getProductId());
    dest.setProductAttributes(source.getProductAttributes());
    dest.setStackId(source.getStackId());
    dest.setStacked(source.isStacked());
    dest.setDevelopmentPool(source.isDevelopmentPool());
    dest.setDerivedProductAttributes(source.getDerivedProductAttributes());
    dest.setDerivedProductId(source.getDerivedProductId());
    dest.setDerivedProductName(source.getDerivedProductName());
    dest.setSourceStackId(source.getSourceStackId());
    dest.setSubscriptionSubKey(source.getSubscriptionSubKey());
    dest.setSubscriptionId(source.getSubscriptionId());
    // Process nested objects if we have a model translator to use to the translation...
    if (modelTranslator != null) {
        Owner owner = source.getOwner();
        dest.setOwner(owner != null ? modelTranslator.translate(owner, OwnerDTO.class) : null);
        SubscriptionsCertificate subCertificate = source.getCertificate();
        dest.setCertificate(subCertificate != null ? modelTranslator.translate(subCertificate, CertificateDTO.class) : null);
        Entitlement sourceEntitlement = source.getSourceEntitlement();
        dest.setSourceEntitlement(sourceEntitlement != null ? modelTranslator.translate(sourceEntitlement, EntitlementDTO.class) : null);
        Set<Branding> branding = source.getBranding();
        if (branding != null && !branding.isEmpty()) {
            for (Branding brand : branding) {
                if (brand != null) {
                    dest.addBranding(modelTranslator.translate(brand, BrandingDTO.class));
                }
            }
        } else {
            dest.setBranding(Collections.emptySet());
        }
        Set<Product> products = source.getProvidedProducts();
        if (products != null && !products.isEmpty()) {
            for (Product prod : products) {
                if (prod != null) {
                    dest.addProvidedProduct(new PoolDTO.ProvidedProductDTO(prod.getId(), prod.getName()));
                }
            }
        } else {
            dest.setProvidedProducts(Collections.emptySet());
        }
        Set<Product> derivedProducts = source.getDerivedProvidedProducts();
        if (derivedProducts != null && !derivedProducts.isEmpty()) {
            for (Product derivedProd : derivedProducts) {
                if (derivedProd != null) {
                    dest.addDerivedProvidedProduct(new PoolDTO.ProvidedProductDTO(derivedProd.getId(), derivedProd.getName()));
                }
            }
        } else {
            dest.setDerivedProvidedProducts(Collections.emptySet());
        }
    }
    return dest;
}
Also used : Owner(org.candlepin.model.Owner) SubscriptionsCertificate(org.candlepin.model.SubscriptionsCertificate) Product(org.candlepin.model.Product) Entitlement(org.candlepin.model.Entitlement) Branding(org.candlepin.model.Branding)

Example 23 with Branding

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

the class EntitlementRules method postBindShareCreate.

private void postBindShareCreate(PoolManager poolManager, Consumer c, Owner sharingOwner, Map<String, Entitlement> entitlementMap) {
    log.debug("Running post-bind share create");
    Owner recipient = ownerCurator.lookupByKey(c.getRecipientOwnerKey());
    List<Pool> sharedPoolsToCreate = new ArrayList<>();
    for (Entitlement entitlement : entitlementMap.values()) {
        Pool sourcePool = entitlement.getPool();
        // resolve and copy all products
        // Handle any product creation/manipulation incurred by the share action
        Set<Product> allProducts = new HashSet<>();
        allProducts.add(sourcePool.getProduct());
        if (sourcePool.getProvidedProducts() != null) {
            allProducts.addAll(sourcePool.getProvidedProducts());
        }
        if (sourcePool.getDerivedProduct() != null) {
            allProducts.add(sourcePool.getDerivedProduct());
        }
        if (sourcePool.getDerivedProvidedProducts() != null) {
            allProducts.addAll(sourcePool.getDerivedProvidedProducts());
        }
        Map<String, Product> resolvedProducts = resolveProductShares(sharingOwner, recipient, allProducts);
        Product product = resolvedProducts.get(sourcePool.getProduct().getId());
        Set<Product> providedProducts = copySetFromResolved(sourcePool.getProvidedProducts(), resolvedProducts);
        Long q = Long.valueOf(entitlement.getQuantity());
        // endDateOverride doesnt really apply here , this is just for posterity.
        Date endDate = (entitlement.getEndDateOverride() == null) ? sourcePool.getEndDate() : entitlement.getEndDateOverride();
        Pool sharedPool = new Pool(recipient, product, providedProducts, q, sourcePool.getStartDate(), endDate, sourcePool.getContractNumber(), sourcePool.getAccountNumber(), sourcePool.getOrderNumber());
        if (sourcePool.getDerivedProduct() != null) {
            Product derivedProduct = resolvedProducts.get(sourcePool.getDerivedProduct().getId());
            sharedPool.setDerivedProduct(derivedProduct);
        }
        Set<Product> derivedProvidedProducts = copySetFromResolved(sourcePool.getDerivedProvidedProducts(), resolvedProducts);
        sharedPool.setDerivedProvidedProducts(derivedProvidedProducts);
        if (entitlement != null && entitlement.getPool() != null) {
            sharedPool.setSourceEntitlement(entitlement);
        }
        /* Since we set the source entitlement id as the subscription sub key for
               entitlement derived pools, it makes sense to do the same for share pools,
               as share pools are also entitlement derived, sort of.
             */
        String subscriptionId = sourcePool.getSubscriptionId();
        if (subscriptionId != null && !subscriptionId.isEmpty()) {
            sharedPool.setSourceSubscription(new SourceSubscription(subscriptionId, entitlement.getId()));
        }
        // Copy the pool's attributes
        for (Entry<String, String> entry : sourcePool.getAttributes().entrySet()) {
            sharedPool.setAttribute(entry.getKey(), entry.getValue());
        }
        sharedPool.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
        sharedPool.setCreatedByShare(Boolean.TRUE);
        sharedPool.setHasSharedAncestor(Boolean.TRUE);
        for (Branding b : sourcePool.getBranding()) {
            sharedPool.getBranding().add(new Branding(b.getProductId(), b.getType(), b.getName()));
        }
        sharedPoolsToCreate.add(sharedPool);
    }
    if (CollectionUtils.isNotEmpty(sharedPoolsToCreate)) {
        poolManager.createPools(sharedPoolsToCreate);
    }
}
Also used : Owner(org.candlepin.model.Owner) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) Branding(org.candlepin.model.Branding) Date(java.util.Date) SourceSubscription(org.candlepin.model.SourceSubscription) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) HashSet(java.util.HashSet)

Example 24 with Branding

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

the class PoolRules method checkForBrandingChanges.

private boolean checkForBrandingChanges(Pool pool, Pool existingPool) {
    boolean brandingChanged = false;
    if (pool.getBranding().size() != existingPool.getBranding().size()) {
        brandingChanged = true;
    } else {
        for (Branding b : pool.getBranding()) {
            if (!existingPool.getBranding().contains(b)) {
                syncBranding(pool, existingPool);
                brandingChanged = true;
                break;
            }
        }
    }
    if (brandingChanged) {
        syncBranding(pool, existingPool);
    }
    return brandingChanged;
}
Also used : Branding(org.candlepin.model.Branding)

Example 25 with Branding

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

the class PoolHelper method clonePool.

public static Pool clonePool(Pool sourcePool, Product product, String quantity, Map<String, String> attributes, String subKey, OwnerProductCurator curator, Entitlement sourceEntitlement, ProductCurator productCurator) {
    Pool pool = createPool(product, sourcePool.getOwner(), quantity, sourcePool.getStartDate(), sourcePool.getEndDate(), sourcePool.getContractNumber(), sourcePool.getAccountNumber(), sourcePool.getOrderNumber(), new HashSet<>(), sourceEntitlement, sourcePool.hasSharedAncestor());
    SourceSubscription srcSub = sourcePool.getSourceSubscription();
    if (srcSub != null && srcSub.getSubscriptionId() != null) {
        pool.setSourceSubscription(new SourceSubscription(srcSub.getSubscriptionId(), subKey));
    }
    copyProvidedProducts(sourcePool, pool, curator, productCurator);
    // Add in the new attributes
    for (Entry<String, String> entry : attributes.entrySet()) {
        pool.setAttribute(entry.getKey(), entry.getValue());
    }
    for (Branding brand : sourcePool.getBranding()) {
        pool.getBranding().add(new Branding(brand.getProductId(), brand.getType(), brand.getName()));
    }
    // Copy upstream fields
    // Impl note/TODO:
    // We are only doing this to facilitate marking pools derived from an upstream source/manifest
    // as also from that same upstream source. A proper pool hierarchy would be a better solution
    // here, but this will work for the interim.
    pool.setUpstreamPoolId(sourcePool.getUpstreamPoolId());
    pool.setUpstreamEntitlementId(sourcePool.getUpstreamEntitlementId());
    pool.setUpstreamConsumerId(sourcePool.getUpstreamConsumerId());
    return pool;
}
Also used : SourceSubscription(org.candlepin.model.SourceSubscription) Pool(org.candlepin.model.Pool) Branding(org.candlepin.model.Branding)

Aggregations

Branding (org.candlepin.model.Branding)26 Pool (org.candlepin.model.Pool)15 Product (org.candlepin.model.Product)14 HashSet (java.util.HashSet)9 Entitlement (org.candlepin.model.Entitlement)9 SourceSubscription (org.candlepin.model.SourceSubscription)8 Test (org.junit.Test)7 Owner (org.candlepin.model.Owner)6 Date (java.util.Date)5 Consumer (org.candlepin.model.Consumer)5 ProvidedProduct (org.candlepin.model.ProvidedProduct)5 SubscriptionsCertificate (org.candlepin.model.SubscriptionsCertificate)5 CertificateSerial (org.candlepin.model.CertificateSerial)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 SourceStack (org.candlepin.model.SourceStack)3 ProductData (org.candlepin.model.dto.ProductData)3 Subscription (org.candlepin.model.dto.Subscription)3 LinkedList (java.util.LinkedList)2 EntitlementDTO (org.candlepin.dto.manifest.v1.EntitlementDTO)2