use of org.candlepin.model.ConsumerInstalledProduct in project candlepin by candlepin.
the class ConsumerResource method checkForInstalledProductsUpdate.
/**
* Check if the consumers installed products have changed. If they do not appear to
* have been specified in this PUT, skip updating installed products entirely.
* <p></p>
* It will return true if installed products were included in request and have changed.
*
* @param existing existing consumer
* @param incoming incoming consumer
* @return a boolean
*/
private boolean checkForInstalledProductsUpdate(Consumer existing, ConsumerDTO incoming) {
if (incoming.getInstalledProducts() == null) {
log.debug("Installed packages not included in this consumer update, skipping update.");
return false;
}
Set<ConsumerInstalledProduct> incomingInstalledProducts = populateInstalledProducts(existing, incoming);
if (existing.getInstalledProducts() == null || !existing.getInstalledProducts().equals(incomingInstalledProducts)) {
log.info("Updating installed products.");
// new collection here without breaking things.
if (existing.getInstalledProducts() != null) {
existing.getInstalledProducts().clear();
}
for (ConsumerInstalledProduct cip : incomingInstalledProducts) {
existing.addInstalledProduct(cip);
}
return true;
}
log.debug("No change to installed products.");
return false;
}
use of org.candlepin.model.ConsumerInstalledProduct in project candlepin by candlepin.
the class ConsumerBindUtil method handleActivationKeyAutoBind.
private void handleActivationKeyAutoBind(Consumer consumer, ActivationKey key) throws AutobindDisabledForOwnerException {
try {
Set<String> productIds = new HashSet<>();
List<String> poolIds = new ArrayList<>();
for (Product akp : key.getProducts()) {
productIds.add(akp.getId());
}
for (ConsumerInstalledProduct cip : consumer.getInstalledProducts()) {
productIds.add(cip.getProductId());
}
for (ActivationKeyPool p : key.getPools()) {
poolIds.add(p.getPool().getId());
}
Owner owner = ownerCurator.findOwnerById(consumer.getOwnerId());
AutobindData autobindData = AutobindData.create(consumer, owner).forProducts(productIds.toArray(new String[0])).withPools(poolIds);
List<Entitlement> ents = entitler.bindByProducts(autobindData);
entitler.sendEvents(ents);
} catch (ForbiddenException fe) {
throw fe;
} catch (CertVersionConflictException cvce) {
throw cvce;
} catch (RuntimeException re) {
log.warn("Unable to attach a subscription for a product that " + "has no pool: " + re.getMessage());
}
}
use of org.candlepin.model.ConsumerInstalledProduct in project candlepin by candlepin.
the class ConsumerEnricher method enrich.
public void enrich(Consumer consumer) {
if (consumer == null || CollectionUtils.isEmpty(consumer.getInstalledProducts())) {
// No consumer or the consumer doesn't have any installed products -- nothing to do here.
return;
}
ComplianceStatus status = this.complianceRules.getStatus(consumer, null, null, false, true, true, true);
Map<String, DateRange> ranges = status.getProductComplianceDateRanges();
// Compile the product IDs for the products we're going to be enriching
Set<String> productIds = new HashSet<>();
Map<String, Product> productMap = new HashMap<>();
for (ConsumerInstalledProduct cip : consumer.getInstalledProducts()) {
productIds.add(cip.getProductId());
}
for (Product product : this.ownerProductCurator.getProductsByIds(consumer.getOwnerId(), productIds)) {
productMap.put(product.getId(), product);
}
// Perform enrichment of the consumer's installed products
for (ConsumerInstalledProduct cip : consumer.getInstalledProducts()) {
String pid = cip.getProductId();
DateRange range = ranges != null ? ranges.get(pid) : null;
// do those first.
if (status.getCompliantProducts().containsKey(pid)) {
cip.setStatus(GREEN_STATUS);
} else if (status.getPartiallyCompliantProducts().containsKey(pid)) {
cip.setStatus(YELLOW_STATUS);
} else if (status.getNonCompliantProducts().contains(pid)) {
cip.setStatus(RED_STATUS);
}
// Set the compliance date range if we have it
if (range != null) {
cip.setStartDate(range.getStartDate());
cip.setEndDate(range.getEndDate());
}
// Fetch missing product information from the actual product
Product product = productMap.get(pid);
if (product != null) {
if (cip.getVersion() == null) {
cip.setVersion(product.getAttributeValue(Product.Attributes.VERSION));
}
if (cip.getArch() == null) {
cip.setArch(product.getAttributeValue(Product.Attributes.ARCHITECTURE));
}
}
}
}
use of org.candlepin.model.ConsumerInstalledProduct 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.ConsumerInstalledProduct 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.setUuid(source.getUuid()).setUsername(source.getUsername()).setServiceLevel(source.getServiceLevel()).setFacts(source.getFacts());
// 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));
}
Set<ConsumerInstalledProduct> installedProducts = source.getInstalledProducts();
if (installedProducts != null) {
Set<String> ips = new HashSet<>();
for (ConsumerInstalledProduct cip : installedProducts) {
if (cip != null && cip.getProductId() != null) {
ips.add(cip.getProductId());
}
}
dest.setInstalledProducts(ips);
}
Set<ConsumerCapability> capabilities = source.getCapabilities();
if (capabilities != null) {
Set<String> capabilitiesDTO = new HashSet<>();
for (ConsumerCapability capability : capabilities) {
if (capability != null && capability.getName() != null) {
capabilitiesDTO.add(capability.getName());
}
}
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);
}
} else {
dest.setOwner(null);
dest.setInstalledProducts(null);
dest.setCapabilities(null);
dest.setType(null);
}
return dest;
}
Aggregations