Search in sources :

Example 1 with ProductCertificate

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();
            }
        }
    }
}
Also used : Owner(org.candlepin.model.Owner) HashMap(java.util.HashMap) FileWriter(java.io.FileWriter) ProductCertificate(org.candlepin.model.ProductCertificate) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) File(java.io.File)

Example 2 with ProductCertificate

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());
}
Also used : Owner(org.candlepin.model.Owner) ProductCertificate(org.candlepin.model.ProductCertificate) Product(org.candlepin.model.Product) Test(org.junit.Test)

Example 3 with ProductCertificate

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);
}
Also used : ProductCertificate(org.candlepin.model.ProductCertificate) Test(org.junit.Test)

Example 4 with ProductCertificate

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;
}
Also used : ProductCertificate(org.candlepin.model.ProductCertificate)

Example 5 with ProductCertificate

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);
}
Also used : Owner(org.candlepin.model.Owner) ProductCertificate(org.candlepin.model.ProductCertificate) Product(org.candlepin.model.Product) ProductCertificateDTO(org.candlepin.dto.api.v1.ProductCertificateDTO) Test(org.junit.Test)

Aggregations

ProductCertificate (org.candlepin.model.ProductCertificate)12 Product (org.candlepin.model.Product)9 Owner (org.candlepin.model.Owner)8 Test (org.junit.Test)8 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 File (java.io.File)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 SecurityHole (org.candlepin.common.auth.SecurityHole)2 ProductCertificateDTO (org.candlepin.dto.api.v1.ProductCertificateDTO)2 Entitlement (org.candlepin.model.Entitlement)2 Pool (org.candlepin.model.Pool)2 Transactional (com.google.inject.persist.Transactional)1 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1 InputStream (java.io.InputStream)1 Key (java.security.Key)1 KeyPair (java.security.KeyPair)1