Search in sources :

Example 1 with ProvidedProduct

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

the class ResolverUtil method resolvePool.

public Pool resolvePool(Pool pool) {
    // doesn't (i.e. during creation). We just need to make sure it's not null.
    if (pool == null) {
        throw new BadRequestException(i18n.tr("No subscription specified"));
    }
    // Ensure the owner is set and is valid
    Owner owner = this.resolveOwner(pool.getOwner());
    pool.setOwner(owner);
    // Ensure the specified product(s) exists for the given owner
    pool.setProduct(this.resolveProduct(owner, pool.getProduct()));
    if (pool.getDerivedProduct() != null) {
        pool.setDerivedProduct(this.resolveProduct(owner, pool.getDerivedProduct()));
    }
    HashSet<Product> presolved = new HashSet<>();
    pool.populateAllTransientProvidedProducts(productCurator);
    for (ProvidedProduct product : pool.getProvidedProductDtos()) {
        // TODO: Maybe add UUID resolution as well?
        presolved.add(resolveProduct(owner, product.getProductId()));
    }
    pool.setProvidedProducts(presolved);
    presolved.clear();
    for (ProvidedProduct product : pool.getDerivedProvidedProductDtos()) {
        presolved.add(this.resolveProduct(owner, product.getProductId()));
    }
    pool.setDerivedProvidedProducts(presolved);
    return pool;
}
Also used : Owner(org.candlepin.model.Owner) BadRequestException(org.candlepin.common.exceptions.BadRequestException) ProvidedProduct(org.candlepin.model.ProvidedProduct) Product(org.candlepin.model.Product) ProvidedProduct(org.candlepin.model.ProvidedProduct) HashSet(java.util.HashSet)

Example 2 with ProvidedProduct

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

the class PoolTranslatorTest method initSourceObject.

