Search in sources :

Example 61 with Product

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

the class HostedTestSubscriptionResource method addBatchContent.

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/owners/{owner_key}/products/{product_id}/batch_content")
@Transactional
public ProductDTO addBatchContent(@PathParam("owner_key") String ownerKey, @PathParam("product_id") String productId, Map<String, Boolean> contentMap) {
    Owner owner = this.getOwnerByKey(ownerKey);
    Product product = this.fetchProduct(owner, productId);
    Collection<ProductContent> productContent = new LinkedList<>();
    ProductDTO pdto = this.translator.translate(product, ProductDTO.class);
    // Impl note:
    // This is a wholely inefficient way of doing this. When we return to using ID-based linking
    // and we're not linking the universe with our model, we can just attach the IDs directly
    // without needing all this DTO conversion back and forth.
    // Alternatively, we can shut off Hibernate's auto-commit junk and get in the habit of
    // calling commit methods as necessary so we don't have to work with DTOs internally.
    boolean changed = false;
    for (Entry<String, Boolean> entry : contentMap.entrySet()) {
        Content content = this.fetchContent(owner, entry.getKey());
        boolean enabled = entry.getValue() != null ? entry.getValue() : ProductContent.DEFAULT_ENABLED_STATE;
        ContentDTO cdto = this.translator.translate(content, ContentDTO.class);
        changed |= pdto.addContent(cdto, enabled);
        addContentToUpstreamSubscriptions(product, content, enabled);
    }
    if (changed) {
        product = this.productManager.updateProduct(pdto, owner, true);
    }
    return this.translator.translate(product, ProductDTO.class);
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) Product(org.candlepin.model.Product) ProductContent(org.candlepin.model.ProductContent) LinkedList(java.util.LinkedList) ProductDTO(org.candlepin.dto.api.v1.ProductDTO) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Transactional(com.google.inject.persist.Transactional)

Example 62 with Product

use of org.candlepin.model.Product 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;
}
Also used : Owner(org.candlepin.model.Owner) SubscriptionsCertificate(org.candlepin.model.SubscriptionsCertificate) Product(org.candlepin.model.Product) Entitlement(org.candlepin.model.Entitlement) Branding(org.candlepin.model.Branding)

Example 63 with Product

use of org.candlepin.model.Product 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;
}
Also used : HashMap(java.util.HashMap) CertificateSerial(org.candlepin.model.CertificateSerial) ProvidedProduct(org.candlepin.model.ProvidedProduct) Product(org.candlepin.model.Product) Branding(org.candlepin.model.Branding) ProvidedProduct(org.candlepin.model.ProvidedProduct) Date(java.util.Date) SourceSubscription(org.candlepin.model.SourceSubscription) Consumer(org.candlepin.model.Consumer) SubscriptionsCertificate(org.candlepin.model.SubscriptionsCertificate) SourceStack(org.candlepin.model.SourceStack) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) HashSet(java.util.HashSet)

Example 64 with Product

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

the class ProductTranslatorTest method initSourceObject.

@Override
protected Product initSourceObject() {
    Product source = new Product();
    Map<String, String> attributes = new HashMap<>();
    attributes.put("attrib_1", "attrib_value_1");
    attributes.put("attrib_2", "attrib_value_2");
    attributes.put("attrib_3", "attrib_value_3");
    Collection<String> depProdIds = new LinkedList<>();
    depProdIds.add("dep_prod_1");
    depProdIds.add("dep_prod_2");
    depProdIds.add("dep_prod_3");
    source.setUuid("test_uuid");
    source.setId("test_id");
    source.setName("test_name");
    source.setMultiplier(10L);
    source.setAttributes(attributes);
    source.setDependentProductIds(depProdIds);
    source.setLocked(true);
    for (int i = 0; i < 3; ++i) {
        Content content = TestUtil.createContent("content-" + i);
        content.setUuid(content.getId() + "_uuid");
        source.addContent(content, true);
    }
    return source;
}
Also used : HashMap(java.util.HashMap) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) Product(org.candlepin.model.Product) LinkedList(java.util.LinkedList)

Example 65 with Product

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

the class ProductManagerTest method testRemoveProductDivergeFromExisting.

@Test
public void testRemoveProductDivergeFromExisting() {
    Owner owner1 = this.createOwner("test-owner-1", "Test Owner 1");
    Owner owner2 = this.createOwner("test-owner-2", "Test Owner 2");
    Product product = this.createProduct("p1", "prod1", owner1, owner2);
    assertTrue(this.ownerProductCurator.isProductMappedToOwner(product, owner1));
    assertTrue(this.ownerProductCurator.isProductMappedToOwner(product, owner2));
    this.productManager.removeProduct(owner1, product);
    assertFalse(this.ownerProductCurator.isProductMappedToOwner(product, owner1));
    assertTrue(this.ownerProductCurator.isProductMappedToOwner(product, owner2));
    assertNotNull(this.productCurator.find(product.getUuid()));
    assertEquals(1, this.ownerProductCurator.getOwnerCount(product));
    verifyZeroInteractions(this.mockEntCertGenerator);
}
Also used : Owner(org.candlepin.model.Owner) Product(org.candlepin.model.Product) Test(org.junit.Test)

Aggregations

Product (org.candlepin.model.Product)407 Test (org.junit.Test)281 Pool (org.candlepin.model.Pool)216 Owner (org.candlepin.model.Owner)153 Consumer (org.candlepin.model.Consumer)112 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)108 HashSet (java.util.HashSet)84 Date (java.util.Date)74 ArrayList (java.util.ArrayList)69 Entitlement (org.candlepin.model.Entitlement)67 LinkedList (java.util.LinkedList)66 HashMap (java.util.HashMap)65 Subscription (org.candlepin.model.dto.Subscription)47 Content (org.candlepin.model.Content)40 ValidationResult (org.candlepin.policy.ValidationResult)38 SourceSubscription (org.candlepin.model.SourceSubscription)36 Matchers.anyString (org.mockito.Matchers.anyString)31 List (java.util.List)29 PoolQuantity (org.candlepin.model.PoolQuantity)29 DateRange (org.candlepin.policy.js.compliance.DateRange)27