org.kie.api.event.rule.ObjectInsertedEvent Java Examples

The following examples show how to use org.kie.api.event.rule.ObjectInsertedEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RuleRuntimeEventTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testEventModel() throws Exception {
    final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_EventModel.drl"));
    final KieSession wm = createKnowledgeSession(kbase);

    final RuleRuntimeEventListener wmel = mock(RuleRuntimeEventListener.class);
    wm.addEventListener(wmel);

    final Cheese stilton = new Cheese("stilton", 15);

    final FactHandle stiltonHandle = wm.insert(stilton);

    final ArgumentCaptor<ObjectInsertedEvent> oic = ArgumentCaptor.forClass(org.kie.api.event.rule.ObjectInsertedEvent.class);
    verify(wmel).objectInserted(oic.capture());
    assertSame(stiltonHandle, oic.getValue().getFactHandle());

    wm.update(stiltonHandle, stilton);
    final ArgumentCaptor<org.kie.api.event.rule.ObjectUpdatedEvent> ouc = ArgumentCaptor.forClass(org.kie.api.event.rule.ObjectUpdatedEvent.class);
    verify(wmel).objectUpdated(ouc.capture());
    assertSame(stiltonHandle, ouc.getValue().getFactHandle());

    wm.delete(stiltonHandle);
    final ArgumentCaptor<ObjectDeletedEvent> orc = ArgumentCaptor.forClass(ObjectDeletedEvent.class);
    verify(wmel).objectDeleted(orc.capture());
    assertSame(stiltonHandle, orc.getValue().getFactHandle());

}
 
Example #2
Source File: TrackingRuleRuntimeEventListener.java    From qzr with Apache License 2.0 5 votes vote down vote up
public Object findInsertedFact(String factType, String[] filters) {
    BeanMatcher matcher = new BeanMatcher();
    
    for (ObjectInsertedEvent event : this.insertions) {
        Object fact = event.getObject();

        if (factType.equals(fact.getClass().getSimpleName())) {
            if (matcher.matches(fact, filters)) {
                return fact;
            }
        }
    }
    return null;
}
 
Example #3
Source File: TrackingRuleRuntimeEventListener.java    From qzr with Apache License 2.0 5 votes vote down vote up
@Override
public void objectInserted(final ObjectInsertedEvent event) {
    if ((handleFilter == null  && classFilter == null)
            || event.getFactHandle() == handleFilter
            || event.getObject().getClass().equals(classFilter)) {
        insertions.add(event);
        allEvents.add(event);
        log.trace("Insertion: " + DroolsUtil.objectDetails(event.getObject()));
    }
}
 
Example #4
Source File: LoggingRuleRuntimeEventListener.java    From qzr with Apache License 2.0 5 votes vote down vote up
@Override
public void objectInserted(final ObjectInsertedEvent event) {
    if ((handleFilter == null  && classFilter == null)
            || event.getFactHandle() == handleFilter
            || event.getObject().getClass().equals(classFilter)) {
        log.trace("Insertion: " + DroolsUtil.objectDetails(event.getObject()));
    }
}
 
Example #5
Source File: HrmaxRulesTest.java    From qzr with Apache License 2.0 5 votes vote down vote up
/**
 * If this passes, then the Drools {@link KieSession} was started without
 * errors.
 */
@Test
public void shouldConfigureDroolsComponents() {
    assertNotNull(kieSession);
    
    for (ObjectInsertedEvent ev : workingMemoryEventListener.getInsertions()) {
        System.out.println(DroolsUtil.objectDetails(ev.getObject()));
    }
}
 
Example #6
Source File: CepEngineImpl.java    From hawkular-alerts with Apache License 2.0 4 votes vote down vote up
@Override
public void objectInserted(ObjectInsertedEvent event) {
    log.debug(event);
}
 
Example #7
Source File: DebugRuleRuntimeEventListener.java    From servicemix with Apache License 2.0 4 votes vote down vote up
/**
 * @see RuleRuntimeEventListener#objectInserted(ObjectInsertedEvent)
 */
@Override
public void objectInserted(ObjectInsertedEvent event) {
    log.info("objectInserted {}", event);
}
 
Example #8
Source File: DebugRuleRuntimeEventListener.java    From servicemix with Apache License 2.0 4 votes vote down vote up
/**
 * @see RuleRuntimeEventListener#objectInserted(ObjectInsertedEvent)
 */
@Override
public void objectInserted(ObjectInsertedEvent event) {
    log.info("objectInserted {}", event);
}
 
Example #9
Source File: DebugRuleRuntimeEventListener.java    From servicemix with Apache License 2.0 4 votes vote down vote up
/**
 * @see RuleRuntimeEventListener#objectInserted(ObjectInsertedEvent)
 */
@Override
public void objectInserted(ObjectInsertedEvent event) {
    log.info("objectInserted {}", event);
}
 
Example #10
Source File: TrackingRuleRuntimeEventListener.java    From qzr with Apache License 2.0 4 votes vote down vote up
public List<ObjectInsertedEvent> getInsertions() {
    return insertions;
}
 
Example #11
Source File: WireListenerTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public void objectInserted(ObjectInsertedEvent event) {
    insertEvents.add(event);
}
 
Example #12
Source File: TestRuleRuntimeEventListener.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
public void objectInserted(final ObjectInsertedEvent event) {
    this.asserted++;
}
 
Example #13
Source File: DebugRuleRuntimeEventListener.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
public void objectInserted(ObjectInsertedEvent event) {
    logger.info( event.toString() );
}
 
Example #14
Source File: DefaultRuleRuntimeEventListener.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
public void objectInserted(final ObjectInsertedEvent event) {
    // intentionally left blank
}
 
Example #15
Source File: StatelessKieSessionMonitoringImpl.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public void objectInserted(ObjectInsertedEvent event) {
    this.data.objectsInserted.incrementAndGet();
}
 
Example #16
Source File: WorkingMemoryLogger.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
/**
 * @see org.kie.api.event.rule.RuleRuntimeEventListener
 */
public void objectInserted(final ObjectInsertedEvent event) {
    filterLogEvent( new ObjectLogEvent( LogEvent.INSERTED,
                                        ((InternalFactHandle) event.getFactHandle()).getId(),
                                        event.getObject().toString() ) );
}
 
Example #17
Source File: ListenersTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public void objectInserted(final ObjectInsertedEvent event) {
    super.objectInserted(event);
    this.fired.compareAndSet(false, true);
}