@Override
protected Pool initSourceObject() {
    Pool source = new Pool();
    source.setId("pool-id");
    source.setOwner(this.ownerTranslatorTest.initSourceObject());
    source.setProduct(this.productTranslatorTest.initSourceObject());
    source.setDerivedProduct(this.productTranslatorTest.initSourceObject());
    Set<Branding> brandingSet = new HashSet<>();
    brandingSet.add(this.brandingTranslatorTest.initSourceObject());
    source.setBranding(brandingSet);
    Entitlement entitlement = new Entitlement();
    entitlement.setId("ent-id");
    source.setSourceEntitlement(entitlement);
    SubscriptionsCertificate subCert = new SubscriptionsCertificate();
    subCert.setId("cert-id");
    subCert.setKey("cert-key");
    subCert.setCert("cert-cert");
    subCert.setSerial(new CertificateSerial());
    source.setCertificate(subCert);
    SourceSubscription sourceSubscription = new SourceSubscription();
    sourceSubscription.setId("source-sub-id-1");
    sourceSubscription.setSubscriptionId("source-sub-subscription-id-1");
    sourceSubscription.setSubscriptionSubKey("source-sub-subscription-sub-key-1");
    source.setSourceSubscription(sourceSubscription);
    source.setActiveSubscription(true);
    source.setCreatedByShare(false);
    source.setHasSharedAncestor(true);
    source.setQuantity(1L);
    source.setStartDate(new Date());
    source.setEndDate(new Date());
    Map<String, String> attributes = new HashMap<>();
    attributes.put(Pool.Attributes.SOURCE_POOL_ID, "true");
    source.setAttributes(attributes);
    source.setRestrictedToUsername("restricted-to-username-value");
    source.setContractNumber("333");
    source.setAccountNumber("444");
    source.setOrderNumber("555");
    source.setConsumed(6L);
    source.setExported(7L);
    source.setShared(8L);
    Map<String, String> calculatedAttributes = new HashMap<>();
    calculatedAttributes.put("calc-attribute-key-3", "calc-attribute-value-3");
    calculatedAttributes.put("calc-attribute-key-4", "calc-attribute-value-4");
    source.setCalculatedAttributes(calculatedAttributes);
    source.setUpstreamPoolId("upstream-pool-id-2");
    source.setUpstreamEntitlementId("upstream-entitlement-id-2");
    source.setUpstreamConsumerId("upstream-consumer-id-2");
    source.setAttribute(Pool.Attributes.DEVELOPMENT_POOL, "true");
    Product derivedProduct = new Product();
    derivedProduct.setId("derived-product-id-2");
    derivedProduct.setName("derived-product-name-2");
    derivedProduct.setAttributes(new HashMap<>());
    derivedProduct.setAttribute(Product.Attributes.ARCHITECTURE, "POWER");
    derivedProduct.setAttribute(Product.Attributes.STACKING_ID, "2221");
    source.setDerivedProduct(derivedProduct);
    ProvidedProduct providedProd = new ProvidedProduct();
    providedProd.setProductId("provided-product-id-1");
    providedProd.setProductName("provided-product-name-1");
    Set<ProvidedProduct> providedProducts = new HashSet<>();
    providedProducts.add(providedProd);
    source.setProvidedProductDtos(providedProducts);
    ProvidedProduct derivedProvidedProd = new ProvidedProduct();
    derivedProvidedProd.setProductId("derived-provided-product-id-1");
    derivedProvidedProd.setProductName("derived-provided-product-name-1");
    Set<ProvidedProduct> derivedProvidedProducts = new HashSet<>();
    derivedProvidedProducts.add(derivedProvidedProd);
    source.setDerivedProvidedProductDtos(derivedProvidedProducts);
    Consumer sourceConsumer = new Consumer();
    sourceConsumer.setUuid("source-consumer-uuid");
    SourceStack sourceStack = new SourceStack();
    sourceStack.setSourceStackId("source-stack-source-stack-id-1");
    sourceStack.setId("source-stack-id-1");
    sourceStack.setSourceConsumer(sourceConsumer);
    source.setSourceStack(sourceStack);
    return source;
}
Also used : HashMap(java.util.HashMap) CertificateSerial(org.candlepin.model.CertificateSerial) ProvidedProduct(org.candlepin.model.ProvidedProduct) Product(org.candlepin.model.Product) Branding(org.candlepin.model.Branding) ProvidedProduct(org.candlepin.model.ProvidedProduct) Date(java.util.Date) SourceSubscription(org.candlepin.model.SourceSubscription) Consumer(org.candlepin.model.Consumer) SubscriptionsCertificate(org.candlepin.model.SubscriptionsCertificate) SourceStack(org.candlepin.model.SourceStack) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) HashSet(java.util.HashSet)

Example 3 with ProvidedProduct

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

the class PoolTranslatorTest method initSourceObject.

