Search in sources :

Example 1 with ObjectModelResolver

use of org.kie.internal.runtime.conf.ObjectModelResolver in project jbpm by kiegroup.

the class CaseConfigurationDeploymentListener method getEventListenerFromDescriptor.

protected List<CaseEventListener> getEventListenerFromDescriptor(InternalRuntimeManager runtimeManager) {
    List<CaseEventListener> listeners = new ArrayList<CaseEventListener>();
    DeploymentDescriptor descriptor = runtimeManager.getDeploymentDescriptor();
    if (descriptor != null) {
        Map<String, Object> params = getParametersMap(runtimeManager);
        for (ObjectModel model : descriptor.getEventListeners()) {
            ObjectModelResolver resolver = ObjectModelResolverProvider.get(model.getResolver());
            if (resolver == null) {
                logger.warn("Unable to find ObjectModelResolver for {}", model.getResolver());
                continue;
            }
            try {
                Object listenerInstance = resolver.getInstance(model, runtimeManager.getEnvironment().getClassLoader(), params);
                if (listenerInstance != null && CaseEventListener.class.isAssignableFrom(listenerInstance.getClass())) {
                    listeners.add((CaseEventListener) listenerInstance);
                } else {
                    // close/cleanup instance as it is not going to be used at the moment, except these that are cacheable
                    if (listenerInstance instanceof Closeable && !(listenerInstance instanceof Cacheable)) {
                        ((Closeable) listenerInstance).close();
                    }
                }
            } catch (Exception e) {
                logger.debug("Unable to build listener {}", model);
            }
        }
    }
    return listeners;
}
Also used : ObjectModel(org.kie.internal.runtime.conf.ObjectModel) Cacheable(org.kie.internal.runtime.Cacheable) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) Closeable(org.kie.internal.runtime.Closeable) ArrayList(java.util.ArrayList) ObjectModelResolver(org.kie.internal.runtime.conf.ObjectModelResolver) CaseEventListener(org.jbpm.casemgmt.api.event.CaseEventListener) NotifyParentCaseEventListener(org.jbpm.casemgmt.impl.wih.NotifyParentCaseEventListener)

Example 2 with ObjectModelResolver

use of org.kie.internal.runtime.conf.ObjectModelResolver in project jbpm by kiegroup.

the class MVELObjectModelResolverTest method testSimpleStaticObjectModel.

@Test
public void testSimpleStaticObjectModel() {
    ObjectModel model = new ObjectModel("Integer.parseInt(\"10\")");
    ObjectModelResolver resolver = new MVELObjectModelResolver();
    Object result = resolver.getInstance(model, this.getClass().getClassLoader(), new HashMap<String, Object>());
    assertNotNull(result);
    assertTrue(result instanceof Integer);
    assertEquals(10, ((Integer) result).intValue());
}
Also used : ObjectModel(org.kie.internal.runtime.conf.ObjectModel) ObjectModelResolver(org.kie.internal.runtime.conf.ObjectModelResolver) SimpleCustomObject(org.jbpm.runtime.manager.impl.deploy.testobject.SimpleCustomObject) Test(org.junit.Test)

Example 3 with ObjectModelResolver

use of org.kie.internal.runtime.conf.ObjectModelResolver in project jbpm by kiegroup.

the class ReflectionObjectModelResolverTest method testSimpleNotExistingObjectModel.

@Test(expected = IllegalArgumentException.class)
public void testSimpleNotExistingObjectModel() {
    ObjectModel model = new ObjectModel("org.jbpm.runtime.manager.impl.deploy.testobject.NotExistingObject");
    ObjectModelResolver resolver = new ReflectionObjectModelResolver();
    resolver.getInstance(model, this.getClass().getClassLoader(), new HashMap<String, Object>());
}
Also used : ObjectModel(org.kie.internal.runtime.conf.ObjectModel) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) ObjectModelResolver(org.kie.internal.runtime.conf.ObjectModelResolver) ThirdLevelCustomObject(org.jbpm.runtime.manager.impl.deploy.testobject.ThirdLevelCustomObject) SimpleCustomObject(org.jbpm.runtime.manager.impl.deploy.testobject.SimpleCustomObject) EmbedingCustomObject(org.jbpm.runtime.manager.impl.deploy.testobject.EmbedingCustomObject) Test(org.junit.Test)

Example 4 with ObjectModelResolver

