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