use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class EventBuilder method setEventData.
/**
* This method is used with any type of event and any target entity.
* <p>
* Note: For {@link Type#MODIFIED} events, it can be called twice consecutively
* to first pass in the original, and then the updated entity. Alternatively,
* {@link #setEventData(Eventful, Eventful)} can be used in the same use case.
* </p>
* @param entity The target entity of the Event
* @return The builder object
*/
public EventBuilder setEventData(Eventful entity) {
if (entity != null) {
// Be careful to check for null before setting so we don't overwrite anything useful
if (entity instanceof Named && ((Named) entity).getName() != null) {
event.setTargetName(((Named) entity).getName());
}
if (entity instanceof Owned) {
String ownerId = ((Owned) entity).getOwnerId();
if (ownerId != null) {
event.setOwnerId(ownerId);
}
}
if (entity instanceof Entitlement) {
event.setReferenceType(Event.ReferenceType.POOL);
Pool referencedPool = ((Entitlement) entity).getPool();
if (referencedPool != null && referencedPool.getId() != null) {
event.setReferenceId(referencedPool.getId());
}
}
if (entity.getId() != null) {
event.setEntityId((String) entity.getId());
if (entity instanceof ConsumerProperty) {
Consumer owningConsumer = ((ConsumerProperty) entity).getConsumer();
if (owningConsumer != null && owningConsumer.getUuid() != null) {
event.setConsumerUuid(owningConsumer.getUuid());
}
}
}
if (event.getTarget().equals(Target.POOL) && event.getType().equals(Type.CREATED)) {
Map<String, String> eventData = new HashMap<>();
eventData.put("subscriptionId", ((Pool) entity).getSubscriptionId());
try {
event.setEventData(mapper.writeValueAsString(eventData));
} catch (JsonProcessingException e) {
log.error("Error while building JSON for pool.created event.", e);
throw new IseException("Error while building JSON for pool.created event.");
}
}
}
return this;
}
use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class ComplianceOp method preProcess.
/**
* Computes the compliance status implemented in java script.
* does not compute the hash or apply the status.
* requires only the consumer to be locked.
* @param context
*/
@Override
public boolean preProcess(BindContext context) {
Consumer consumer = context.getLockedConsumer();
Map<String, Entitlement> entitlementMap = context.getEntitlementMap();
Map<String, PoolQuantity> poolQuantityMap = context.getPoolQuantities();
for (Map.Entry<String, Entitlement> entry : entitlementMap.entrySet()) {
PoolQuantity pq = poolQuantityMap.get(entry.getKey());
entry.getValue().setPool(pq.getPool());
}
status = complianceRules.getStatus(consumer, entitlementMap.values(), null, false, false, false, false);
for (Map.Entry<String, Entitlement> entry : entitlementMap.entrySet()) {
PoolQuantity pq = poolQuantityMap.get(entry.getKey());
entry.getValue().setPool(null);
}
return true;
}
use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class DefaultEntitlementCertServiceAdapterTest method setUp.
@Before
public void setUp() {
Injector injector = Guice.createInjector(new TestingModules.MockJpaModule(), new TestingModules.ServletEnvironmentModule(), new TestingModules.StandardTest());
injector.injectMembers(this);
v3extensionUtil = new X509V3ExtensionUtil(config, entCurator);
certServiceAdapter = new DefaultEntitlementCertServiceAdapter(mockedPKI, extensionUtil, v3extensionUtil, mock(EntitlementCertificateCurator.class), keyPairCurator, serialCurator, ownerCurator, entCurator, I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK), config, productCurator, this.mockConsumerTypeCurator, this.mockEnvironmentCurator);
product = TestUtil.createProduct("12345", "a product");
product.setAttribute(Product.Attributes.VERSION, "version");
product.setAttribute(Product.Attributes.VARIANT, "variant");
product.setAttribute(Product.Attributes.TYPE, "SVC");
product.setAttribute(Product.Attributes.ARCHITECTURE, ARCH_LABEL);
largeContentProduct = TestUtil.createProduct("67890", "large content product");
largeContentProduct.setAttribute(Product.Attributes.VERSION, "version");
largeContentProduct.setAttribute(Product.Attributes.VARIANT, "variant");
largeContentProduct.setAttribute(Product.Attributes.TYPE, "SVC");
largeContentProduct.setAttribute(Product.Attributes.ARCHITECTURE, ARCH_LABEL);
content = createContent(CONTENT_NAME, CONTENT_ID, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, CONTENT_URL, CONTENT_GPG_URL, ARCH_LABEL);
content.setMetadataExpire(CONTENT_METADATA_EXPIRE);
content.setRequiredTags(REQUIRED_TAGS);
kickstartContent = createContent(CONTENT_NAME, CONTENT_ID_KICKSTART, CONTENT_LABEL, CONTENT_TYPE_KICKSTART, CONTENT_VENDOR, CONTENT_URL, CONTENT_GPG_URL, ARCH_LABEL);
kickstartContent.setMetadataExpire(CONTENT_METADATA_EXPIRE);
kickstartContent.setRequiredTags(REQUIRED_TAGS);
fileContent = createContent(CONTENT_NAME, CONTENT_ID_FILE, CONTENT_LABEL, CONTENT_TYPE_FILE, CONTENT_VENDOR, CONTENT_URL, CONTENT_GPG_URL, ARCH_LABEL);
fileContent.setMetadataExpire(CONTENT_METADATA_EXPIRE);
fileContent.setRequiredTags(REQUIRED_TAGS);
unknownTypeContent = createContent(CONTENT_NAME, CONTENT_ID_UNKNOWN, CONTENT_LABEL, CONTENT_TYPE_UNKNOWN, CONTENT_VENDOR, CONTENT_URL_UNKNOWN_TYPE, CONTENT_GPG_URL, ARCH_LABEL);
unknownTypeContent.setMetadataExpire(CONTENT_METADATA_EXPIRE);
unknownTypeContent.setRequiredTags(REQUIRED_TAGS);
String emptyArches = "";
noArchContent = createContent(CONTENT_NAME, CONTENT_ID, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, CONTENT_URL, CONTENT_GPG_URL, emptyArches);
superContent = new HashSet<>();
int index = 0;
for (String url : testUrls) {
++index;
superContent.add(createContent(CONTENT_NAME + "-" + index, CONTENT_ID + "-" + index, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, url, CONTENT_GPG_URL, ARCH_LABEL));
}
largeContent = new HashSet<>();
index = 0;
for (String url : largeTestUrls) {
++index;
largeContent.add(createContent(CONTENT_NAME + "-" + index, CONTENT_ID + "-" + index, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, url, CONTENT_GPG_URL, ARCH_LABEL));
}
subscription = TestUtil.createSubscription(null, product, new HashSet<>());
subscription.setId("1");
subscription.setQuantity(1L);
largeContentSubscription = TestUtil.createSubscription(null, largeContentProduct, new HashSet<>());
largeContentSubscription.setId("2");
largeContentSubscription.setQuantity(1L);
owner = new Owner();
owner.setId(TestUtil.randomString());
when(ownerCurator.findOwnerById(owner.getId())).thenReturn(owner);
pool = new Pool();
pool.setQuantity(1L);
pool.setProduct(product);
pool.setStartDate(subscription.getStartDate());
pool.setEndDate(subscription.getEndDate());
largeContentPool = new Pool();
largeContentPool.setProduct(largeContentProduct);
ConsumerType type = new ConsumerType(ConsumerType.ConsumerTypeEnum.SYSTEM);
type.setId("test-id");
consumer = new Consumer("Test Consumer", "bob", owner, type);
consumer.setUuid("test-consumer");
when(this.mockConsumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(type);
when(this.mockConsumerTypeCurator.find(eq(type.getId()))).thenReturn(type);
entitlement = new Entitlement();
entitlement.setQuantity(new Integer(ENTITLEMENT_QUANTITY));
entitlement.setConsumer(consumer);
entitlement.setPool(pool);
entitlement.setOwner(owner);
largeContentEntitlement = new Entitlement();
largeContentEntitlement.setQuantity(new Integer(ENTITLEMENT_QUANTITY));
largeContentEntitlement.setConsumer(consumer);
largeContentEntitlement.setPool(largeContentPool);
largeContentEntitlement.setOwner(owner);
product.addContent(content, false);
Set empty = new HashSet<String>();
when(productCurator.getPoolProvidedProductUuids(anyString())).thenReturn(empty);
// when(productAdapter.getProductById(eq(product.getOwner()), eq(product.getId())))
// .thenReturn(product);
// when(productAdapter.getProductById(
// eq(largeContentProduct.getOwner()), eq(largeContentProduct.getId()))
// ).thenReturn(largeContentProduct);
}
use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class DefaultEntitlementCertServiceAdapterTest method testFilterProductContent.
@Test
public void testFilterProductContent() {
Product modProduct = new Product("12345", "a product", "variant", "version", ARCH_LABEL, "SVC");
// Use this set for successful providing queries:
Set<Entitlement> successResult = new HashSet<>();
// just need something in there
successResult.add(new Entitlement());
Content normalContent = createContent(CONTENT_NAME, CONTENT_ID, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, CONTENT_URL, CONTENT_GPG_URL, ARCH_LABEL);
// Change label to prevent an equals match:
Content modContent = createContent(CONTENT_NAME, CONTENT_ID + "_2", "differentlabel", CONTENT_TYPE, CONTENT_VENDOR, CONTENT_URL, CONTENT_GPG_URL, ARCH_LABEL);
modContent.setLabel("mod content");
Set<String> modifiedProductIds = new HashSet<>(Arrays.asList(new String[] { "product1", "product2" }));
modContent.setModifiedProductIds(modifiedProductIds);
modProduct.addContent(normalContent, false);
modProduct.addContent(modContent, false);
// First check that if we have no entitlements providing the modified
// products,
// the content set is filtered out:
// Mod content should get filtered out because we have no ents providing
// the product it modifies:
assertEquals(1, extensionUtil.filterProductContent(modProduct, consumer, new HashMap<>(), false, new HashSet<>()).size());
// Now mock that we have an entitlement providing one of the modified
// products,
// and we should see both content sets included in the cert:
Set<String> entitledProdIds = new HashSet<>();
entitledProdIds.add("product2");
assertEquals(2, extensionUtil.filterProductContent(modProduct, consumer, new HashMap<>(), false, entitledProdIds).size());
// Make sure that we filter by environment when asked.
Environment environment = this.mockEnvironment(new Environment());
consumer.setEnvironment(environment);
Map<String, EnvironmentContent> promotedContent = new HashMap<>();
promotedContent.put(normalContent.getId(), new EnvironmentContent(environment, normalContent, true));
assertEquals(1, extensionUtil.filterProductContent(modProduct, consumer, promotedContent, true, entitledProdIds).size());
}
use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class InstalledProductStatusCalculatorTest method validRangeForUnmappedGuestEntitlement.
@Test
public void validRangeForUnmappedGuestEntitlement() {
Date now = new Date();
Owner owner = TestUtil.createOwner();
Product product = TestUtil.createProduct("p1", "product1");
Consumer consumer = this.mockConsumer(owner, product);
consumer.setCreated(now);
DateRange range = this.rangeRelativeToDate(now, -6, 6);
Entitlement entitlement = this.mockUnmappedGuestEntitlement(owner, consumer, product, range, product);
consumer.addEntitlement(entitlement);
this.mockConsumerEntitlements(consumer, consumer.getEntitlements());
this.mockOwnerProducts(owner, Arrays.asList(product));
this.consumerEnricher.enrich(consumer);
Date expectedEnd = new Date(now.getTime() + (24 * 60 * 60 * 1000));
ConsumerInstalledProduct cip = this.getInstalledProduct(consumer, product);
assertEquals(range.getStartDate(), cip.getStartDate());
assertEquals(expectedEnd, cip.getEndDate());
}
Aggregations