use of org.candlepin.model.Branding in project candlepin by candlepin.
the class OwnerResource method populateEntity.
/**
* Populates an entity that is to be created with data from the provided DTO.
*
* @param entity
* The entity instance to populate
*
* @param dto
* The DTO containing the data with which to populate the entity
*
* @throws IllegalArgumentException
* if either entity or dto are null
*/
@SuppressWarnings("checkstyle:methodlength")
protected void populateEntity(Pool entity, PoolDTO dto) {
if (entity == null) {
throw new IllegalArgumentException("entity is null");
}
if (dto == null) {
throw new IllegalArgumentException("dto is null");
}
if (dto.getId() != null) {
entity.setId(dto.getId());
}
if (dto.getStartDate() != null) {
entity.setStartDate(dto.getStartDate());
}
if (dto.getEndDate() != null) {
entity.setEndDate(dto.getEndDate());
}
if (dto.getQuantity() != null) {
entity.setQuantity(dto.getQuantity());
}
if (dto.getAttributes() != null) {
if (dto.getAttributes().isEmpty()) {
entity.setAttributes(Collections.emptyMap());
} else {
entity.setAttributes(dto.getAttributes());
}
}
if (dto.getProvidedProducts() != null) {
if (dto.getProvidedProducts().isEmpty()) {
entity.setProvidedProducts(Collections.emptySet());
} else {
Set<Product> products = new HashSet<>();
for (PoolDTO.ProvidedProductDTO providedProductDTO : dto.getProvidedProducts()) {
if (providedProductDTO != null) {
Product newProd = findProduct(entity.getOwner(), providedProductDTO.getProductId());
products.add(newProd);
}
}
entity.setProvidedProducts(products);
}
}
if (dto.getDerivedProvidedProducts() != null) {
if (dto.getDerivedProvidedProducts().isEmpty()) {
entity.setDerivedProvidedProducts(Collections.emptySet());
} else {
Set<Product> derivedProducts = new HashSet<>();
for (PoolDTO.ProvidedProductDTO derivedProvidedProductDTO : dto.getDerivedProvidedProducts()) {
if (derivedProvidedProductDTO != null) {
Product newDerivedProd = findProduct(entity.getOwner(), derivedProvidedProductDTO.getProductId());
derivedProducts.add(newDerivedProd);
}
}
entity.setDerivedProvidedProducts(derivedProducts);
}
}
if (dto.getBranding() != null) {
if (dto.getBranding().isEmpty()) {
entity.setBranding(Collections.emptySet());
} else {
Set<Branding> branding = new HashSet<>();
for (BrandingDTO brandingDTO : dto.getBranding()) {
if (brandingDTO != null) {
branding.add(new Branding(brandingDTO.getProductId(), brandingDTO.getType(), brandingDTO.getName()));
}
}
entity.setBranding(branding);
}
}
}
use of org.candlepin.model.Branding in project candlepin by candlepin.
the class CandlepinPoolManager method convertToMasterPoolImpl.
/**
* Builds a pool instance from the given subscription, using the specified owner and products
* for resolution.
* <p></p>
* The provided owner and products will be used to match and resolve the owner and product
* DTOs present on the subscription. If the subscription uses DTOs which cannot be resolved,
* this method will throw an exception.
*
* @param sub
* The subscription to convert to a pool
*
* @param owner
* The owner the pool will be assigned to
*/
private Pool convertToMasterPoolImpl(Subscription sub, Owner owner, Map<String, Product> productMap) {
if (sub == null) {
throw new IllegalArgumentException("subscription is null");
}
if (owner == null || (owner.getKey() == null && owner.getId() == null)) {
throw new IllegalArgumentException("owner is null or incomplete");
}
if (productMap == null) {
throw new IllegalArgumentException("productMap is null");
}
Pool pool = new Pool();
// Validate and resolve owner...
if (sub.getOwner() == null || (sub.getOwner().getId() != null ? !owner.getId().equals(sub.getOwner().getId()) : !owner.getKey().equals(sub.getOwner().getKey()))) {
throw new IllegalStateException("Subscription references an invalid owner: " + sub.getOwner());
}
pool.setOwner(owner);
pool.setQuantity(sub.getQuantity());
pool.setStartDate(sub.getStartDate());
pool.setEndDate(sub.getEndDate());
pool.setContractNumber(sub.getContractNumber());
pool.setAccountNumber(sub.getAccountNumber());
pool.setOrderNumber(sub.getOrderNumber());
// Copy over subscription details
pool.setSourceSubscription(new SourceSubscription(sub.getId(), "master"));
// Copy over upstream details
pool.setUpstreamPoolId(sub.getUpstreamPoolId());
pool.setUpstreamEntitlementId(sub.getUpstreamEntitlementId());
pool.setUpstreamConsumerId(sub.getUpstreamConsumerId());
pool.setCdn(sub.getCdn());
pool.setCertificate(sub.getCertificate());
// Add in branding
if (sub.getBranding() != null) {
Set<Branding> branding = new HashSet<>();
for (Branding brand : sub.getBranding()) {
// Impl note:
// We create a new instance here since we don't have a separate branding DTO (yet),
// and we need to be certain that we don't try to move or change a branding object
// associated with another pool.
branding.add(new Branding(brand.getProductId(), brand.getType(), brand.getName()));
}
pool.setBranding(branding);
}
if (sub.getProduct() == null || sub.getProduct().getId() == null) {
throw new IllegalStateException("Subscription has no product, or its product is incomplete: " + sub.getProduct());
}
Product product = productMap.get(sub.getProduct().getId());
if (product == null) {
throw new IllegalStateException("Subscription references a product which cannot be resolved: " + sub.getProduct());
}
pool.setProduct(product);
if (sub.getDerivedProduct() != null) {
product = productMap.get(sub.getDerivedProduct().getId());
if (product == null) {
throw new IllegalStateException("Subscription's derived product references a product which " + "cannot be resolved: " + sub.getDerivedProduct());
}
pool.setDerivedProduct(product);
}
if (sub.getProvidedProducts() != null) {
Set<Product> products = new HashSet<>();
for (ProductData pdata : sub.getProvidedProducts()) {
if (pdata != null) {
product = productMap.get(pdata.getId());
if (product == null) {
throw new IllegalStateException("Subscription's provided products references a " + "product which cannot be resolved: " + pdata);
}
products.add(product);
}
}
pool.setProvidedProducts(products);
}
if (sub.getDerivedProvidedProducts() != null) {
Set<Product> products = new HashSet<>();
for (ProductData pdata : sub.getDerivedProvidedProducts()) {
if (pdata != null) {
product = productMap.get(pdata.getId());
if (product == null) {
throw new IllegalStateException("Subscription's derived provided products " + "references a product which cannot be resolved: " + pdata);
}
products.add(product);
}
}
pool.setDerivedProvidedProducts(products);
}
return pool;
}
use of org.candlepin.model.Branding in project candlepin by candlepin.
the class PoolHelperTest method clonePoolTest.
@Test
public void clonePoolTest() {
Product product = TestUtil.createProduct();
Product product2 = TestUtil.createProduct();
Map<String, String> attributes = new HashMap<>();
for (int i = 0; i < 3; i++) {
attributes.put("a" + i, "b" + i);
}
Branding branding = new Branding("id", "type", "name");
Pool pool = TestUtil.createPool(owner, product);
pool.getBranding().add(branding);
String quant = "unlimited";
Pool clone = PoolHelper.clonePool(pool, product2, quant, attributes, "TaylorSwift", null, ent, productCurator);
assertEquals(owner, clone.getOwner());
assertEquals(new Long(-1L), clone.getQuantity());
assertEquals(product2, clone.getProduct());
assertEquals(attributes.size() + 1, clone.getAttributes().size());
for (int i = 0; i < 3; i++) {
assertEquals("b" + i, clone.getAttributeValue("a" + i));
}
assertNotEquals(pool.getSourceSubscription(), clone);
assertEquals(pool.getSourceSubscription().getSubscriptionId(), clone.getSubscriptionId());
assertEquals(pool.getSourceSubscription().getSubscriptionId(), clone.getSourceSubscription().getSubscriptionId());
assertEquals("TaylorSwift", clone.getSourceSubscription().getSubscriptionSubKey());
assertEquals(1, clone.getBranding().size());
Branding brandingClone = clone.getBranding().iterator().next();
assertEquals(branding, brandingClone);
}
use of org.candlepin.model.Branding in project candlepin by candlepin.
the class PoolManagerTest method brandingCopiedWhenCreatingPools.
@Test
public void brandingCopiedWhenCreatingPools() {
Product product = TestUtil.createProduct();
Subscription sub = TestUtil.createSubscription(owner, product);
Branding b1 = new Branding("8000", "OS", "Branded Awesome OS");
Branding b2 = new Branding("8001", "OS", "Branded Awesome OS 2");
sub.getBranding().add(b1);
sub.getBranding().add(b2);
this.mockProducts(owner, product);
PoolRules pRules = new PoolRules(manager, mockConfig, entitlementCurator, mockOwnerProductCurator, mockProductCurator);
List<Pool> pools = pRules.createAndEnrichPools(sub);
assertEquals(1, pools.size());
Pool resultPool = pools.get(0);
assertEquals(2, resultPool.getBranding().size());
assertTrue(resultPool.getBranding().contains(b1));
assertTrue(resultPool.getBranding().contains(b2));
}
use of org.candlepin.model.Branding in project candlepin by candlepin.
the class PoolManagerFunctionalTest method init.
@Before
@Override
public void init() throws Exception {
super.init();
o = createOwner();
ownerCurator.create(o);
this.ownerAdapter = new DefaultOwnerServiceAdapter(this.ownerCurator, this.i18n);
virtHost = TestUtil.createProduct(PRODUCT_VIRT_HOST, PRODUCT_VIRT_HOST);
virtHostPlatform = TestUtil.createProduct(PRODUCT_VIRT_HOST_PLATFORM, PRODUCT_VIRT_HOST_PLATFORM);
virtGuest = TestUtil.createProduct(PRODUCT_VIRT_GUEST, PRODUCT_VIRT_GUEST);
monitoring = TestUtil.createProduct(PRODUCT_MONITORING, PRODUCT_MONITORING);
monitoring.setAttribute(Pool.Attributes.MULTI_ENTITLEMENT, "yes");
provisioning = TestUtil.createProduct(PRODUCT_PROVISIONING, PRODUCT_PROVISIONING);
provisioning.setAttribute(Pool.Attributes.MULTI_ENTITLEMENT, "yes");
provisioning.setMultiplier(2L);
provisioning.setAttribute(Product.Attributes.INSTANCE_MULTIPLIER, "4");
virtHost.setAttribute(PRODUCT_VIRT_HOST, "");
virtHostPlatform.setAttribute(PRODUCT_VIRT_HOST_PLATFORM, "");
virtGuest.setAttribute(PRODUCT_VIRT_GUEST, "");
monitoring.setAttribute(PRODUCT_MONITORING, "");
provisioning.setAttribute(PRODUCT_PROVISIONING, "");
socketLimitedProduct = TestUtil.createProduct("socket-limited-prod", "Socket Limited Product");
socketLimitedProduct.setAttribute(Product.Attributes.SOCKETS, "2");
productCurator.create(socketLimitedProduct);
productCurator.create(virtHost);
productCurator.create(virtHostPlatform);
productCurator.create(virtGuest);
productCurator.create(monitoring);
productCurator.create(provisioning);
List<Subscription> subscriptions = new LinkedList<>();
ImportSubscriptionServiceAdapter subAdapter = new ImportSubscriptionServiceAdapter(subscriptions);
Subscription sub1 = TestUtil.createSubscription(o, virtHost, new HashSet<>());
sub1.setId(Util.generateDbUUID());
sub1.setQuantity(5L);
sub1.setStartDate(new Date());
sub1.setEndDate(TestUtil.createDate(3020, 12, 12));
sub1.setModified(new Date());
Subscription sub2 = TestUtil.createSubscription(o, virtHostPlatform, new HashSet<>());
sub2.setId(Util.generateDbUUID());
sub2.setQuantity(5L);
sub2.setStartDate(new Date());
sub2.setEndDate(TestUtil.createDate(3020, 12, 12));
sub2.setModified(new Date());
Subscription sub3 = TestUtil.createSubscription(o, monitoring, new HashSet<>());
sub3.setId(Util.generateDbUUID());
sub3.setQuantity(5L);
sub3.setStartDate(new Date());
sub3.setEndDate(TestUtil.createDate(3020, 12, 12));
sub3.setModified(new Date());
sub4 = TestUtil.createSubscription(o, provisioning, new HashSet<>());
sub4.setId(Util.generateDbUUID());
sub4.setQuantity(5L);
sub4.setStartDate(new Date());
sub4.setEndDate(TestUtil.createDate(3020, 12, 12));
sub4.setModified(new Date());
sub4.getBranding().add(new Branding("product1", "type1", "branding1"));
sub4.getBranding().add(new Branding("product2", "type2", "branding2"));
subscriptions.add(sub1);
subscriptions.add(sub2);
subscriptions.add(sub3);
subscriptions.add(sub4);
poolManager.getRefresher(subAdapter, ownerAdapter).add(o).run();
this.systemType = new ConsumerType(ConsumerTypeEnum.SYSTEM);
consumerTypeCurator.create(systemType);
parentSystem = new Consumer("system", "user", o, systemType);
parentSystem.getFacts().put("total_guests", "0");
consumerCurator.create(parentSystem);
childVirtSystem = new Consumer("virt system", "user", o, systemType);
consumerCurator.create(childVirtSystem);
}
Aggregations