use of org.kie.internal.runtime.conf.ObjectModel in project jbpm by kiegroup.
the class CaseSLAComplianceTest method getProcessListeners.
@Override
protected List<ObjectModel> getProcessListeners() {
List<ObjectModel> listeners = super.getProcessListeners();
listeners.add(new ObjectModel("mvel", "org.jbpm.casemgmt.impl.util.CountDownListenerFactory.getSLA(\"slaCompliance\", 1)"));
if (name.getMethodName().equals("testStartCaseWithSLAEscalation")) {
listeners.add(new ObjectModel("mvel", "new org.jbpm.casemgmt.impl.wih.EscalateToAdminSLAViolationListener()"));
} else if (name.getMethodName().equals("testStartCaseWithSLANotification")) {
listeners.add(new ObjectModel("mvel", "new org.jbpm.casemgmt.impl.wih.NotifyOwnerSLAViolationListener()"));
} else if (name.getMethodName().equals("testStartCaseWithSLASubprocess")) {
listeners.add(new ObjectModel("mvel", "new org.jbpm.casemgmt.impl.wih.StartProcessSLAViolationListener(\"DataVerification\")"));
}
return listeners;
}
use of org.kie.internal.runtime.conf.ObjectModel 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;
}
use of org.kie.internal.runtime.conf.ObjectModel 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;
}
use of org.kie.internal.runtime.conf.ObjectModel 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;
}
use of org.kie.internal.runtime.conf.ObjectModel in project jbpm by kiegroup.
the class DefaultRegisterableItemsFactory method getEventListenerFromDescriptor.
@SuppressWarnings("unchecked")
protected <T> List<T> getEventListenerFromDescriptor(RuntimeEngine runtime, Class<T> type) {
List<T> listeners = new ArrayList<T>();
DeploymentDescriptor descriptor = getRuntimeManager().getDeploymentDescriptor();
if (descriptor != null) {
Map<String, Object> params = getParametersMap(runtime);
for (ObjectModel model : descriptor.getEventListeners()) {
Object listenerInstance = getInstanceFromModel(model, getRuntimeManager().getEnvironment().getClassLoader(), params);
if (listenerInstance != null && type.isAssignableFrom(listenerInstance.getClass())) {
listeners.add((T) 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();
}
}
}
}
return listeners;
}
Aggregations