use of org.kie.internal.runtime.conf.ObjectModel in project drools by kiegroup.
the class DeploymentDescriptorMergerTest method testDeploymentDesciptorMergeKeepAll.
@Test
public void testDeploymentDesciptorMergeKeepAll() {
DeploymentDescriptor primary = new DeploymentDescriptorImpl("org.jbpm.domain");
primary.getBuilder().addMarshalingStrategy(new ObjectModel("org.jbpm.test.CustomStrategy", new Object[] { "param2" })).setLimitSerializationClasses(true);
assertNotNull(primary);
assertEquals("org.jbpm.domain", primary.getPersistenceUnit());
assertEquals("org.jbpm.domain", primary.getAuditPersistenceUnit());
assertEquals(AuditMode.JPA, primary.getAuditMode());
assertEquals(PersistenceMode.JPA, primary.getPersistenceMode());
assertEquals(RuntimeStrategy.SINGLETON, primary.getRuntimeStrategy());
assertEquals(1, primary.getMarshallingStrategies().size());
assertEquals(0, primary.getConfiguration().size());
assertEquals(0, primary.getEnvironmentEntries().size());
assertEquals(0, primary.getEventListeners().size());
assertEquals(0, primary.getGlobals().size());
assertEquals(0, primary.getTaskEventListeners().size());
assertEquals(0, primary.getWorkItemHandlers().size());
assertTrue(primary.getLimitSerializationClasses());
DeploymentDescriptor secondary = new DeploymentDescriptorImpl("org.jbpm.domain");
secondary.getBuilder().auditMode(AuditMode.JMS).persistenceMode(PersistenceMode.JPA).persistenceUnit("my.custom.unit").auditPersistenceUnit("my.custom.unit2").setLimitSerializationClasses(false);
assertNotNull(secondary);
assertEquals("my.custom.unit", secondary.getPersistenceUnit());
assertEquals("my.custom.unit2", secondary.getAuditPersistenceUnit());
assertEquals(AuditMode.JMS, secondary.getAuditMode());
assertEquals(PersistenceMode.JPA, secondary.getPersistenceMode());
assertEquals(RuntimeStrategy.SINGLETON, secondary.getRuntimeStrategy());
assertEquals(0, secondary.getMarshallingStrategies().size());
assertEquals(0, secondary.getConfiguration().size());
assertEquals(0, secondary.getEnvironmentEntries().size());
assertEquals(0, secondary.getEventListeners().size());
assertEquals(0, secondary.getGlobals().size());
assertEquals(0, secondary.getTaskEventListeners().size());
assertEquals(0, secondary.getWorkItemHandlers().size());
assertFalse(secondary.getLimitSerializationClasses());
// and now let's merge them
DeploymentDescriptor outcome = DeploymentDescriptorMerger.merge(primary, secondary, MergeMode.KEEP_ALL);
assertNotNull(outcome);
assertEquals("org.jbpm.domain", outcome.getPersistenceUnit());
assertEquals("org.jbpm.domain", outcome.getAuditPersistenceUnit());
assertEquals(AuditMode.JPA, outcome.getAuditMode());
assertEquals(PersistenceMode.JPA, outcome.getPersistenceMode());
assertEquals(RuntimeStrategy.SINGLETON, outcome.getRuntimeStrategy());
assertEquals(1, 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(0, outcome.getWorkItemHandlers().size());
assertTrue(outcome.getLimitSerializationClasses());
}
use of org.kie.internal.runtime.conf.ObjectModel in project drools by kiegroup.
the class DeploymentDescriptorMerger method merge.
public static DeploymentDescriptor merge(DeploymentDescriptor primary, DeploymentDescriptor secondary, MergeMode mode) {
if (primary == null || secondary == null) {
throw new IllegalArgumentException("Descriptors to merge must be provided");
}
if (mode == null) {
mode = MergeMode.MERGE_COLLECTIONS;
}
DeploymentDescriptor merged = null;
DeploymentDescriptorBuilder builder = primary.getBuilder();
builder.setBuildHandler(new MergeModeBuildHandler(mode));
switch(mode) {
case KEEP_ALL:
// do nothing as primary wins
merged = primary;
break;
case OVERRIDE_ALL:
// do nothing as secondary wins
merged = secondary;
break;
case OVERRIDE_EMPTY:
builder.auditMode(secondary.getAuditMode());
builder.auditPersistenceUnit(secondary.getAuditPersistenceUnit());
builder.persistenceMode(secondary.getPersistenceMode());
builder.persistenceUnit(secondary.getPersistenceUnit());
builder.runtimeStrategy(secondary.getRuntimeStrategy());
builder.setConfiguration(secondary.getConfiguration());
builder.setEnvironmentEntries(secondary.getEnvironmentEntries());
builder.setEventListeners(secondary.getEventListeners());
builder.setGlobals(secondary.getGlobals());
builder.setMarshalingStrategies(secondary.getMarshallingStrategies());
builder.setTaskEventListeners(secondary.getTaskEventListeners());
builder.setWorkItemHandlers(secondary.getWorkItemHandlers());
builder.setRequiredRoles(secondary.getRequiredRoles());
builder.setClasses(secondary.getClasses());
builder.setLimitSerializationClasses(secondary.getLimitSerializationClasses());
merged = builder.get();
break;
case MERGE_COLLECTIONS:
default:
builder.auditMode(secondary.getAuditMode());
builder.auditPersistenceUnit(secondary.getAuditPersistenceUnit());
builder.persistenceMode(secondary.getPersistenceMode());
builder.persistenceUnit(secondary.getPersistenceUnit());
builder.runtimeStrategy(secondary.getRuntimeStrategy());
for (ObjectModel model : secondary.getEventListeners()) {
builder.addEventListener(model);
}
for (ObjectModel model : secondary.getMarshallingStrategies()) {
builder.addMarshalingStrategy(model);
}
// we need to keep the order of task listeners otherwise they will rise in different order
// so the primary must be the latest one
List<ObjectModel> taskEventListeners = new ArrayList<>(secondary.getTaskEventListeners());
for (ObjectModel model : primary.getTaskEventListeners()) {
if (!taskEventListeners.contains(model)) {
taskEventListeners.add(model);
}
}
builder.setTaskEventListeners(taskEventListeners);
for (NamedObjectModel model : secondary.getConfiguration()) {
builder.addConfiguration(model);
}
for (NamedObjectModel model : secondary.getEnvironmentEntries()) {
builder.addEnvironmentEntry(model);
}
for (NamedObjectModel model : secondary.getGlobals()) {
builder.addGlobal(model);
}
for (NamedObjectModel model : secondary.getWorkItemHandlers()) {
builder.addWorkItemHandler(model);
}
for (String requiredRole : secondary.getRequiredRoles()) {
builder.addRequiredRole(requiredRole);
}
for (String clazz : secondary.getClasses()) {
builder.addClass(clazz);
}
Boolean secondaryLimit = secondary.getLimitSerializationClasses();
Boolean primaryLimit = primary.getLimitSerializationClasses();
if (secondaryLimit != null && primaryLimit != null && (!secondaryLimit || !primaryLimit)) {
builder.setLimitSerializationClasses(false);
}
merged = builder.get();
break;
}
return merged;
}
use of org.kie.internal.runtime.conf.ObjectModel in project jbpm by kiegroup.
the class CarInsuranceClaimCaseTest method getProcessListeners.
@Override
protected List<ObjectModel> getProcessListeners() {
List<ObjectModel> listeners = super.getProcessListeners();
listeners.add(new ObjectModel("mvel", "org.jbpm.casemgmt.impl.util.CountDownListenerFactory.get(\"carInsuranceCase\", \"wait before callback\", 1)"));
return listeners;
}
use of org.kie.internal.runtime.conf.ObjectModel in project jbpm by kiegroup.
the class CaseCommentNotificationTest 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 ObjectModel("mvel", "new org.jbpm.kie.services.impl.IdentityProviderAwareProcessListener(ksession)")).addEventListener(new ObjectModel("mvel", "org.jbpm.casemgmt.impl.util.CommentNotificationEventListenerFactory.get(\"test\")"));
deploymentUnit.setDeploymentDescriptor(descriptor);
deploymentUnit.setStrategy(RuntimeStrategy.PER_CASE);
deploymentService.deploy(deploymentUnit);
return deploymentUnit;
}
use of org.kie.internal.runtime.conf.ObjectModel in project jbpm by kiegroup.
the class KModuleDeploymentService method boostrapRuntimeEnvironmentBuilder.
/**
* This creates and fills a {@link RuntimeEnvironmentBuilder} instance, which is later used when creating services.
* </p>
* A lot of the logic here is used to process the information in the {@link DeploymentDescriptor} instance, which is
* part of the {@link DeploymentUnit}.
*
* @param deploymentUnit The {@link KModuleDeploymentUnit}, which is filled by the method
* @param deployedUnit The {@link DeployedUnit}, which is also filled by the method
* @param kieContainer The {@link KieContainer}, which contains information needed to fill the above two arguments
* @param mode The {@link MergeMode} used to resolve conflicts in the {@link DeploymentDescriptor}.
* @return A {@link RuntimeEnvironmentBuilder} instance ready for use
*/
protected RuntimeEnvironmentBuilder boostrapRuntimeEnvironmentBuilder(KModuleDeploymentUnit deploymentUnit, DeployedUnit deployedUnit, KieContainer kieContainer, MergeMode mode) {
DeploymentDescriptor descriptor = deploymentUnit.getDeploymentDescriptor();
if (descriptor == null || ((DeploymentDescriptorImpl) descriptor).isEmpty()) {
// skip empty descriptors as its default can override settings
DeploymentDescriptorManager descriptorManager = new DeploymentDescriptorManager("org.jbpm.domain");
List<DeploymentDescriptor> descriptorHierarchy = descriptorManager.getDeploymentDescriptorHierarchy(kieContainer);
descriptor = merger.merge(descriptorHierarchy, mode);
deploymentUnit.setDeploymentDescriptor(descriptor);
} else if (descriptor != null && !deploymentUnit.isDeployed()) {
DeploymentDescriptorManager descriptorManager = new DeploymentDescriptorManager("org.jbpm.domain");
List<DeploymentDescriptor> descriptorHierarchy = descriptorManager.getDeploymentDescriptorHierarchy(kieContainer);
descriptorHierarchy.add(0, descriptor);
descriptor = merger.merge(descriptorHierarchy, mode);
deploymentUnit.setDeploymentDescriptor(descriptor);
}
// first set on unit the strategy
deploymentUnit.setStrategy(descriptor.getRuntimeStrategy());
// setting up runtime environment via builder
RuntimeEnvironmentBuilder builder = null;
if (descriptor.getPersistenceMode() == PersistenceMode.NONE) {
builder = RuntimeEnvironmentBuilder.Factory.get().newDefaultInMemoryBuilder();
} else {
builder = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder();
}
// populate various properties of the builder
EntityManagerFactory emf = EntityManagerFactoryManager.get().getOrCreate(descriptor.getPersistenceUnit());
builder.entityManagerFactory(emf);
Map<String, Object> contaxtParams = new HashMap<String, Object>();
contaxtParams.put("entityManagerFactory", emf);
contaxtParams.put("classLoader", kieContainer.getClassLoader());
// 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);
builder.addEnvironmentEntry("KieContainer", kieContainer);
if (executorService != null) {
builder.addEnvironmentEntry("ExecutorService", executorService);
}
if (identityProvider != null) {
builder.addEnvironmentEntry(EnvironmentName.IDENTITY_PROVIDER, identityProvider);
}
// populate all assets with roles for this deployment unit
List<String> requiredRoles = descriptor.getRequiredRoles(DeploymentDescriptor.TYPE_VIEW);
if (requiredRoles != null && !requiredRoles.isEmpty()) {
for (DeployedAsset desc : deployedUnit.getDeployedAssets()) {
if (desc instanceof ProcessAssetDesc) {
((ProcessAssetDesc) desc).setRoles(requiredRoles);
}
}
}
// Classes 3: classes added from descriptor
List<String> remoteableClasses = descriptor.getClasses();
if (remoteableClasses != null && !remoteableClasses.isEmpty()) {
for (String className : remoteableClasses) {
Class descriptorClass = null;
try {
descriptorClass = kieContainer.getClassLoader().loadClass(className);
logger.debug("Loaded {} into the classpath from deployment descriptor {}", className, kieContainer.getReleaseId().toExternalForm());
} catch (ClassNotFoundException cnfe) {
throw new IllegalArgumentException("Class " + className + " not found in the project");
} catch (NoClassDefFoundError e) {
throw new IllegalArgumentException("Class " + className + " not found in the project");
}
addClassToDeployedUnit(descriptorClass, (DeployedUnitImpl) deployedUnit);
}
}
return builder;
}
Aggregations