Package org.candlepin.model

Examples of org.candlepin.model.Subscription


        Product product = TestUtil.createProduct();
        productCurator.create(product);

        Set<Product> providedProducts = new HashSet<Product>();
        providedProducts.add(product);
        Subscription sub = TestUtil.createSubscription(owner, product, providedProducts);
        adapter.createSubscription(sub);

        List<Subscription> results = adapter.getSubscriptions(product);
        assertEquals(1, results.size());
        assertTrue(results.contains(sub));
View Full Code Here


        productCurator.create(product3);

        Set<Product> providedProducts = new HashSet<Product>();
        providedProducts.add(product);

        Subscription sub = TestUtil.createSubscription(owner, product2, providedProducts);
        adapter.createSubscription(sub);

        Set<Product> providedProducts2 = new HashSet<Product>();
        providedProducts2.add(product3);
        Subscription sub2 = TestUtil.createSubscription(owner, product, providedProducts2);
        adapter.createSubscription(sub2);

        List<Subscription> results = adapter.getSubscriptions(product);
        assertEquals(2, results.size());
        assertTrue(results.contains(sub));
View Full Code Here

        productCurator.create(product3);

        Set<Product> providedProducts = new HashSet<Product>();
        providedProducts.add(product);

        Subscription sub = TestUtil.createSubscription(owner, product2, providedProducts);
        adapter.createSubscription(sub);

        Set<Product> providedProducts2 = new HashSet<Product>();
        providedProducts2.add(product3);
        Subscription sub2 = TestUtil.createSubscription(owner, product, providedProducts2);
        adapter.createSubscription(sub2);

        List<Subscription> results = adapter.getSubscriptions(product3);
        assertEquals(1, results.size());
        assertTrue(results.contains(sub2));
View Full Code Here

    @Test
    public void testAddBranding() {
        s1.getBranding().add(new Branding("8000", "OS", "Awesome OS Branded"));
        subCurator.merge(s1);
        Subscription lookedUp = subCurator.find(s1.getId());
        assertEquals(1, lookedUp.getBranding().size());
        assertEquals("8000", lookedUp.getBranding().iterator().next().getProductId());
    }
View Full Code Here

    @Test
    public void testRemoveBranding() {
        s1.getBranding().add(new Branding("8000", "OS", "Awesome OS Branded"));
        subCurator.merge(s1);
        Subscription lookedUp = subCurator.find(s1.getId());
        assertEquals(1, lookedUp.getBranding().size());

        lookedUp.getBranding().clear();
        subCurator.merge(lookedUp);

        lookedUp = subCurator.find(s1.getId());
        assertEquals(0, lookedUp.getBranding().size());
    }
View Full Code Here

    @Test
    public void testMultiplierCreation() {
        Product product = new Product("someProduct", "An Extremely Great Product", 10L);
        productCurator.create(product);

        Subscription sub = new Subscription(owner, product, new HashSet<Product>(), 16L,
            TestUtil.createDate(2006, 10, 21), TestUtil.createDate(2020, 1, 1), new Date());
        this.subCurator.create(sub);

        Pool newPool = poolManager.createPoolsForSubscription(sub).get(0);
        List<Pool> pools = poolCurator.lookupBySubscriptionId(sub.getId());

        assertEquals(160L, pools.get(0).getQuantity().longValue());
        assertEquals(newPool.getQuantity(), pools.get(0).getQuantity());
    }
View Full Code Here

        assertNotNull(pool);
    }

    @Test
    public void confirmBonusPoolDeleted() {
        Subscription sub = new Subscription(owner, product, new HashSet<Product>(), 16L,
            TestUtil.createDate(2006, 10, 21), TestUtil.createDate(2020, 1, 1), new Date());
        subCurator.create(sub);

        Pool sourcePool = poolManager.createPoolsForSubscription(sub).get(0);
        poolCurator.create(sourcePool);
        Entitlement e = new Entitlement(sourcePool, consumer, 1);
        entitlementCurator.create(e);

        Pool pool2 = TestUtil.createPool(owner, product);
        pool2.setSourceEntitlement(e);
        pool2.setSourceSubscription(new SourceSubscription(
            sourcePool.getSubscriptionId(), "derived"));
        poolCurator.create(pool2);

        assertTrue(poolCurator.lookupBySubscriptionId(sub.getId()).size() == 2);
        poolManager.deletePool(sourcePool);

        // because we check for null now, we want to verify the
        // subpool gets deleted when the original pool is deleted.
        Pool gone = poolCurator.find(pool2.getId());
View Full Code Here

        for (String url : largeTestUrls) {
            largeContent.add(createContent(CONTENT_NAME, CONTENT_ID, CONTENT_LABEL,
                CONTENT_TYPE, CONTENT_VENDOR, url, CONTENT_GPG_URL, ARCH_LABEL));
        }

        subscription = new Subscription(null, product, new HashSet<Product>(),
            1L, new Date(), new Date(), new Date());
        subscription.setId("1");
        largeContentSubscription = new Subscription(null, largeContentProduct,
            new HashSet<Product>(),
            1L, new Date(), new Date(), new Date());
        largeContentSubscription.setId("2");

        owner = new Owner();
View Full Code Here

    public Subscription importObject(ObjectMapper mapper, Reader reader, Owner owner,
        Map<String, Product> productsById, ConsumerDto consumer, Meta meta)
        throws IOException, SyncDataFormatException {

        Entitlement entitlement = mapper.readValue(reader, Entitlement.class);
        Subscription subscription = new Subscription();

        subscription.setUpstreamPoolId(entitlement.getPool().getId());
        subscription.setUpstreamEntitlementId(entitlement.getId());
        subscription.setUpstreamConsumerId(consumer.getUuid());

        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()));
        }

        subscription.setProduct(findProduct(productsById, entitlement.getProductId()));
        String cdnLabel = meta.getCdnLabel();
        if (!StringUtils.isBlank(cdnLabel)) {
            Cdn cdn = cdnCurator.lookupByLabel(cdnLabel);
            if (cdn != null) {
                subscription.setCdn(cdn);
            }
        }

        Set<Product> products = new HashSet<Product>();
        for (ProvidedProduct providedProduct : entitlement.getPool().
            getProvidedProducts()) {
            products.add(findProduct(productsById, providedProduct.getProductId()));
        }
        subscription.setProvidedProducts(products);

        // Add any sub product data to the subscription.
        if (entitlement.getPool().getDerivedProductId() != null) {
            subscription.setDerivedProduct(findProduct(productsById,
                entitlement.getPool().getDerivedProductId()));
        }

        Set<Product> subProvProds = new HashSet<Product>();
        for (DerivedProvidedProduct subProvProd : entitlement.getPool().
            getDerivedProvidedProducts()) {
            subProvProds.add(findProduct(productsById, subProvProd.getProductId()));
        }
        subscription.setDerivedProvidedProducts(subProvProds);

        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());
            csCurator.create(cs);
            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");
        }
