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