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