use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class HandleEntitlementsOp method execute.
/**
* associates the pools, consumers with entitlements, and persists the entities as needed.
* also computes all the consumed counts.
* @param context
*/
@Override
public boolean execute(BindContext context) {
Consumer consumer = context.getLockedConsumer();
ConsumerType ctype = context.getConsumerType();
Map<String, Entitlement> entitlementMap = context.getEntitlementMap();
Map<String, PoolQuantity> lockedPools = context.getPoolQuantities();
List<Pool> poolsToSave = new LinkedList<>();
for (Entry<String, PoolQuantity> entry : lockedPools.entrySet()) {
Entitlement ent = entitlementMap.get(entry.getKey());
Pool pool = entry.getValue().getPool();
Integer quantity = ent.getQuantity();
pool.getEntitlements().add(ent);
ent.setPool(pool);
ent.setConsumer(consumer);
ent.setOwner(pool.getOwner());
pool.setConsumed(pool.getConsumed() + quantity);
if (ctype.isManifest()) {
pool.setExported(pool.getExported() + quantity);
} else if (ctype.isType(ConsumerTypeEnum.SHARE)) {
pool.setShared(pool.getShared() + quantity);
}
consumer.addEntitlement(ent);
consumer.setEntitlementCount(consumer.getEntitlementCount() + quantity);
poolsToSave.add(pool);
}
entitlementCurator.saveAll(entitlementMap.values(), false, false);
poolCurator.updateAll(poolsToSave, false, false);
return true;
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ConsumerTranslatorTest method initSourceObject.
@Override
protected Consumer initSourceObject() {
ConsumerType ctype = this.consumerTypeTranslatorTest.initSourceObject();
Consumer consumer = new Consumer();
consumer.setUuid("consumer_uuid");
consumer.setUsername("consumer_user_name");
consumer.setServiceLevel("consumer_service_level");
Owner owner = this.ownerTranslatorTest.initSourceObject();
when(mockOwnerCurator.findOwnerById(eq(owner.getId()))).thenReturn(owner);
consumer.setOwner(owner);
consumer.setType(ctype);
Map<String, String> facts = new HashMap<>();
for (int i = 0; i < 5; ++i) {
facts.put("fact-" + i, "value-" + i);
}
consumer.setFacts(facts);
Set<ConsumerInstalledProduct> installedProducts = new HashSet<>();
for (int i = 0; i < 5; ++i) {
ConsumerInstalledProduct installedProduct = new ConsumerInstalledProduct();
installedProduct.setProductId("installedProduct-" + i);
installedProducts.add(installedProduct);
}
consumer.setInstalledProducts(installedProducts);
Set<ConsumerCapability> capabilities = new HashSet<>();
for (int i = 0; i < 5; ++i) {
ConsumerCapability capability = new ConsumerCapability();
capability.setName("capability-" + i);
capabilities.add(capability);
}
consumer.setCapabilities(capabilities);
when(mockConsumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
when(mockConsumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(ctype);
return consumer;
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ConsumerTranslatorTest method verifyOutput.
@Override
protected void verifyOutput(Consumer source, ConsumerDTO dest, boolean childrenGenerated) {
if (source != null) {
assertEquals(source.getUuid(), dest.getUuid());
assertEquals(source.getUsername(), dest.getUsername());
assertEquals(source.getServiceLevel(), dest.getServiceLevel());
assertEquals(source.getFacts(), dest.getFacts());
assertEquals(source.getCreated(), dest.getCreated());
assertEquals(source.getUpdated(), dest.getUpdated());
if (childrenGenerated) {
ConsumerType ctype = this.mockConsumerTypeCurator.getConsumerType(source);
assertEquals(source.getOwnerId(), dest.getOwner().getId());
this.consumerTypeTranslatorTest.verifyOutput(ctype, dest.getType(), true);
if (source.getInstalledProducts() != null) {
for (ConsumerInstalledProduct cip : source.getInstalledProducts()) {
boolean verified = false;
for (String cipDTO : dest.getInstalledProducts()) {
assertNotNull(cip);
assertNotNull(cipDTO);
if (cip.getProductId().contentEquals(cipDTO)) {
verified = true;
}
}
assertTrue(verified);
}
} else {
assertNull(dest.getInstalledProducts());
}
if (source.getCapabilities() != null) {
for (ConsumerCapability cc : source.getCapabilities()) {
boolean verified = false;
for (String ccDTO : dest.getCapabilities()) {
assertNotNull(cc);
assertNotNull(ccDTO);
if (cc.getName().contentEquals(ccDTO)) {
verified = true;
}
}
assertTrue(verified);
}
} else {
assertNull(dest.getCapabilities());
}
} else {
assertNull(dest.getOwner());
assertNull(dest.getType());
assertNull(dest.getInstalledProducts());
assertNull(dest.getCapabilities());
}
} else {
assertNull(dest);
}
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ConsumerResourceTest method testAsyncExport.
@Test
public void testAsyncExport() {
CdnCurator mockCdnCurator = mock(CdnCurator.class);
ManifestManager manifestManager = mock(ManifestManager.class);
ConsumerResource cr = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, null, null, null, i18n, null, null, null, null, null, null, null, mockOwnerCurator, null, null, null, null, null, null, this.config, null, mockCdnCurator, null, null, manifestManager, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
List<KeyValueParameter> extParams = new ArrayList<>();
Owner owner = this.createOwner();
owner.setId(TestUtil.randomString());
when(mockOwnerCurator.findOwnerById(eq(owner.getId()))).thenReturn(owner);
ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerType.ConsumerTypeEnum.CANDLEPIN));
Consumer consumer = this.createConsumer(owner, ctype);
Cdn cdn = new Cdn("cdn-label", "test", "url");
when(mockCdnCurator.lookupByLabel(eq(cdn.getLabel()))).thenReturn(cdn);
cr.exportDataAsync(null, consumer.getUuid(), cdn.getLabel(), "prefix", cdn.getUrl(), extParams);
verify(manifestManager).generateManifestAsync(eq(consumer.getUuid()), eq(owner.getKey()), eq(cdn.getLabel()), eq("prefix"), eq(cdn.getUrl()), any(Map.class));
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ConsumerResourceTest method createConsumer.
protected Consumer createConsumer(Owner owner, ConsumerType ctype) {
if (ctype == null) {
ctype = new ConsumerType("test-ctype-" + TestUtil.randomInt());
}
if (owner == null) {
owner = this.createOwner();
}
this.mockConsumerType(ctype);
Consumer consumer = this.mockConsumer(new Consumer("test-consumer", "test-user", owner, ctype));
return consumer;
}
Aggregations