Search in sources :

Example 91 with Subscription

use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.

the class Importer method recordImportSuccess.

/**
 * Records a successful import of a manifest.
 *
 * @param owner the owner that the manifest was imported into.
 * @param data the data to store in this record.
 * @param forcedConflicts the conflicts that were forced.
 * @param filename the name of the originally uploaded file.
 * @return the newly created {@link ImportRecord}.
 */
public ImportRecord recordImportSuccess(Owner owner, Map<String, Object> data, ConflictOverrides forcedConflicts, String filename) {
    ImportRecord record = new ImportRecord(owner);
    Meta meta = (Meta) data.get("meta");
    if (meta != null) {
        record.setGeneratedBy(meta.getPrincipalName());
        record.setGeneratedDate(meta.getCreated());
    }
    record.setUpstreamConsumer(createImportUpstreamConsumer(owner, null));
    record.setFileName(filename);
    List<Subscription> subscriptions = (List<Subscription>) data.get("subscriptions");
    boolean activeSubscriptionFound = false, expiredSubscriptionFound = false;
    Date currentDate = new Date();
    for (Subscription subscription : subscriptions) {
        if (subscription.getEndDate() == null || subscription.getEndDate().after(currentDate)) {
            activeSubscriptionFound = true;
        } else {
            expiredSubscriptionFound = true;
            sink.emitSubscriptionExpired(subscription);
        }
    }
    String msg = i18n.tr("{0} file imported successfully.", owner.getKey());
    if (!forcedConflicts.isEmpty()) {
        msg = i18n.tr("{0} file imported forcibly.", owner.getKey());
    }
    if (!activeSubscriptionFound) {
        msg += i18n.tr("No active subscriptions found in the file.");
        record.recordStatus(ImportRecord.Status.SUCCESS_WITH_WARNING, msg);
    } else if (expiredSubscriptionFound) {
        msg += i18n.tr("One or more inactive subscriptions found in the file.");
        record.recordStatus(ImportRecord.Status.SUCCESS_WITH_WARNING, msg);
    } else {
        record.recordStatus(ImportRecord.Status.SUCCESS, msg);
    }
    this.importRecordCurator.create(record);
    return record;
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ImportRecord(org.candlepin.model.ImportRecord) Subscription(org.candlepin.model.dto.Subscription) Date(java.util.Date)

Example 92 with Subscription

use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.

the class OwnerResource method getSubscriptions.

/**
 * Retrieves a list of Subscriptions for an Owner
 *
 * @return a list of Subscription objects
 * @httpcode 404
 * @httpcode 200
 */
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{owner_key}/subscriptions")
@ApiOperation(notes = "Retrieves a list of Subscriptions for an Owner", value = "List Subscriptions")
@ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") })
public List<Subscription> getSubscriptions(@PathParam("owner_key") String ownerKey) {
    Owner owner = this.findOwnerByKey(ownerKey);
    List<Subscription> subscriptions = new LinkedList<>();
    for (Pool pool : this.poolManager.listPoolsByOwner(owner).list()) {
        SourceSubscription srcsub = pool.getSourceSubscription();
        if (srcsub != null && "master".equalsIgnoreCase(srcsub.getSubscriptionSubKey())) {
            subscriptions.add(this.poolManager.fabricateSubscriptionFromPool(pool));
        }
    }
    return subscriptions;
}
Also used : Owner(org.candlepin.model.Owner) SourceSubscription(org.candlepin.model.SourceSubscription) Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) LinkedList(java.util.LinkedList) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 93 with Subscription

use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.

the class PoolRulesInstanceTest method standaloneCreateInstanceBasedPool.

@Test
public void standaloneCreateInstanceBasedPool() {
    Subscription s = createInstanceBasedSub("INSTANCEPROD", 100, 2, true);
    Pool p = TestUtil.copyFromSub(s);
    List<Pool> pools = poolRules.createAndEnrichPools(p, new LinkedList<>());
    assertEquals(1, pools.size());
    Pool pool = pools.get(0);
    // In this case the exported entitlement becomes a subscription, the quantity
    // was already doubled in hosted, so from then on whenever it is exported we
    // respect it's quantity.
    assertEquals(new Long(100), pool.getQuantity());
}
Also used : Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) Test(org.junit.Test)

