Search in sources :

Example 1 with ActivationKeyContentOverride

use of org.candlepin.model.activationkeys.ActivationKeyContentOverride in project candlepin by candlepin.

the class ConsumerBindUtil method handleActivationKeyOverrides.

private void handleActivationKeyOverrides(Consumer consumer, Set<ActivationKeyContentOverride> overrides) {
    for (ActivationKeyContentOverride akco : overrides) {
        ConsumerContentOverride consumerOverride = akco.buildConsumerContentOverride(consumer);
        this.consumerContentOverrideCurator.addOrUpdate(consumer, consumerOverride);
    }
}
Also used : ConsumerContentOverride(org.candlepin.model.ConsumerContentOverride) ActivationKeyContentOverride(org.candlepin.model.activationkeys.ActivationKeyContentOverride)

Example 2 with ActivationKeyContentOverride

use of org.candlepin.model.activationkeys.ActivationKeyContentOverride in project candlepin by candlepin.

the class ActivationKeyTranslator method populate.

/**
 * {@inheritDoc}
 */
@Override
public ActivationKeyDTO populate(ModelTranslator modelTranslator, ActivationKey source, ActivationKeyDTO dest) {
    dest = super.populate(modelTranslator, source, dest);
    dest.setId(source.getId()).setName(source.getName()).setDescription(source.getDescription()).setServiceLevel(source.getServiceLevel()).setAutoAttach(source.isAutoAttach());
    // Process nested objects if we have a model translator to use to the translation...
    if (modelTranslator != null) {
        Owner owner = source.getOwner();
        dest.setOwner(owner != null ? modelTranslator.translate(owner, OwnerDTO.class) : null);
        Set<ActivationKeyPool> pools = source.getPools();
        if (pools != null && !pools.isEmpty()) {
            for (ActivationKeyPool poolEntry : pools) {
                if (poolEntry != null) {
                    dest.addPool(new ActivationKeyDTO.ActivationKeyPoolDTO(poolEntry.getPool().getId(), poolEntry.getQuantity()));
                }
            }
        } else {
            dest.setPools(Collections.<ActivationKeyDTO.ActivationKeyPoolDTO>emptySet());
        }
        Set<Product> products = source.getProducts();
        if (products != null && !products.isEmpty()) {
            for (Product prod : products) {
                if (prod != null) {
                    dest.addProductId(prod.getId());
                }
            }
        } else {
            dest.setProductIds(Collections.<String>emptySet());
        }
        Set<ActivationKeyContentOverride> overrides = source.getContentOverrides();
        if (overrides != null && !overrides.isEmpty()) {
            for (ActivationKeyContentOverride override : overrides) {
                if (override != null) {
                    dest.addContentOverride(new ActivationKeyDTO.ActivationKeyContentOverrideDTO(override.getContentLabel(), override.getName(), override.getValue()));
                }
            }
        } else {
            dest.setContentOverrides(Collections.<ActivationKeyDTO.ActivationKeyContentOverrideDTO>emptySet());
        }
        Release release = source.getReleaseVer();
        if (release != null) {
            dest.setReleaseVersion(release.getReleaseVer());
        }
    }
    return dest;
}
Also used : Owner(org.candlepin.model.Owner) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) Product(org.candlepin.model.Product) Release(org.candlepin.model.Release) ActivationKeyContentOverride(org.candlepin.model.activationkeys.ActivationKeyContentOverride) ActivationKeyContentOverride(org.candlepin.model.activationkeys.ActivationKeyContentOverride)

Example 3 with ActivationKeyContentOverride

use of org.candlepin.model.activationkeys.ActivationKeyContentOverride in project candlepin by candlepin.

the class ActivationKeyTranslatorTest method verifyOutput.

