Search in sources :

Example 26 with EntitlementCertificate

use of org.candlepin.model.EntitlementCertificate in project candlepin by candlepin.

the class DefaultEntitlementCertServiceAdapter method generateEntitlementCert.

// NOTE: we use entitlement here, but it version does not...
// NOTE: we can get consumer from entitlement.getConsumer()
@Override
public EntitlementCertificate generateEntitlementCert(Entitlement entitlement, Product product) throws GeneralSecurityException, IOException {
    Map<String, Entitlement> entitlements = new HashMap<>();
    entitlements.put(entitlement.getPool().getId(), entitlement);
    Map<String, PoolQuantity> poolQuantities = new HashMap<>();
    poolQuantities.put(entitlement.getPool().getId(), new PoolQuantity(entitlement.getPool(), entitlement.getQuantity()));
    Map<String, Product> products = new HashMap<>();
    products.put(entitlement.getPool().getId(), product);
    Map<String, EntitlementCertificate> result = generateEntitlementCerts(entitlement.getConsumer(), poolQuantities, entitlements, products, true);
    return result.get(entitlement.getPool().getId());
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) HashMap(java.util.HashMap) Product(org.candlepin.model.Product) Entitlement(org.candlepin.model.Entitlement)

Example 27 with EntitlementCertificate

use of org.candlepin.model.EntitlementCertificate in project candlepin by candlepin.

the class Exporter method exportEntitlementsCerts.

private void exportEntitlementsCerts(File baseDir, Consumer consumer, Set<Long> serials, boolean manifest) throws IOException {
    File entCertDir = new File(baseDir.getCanonicalPath(), "entitlement_certificates");
    entCertDir.mkdir();
    for (EntitlementCertificate cert : entCertAdapter.listForConsumer(consumer)) {
        if (manifest && !this.exportRules.canExport(cert.getEntitlement())) {
            if (log.isDebugEnabled()) {
                log.debug("Skipping export of entitlement cert with product: {}", cert.getEntitlement().getPool().getProductId());
            }
            continue;
        }
        if ((serials == null) || (serials.contains(cert.getSerial().getId()))) {
            log.debug("Exporting entitlement certificate: " + cert.getSerial());
            File file = new File(entCertDir.getCanonicalPath(), cert.getSerial().getId() + ".pem");
            FileWriter writer = null;
            try {
                writer = new FileWriter(file);
                entCert.export(writer, cert);
            } finally {
                if (writer != null) {
                    writer.close();
                }
            }
        }
    }
}
Also used : EntitlementCertificate(org.candlepin.model.EntitlementCertificate) FileWriter(java.io.FileWriter) File(java.io.File)

Example 28 with EntitlementCertificate

use of org.candlepin.model.EntitlementCertificate in project candlepin by candlepin.

the class EntitlementTranslator method populate.

/**
 * {@inheritDoc}
 */
@Override
public EntitlementDTO populate(ModelTranslator modelTranslator, Entitlement source, EntitlementDTO dest) {
    dest = super.populate(modelTranslator, source, dest);
    dest.setId(source.getId());
    dest.setQuantity(source.getQuantity());
    dest.setDeletedFromPool(source.deletedFromPool());
    dest.setStartDate(source.getStartDate());
    dest.setEndDate(source.getEndDate());
    if (modelTranslator != null) {
        Owner owner = source.getOwner();
        dest.setOwner(owner != null ? modelTranslator.translate(owner, OwnerDTO.class) : null);
        Pool pool = source.getPool();
        dest.setPool(pool != null ? modelTranslator.translate(pool, PoolDTO.class) : null);
        Consumer consumer = source.getConsumer();
        dest.setConsumer(consumer != null ? modelTranslator.translate(consumer, ConsumerDTO.class) : null);
        Set<EntitlementCertificate> certs = source.getCertificates();
        if (certs != null && !certs.isEmpty()) {
            for (Certificate cert : certs) {
                if (cert != null) {
                    dest.addCertificate(modelTranslator.translate(cert, CertificateDTO.class));
                }
            }
        } else {
            dest.setCertificates(Collections.<CertificateDTO>emptySet());
        }
    }
    return dest;
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) Pool(org.candlepin.model.Pool) Certificate(org.candlepin.model.Certificate) EntitlementCertificate(org.candlepin.model.EntitlementCertificate)

Example 29 with EntitlementCertificate

use of org.candlepin.model.EntitlementCertificate in project candlepin by candlepin.

the class QuantityRulesTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    // Load the default production rules:
    InputStream is = this.getClass().getResourceAsStream(RulesCurator.DEFAULT_RULES_FILE);
    Rules rules = new Rules(Util.readFile(is));
    when(rulesCuratorMock.getUpdated()).thenReturn(new Date());
    when(rulesCuratorMock.getRules()).thenReturn(rules);
    when(cacheProvider.get()).thenReturn(cache);
    provider = new JsRunnerProvider(rulesCuratorMock, cacheProvider);
    translator = new StandardTranslator(consumerTypeCurator, environmentCurator, ownerCuratorMock);
    quantityRules = new QuantityRules(provider.get(), new RulesObjectMapper(new ProductCachedSerializationModule(productCurator)), translator);
    owner = new Owner("Test Owner " + TestUtil.randomInt());
    product = TestUtil.createProduct();
    pool = TestUtil.createPool(owner, product);
    pool.setId("fakepoolid");
    ctype = TestUtil.createConsumerType();
    consumer = TestUtil.createConsumer(owner);
    when(consumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
    when(consumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(ctype);
    Entitlement e = TestUtil.createEntitlement(owner, consumer, pool, new EntitlementCertificate());
    Set<Entitlement> entSet = new HashSet<>();
    entSet.add(e);
    pool.setEntitlements(entSet);
    pool.getProduct().setAttribute(Pool.Attributes.MULTI_ENTITLEMENT, "yes");
    pool.getProduct().setAttribute(Product.Attributes.STACKING_ID, "1");
}
Also used : Owner(org.candlepin.model.Owner) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) InputStream(java.io.InputStream) RulesObjectMapper(org.candlepin.policy.js.RulesObjectMapper) Rules(org.candlepin.model.Rules) StandardTranslator(org.candlepin.dto.StandardTranslator) Date(java.util.Date) ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) JsRunnerProvider(org.candlepin.policy.js.JsRunnerProvider) Entitlement(org.candlepin.model.Entitlement) HashSet(java.util.HashSet) Before(org.junit.Before)

Aggregations

EntitlementCertificate (org.candlepin.model.EntitlementCertificate)29 Entitlement (org.candlepin.model.Entitlement)15 Consumer (org.candlepin.model.Consumer)14 CertificateSerial (org.candlepin.model.CertificateSerial)11 Date (java.util.Date)10 HashSet (java.util.HashSet)10 Test (org.junit.Test)10 HashMap (java.util.HashMap)9 Owner (org.candlepin.model.Owner)8 Pool (org.candlepin.model.Pool)8 Product (org.candlepin.model.Product)7 Map (java.util.Map)5 Event (org.candlepin.audit.Event)4 Certificate (org.candlepin.model.Certificate)3 PoolQuantity (org.candlepin.model.PoolQuantity)3 KeyPair (java.security.KeyPair)2 X509Certificate (java.security.cert.X509Certificate)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 CertificateDTO (org.candlepin.dto.api.v1.CertificateDTO)2