Search in sources :

Example 1 with NamedObjectModel

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

the class AbstractCaseServicesBaseTest method prepareDeploymentUnit.

protected DeploymentUnit prepareDeploymentUnit() {
    assertThat(deploymentService).isNotNull();
    KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    final DeploymentDescriptor descriptor = new DeploymentDescriptorImpl();
    descriptor.getBuilder().addEventListener(new NamedObjectModel("mvel", "processIdentity", "new org.jbpm.kie.services.impl.IdentityProviderAwareProcessListener(ksession)"));
    deploymentUnit.setDeploymentDescriptor(descriptor);
    deploymentUnit.setStrategy(RuntimeStrategy.PER_CASE);
    deploymentService.deploy(deploymentUnit);
    return deploymentUnit;
}
Also used : NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DeploymentDescriptorImpl(org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit)

Example 2 with NamedObjectModel

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

the class AbstractCaseServicesBaseTest method createDeploymentDescriptor.

protected DeploymentDescriptor createDeploymentDescriptor() {
    // add this listener by default
    listenerMvelDefinitions.add("new org.jbpm.casemgmt.impl.util.TrackingCaseEventListener()");
    DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.domain");
    DeploymentDescriptorBuilder ddBuilder = customDescriptor.getBuilder().runtimeStrategy(RuntimeStrategy.PER_CASE).addMarshalingStrategy(new ObjectModel("mvel", CaseMarshallerFactory.builder().withDoc().toString())).addWorkItemHandler(new NamedObjectModel("mvel", "StartCaseInstance", "new org.jbpm.casemgmt.impl.wih.StartCaseWorkItemHandler(ksession)"));
    listenerMvelDefinitions.forEach(listenerDefinition -> ddBuilder.addEventListener(new ObjectModel("mvel", listenerDefinition)));
    getProcessListeners().forEach(listener -> ddBuilder.addEventListener(listener));
    getWorkItemHandlers().forEach(listener -> ddBuilder.addWorkItemHandler(listener));
    return customDescriptor;
}
Also used : NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) ObjectModel(org.kie.internal.runtime.conf.ObjectModel) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DeploymentDescriptorImpl(org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl) DeploymentDescriptorBuilder(org.kie.internal.runtime.conf.DeploymentDescriptorBuilder)

Example 3 with NamedObjectModel

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

the class RuntimeEnvironmentBuilder method getDefault.

/**
 * Provides default configuration of <code>RuntimeEnvironmentBuilder</code> that is based on:
 * <ul>
 * 	<li>DefaultRuntimeEnvironment</li>
 * </ul>
 * This one is tailored to works smoothly with kjars as the notion of kbase and ksessions
 * @param releaseId <code>ReleaseId</code> that described the kjar
 * @param kbaseName name of the kbase defined in kmodule.xml stored in kjar
 * @param ksessionName name of the ksession define in kmodule.xml stored in kjar
 * @return new instance of <code>RuntimeEnvironmentBuilder</code> that is already preconfigured with defaults
 *
 * @see DefaultRuntimeEnvironment
 */
