use of org.candlepin.model.Product 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();
}
}
}
}
use of org.candlepin.model.Product in project candlepin by candlepin.
the class ResolverUtil method validateProductData.
public void validateProductData(ProductData dto, Owner owner, boolean allowNull) {
if (dto != null) {
if (dto.getUuid() != null) {
// UUID is set. Verify that product exists and matches the ID provided, if any
Product product = this.productCurator.find(dto.getUuid());
if (product == null) {
throw new NotFoundException(i18n.tr("Unable to find a product with the UUID \"{0}\"", dto.getUuid()));
}
dto.setId(product.getId());
} else if (dto.getId() != null) {
Product product = this.ownerProductCurator.getProductById(owner, dto.getId());
if (product == null) {
throw new NotFoundException(i18n.tr("Unable to find a product with the ID \"{0}\" for owner \"{1}\"", dto.getId(), owner.getKey()));
}
} else {
throw new BadRequestException(i18n.tr("No product specified, or product lacks identifying information"));
}
} else if (!allowNull) {
throw new BadRequestException(i18n.tr("No product specified, or product lacks identifying information"));
}
}
use of org.candlepin.model.Product 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.Product 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);
}
use of org.candlepin.model.Product in project candlepin by candlepin.
the class HandleCertificatesOp method preProcess.
/**
* create certificates without associating the entitlements and certs with each other.
* also, dont persist the certs.
* @param context
*/
@Override
public boolean preProcess(BindContext context) {
if (!context.getConsumerType().isType(ConsumerTypeEnum.SHARE)) {
List<String> poolIds = new LinkedList<>();
Map<String, Product> products = new HashMap<>();
Map<String, PoolQuantity> poolQuantities = context.getPoolQuantities();
for (PoolQuantity poolQuantity : poolQuantities.values()) {
Pool pool = poolQuantity.getPool();
products.put(pool.getId(), pool.getProduct());
poolIds.add(pool.getId());
}
certs = ecGenerator.generateEntitlementCertificates(context.getConsumer(), products, poolQuantities, context.getEntitlementMap(), false);
modifyingEnts = this.eCurator.getDependentEntitlementIdsForPools(context.getConsumer(), poolIds);
}
return true;
}
Aggregations