Пример #1
0
 private void setEventData(AbstractHibernateObject entity) {
   // 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) {
     Owner entityOwner = ((Owned) entity).getOwner();
     if (entityOwner != null && entityOwner.getId() != null) {
       event.setOwnerId(entityOwner.getId());
     }
   }
   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 ((String) entity.getId() != null) {
     event.setEntityId((String) entity.getId());
     if (entity instanceof ConsumerProperty) {
       Consumer owningConsumer = ((ConsumerProperty) entity).getConsumer();
       if (owningConsumer != null && owningConsumer.getId() != null) {
         event.setConsumerId(owningConsumer.getId());
       }
     }
   }
 }
Пример #2
0
  @Test
  public void createEntitlementShouldUpdateConsumer() throws Exception {
    Long numAvailEntitlements = 1L;

    Product newProduct = TestUtil.createProduct();
    productCurator.create(newProduct);

    Pool consumerPool =
        createPoolAndSub(
            owner,
            newProduct,
            numAvailEntitlements,
            TestUtil.createDate(2009, 11, 30),
            TestUtil.createDate(2050, 11, 30));
    poolCurator.create(consumerPool);

    assertEquals(0, consumer.getEntitlements().size());
    poolManager.entitleByProduct(consumer, newProduct.getId());

    assertEquals(1, consumerCurator.find(consumer.getId()).getEntitlements().size());
  }