public static RuntimeEnvironmentBuilder getDefault(ReleaseId releaseId, String kbaseName, String ksessionName) {
    KieMavenRepository repository = KieMavenRepository.getKieMavenRepository();
    repository.resolveArtifact(releaseId.toExternalForm());
    KieServices ks = KieServices.Factory.get();
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    DeploymentDescriptorManager descriptorManager = new DeploymentDescriptorManager();
    List<DeploymentDescriptor> descriptorHierarchy = descriptorManager.getDeploymentDescriptorHierarchy(kieContainer);
    DeploymentDescriptorMerger merger = new DeploymentDescriptorMerger();
    DeploymentDescriptor descriptor = merger.merge(descriptorHierarchy, MergeMode.MERGE_COLLECTIONS);
    if (StringUtils.isEmpty(kbaseName)) {
        KieBaseModel defaultKBaseModel = ((KieContainerImpl) kieContainer).getKieProject().getDefaultKieBaseModel();
        if (defaultKBaseModel != null) {
            kbaseName = defaultKBaseModel.getName();
        } else {
            kbaseName = DEFAULT_KBASE_NAME;
        }
    }
    InternalKieModule module = (InternalKieModule) ((KieContainerImpl) kieContainer).getKieModuleForKBase(kbaseName);
    if (module == null) {
        throw new IllegalStateException("Cannot find kbase, either it does not exist or there are multiple default kbases in kmodule.xml");
    }
    KieBase kbase = kieContainer.getKieBase(kbaseName);
    RuntimeEnvironmentBuilder builder = null;
    if (descriptor.getPersistenceMode() == PersistenceMode.NONE) {
        builder = getDefaultInMemory();
    } else {
        builder = getDefault();
    }
    Map<String, Object> contaxtParams = new HashMap<String, Object>();
    contaxtParams.put("classLoader", kieContainer.getClassLoader());
    // populate various properties of the builder
    if (descriptor.getPersistenceUnit() != null) {
        EntityManagerFactory emf = EntityManagerFactoryManager.get().getOrCreate(descriptor.getPersistenceUnit());
        builder.entityManagerFactory(emf);
        contaxtParams.put("entityManagerFactory", emf);
    }
    // process object models that are globally configured (environment entries, session configuration)
    for (NamedObjectModel model : descriptor.getEnvironmentEntries()) {
        Object entry = getInstanceFromModel(model, kieContainer, contaxtParams);
        builder.addEnvironmentEntry(model.getName(), entry);
    }
    for (NamedObjectModel model : descriptor.getConfiguration()) {
        Object entry = getInstanceFromModel(model, kieContainer, contaxtParams);
        builder.addConfiguration(model.getName(), (String) entry);
    }
    ObjectMarshallingStrategy[] mStrategies = new ObjectMarshallingStrategy[descriptor.getMarshallingStrategies().size() + 1];
    int index = 0;
    for (ObjectModel model : descriptor.getMarshallingStrategies()) {
        Object strategy = getInstanceFromModel(model, kieContainer, contaxtParams);
        mStrategies[index] = (ObjectMarshallingStrategy) strategy;
        index++;
    }
    // lastly add the main default strategy
    mStrategies[index] = new SerializablePlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT);
    builder.addEnvironmentEntry(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, mStrategies);
    builder.addEnvironmentEntry("KieDeploymentDescriptor", descriptor).knowledgeBase(kbase).classLoader(kieContainer.getClassLoader()).registerableItemsFactory(new KModuleRegisterableItemsFactory(kieContainer, ksessionName));
    return builder;
}
Also used : SerializablePlaceholderResolverStrategy(org.drools.core.marshalling.impl.SerializablePlaceholderResolverStrategy) ObjectModel(org.kie.internal.runtime.conf.ObjectModel) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) HashMap(java.util.HashMap) ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DeploymentDescriptorManager(org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorManager) KieServices(org.kie.api.KieServices) KieBaseModel(org.kie.api.builder.model.KieBaseModel) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) KieBase(org.kie.api.KieBase) EntityManagerFactory(javax.persistence.EntityManagerFactory) KieMavenRepository(org.kie.scanner.KieMavenRepository) DeploymentDescriptorMerger(org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorMerger) KieContainer(org.kie.api.runtime.KieContainer) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 4 with NamedObjectModel

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

the class DefaultRegisterableItemsFactory method getWorkItemHandlersFromDescriptor.

protected Map<String, WorkItemHandler> getWorkItemHandlersFromDescriptor(RuntimeEngine runtime) {
    Map<String, WorkItemHandler> defaultHandlers = new HashMap<String, WorkItemHandler>();
    DeploymentDescriptor descriptor = getRuntimeManager().getDeploymentDescriptor();
    if (descriptor != null) {
        Map<String, Object> params = getParametersMap(runtime);
        for (NamedObjectModel model : descriptor.getWorkItemHandlers()) {
            Object hInstance = getInstanceFromModel(model, getRuntimeManager().getEnvironment().getClassLoader(), params);
            if (hInstance != null) {
                defaultHandlers.put(model.getName(), (WorkItemHandler) hInstance);
            }
        }
    }
    return defaultHandlers;
}
Also used : WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) LocalHTWorkItemHandler(org.jbpm.services.task.wih.LocalHTWorkItemHandler) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) HashMap(java.util.HashMap) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor)

Example 5 with NamedObjectModel

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

the class DeploymentDescriptorMergerTest method testDeploymentDesciptorMergeMergeCollectionsAvoidDuplicatesNamedObject.