use of org.kie.internal.runtime.conf.ObjectModelResolver in project jbpm by kiegroup.

the class ReflectionObjectModelResolverTest method testSimpleSingleObjectArgObjectModel.

@Test
public void testSimpleSingleObjectArgObjectModel() {
    ObjectModel model = new ObjectModel("org.jbpm.runtime.manager.impl.deploy.testobject.EmbedingCustomObject", new Object[] { new ObjectModel("org.jbpm.runtime.manager.impl.deploy.testobject.SimpleCustomObject", new Object[] { "john" }), "testing object model" });
    ObjectModelResolver resolver = new ReflectionObjectModelResolver();
    Object result = resolver.getInstance(model, this.getClass().getClassLoader(), new HashMap<String, Object>());
    assertNotNull(result);
    assertTrue(result instanceof EmbedingCustomObject);
    assertEquals("testing object model", ((EmbedingCustomObject) result).getDescription());
    SimpleCustomObject customObject = ((EmbedingCustomObject) result).getCustomObject();
    assertNotNull(customObject);
    assertEquals("john", customObject.getName());
}
Also used : EmbedingCustomObject(org.jbpm.runtime.manager.impl.deploy.testobject.EmbedingCustomObject) ObjectModel(org.kie.internal.runtime.conf.ObjectModel) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) ObjectModelResolver(org.kie.internal.runtime.conf.ObjectModelResolver) ThirdLevelCustomObject(org.jbpm.runtime.manager.impl.deploy.testobject.ThirdLevelCustomObject) SimpleCustomObject(org.jbpm.runtime.manager.impl.deploy.testobject.SimpleCustomObject) EmbedingCustomObject(org.jbpm.runtime.manager.impl.deploy.testobject.EmbedingCustomObject) SimpleCustomObject(org.jbpm.runtime.manager.impl.deploy.testobject.SimpleCustomObject) Test(org.junit.Test)

Example 5 with ObjectModelResolver

use of org.kie.internal.runtime.conf.ObjectModelResolver in project jbpm by kiegroup.

the class ReflectionObjectModelResolverTest method testSimpleNoArgNamedObjectModel.

@Test
public void testSimpleNoArgNamedObjectModel() {
    NamedObjectModel model = new NamedObjectModel("CustomObject", "org.jbpm.runtime.manager.impl.deploy.testobject.SimpleCustomObject");
    assertEquals("CustomObject", model.getName());
    ObjectModelResolver resolver = new ReflectionObjectModelResolver();
    Object result = resolver.getInstance(model, this.getClass().getClassLoader(), new HashMap<String, Object>());
    assertNotNull(result);
    assertTrue(result instanceof SimpleCustomObject);
    assertEquals("default", ((SimpleCustomObject) result).getName());
}
Also used : NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) ObjectModelResolver(org.kie.internal.runtime.conf.ObjectModelResolver) ThirdLevelCustomObject(org.jbpm.runtime.manager.impl.deploy.testobject.ThirdLevelCustomObject) SimpleCustomObject(org.jbpm.runtime.manager.impl.deploy.testobject.SimpleCustomObject) EmbedingCustomObject(org.jbpm.runtime.manager.impl.deploy.testobject.EmbedingCustomObject) SimpleCustomObject(org.jbpm.runtime.manager.impl.deploy.testobject.SimpleCustomObject) Test(org.junit.Test)

Aggregations

ObjectModelResolver (org.kie.internal.runtime.conf.ObjectModelResolver)11 SimpleCustomObject (org.jbpm.runtime.manager.impl.deploy.testobject.SimpleCustomObject)10 Test (org.junit.Test)10 ObjectModel (org.kie.internal.runtime.conf.ObjectModel)10 EmbedingCustomObject (org.jbpm.runtime.manager.impl.deploy.testobject.EmbedingCustomObject)7 ThirdLevelCustomObject (org.jbpm.runtime.manager.impl.deploy.testobject.ThirdLevelCustomObject)7 NamedObjectModel (org.kie.internal.runtime.conf.NamedObjectModel)7 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 CaseEventListener (org.jbpm.casemgmt.api.event.CaseEventListener)1 NotifyParentCaseEventListener (org.jbpm.casemgmt.impl.wih.NotifyParentCaseEventListener)1 Cacheable (org.kie.internal.runtime.Cacheable)1 Closeable (org.kie.internal.runtime.Closeable)1 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)1