Search in sources :

Example 36 with Pool

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

the class TestUtil method clone.

/**
 * @param pool source pool
 * @return pool the clone pool
 */
public static Pool clone(Pool pool) {
    Pool p = new Pool(pool.getOwner(), pool.getProduct(), new HashSet<>(pool.getProvidedProducts()), pool.getQuantity(), pool.getStartDate(), pool.getEndDate(), pool.getContractNumber(), pool.getAccountNumber(), pool.getOrderNumber());
    p.setSourceSubscription(new SourceSubscription(pool.getSubscriptionId(), pool.getSubscriptionSubKey()));
    // Copy sub-product data if there is any:
    p.setDerivedProduct(pool.getDerivedProduct());
    for (Branding b : pool.getBranding()) {
        p.getBranding().add(new Branding(b.getProductId(), b.getType(), b.getName()));
    }
    return p;
}
Also used : SourceSubscription(org.candlepin.model.SourceSubscription) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) Pool(org.candlepin.model.Pool) Branding(org.candlepin.model.Branding)

Example 37 with Pool

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

the class TestUtil method copyFromSub.

/**
 * Returns a pool which will look like it was created from the given subscription
 * during refresh pools.
 *
 * @param sub source subscription
 * @return pool for subscription
 */
public static Pool copyFromSub(Subscription sub) {
    Product product = createProduct((ProductData) sub.getProduct());
    Product derivedProduct = createProduct((ProductData) sub.getDerivedProduct());
    List<Product> providedProducts = new LinkedList<>();
    if (sub.getProvidedProducts() != null) {
        for (ProductData pdata : sub.getProvidedProducts()) {
            if (pdata != null) {
                providedProducts.add(TestUtil.createProduct(pdata));
            }
        }
    }
    List<Product> derivedProvidedProducts = new LinkedList<>();
    if (sub.getDerivedProvidedProducts() != null) {
        for (ProductData pdata : sub.getDerivedProvidedProducts()) {
            if (pdata != null) {
                derivedProvidedProducts.add(TestUtil.createProduct(pdata));
            }
        }
    }
    Pool pool = new Pool(sub.getOwner(), product, providedProducts, sub.getQuantity(), sub.getStartDate(), sub.getEndDate(), sub.getContractNumber(), sub.getAccountNumber(), sub.getOrderNumber());
    pool.setDerivedProduct(derivedProduct);
    pool.setDerivedProvidedProducts(derivedProvidedProducts);
    if (sub.getId() != null) {
        pool.setSourceSubscription(new SourceSubscription(sub.getId(), "master"));
    }
    pool.setUpstreamPoolId(sub.getUpstreamPoolId());
    pool.setUpstreamConsumerId(sub.getUpstreamConsumerId());
    pool.setUpstreamEntitlementId(sub.getUpstreamEntitlementId());
    for (Branding branding : sub.getBranding()) {
        pool.getBranding().add(new Branding(branding.getProductId(), branding.getType(), branding.getName()));
    }
    return pool;
}
Also used : ProductData(org.candlepin.model.dto.ProductData) SourceSubscription(org.candlepin.model.SourceSubscription) Product(org.candlepin.model.Product) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) Pool(org.candlepin.model.Pool) Branding(org.candlepin.model.Branding) LinkedList(java.util.LinkedList)

Example 38 with Pool

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

the class DatabaseTestFixture method createPool.

protected Pool createPool(Owner owner, Product product, Long quantity, Date startDate, Date endDate, String contractNr, String subscriptionId) {
    Pool pool = createPool(owner, product, quantity, subscriptionId, "master", startDate, endDate);
    pool.setContractNumber(contractNr);
    return poolCurator.merge(pool);
}
Also used : Pool(org.candlepin.model.Pool)

Example 39 with Pool

use of org.candlepin.model.Pool 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.emptySet());
        }
    }
    return dest;
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) Pool(org.candlepin.model.Pool) Certificate(org.candlepin.model.Certificate) EntitlementCertificate(org.candlepin.model.EntitlementCertificate)

Example 40 with Pool

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

the class EntitlementTranslator method populate.

/**
 * {@inheritDoc}
 */
@Override
public EntitlementDTO populate(ModelTranslator modelTranslator, Entitlement source, EntitlementDTO dest) {
    if (source == null) {
        throw new IllegalArgumentException("source is null");
    }
    if (dest == null) {
        throw new IllegalArgumentException("destination is null");
    }
    dest.setId(source.getId());
    dest.setQuantity(source.getQuantity());
    dest.setStartDate(source.getStartDate());
    dest.setEndDate(source.getEndDate());
    if (modelTranslator != null) {
        Pool pool = source.getPool();
        dest.setPool(pool != null ? modelTranslator.translate(pool, PoolDTO.class) : null);
    }
    return dest;
}
Also used : Pool(org.candlepin.model.Pool)

Aggregations

Pool (org.candlepin.model.Pool)508 Test (org.junit.Test)358 Product (org.candlepin.model.Product)217 Entitlement (org.candlepin.model.Entitlement)125 Consumer (org.candlepin.model.Consumer)115 ValidationResult (org.candlepin.policy.ValidationResult)111 ArrayList (java.util.ArrayList)100 LinkedList (java.util.LinkedList)100 Owner (org.candlepin.model.Owner)80 HashSet (java.util.HashSet)76 HashMap (java.util.HashMap)67 PoolQuantity (org.candlepin.model.PoolQuantity)66 Date (java.util.Date)65 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)62 Subscription (org.candlepin.model.dto.Subscription)60 List (java.util.List)48 ConsumerType (org.candlepin.model.ConsumerType)48 SourceSubscription (org.candlepin.model.SourceSubscription)47 ActivationKey (org.candlepin.model.activationkeys.ActivationKey)38 Matchers.anyString (org.mockito.Matchers.anyString)30