@Test
public void testDeploymentDesciptorMergeMergeCollectionsAvoidDuplicatesNamedObject() {
    DeploymentDescriptor master = new DeploymentDescriptorImpl("org.jbpm.domain");
    master.getBuilder().addWorkItemHandler(new NamedObjectModel("mvel", "Log", "new org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler()"));
    assertNotNull(master);
    assertEquals("org.jbpm.domain", master.getPersistenceUnit());
    assertEquals("org.jbpm.domain", master.getAuditPersistenceUnit());
    assertEquals(AuditMode.JPA, master.getAuditMode());
    assertEquals(PersistenceMode.JPA, master.getPersistenceMode());
    assertEquals(RuntimeStrategy.SINGLETON, master.getRuntimeStrategy());
    assertEquals(0, master.getMarshallingStrategies().size());
    assertEquals(0, master.getConfiguration().size());
    assertEquals(0, master.getEnvironmentEntries().size());
    assertEquals(0, master.getEventListeners().size());
    assertEquals(0, master.getGlobals().size());
    assertEquals(0, master.getTaskEventListeners().size());
    assertEquals(1, master.getWorkItemHandlers().size());
    DeploymentDescriptor slave = new DeploymentDescriptorImpl("org.jbpm.domain");
    slave.getBuilder().auditMode(AuditMode.JMS).persistenceMode(PersistenceMode.JPA).persistenceUnit(null).auditPersistenceUnit("").addWorkItemHandler(new NamedObjectModel("mvel", "Log", "new org.jbpm.process.instance.impl.demo.CustomSystemOutWorkItemHandler()"));
    assertNotNull(slave);
    assertEquals(null, slave.getPersistenceUnit());
    assertEquals("", slave.getAuditPersistenceUnit());
    assertEquals(AuditMode.JMS, slave.getAuditMode());
    assertEquals(PersistenceMode.JPA, slave.getPersistenceMode());
    assertEquals(RuntimeStrategy.SINGLETON, slave.getRuntimeStrategy());
    assertEquals(0, slave.getMarshallingStrategies().size());
    assertEquals(0, slave.getConfiguration().size());
    assertEquals(0, slave.getEnvironmentEntries().size());
    assertEquals(0, slave.getEventListeners().size());
    assertEquals(0, slave.getGlobals().size());
    assertEquals(0, slave.getTaskEventListeners().size());
    assertEquals(1, slave.getWorkItemHandlers().size());
    // and now let's merge them
    DeploymentDescriptorMerger merger = new DeploymentDescriptorMerger();
    DeploymentDescriptor outcome = merger.merge(master, slave, MergeMode.MERGE_COLLECTIONS);
    assertNotNull(outcome);
    assertEquals("org.jbpm.domain", outcome.getPersistenceUnit());
    assertEquals("org.jbpm.domain", outcome.getAuditPersistenceUnit());
    assertEquals(AuditMode.JMS, outcome.getAuditMode());
    assertEquals(PersistenceMode.JPA, outcome.getPersistenceMode());
    assertEquals(RuntimeStrategy.SINGLETON, outcome.getRuntimeStrategy());
    assertEquals(0, outcome.getMarshallingStrategies().size());
    assertEquals(0, outcome.getConfiguration().size());
    assertEquals(0, outcome.getEnvironmentEntries().size());
    assertEquals(0, outcome.getEventListeners().size());
    assertEquals(0, outcome.getGlobals().size());
    assertEquals(0, outcome.getTaskEventListeners().size());
    assertEquals(1, outcome.getWorkItemHandlers().size());
    // let's check if the slave version is preserved
    NamedObjectModel model = outcome.getWorkItemHandlers().get(0);
    assertEquals("Log", model.getName());
    assertEquals("new org.jbpm.process.instance.impl.demo.CustomSystemOutWorkItemHandler()", model.getIdentifier());
}
Also used : NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) Test(org.junit.Test)

Aggregations

NamedObjectModel (org.kie.internal.runtime.conf.NamedObjectModel)29 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)24 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)11 ObjectModel (org.kie.internal.runtime.conf.ObjectModel)10 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)9 KieServices (org.kie.api.KieServices)9 ReleaseId (org.kie.api.builder.ReleaseId)8 DeploymentDescriptorImpl (org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl)7 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)6 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)6 File (java.io.File)5 FileOutputStream (java.io.FileOutputStream)5 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)5 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)5 DeploymentDescriptorBuilder (org.kie.internal.runtime.conf.DeploymentDescriptorBuilder)5 KieMavenRepository (org.kie.scanner.KieMavenRepository)5 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)4 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)4