use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class TestUtil method createEntitlement.
public static Entitlement createEntitlement(Owner owner, Consumer consumer, Pool pool, EntitlementCertificate cert) {
Entitlement toReturn = new Entitlement();
toReturn.setId(Util.generateDbUUID());
toReturn.setOwner(owner);
toReturn.setPool(pool);
consumer.addEntitlement(toReturn);
if (cert != null) {
cert.setEntitlement(toReturn);
toReturn.getCertificates().add(cert);
}
return toReturn;
}
use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class PoolTranslator method populate.
/**
* {@inheritDoc}
*/
@Override
@SuppressWarnings("checkstyle:methodlength")
public PoolDTO populate(ModelTranslator modelTranslator, Pool source, PoolDTO dest) {
dest = super.populate(modelTranslator, source, dest);
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.<BrandingDTO>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.<PoolDTO.ProvidedProductDTO>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.<PoolDTO.ProvidedProductDTO>emptySet());
}
}
return dest;
}
use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class PoolTranslatorTest method initSourceObject.
@Override
protected Pool initSourceObject() {
Pool source = new Pool();
source.setId("pool-id");
source.setOwner(this.ownerTranslatorTest.initSourceObject());
source.setProduct(this.productTranslatorTest.initSourceObject());
source.setDerivedProduct(this.productTranslatorTest.initSourceObject());
Set<Branding> brandingSet = new HashSet<>();
brandingSet.add(this.brandingTranslatorTest.initSourceObject());
source.setBranding(brandingSet);
Entitlement entitlement = new Entitlement();
entitlement.setId("ent-id");
source.setSourceEntitlement(entitlement);
SubscriptionsCertificate subCert = new SubscriptionsCertificate();
subCert.setId("cert-id");
subCert.setKey("cert-key");
subCert.setCert("cert-cert");
subCert.setSerial(new CertificateSerial());
source.setCertificate(subCert);
SourceSubscription sourceSubscription = new SourceSubscription();
sourceSubscription.setId("source-sub-id-1");
sourceSubscription.setSubscriptionId("source-sub-subscription-id-1");
sourceSubscription.setSubscriptionSubKey("source-sub-subscription-sub-key-1");
source.setSourceSubscription(sourceSubscription);
source.setActiveSubscription(true);
source.setCreatedByShare(false);
source.setHasSharedAncestor(true);
source.setQuantity(1L);
source.setStartDate(new Date());
source.setEndDate(new Date());
Map<String, String> attributes = new HashMap<>();
attributes.put(Pool.Attributes.SOURCE_POOL_ID, "true");
source.setAttributes(attributes);
source.setRestrictedToUsername("restricted-to-username-value");
source.setContractNumber("333");
source.setAccountNumber("444");
source.setOrderNumber("555");
source.setConsumed(6L);
source.setExported(7L);
source.setShared(8L);
Map<String, String> calculatedAttributes = new HashMap<>();
calculatedAttributes.put("calc-attribute-key-3", "calc-attribute-value-3");
calculatedAttributes.put("calc-attribute-key-4", "calc-attribute-value-4");
source.setCalculatedAttributes(calculatedAttributes);
source.setUpstreamPoolId("upstream-pool-id-2");
source.setUpstreamEntitlementId("upstream-entitlement-id-2");
source.setUpstreamConsumerId("upstream-consumer-id-2");
source.setAttribute(Pool.Attributes.DEVELOPMENT_POOL, "true");
Product derivedProduct = new Product();
derivedProduct.setId("derived-product-id-2");
derivedProduct.setName("derived-product-name-2");
derivedProduct.setAttributes(new HashMap<>());
derivedProduct.setAttribute(Product.Attributes.ARCHITECTURE, "POWER");
derivedProduct.setAttribute(Product.Attributes.STACKING_ID, "2221");
source.setDerivedProduct(derivedProduct);
ProvidedProduct providedProd = new ProvidedProduct();
providedProd.setProductId("provided-product-id-1");
providedProd.setProductName("provided-product-name-1");
Set<ProvidedProduct> providedProducts = new HashSet<>();
providedProducts.add(providedProd);
source.setProvidedProductDtos(providedProducts);
ProvidedProduct derivedProvidedProd = new ProvidedProduct();
derivedProvidedProd.setProductId("derived-provided-product-id-1");
derivedProvidedProd.setProductName("derived-provided-product-name-1");
Set<ProvidedProduct> derivedProvidedProducts = new HashSet<>();
derivedProvidedProducts.add(derivedProvidedProd);
source.setDerivedProvidedProductDtos(derivedProvidedProducts);
Consumer sourceConsumer = new Consumer();
sourceConsumer.setUuid("source-consumer-uuid");
SourceStack sourceStack = new SourceStack();
sourceStack.setSourceStackId("source-stack-source-stack-id-1");
sourceStack.setId("source-stack-id-1");
sourceStack.setSourceConsumer(sourceConsumer);
source.setSourceStack(sourceStack);
return source;
}
use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class PoolTranslatorTest method initSourceObject.
@Override
protected Pool initSourceObject() {
Pool source = new Pool();
source.setId("pool-id");
source.setOwner(this.ownerTranslatorTest.initSourceObject());
source.setProduct(this.productTranslatorTest.initSourceObject());
source.setDerivedProduct(this.productTranslatorTest.initSourceObject());
Set<Branding> brandingSet = new HashSet<>();
brandingSet.add(this.brandingTranslatorTest.initSourceObject());
source.setBranding(brandingSet);
Entitlement entitlement = new Entitlement();
entitlement.setId("ent-id");
source.setSourceEntitlement(entitlement);
SubscriptionsCertificate subCert = new SubscriptionsCertificate();
subCert.setId("cert-id");
subCert.setKey("cert-key");
subCert.setCert("cert-cert");
subCert.setSerial(new CertificateSerial());
source.setCertificate(subCert);
SourceSubscription sourceSubscription = new SourceSubscription();
sourceSubscription.setId("source-sub-id-1");
sourceSubscription.setSubscriptionId("source-sub-subscription-id-1");
sourceSubscription.setSubscriptionSubKey("source-sub-subscription-sub-key-1");
source.setSourceSubscription(sourceSubscription);
source.setActiveSubscription(true);
source.setCreatedByShare(false);
source.setHasSharedAncestor(true);
source.setQuantity(1L);
source.setStartDate(new Date());
source.setEndDate(new Date());
Map<String, String> attributes = new HashMap<>();
attributes.put(Pool.Attributes.SOURCE_POOL_ID, "true");
source.setAttributes(attributes);
source.setRestrictedToUsername("restricted-to-username-value");
source.setContractNumber("333");
source.setAccountNumber("444");
source.setOrderNumber("555");
source.setConsumed(6L);
source.setExported(7L);
source.setShared(8L);
Map<String, String> calculatedAttributes = new HashMap<>();
calculatedAttributes.put("calc-attribute-key-3", "calc-attribute-value-3");
calculatedAttributes.put("calc-attribute-key-4", "calc-attribute-value-4");
source.setCalculatedAttributes(calculatedAttributes);
source.setUpstreamPoolId("upstream-pool-id-2");
source.setUpstreamEntitlementId("upstream-entitlement-id-2");
source.setUpstreamConsumerId("upstream-consumer-id-2");
source.setAttribute(Pool.Attributes.DEVELOPMENT_POOL, "true");
ProvidedProduct providedProd = new ProvidedProduct();
providedProd.setProductId("provided-product-id-1");
providedProd.setProductName("provided-product-name-1");
Set<ProvidedProduct> providedProducts = new HashSet<>();
providedProducts.add(providedProd);
source.setProvidedProductDtos(providedProducts);
ProvidedProduct derivedProvidedProd = new ProvidedProduct();
derivedProvidedProd.setProductId("derived-provided-product-id-1");
derivedProvidedProd.setProductName("derived-provided-product-name-1");
Set<ProvidedProduct> derivedProvidedProducts = new HashSet<>();
derivedProvidedProducts.add(derivedProvidedProd);
source.setDerivedProvidedProductDtos(derivedProvidedProducts);
Consumer sourceConsumer = new Consumer();
sourceConsumer.setUuid("source-consumer-uuid");
SourceStack sourceStack = new SourceStack();
sourceStack.setSourceStackId("source-stack-source-stack-id-1");
sourceStack.setId("source-stack-id-1");
sourceStack.setSourceConsumer(sourceConsumer);
source.setSourceStack(sourceStack);
return source;
}
use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class PoolTranslatorTest method verifyOutput.
@Override
protected void verifyOutput(Pool source, PoolDTO dest, boolean childrenGenerated) {
if (source != null) {
assertEquals(source.getId(), dest.getId());
assertEquals(source.getType().toString(), dest.getType());
assertEquals(source.getActiveSubscription(), dest.isActiveSubscription());
assertEquals(source.isCreatedByShare(), dest.isCreatedByShare());
assertEquals(source.hasSharedAncestor(), dest.hasSharedAncestor());
assertEquals(source.getQuantity(), dest.getQuantity());
assertEquals(source.getStartDate(), dest.getStartDate());
assertEquals(source.getEndDate(), dest.getEndDate());
assertEquals(source.getAttributes(), dest.getAttributes());
assertEquals(source.getRestrictedToUsername(), dest.getRestrictedToUsername());
assertEquals(source.getContractNumber(), dest.getContractNumber());
assertEquals(source.getAccountNumber(), dest.getAccountNumber());
assertEquals(source.getOrderNumber(), dest.getOrderNumber());
assertEquals(source.getConsumed(), dest.getConsumed());
assertEquals(source.getExported(), dest.getExported());
assertEquals(source.getShared(), dest.getShared());
assertEquals(source.getCalculatedAttributes(), dest.getCalculatedAttributes());
assertEquals(source.getUpstreamPoolId(), dest.getUpstreamPoolId());
assertEquals(source.getUpstreamEntitlementId(), dest.getUpstreamEntitlementId());
assertEquals(source.getUpstreamConsumerId(), dest.getUpstreamConsumerId());
assertEquals(source.getProductName(), dest.getProductName());
assertEquals(source.getProductId(), dest.getProductId());
assertEquals(source.getProductAttributes(), dest.getProductAttributes());
assertEquals(source.getStackId(), dest.getStackId());
assertEquals(source.isStacked(), dest.isStacked());
assertEquals(source.isDevelopmentPool(), dest.isDevelopmentPool());
assertEquals(source.getDerivedProductAttributes(), dest.getDerivedProductAttributes());
assertEquals(source.getDerivedProductId(), dest.getDerivedProductId());
assertEquals(source.getDerivedProductName(), dest.getDerivedProductName());
assertEquals(source.getSourceStackId(), dest.getSourceStackId());
assertEquals(source.getSubscriptionSubKey(), dest.getSubscriptionSubKey());
assertEquals(source.getSubscriptionId(), dest.getSubscriptionId());
if (childrenGenerated) {
this.ownerTranslatorTest.verifyOutput(source.getOwner(), dest.getOwner(), true);
this.certificateTranslatorTest.verifyOutput(source.getCertificate(), dest.getCertificate(), true);
Entitlement sourceSourceEntitlement = source.getSourceEntitlement();
EntitlementDTO destSourceEntitlement = dest.getSourceEntitlement();
if (sourceSourceEntitlement != null) {
assertEquals(sourceSourceEntitlement.getId(), destSourceEntitlement.getId());
} else {
assertNull(destSourceEntitlement);
}
for (Branding brandingSource : source.getBranding()) {
for (BrandingDTO brandingDTO : dest.getBranding()) {
assertNotNull(brandingDTO);
assertNotNull(brandingDTO.getProductId());
if (brandingDTO.getProductId().equals(brandingSource.getProductId())) {
this.brandingTranslatorTest.verifyOutput(brandingSource, brandingDTO, true);
}
}
}
Set<Product> sourceProducts = source.getProvidedProducts();
Set<PoolDTO.ProvidedProductDTO> productsDTO = dest.getProvidedProducts();
verifyProductsOutput(sourceProducts, productsDTO);
Set<Product> sourceDerivedProducts = source.getDerivedProvidedProducts();
Set<PoolDTO.ProvidedProductDTO> derivedProductsDTO = dest.getDerivedProvidedProducts();
verifyProductsOutput(sourceDerivedProducts, derivedProductsDTO);
} else {
assertNull(dest.getOwner());
assertNull(dest.getSourceEntitlement());
assertNull(dest.getBranding());
assertNull(dest.getProvidedProducts());
assertNull(dest.getDerivedProvidedProducts());
assertNull(dest.getCertificate());
}
} else {
assertNull(dest);
}
}
Aggregations