use of org.candlepin.model.ProductCertificate 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.ProductCertificate in project candlepin by candlepin.
the class ProductCertCreationTest method validProduct.
@Test
public void validProduct() {
Owner owner = TestUtil.createOwner("Example-Corporation");
Product product = this.createProduct("50", "Test Product", "Standard", "1", "x86_64", "Base");
ProductCertificate cert = this.createCert(owner, product);
Assert.assertEquals(product, cert.getProduct());
}
use of org.candlepin.model.ProductCertificate in project candlepin by candlepin.
the class ProductCertCreationTest method hasKey.
@Test
public void hasKey() {
ProductCertificate cert = createDummyCert();
Assert.assertTrue(cert.getKey().length() > 0);
}
use of org.candlepin.model.ProductCertificate in project candlepin by candlepin.
the class ProductCertificateTranslatorTest method initSourceObject.
@Override
protected ProductCertificate initSourceObject() {
ProductCertificate cert = new ProductCertificate();
cert.setId("123");
cert.setKey("cert_key");
cert.setCert("cert_cert");
cert.setProduct(this.productTranslatorTest.initSourceObject());
return cert;
}
use of org.candlepin.model.ProductCertificate in project candlepin by candlepin.
the class OwnerProductResourceTest method getProductCertificate.
@Test
public void getProductCertificate() {
Owner owner = this.createOwner("Example-Corporation");
Product entity = this.createProduct("123", "AwesomeOS Core", owner);
// ensure we check SecurityHole
securityInterceptor.enable();
ProductCertificate cert = new ProductCertificate();
cert.setCert("some text");
cert.setKey("some key");
cert.setProduct(entity);
productCertificateCurator.create(cert);
ProductCertificateDTO cert1 = ownerProductResource.getProductCertificate(owner.getKey(), entity.getId());
ProductCertificateDTO expected = this.modelTranslator.translate(cert, ProductCertificateDTO.class);
assertEquals(cert1, expected);
}
Aggregations