View Full Code Here

        // if we can match to the entitlement id do it.
        // we need a new list to hold the ones that are left
        Set<Subscription> subscriptionsStillToImport = new HashSet<Subscription>();
        for (Subscription subscription : subsToImport) {
            Subscription local = null;
            Map<String, Subscription> map = existingSubsByUpstreamPool.get(
                subscription.getUpstreamPoolId());
            if (map == null || map.isEmpty()) {
                createSubscription(subscription);
                log.info("Creating new subscription for incoming entitlement with id [" +
                    subscription.getUpstreamEntitlementId() +
                    "]");
                continue;
            }
            local = map.get(subscription.getUpstreamEntitlementId());
            if (local != null) {
                mergeSubscription(subscription, local, map);
                log.info("Merging subscription for incoming entitlement id [" +
                    subscription.getUpstreamEntitlementId() +
                    "] into subscription with existing entitlement id [" +
                    local.getUpstreamEntitlementId() +
                    "]. Entitlement id match.");
            }
            else {
                subscriptionsStillToImport.add(subscription);
                log.warn("Subscription for incoming entitlement id [" +
                    subscription.getUpstreamEntitlementId() +
                    "] does not have an entitlement id match " +
                    "in the current subscriptions for the upstream pool id [" +
                    subscription.getUpstreamPoolId() +
                    "]");
            }
        }

        // matches will be made against the upstream pool id and quantity.
        // we need a new list to hold the ones that are left
        List<Subscription> subscriptionsNeedQuantityMatch = new ArrayList<Subscription>();
        for (Subscription subscription : subscriptionsStillToImport) {
            Subscription local = null;
            Map<String, Subscription> map = existingSubsByUpstreamPool.get(
                subscription.getUpstreamPoolId());
            if (map == null) {
                map = new HashMap<String, Subscription>();
            }
            for (Subscription localSub : map.values()) {
                if (localSub.getQuantity().equals(subscription.getQuantity())) {
                    local = localSub;
                    break;
                }
            }
            if (local != null) {
                mergeSubscription(subscription, local, map);
                log.info("Merging subscription for incoming entitlement id [" +
                    subscription.getUpstreamEntitlementId() +
                    "] into subscription with existing entitlement id [" +
                    local.getUpstreamEntitlementId() +
                    "]. Exact quantity match.");
            }
            else {
                subscriptionsNeedQuantityMatch.add(subscription);
                log.warn("Subscription for incoming entitlement id [" +
                    subscription.getUpstreamEntitlementId() +
                    "] does not have an exact quantity match " +
                    "in the current subscriptions for the upstream pool id [" +
                    subscription.getUpstreamPoolId() +
                    "]");
            }
        }

        // matches will be made against the upstream pool id and quantity.
        // quantities will just match by position from highest to lowest
        // we need a new list to hold the ones that are left
        Subscription[] inNeed = subscriptionsNeedQuantityMatch.toArray(
            new Subscription[0]);
        Arrays.sort(inNeed, new QuantityComparator());
        for (Subscription subscription : inNeed) {
            Subscription local = null;
            Map<String, Subscription> map = existingSubsByUpstreamPool.get(
                subscription.getUpstreamPoolId());
            if (map == null || map.isEmpty()) {
                createSubscription(subscription);
                log.info("Creating new subscription for incoming entitlement with id [" +
                    subscription.getUpstreamEntitlementId() +
                    "]");
                continue;
            }
            Subscription[] locals = map.values().toArray(new Subscription[0]);
            Arrays.sort(locals, new QuantityComparator());
            local = locals[0];
            mergeSubscription(subscription, local, map);
            log.info("Merging subscription for incoming entitlement id [" +
                subscription.getUpstreamEntitlementId() +
                "] into subscription with existing entitlement id [" +
                local.getUpstreamEntitlementId() +
                "]. Ordered quantity match.");
        }
        deleteRemainingLocalSubscriptions(existingSubsByUpstreamPool);
    }
View Full Code Here

TOP

Related Classes of org.candlepin.model.Subscription

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.