use of org.candlepin.model.SubscriptionsCertificate in project candlepin by candlepin.
the class EntitlementImporter method importObject.
public Subscription importObject(ObjectMapper mapper, Reader reader, Owner owner, Map<String, ProductDTO> productsById, String consumerUuid, Meta meta) throws IOException, SyncDataFormatException {
EntitlementDTO entitlementDTO = mapper.readValue(reader, EntitlementDTO.class);
Entitlement entitlement = new Entitlement();
populateEntity(entitlement, entitlementDTO);
Subscription subscription = new Subscription();
log.debug("Building subscription for owner: {}", owner);
log.debug("Using pool from entitlement: {}", entitlement.getPool());
// Now that we no longer store Subscriptions in the on-site database, we need to
// manually give the subscription a downstream ID. Note that this may later be
// overwritten by reconciliation code if it determines this Subscription
// should replace and existing one.
subscription.setId(Util.generateDbUUID());
subscription.setUpstreamPoolId(entitlement.getPool().getId());
subscription.setUpstreamEntitlementId(entitlement.getId());
subscription.setUpstreamConsumerId(consumerUuid);
subscription.setOwner(owner);
subscription.setStartDate(entitlement.getStartDate());
subscription.setEndDate(entitlement.getEndDate());
subscription.setAccountNumber(entitlement.getPool().getAccountNumber());
subscription.setContractNumber(entitlement.getPool().getContractNumber());
subscription.setOrderNumber(entitlement.getPool().getOrderNumber());
subscription.setQuantity(entitlement.getQuantity().longValue());
for (Branding b : entitlement.getPool().getBranding()) {
subscription.getBranding().add(new Branding(b.getProductId(), b.getType(), b.getName()));
}
String cdnLabel = meta.getCdnLabel();
if (!StringUtils.isBlank(cdnLabel)) {
Cdn cdn = cdnCurator.lookupByLabel(cdnLabel);
if (cdn != null) {
subscription.setCdn(cdn);
}
}
ProductDTO productDTO = this.findProduct(productsById, entitlement.getPool().getProductId());
subscription.setProduct(this.translator.translate(productDTO, ProductData.class));
// Add any sub product data to the subscription.
if (entitlement.getPool().getDerivedProductId() != null) {
productDTO = this.findProduct(productsById, entitlement.getPool().getDerivedProductId());
subscription.setDerivedProduct(this.translator.translate(productDTO, ProductData.class));
}
associateProvidedProducts(productsById, entitlement, subscription);
Set<EntitlementCertificate> certs = entitlement.getCertificates();
// subscriptions have one cert
int entcnt = 0;
for (EntitlementCertificate cert : certs) {
++entcnt;
CertificateSerial cs = new CertificateSerial();
cs.setCollected(cert.getSerial().isCollected());
cs.setExpiration(cert.getSerial().getExpiration());
cs.setUpdated(cert.getSerial().getUpdated());
cs.setCreated(cert.getSerial().getCreated());
SubscriptionsCertificate sc = new SubscriptionsCertificate();
sc.setKey(cert.getKey());
sc.setCertAsBytes(cert.getCertAsBytes());
sc.setSerial(cs);
subscription.setCertificate(sc);
}
if (entcnt > 1) {
log.error("More than one entitlement cert found for subscription");
}
return subscription;
}
use of org.candlepin.model.SubscriptionsCertificate in project candlepin by candlepin.
the class PoolTranslator method populate.
/**
* {@inheritDoc}
*/
@Override
public PoolDTO populate(ModelTranslator modelTranslator, Pool source, PoolDTO dest) {
if (source == null) {
throw new IllegalArgumentException("source is null");
}
if (dest == null) {
throw new IllegalArgumentException("destination is null");
}
dest.setId(source.getId());
dest.setType(source.getType().toString());
dest.setActiveSubscription(source.getActiveSubscription());
dest.setCreatedByShare(source.isCreatedByShare());
dest.setHasSharedAncestor(source.hasSharedAncestor());
dest.setQuantity(source.getQuantity());
dest.setStartDate(source.getStartDate());
dest.setEndDate(source.getEndDate());
dest.setAttributes(source.getAttributes());
dest.setRestrictedToUsername(source.getRestrictedToUsername());
dest.setContractNumber(source.getContractNumber());
dest.setAccountNumber(source.getAccountNumber());
dest.setOrderNumber(source.getOrderNumber());
dest.setConsumed(source.getConsumed());
dest.setExported(source.getExported());
dest.setShared(source.getShared());
dest.setCalculatedAttributes(source.getCalculatedAttributes());
dest.setUpstreamPoolId(source.getUpstreamPoolId());
dest.setUpstreamEntitlementId(source.getUpstreamEntitlementId());
dest.setUpstreamConsumerId(source.getUpstreamConsumerId());
dest.setProductName(source.getProductName());
dest.setProductId(source.getProductId());
dest.setProductAttributes(source.getProductAttributes());
dest.setStackId(source.getStackId());
dest.setStacked(source.isStacked());
dest.setDevelopmentPool(source.isDevelopmentPool());
dest.setDerivedProductAttributes(source.getDerivedProductAttributes());
dest.setDerivedProductId(source.getDerivedProductId());
dest.setDerivedProductName(source.getDerivedProductName());
dest.setSourceStackId(source.getSourceStackId());
dest.setSubscriptionSubKey(source.getSubscriptionSubKey());
dest.setSubscriptionId(source.getSubscriptionId());
// Process nested objects if we have a model translator to use to the translation...
if (modelTranslator != null) {
Owner owner = source.getOwner();
dest.setOwner(owner != null ? modelTranslator.translate(owner, OwnerDTO.class) : null);
SubscriptionsCertificate subCertificate = source.getCertificate();
dest.setCertificate(subCertificate != null ? modelTranslator.translate(subCertificate, CertificateDTO.class) : null);
Entitlement sourceEntitlement = source.getSourceEntitlement();
dest.setSourceEntitlement(sourceEntitlement != null ? modelTranslator.translate(sourceEntitlement, EntitlementDTO.class) : null);
Set<Branding> branding = source.getBranding();
if (branding != null && !branding.isEmpty()) {
for (Branding brand : branding) {
if (brand != null) {
dest.addBranding(modelTranslator.translate(brand, BrandingDTO.class));
}
}
} else {
dest.setBranding(Collections.emptySet());
}
Set<Product> products = source.getProvidedProducts();
if (products != null && !products.isEmpty()) {
for (Product prod : products) {
if (prod != null) {
dest.addProvidedProduct(new PoolDTO.ProvidedProductDTO(prod.getId(), prod.getName()));
}
}
} else {
dest.setProvidedProducts(Collections.emptySet());
}
Set<Product> derivedProducts = source.getDerivedProvidedProducts();
if (derivedProducts != null && !derivedProducts.isEmpty()) {
for (Product derivedProd : derivedProducts) {
if (derivedProd != null) {
dest.addDerivedProvidedProduct(new PoolDTO.ProvidedProductDTO(derivedProd.getId(), derivedProd.getName()));
}
}
} else {
dest.setDerivedProvidedProducts(Collections.emptySet());
}
}
return dest;
}
use of org.candlepin.model.SubscriptionsCertificate in project candlepin by candlepin.
the class EntitlementResourceTest method getUpstreamCertSimple.
@Test
public void getUpstreamCertSimple() {
Entitlement e = TestUtil.createEntitlement();
e.setId("entitlementID");
SubscriptionsCertificate subcert = new SubscriptionsCertificate();
subcert.setCert("HELLO");
subcert.setKey("CERT");
e.getPool().setCertificate(subcert);
when(entitlementCurator.find(eq(e.getId()))).thenReturn(e);
String expected = "HELLOCERT";
String result = entResource.getUpstreamCert(e.getId());
assertEquals(expected, result);
}
Aggregations