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;
}
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;
}
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;
}
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;
}
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());
}
Aggregations