Search in sources :

Example 26 with Environment

use of org.candlepin.model.Environment in project candlepin by candlepin.

the class DefaultContentAccessCertServiceAdapter method createDN.

private String createDN(Consumer consumer, Owner owner) {
    StringBuilder sb = new StringBuilder("CN=");
    sb.append(consumer.getUuid());
    sb.append(", O=");
    sb.append(owner.getKey());
    if (consumer.getEnvironmentId() != null) {
        Environment environment = this.environmentCurator.getConsumerEnvironment(consumer);
        sb.append(", OU=");
        sb.append(environment.getName());
    }
    return sb.toString();
}
Also used : Environment(org.candlepin.model.Environment)

Example 27 with Environment

use of org.candlepin.model.Environment in project candlepin by candlepin.

the class ConsumerTranslator method populate.

/**
 * {@inheritDoc}
 */
@Override
public ConsumerDTO populate(ModelTranslator translator, Consumer source, ConsumerDTO dest) {
    dest = super.populate(translator, source, dest);
    dest.setId(source.getId()).setUuid(source.getUuid()).setName(source.getName()).setUsername(source.getUsername()).setEntitlementStatus(source.getEntitlementStatus()).setServiceLevel(source.getServiceLevel()).setEntitlementCount(source.getEntitlementCount()).setFacts(source.getFacts()).setLastCheckin(source.getLastCheckin()).setCanActivate(source.isCanActivate()).setContentTags(source.getContentTags()).setAutoheal(source.isAutoheal()).setRecipientOwnerKey(source.getRecipientOwnerKey()).setAnnotations(source.getAnnotations()).setContentAccessMode(source.getContentAccessMode());
    Release release = source.getReleaseVer();
    if (release != null) {
        dest.setReleaseVersion(release.getReleaseVer());
    }
    // Process nested objects if we have a ModelTranslator to use to the translation...
    if (translator != null) {
        if (StringUtils.isNotEmpty(source.getOwnerId())) {
            Owner owner = ownerCurator.findOwnerById(source.getOwnerId());
            dest.setOwner(translator.translate(owner, OwnerDTO.class));
        }
        Environment environment = this.environmentCurator.getConsumerEnvironment(source);
        dest.setEnvironment(translator.translate(environment, EnvironmentDTO.class));
        Set<ConsumerInstalledProduct> installedProducts = source.getInstalledProducts();
        if (installedProducts != null) {
            ObjectTranslator<ConsumerInstalledProduct, ConsumerInstalledProductDTO> cipTranslator = translator.findTranslatorByClass(ConsumerInstalledProduct.class, ConsumerInstalledProductDTO.class);
            Set<ConsumerInstalledProductDTO> ips = new HashSet<>();
            for (ConsumerInstalledProduct cip : installedProducts) {
                if (cip != null) {
                    ConsumerInstalledProductDTO dto = cipTranslator.translate(translator, cip);
                    if (dto != null) {
                        ips.add(dto);
                    }
                }
            }
            dest.setInstalledProducts(ips);
        }
        Set<ConsumerCapability> capabilities = source.getCapabilities();
        if (capabilities != null) {
            Set<CapabilityDTO> capabilitiesDTO = new HashSet<>();
            ObjectTranslator<ConsumerCapability, CapabilityDTO> capabilityTranslator = translator.findTranslatorByClass(ConsumerCapability.class, CapabilityDTO.class);
            for (ConsumerCapability capability : capabilities) {
                if (capability != null) {
                    CapabilityDTO dto = capabilityTranslator.translate(translator, capability);
                    if (dto != null) {
                        capabilitiesDTO.add(dto);
                    }
                }
            }
            dest.setCapabilities(capabilitiesDTO);
        }
        // Temporary measure to maintain API compatibility
        if (source.getTypeId() != null) {
            ConsumerType ctype = this.consumerTypeCurator.getConsumerType(source);
            dest.setType(translator.translate(ctype, ConsumerTypeDTO.class));
        } else {
            dest.setType(null);
        }
        // This will put in the property so that the virtWho instances won't error
        dest.setGuestIds(new ArrayList<>());
        dest.setHypervisorId(translator.translate(source.getHypervisorId(), HypervisorIdDTO.class));
        dest.setIdCert(translator.translate(source.getIdCert(), CertificateDTO.class));
    } else {
        dest.setReleaseVersion(null);
        dest.setOwner(null);
        dest.setEnvironment(null);
        dest.setInstalledProducts(null);
        dest.setCapabilities(null);
        dest.setHypervisorId(null);
        dest.setType(null);
        dest.setIdCert(null);
    }
    return dest;
}
Also used : Owner(org.candlepin.model.Owner) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ConsumerCapability(org.candlepin.model.ConsumerCapability) Environment(org.candlepin.model.Environment) ConsumerType(org.candlepin.model.ConsumerType) Release(org.candlepin.model.Release) HashSet(java.util.HashSet)

Example 28 with Environment

use of org.candlepin.model.Environment in project candlepin by candlepin.

the class RegenEnvEntitlementCertsJob method toExecute.

@Override
public void toExecute(JobExecutionContext arg0) throws JobExecutionException {
    Environment env = (Environment) arg0.getJobDetail().getJobDataMap().get(ENV);
    Set<String> contentIds = (Set<String>) arg0.getJobDetail().getJobDataMap().get(CONTENT);
    Boolean lazy = arg0.getMergedJobDataMap().getBoolean(LAZY_REGEN);
    this.poolManager.regenerateCertificatesOf(env, contentIds, lazy);
}
Also used : Set(java.util.Set) Environment(org.candlepin.model.Environment)

Example 29 with Environment

use of org.candlepin.model.Environment in project candlepin by candlepin.

the class ConsumerResourceUpdateTest method canUpdateConsumerEnvironment.

@Test
public void canUpdateConsumerEnvironment() {
    Environment changedEnvironment = new Environment("42", "environment", null);
    Consumer existing = getFakeConsumer();
    ConsumerDTO updated = new ConsumerDTO();
    updated.setEnvironment(translator.translate(changedEnvironment, EnvironmentDTO.class));
    when(environmentCurator.find(changedEnvironment.getId())).thenReturn(changedEnvironment);
    resource.updateConsumer(existing.getUuid(), updated, principal);
    verify(poolManager, atMost(1)).regenerateCertificatesOf(existing, true);
    verify(sink).queueEvent((Event) any());
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) EnvironmentDTO(org.candlepin.dto.api.v1.EnvironmentDTO) Environment(org.candlepin.model.Environment) Test(org.junit.Test)

Aggregations

Environment (org.candlepin.model.Environment)29 EnvironmentContent (org.candlepin.model.EnvironmentContent)10 Test (org.junit.Test)9 HashSet (java.util.HashSet)8 Owner (org.candlepin.model.Owner)7 ApiOperation (io.swagger.annotations.ApiOperation)6 HashMap (java.util.HashMap)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 Content (org.candlepin.model.Content)6 ApiResponses (io.swagger.annotations.ApiResponses)5 Date (java.util.Date)5 Consumer (org.candlepin.model.Consumer)5 NotFoundException (org.candlepin.common.exceptions.NotFoundException)4 ConsumerCapability (org.candlepin.model.ConsumerCapability)4 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)4 ConsumerType (org.candlepin.model.ConsumerType)4 Release (org.candlepin.model.Release)4 Matchers.anyString (org.mockito.Matchers.anyString)4 KeyPair (java.security.KeyPair)3