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