Example 94 with Subscription

use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.

the class PoolRulesInstanceTest method standaloneInstanceBasedUpdatePool.

@Test
public void standaloneInstanceBasedUpdatePool() {
    Subscription s = createInstanceBasedSub("INSTANCEPROD", 100, 2, true);
    Pool masterPool = TestUtil.copyFromSub(s);
    List<Pool> pools = poolRules.createAndEnrichPools(masterPool, new LinkedList<>());
    assertEquals(1, pools.size());
    Pool pool = pools.get(0);
    masterPool = TestUtil.copyFromSub(s);
    // Change the value of instance multiplier:
    masterPool.getProduct().setAttribute(Product.Attributes.INSTANCE_MULTIPLIER, "4");
    // Change the quantity as well:
    masterPool.setQuantity(new Long(200));
    List<Pool> existingPools = new LinkedList<>();
    existingPools.add(pool);
    List<PoolUpdate> updates = poolRules.updatePools(masterPool, existingPools, masterPool.getQuantity(), TestUtil.stubChangedProducts(masterPool.getProduct()));
    assertEquals(1, updates.size());
    PoolUpdate update = updates.get(0);
    assertTrue(update.getQuantityChanged());
    // Change in instance multiplier would have no impact on a standalone update, we
    // only need to worry about an actual change on the subscription quantity.
    assertEquals(new Long(200), update.getPool().getQuantity());
}
Also used : Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 95 with Subscription

use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.

the class PoolRulesInstanceTest method hostedInstanceBasedUpdatePool.

@Test
public void hostedInstanceBasedUpdatePool() {
    Subscription s = createInstanceBasedSub("INSTANCEPROD", 100, 2, false);
    Pool p = TestUtil.copyFromSub(s);
    List<Pool> pools = poolRules.createAndEnrichPools(p, new LinkedList<>());
    assertEquals(1, pools.size());
    Pool pool = pools.get(0);
    p = TestUtil.copyFromSub(s);
    // Change the value of instance multiplier:
    p.getProduct().setAttribute(Product.Attributes.INSTANCE_MULTIPLIER, "4");
    // Change the quantity:
    p.setQuantity(new Long(200));
    List<Pool> existingPools = new LinkedList<>();
    existingPools.add(pool);
    List<PoolUpdate> updates = poolRules.updatePools(p, existingPools, p.getQuantity(), TestUtil.stubChangedProducts(p.getProduct()));
    assertEquals(1, updates.size());
    PoolUpdate update = updates.get(0);
    assertTrue(update.getQuantityChanged());
    assertEquals(new Long(800), update.getPool().getQuantity());
}
Also used : Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

Subscription (org.candlepin.model.dto.Subscription)101 Test (org.junit.Test)77 Pool (org.candlepin.model.Pool)60 Product (org.candlepin.model.Product)48 SourceSubscription (org.candlepin.model.SourceSubscription)36 LinkedList (java.util.LinkedList)35 ArrayList (java.util.ArrayList)34 Owner (org.candlepin.model.Owner)33 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)27 HashMap (java.util.HashMap)20 HashSet (java.util.HashSet)18 Matchers.anyString (org.mockito.Matchers.anyString)18 Entitlement (org.candlepin.model.Entitlement)16 Date (java.util.Date)15 PoolType (org.candlepin.model.Pool.PoolType)13 ImportSubscriptionServiceAdapter (org.candlepin.service.impl.ImportSubscriptionServiceAdapter)13 List (java.util.List)11 OwnerServiceAdapter (org.candlepin.service.OwnerServiceAdapter)11 ConsumerType (org.candlepin.model.ConsumerType)10 ProductData (org.candlepin.model.dto.ProductData)9