@Override
protected void verifyOutput(ActivationKey source, ActivationKeyDTO dest, boolean childrenGenerated) {
    if (source != null) {
        assertEquals(source.getId(), dest.getId());
        assertEquals(source.getName(), dest.getName());
        assertEquals(source.getDescription(), dest.getDescription());
        assertEquals(source.getServiceLevel(), dest.getServiceLevel());
        assertEquals(source.isAutoAttach(), dest.isAutoAttach());
        if (childrenGenerated) {
            this.ownerTranslatorTest.verifyOutput(source.getOwner(), dest.getOwner(), true);
            for (Product prod : source.getProducts()) {
                for (String prodDto : dest.getProductIds()) {
                    assertNotNull(prodDto);
                    if (prodDto.equals(prod.getId())) {
                    // Nothing else to assert on, since prodDto only holds the product id.
                    }
                }
            }
            for (ActivationKeyPool akPool : source.getPools()) {
                for (ActivationKeyDTO.ActivationKeyPoolDTO akPoolDto : dest.getPools()) {
                    assertNotNull(akPoolDto);
                    if (akPoolDto.getPoolId().equals(akPool.getId())) {
                        assertEquals(akPool.getQuantity(), akPoolDto.getQuantity());
                    }
                }
            }
            for (ActivationKeyContentOverride akOverride : source.getContentOverrides()) {
                for (ActivationKeyDTO.ActivationKeyContentOverrideDTO akOverrideDto : dest.getContentOverrides()) {
                    assertNotNull(akOverrideDto);
                    if (akOverrideDto.getName().equals(akOverride.getName())) {
                        assertEquals(akOverrideDto.getContentLabel(), akOverride.getContentLabel());
                        assertEquals(akOverrideDto.getValue(), akOverride.getValue());
                    }
                }
            }
            Release releaseSource = source.getReleaseVer();
            String releaseDestination = dest.getReleaseVersion();
            if (releaseSource != null) {
                assertEquals(releaseSource.getReleaseVer(), releaseDestination);
            } else {
                assertNull(releaseDestination);
            }
        } else {
            assertNull(dest.getOwner());
            assertNull(dest.getProductIds());
            assertNull(dest.getPools());
            assertNull(dest.getContentOverrides());
            assertNull(dest.getReleaseVersion());
        }
    } else {
        assertNull(dest);
    }
}
Also used : Product(org.candlepin.model.Product) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) Release(org.candlepin.model.Release) ActivationKeyContentOverride(org.candlepin.model.activationkeys.ActivationKeyContentOverride) ActivationKeyContentOverride(org.candlepin.model.activationkeys.ActivationKeyContentOverride)

Example 4 with ActivationKeyContentOverride

use of org.candlepin.model.activationkeys.ActivationKeyContentOverride in project candlepin by candlepin.

the class ActivationKeyContentOverrideCuratorTest method testRetrieveByNameIsCaseInsensitive.

@Test
public void testRetrieveByNameIsCaseInsensitive() {
    activationKeyContentOverrideCurator.create(new ActivationKeyContentOverride(key, "test-repo", "gpgcheck", "1"));
    ActivationKeyContentOverride found = activationKeyContentOverrideCurator.retrieve(key, "test-repo", "GPGCheck");
    assertNotNull(found);
    assertEquals(key, found.getKey());
    assertEquals("test-repo", found.getContentLabel());
    assertEquals("gpgcheck", found.getName());
    assertEquals("1", found.getValue());
}
Also used : ActivationKeyContentOverride(org.candlepin.model.activationkeys.ActivationKeyContentOverride) Test(org.junit.Test)

Example 5 with ActivationKeyContentOverride

use of org.candlepin.model.activationkeys.ActivationKeyContentOverride in project candlepin by candlepin.

the class ActivationKeyContentOverrideCuratorTest method testRemoveByNameCaseInsensitive.

@Test
public void testRemoveByNameCaseInsensitive() {
    activationKeyContentOverrideCurator.create(new ActivationKeyContentOverride(key, "test-repo", "gpgcheck", "1"));
    activationKeyContentOverrideCurator.create(new ActivationKeyContentOverride(key, "test-repo", "remaining-override", "remaining"));
    activationKeyContentOverrideCurator.removeByName(key, "test-repo", "GpGChecK");
    List<ActivationKeyContentOverride> remaining = activationKeyContentOverrideCurator.getList(key);
    assertEquals(1, remaining.size());
    assertEquals("remaining-override", remaining.get(0).getName());
}
Also used : ActivationKeyContentOverride(org.candlepin.model.activationkeys.ActivationKeyContentOverride) Test(org.junit.Test)

Aggregations

ActivationKeyContentOverride (org.candlepin.model.activationkeys.ActivationKeyContentOverride)26 Test (org.junit.Test)22 LinkedList (java.util.LinkedList)4 ContentOverride (org.candlepin.model.ContentOverride)3 Product (org.candlepin.model.Product)3 Release (org.candlepin.model.Release)3 ActivationKeyPool (org.candlepin.model.activationkeys.ActivationKeyPool)2 ActivationKeyDTO (org.candlepin.dto.api.v1.ActivationKeyDTO)1 ConsumerContentOverride (org.candlepin.model.ConsumerContentOverride)1 Owner (org.candlepin.model.Owner)1 Pool (org.candlepin.model.Pool)1 ActivationKey (org.candlepin.model.activationkeys.ActivationKey)1