Search in sources :

Example 96 with ConsumerType

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;
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Consumer(org.candlepin.model.Consumer) Pool(org.candlepin.model.Pool) ConsumerType(org.candlepin.model.ConsumerType) Entitlement(org.candlepin.model.Entitlement) LinkedList(java.util.LinkedList)

Example 97 with ConsumerType

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;
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ConsumerCapability(org.candlepin.model.ConsumerCapability) ConsumerType(org.candlepin.model.ConsumerType) HashSet(java.util.HashSet)

Example 98 with ConsumerType

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);
    }
}
Also used : ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ConsumerCapability(org.candlepin.model.ConsumerCapability) ConsumerType(org.candlepin.model.ConsumerType)

Example 99 with ConsumerType

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));
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ArrayList(java.util.ArrayList) KeyValueParameter(org.candlepin.resteasy.parameter.KeyValueParameter) CdnCurator(org.candlepin.model.CdnCurator) ManifestManager(org.candlepin.controller.ManifestManager) ConsumerType(org.candlepin.model.ConsumerType) Cdn(org.candlepin.model.Cdn) Map(java.util.Map) Test(org.junit.Test)

Example 100 with ConsumerType

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;
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerType(org.candlepin.model.ConsumerType)

Aggregations

ConsumerType (org.candlepin.model.ConsumerType)169 Consumer (org.candlepin.model.Consumer)92 Test (org.junit.Test)71 Owner (org.candlepin.model.Owner)53 Pool (org.candlepin.model.Pool)47 Entitlement (org.candlepin.model.Entitlement)33 ArrayList (java.util.ArrayList)29 Date (java.util.Date)27 HashMap (java.util.HashMap)24 HashSet (java.util.HashSet)24 ValidationResult (org.candlepin.policy.ValidationResult)22 ApiOperation (io.swagger.annotations.ApiOperation)21 Produces (javax.ws.rs.Produces)21 Before (org.junit.Before)20 ApiResponses (io.swagger.annotations.ApiResponses)19 Path (javax.ws.rs.Path)18 LinkedList (java.util.LinkedList)16 BadRequestException (org.candlepin.common.exceptions.BadRequestException)16 DeletedConsumer (org.candlepin.model.DeletedConsumer)16 Matchers.anyString (org.mockito.Matchers.anyString)16