@Override
protected Pool initSourceObject() {
    Pool source = new Pool();
    source.setId("pool-id");
    source.setOwner(this.ownerTranslatorTest.initSourceObject());
    source.setProduct(this.productTranslatorTest.initSourceObject());
    source.setDerivedProduct(this.productTranslatorTest.initSourceObject());
    Set<Branding> brandingSet = new HashSet<>();
    brandingSet.add(this.brandingTranslatorTest.initSourceObject());
    source.setBranding(brandingSet);
    Entitlement entitlement = new Entitlement();
    entitlement.setId("ent-id");
    source.setSourceEntitlement(entitlement);
    SubscriptionsCertificate subCert = new SubscriptionsCertificate();
    subCert.setId("cert-id");
    subCert.setKey("cert-key");
    subCert.setCert("cert-cert");
    subCert.setSerial(new CertificateSerial());
    source.setCertificate(subCert);
    SourceSubscription sourceSubscription = new SourceSubscription();
    sourceSubscription.setId("source-sub-id-1");
    sourceSubscription.setSubscriptionId("source-sub-subscription-id-1");
    sourceSubscription.setSubscriptionSubKey("source-sub-subscription-sub-key-1");
    source.setSourceSubscription(sourceSubscription);
    source.setActiveSubscription(true);
    source.setCreatedByShare(false);
    source.setHasSharedAncestor(true);
    source.setQuantity(1L);
    source.setStartDate(new Date());
    source.setEndDate(new Date());
    Map<String, String> attributes = new HashMap<>();
    attributes.put(Pool.Attributes.SOURCE_POOL_ID, "true");
    source.setAttributes(attributes);
    source.setRestrictedToUsername("restricted-to-username-value");
    source.setContractNumber("333");
    source.setAccountNumber("444");
    source.setOrderNumber("555");
    source.setConsumed(6L);
    source.setExported(7L);
    source.setShared(8L);
    Map<String, String> calculatedAttributes = new HashMap<>();
    calculatedAttributes.put("calc-attribute-key-3", "calc-attribute-value-3");
    calculatedAttributes.put("calc-attribute-key-4", "calc-attribute-value-4");
    source.setCalculatedAttributes(calculatedAttributes);
    source.setUpstreamPoolId("upstream-pool-id-2");
    source.setUpstreamEntitlementId("upstream-entitlement-id-2");
    source.setUpstreamConsumerId("upstream-consumer-id-2");
    source.setAttribute(Pool.Attributes.DEVELOPMENT_POOL, "true");
    ProvidedProduct providedProd = new ProvidedProduct();
    providedProd.setProductId("provided-product-id-1");
    providedProd.setProductName("provided-product-name-1");
    Set<ProvidedProduct> providedProducts = new HashSet<>();
    providedProducts.add(providedProd);
    source.setProvidedProductDtos(providedProducts);
    ProvidedProduct derivedProvidedProd = new ProvidedProduct();
    derivedProvidedProd.setProductId("derived-provided-product-id-1");
    derivedProvidedProd.setProductName("derived-provided-product-name-1");
    Set<ProvidedProduct> derivedProvidedProducts = new HashSet<>();
    derivedProvidedProducts.add(derivedProvidedProd);
    source.setDerivedProvidedProductDtos(derivedProvidedProducts);
    Consumer sourceConsumer = new Consumer();
    sourceConsumer.setUuid("source-consumer-uuid");
    SourceStack sourceStack = new SourceStack();
    sourceStack.setSourceStackId("source-stack-source-stack-id-1");
    sourceStack.setId("source-stack-id-1");
    sourceStack.setSourceConsumer(sourceConsumer);
    source.setSourceStack(sourceStack);
    return source;
}
Also used : HashMap(java.util.HashMap) CertificateSerial(org.candlepin.model.CertificateSerial) Branding(org.candlepin.model.Branding) ProvidedProduct(org.candlepin.model.ProvidedProduct) Date(java.util.Date) SourceSubscription(org.candlepin.model.SourceSubscription) Consumer(org.candlepin.model.Consumer) SubscriptionsCertificate(org.candlepin.model.SubscriptionsCertificate) SourceStack(org.candlepin.model.SourceStack) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) HashSet(java.util.HashSet)

Example 4 with ProvidedProduct

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

the class PoolTranslatorTest method initSourceObject.

@Override
protected Pool initSourceObject() {
    Pool source = new Pool();
    source.setId("pool-id");
    source.setHasSharedAncestor(true);
    source.setQuantity(1L);
    source.setStartDate(new Date());
    source.setEndDate(new Date());
    Map<String, String> attributes = new HashMap<>();
    attributes.put(Pool.Attributes.SOURCE_POOL_ID, "true");
    source.setAttributes(attributes);
    source.setRestrictedToUsername("restricted-to-username-value");
    source.setConsumed(6L);
    source.setAttribute(Pool.Attributes.DEVELOPMENT_POOL, "true");
    Product derivedProduct = new Product();
    derivedProduct.setId("derived-product-id-2");
    derivedProduct.setName("derived-product-name-2");
    derivedProduct.setAttributes(new HashMap<>());
    derivedProduct.setAttribute(Product.Attributes.ARCHITECTURE, "POWER");
    derivedProduct.setAttribute(Product.Attributes.STACKING_ID, "2221");
    source.setDerivedProduct(derivedProduct);
    ProvidedProduct providedProd = new ProvidedProduct();
    providedProd.setProductId("provided-product-id-1");
    providedProd.setProductName("provided-product-name-1");
    Set<ProvidedProduct> providedProducts = new HashSet<>();
    providedProducts.add(providedProd);
    source.setProvidedProductDtos(providedProducts);
    ProvidedProduct derivedProvidedProd = new ProvidedProduct();
    derivedProvidedProd.setProductId("derived-provided-product-id-1");
    derivedProvidedProd.setProductName("derived-provided-product-name-1");
    Set<ProvidedProduct> derivedProvidedProducts = new HashSet<>();
    derivedProvidedProducts.add(derivedProvidedProd);
    source.setDerivedProvidedProductDtos(derivedProvidedProducts);
    return source;
}
Also used : HashMap(java.util.HashMap) ProvidedProduct(org.candlepin.model.ProvidedProduct) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) ProvidedProduct(org.candlepin.model.ProvidedProduct) Date(java.util.Date) HashSet(java.util.HashSet)

Example 5 with ProvidedProduct

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

the class EntitlementImporter method associateProvidedProducts.

/*
     * Transfer associations to provided and derived provided products over to the
     * subscription.
     *
     * WARNING: This is a bit tricky due to backward compatibility issues. Prior to
     * candlepin 2.0, pools serialized a collection of disjoint provided product info,
     * an object with just a product ID and name, not directly linked to anything in the db.
     *
     * In candlepin 2.0 we have referential integrity and links to full product objects,
     * but we need to maintain both API and import compatibility with old manifests and
     * servers that may import new manifests.
     *
     * To do this, we serialize the providedProductDtos and derivedProvidedProductDtos
     * collections on pool which keeps the API/manifest JSON identical to what it was
     * before. On import we load into these transient collections, and here we transfer
     * to the actual persisted location.
     */
public void associateProvidedProducts(Map<String, ProductDTO> productsById, Entitlement entitlement, Subscription subscription) throws SyncDataFormatException {
    // Associate main provided products:
    Set<ProductData> providedProducts = new HashSet<>();
    entitlement.getPool().populateAllTransientProvidedProducts(productCurator);
    for (ProvidedProduct providedProduct : entitlement.getPool().getProvidedProductDtos()) {
        ProductDTO productDTO = this.findProduct(productsById, providedProduct.getProductId());
        providedProducts.add(this.translator.translate(productDTO, ProductData.class));
    }
    subscription.setProvidedProducts(providedProducts);
    // Associate derived provided products:
    Set<ProductData> derivedProvidedProducts = new HashSet<>();
    for (ProvidedProduct pp : entitlement.getPool().getDerivedProvidedProductDtos()) {
        ProductDTO productDTO = this.findProduct(productsById, pp.getProductId());
        derivedProvidedProducts.add(this.translator.translate(productDTO, ProductData.class));
    }
    subscription.setDerivedProvidedProducts(derivedProvidedProducts);
    log.debug("Subscription has {} provided products.", derivedProvidedProducts.size());
    log.debug("Subscription has {} derived provided products.", derivedProvidedProducts.size());
}
Also used : ProductData(org.candlepin.model.dto.ProductData) ProvidedProduct(org.candlepin.model.ProvidedProduct) ProductDTO(org.candlepin.dto.manifest.v1.ProductDTO) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)6 ProvidedProduct (org.candlepin.model.ProvidedProduct)6 Pool (org.candlepin.model.Pool)4 Date (java.util.Date)3 HashMap (java.util.HashMap)3 Branding (org.candlepin.model.Branding)3 CertificateSerial (org.candlepin.model.CertificateSerial)3 Product (org.candlepin.model.Product)3 SourceStack (org.candlepin.model.SourceStack)3 Consumer (org.candlepin.model.Consumer)2 Entitlement (org.candlepin.model.Entitlement)2 Owner (org.candlepin.model.Owner)2 SourceSubscription (org.candlepin.model.SourceSubscription)2 SubscriptionsCertificate (org.candlepin.model.SubscriptionsCertificate)2 BadRequestException (org.candlepin.common.exceptions.BadRequestException)1 BrandingDTO (org.candlepin.dto.manifest.v1.BrandingDTO)1 CertificateDTO (org.candlepin.dto.manifest.v1.CertificateDTO)1 CertificateSerialDTO (org.candlepin.dto.manifest.v1.CertificateSerialDTO)1 EntitlementDTO (org.candlepin.dto.manifest.v1.EntitlementDTO)1 PoolDTO (org.candlepin.dto.manifest.v1.PoolDTO)1