use of org.kie.internal.runtime.conf.DeploymentDescriptorBuilder 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.DeploymentDescriptorBuilder in project jbpm by kiegroup.
the class AbstractKieServicesBaseTest method createKieJar.
protected InternalKieModule createKieJar(KieServices ks, ReleaseId releaseId, List<String> resources, Map<String, String> extraResources) {
KieFileSystem kfs = createKieFileSystemWithKProject(ks);
kfs.writePomXML(getPom(releaseId));
if (createDescriptor()) {
DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.domain");
DeploymentDescriptorBuilder ddBuilder = customDescriptor.getBuilder();
for (ObjectModel listener : getProcessListeners()) {
ddBuilder.addEventListener(listener);
}
for (ObjectModel listener : getTaskListeners()) {
ddBuilder.addTaskEventListener(listener);
}
if (extraResources == null) {
extraResources = new HashMap<String, String>();
}
extraResources.put("src/main/resources/" + DeploymentDescriptor.META_INF_LOCATION, customDescriptor.toXml());
}
for (String resource : resources) {
kfs.write("src/main/resources/KBase-test/" + resource, ResourceFactory.newClassPathResource(resource));
}
if (extraResources != null) {
for (Map.Entry<String, String> entry : extraResources.entrySet()) {
kfs.write(entry.getKey(), ResourceFactory.newByteArrayResource(entry.getValue().getBytes()));
}
}
kfs.write("src/main/resources/forms/DefaultProcess.ftl", ResourceFactory.newClassPathResource("repo/globals/forms/DefaultProcess.ftl"));
kfs.write("src/main/resources/forms/DefaultProcess.form", ResourceFactory.newClassPathResource("repo/globals/forms/DefaultProcess.form"));
kfs.write("src/main/resources/forms/DefaultProcess.frm", ResourceFactory.newClassPathResource("repo/globals/forms/DefaultProcess.frm"));
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
if (!kieBuilder.buildAll().getResults().getMessages().isEmpty()) {
for (Message message : kieBuilder.buildAll().getResults().getMessages()) {
logger.error("Error Message: ({}) {}", message.getPath(), message.getText());
}
throw new RuntimeException("There are errors builing the package, please check your knowledge assets!");
}
return (InternalKieModule) kieBuilder.getKieModule();
}
use of org.kie.internal.runtime.conf.DeploymentDescriptorBuilder 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.DeploymentDescriptorBuilder in project jbpm by kiegroup.
the class ProcessServiceImplWithoutAuditTest method prepare.
@Before
public void prepare() {
configureServices();
logger.debug("Preparing kjar");
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION);
List<String> processes = new ArrayList<String>();
processes.add("repo/processes/general/customtask.bpmn");
processes.add("repo/processes/general/humanTask.bpmn");
processes.add("repo/processes/general/import.bpmn");
processes.add("repo/processes/general/signal.bpmn");
processes.add("repo/processes/general/signalWithExpression.bpmn2");
processes.add("repo/processes/general/callactivity.bpmn");
DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.domain");
DeploymentDescriptorBuilder ddBuilder = customDescriptor.getBuilder();
ddBuilder.auditMode(AuditMode.NONE);
Map<String, String> extraResources = new HashMap<String, String>();
extraResources.put("src/main/resources/" + DeploymentDescriptor.META_INF_LOCATION, customDescriptor.toXml());
InternalKieModule kJar1 = createKieJar(ks, releaseId, processes, extraResources);
File pom = new File("target/kmodule", "pom.xml");
pom.getParentFile().mkdir();
try {
FileOutputStream fs = new FileOutputStream(pom);
fs.write(getPom(releaseId).getBytes());
fs.close();
} catch (Exception e) {
throw new RuntimeException("Unable to save pom content", e);
}
KieMavenRepository repository = getKieMavenRepository();
repository.deployArtifact(releaseId, kJar1, pom);
}
use of org.kie.internal.runtime.conf.DeploymentDescriptorBuilder in project jbpm by kiegroup.
the class DeploymentDescriptorImpl method getBuilder.
@Override
public DeploymentDescriptorBuilder getBuilder() {
return new DeploymentDescriptorBuilder() {
private BuilderHandler handler = new BuilderHandler() {
@Override
public boolean accepted(Object value) {
return true;
}
};
private DeploymentDescriptorImpl descriptor = DeploymentDescriptorImpl.this;
@Override
public DeploymentDescriptorBuilder runtimeStrategy(RuntimeStrategy strategy) {
if (handler.accepted(strategy)) {
descriptor.setRuntimeStrategy(strategy);
}
return this;
}
@Override
public DeploymentDescriptorBuilder persistenceUnit(String pu) {
if (handler.accepted(pu)) {
descriptor.setPersistenceUnit(pu);
}
return this;
}
@Override
public DeploymentDescriptorBuilder persistenceMode(PersistenceMode mode) {
if (handler.accepted(mode)) {
descriptor.setPersistenceMode(mode);
}
return this;
}
@Override
public DeploymentDescriptorBuilder auditPersistenceUnit(String pu) {
if (handler.accepted(pu)) {
descriptor.setAuditPersistenceUnit(pu);
}
return this;
}
@Override
public DeploymentDescriptorBuilder auditMode(AuditMode mode) {
if (handler.accepted(mode)) {
descriptor.setAuditMode(mode);
}
return this;
}
@Override
public DeploymentDescriptorBuilder addWorkItemHandler(NamedObjectModel model) {
if (handler.accepted(model)) {
if (!descriptor.workItemHandlers.add(model)) {
descriptor.workItemHandlers.remove(model);
descriptor.workItemHandlers.add(model);
}
}
return this;
}
@Override
public DeploymentDescriptorBuilder addTaskEventListener(ObjectModel model) {
if (handler.accepted(model)) {
if (!descriptor.taskEventListeners.add(model)) {
descriptor.taskEventListeners.remove(model);
descriptor.taskEventListeners.add(model);
}
}
return this;
}
@Override
public DeploymentDescriptorBuilder addMarshalingStrategy(ObjectModel model) {
if (handler.accepted(model)) {
if (!descriptor.marshallingStrategies.add(model)) {
descriptor.marshallingStrategies.remove(model);
descriptor.marshallingStrategies.add(model);
}
}
return this;
}
@Override
public DeploymentDescriptorBuilder addGlobal(NamedObjectModel model) {
if (handler.accepted(model)) {
if (!descriptor.globals.add(model)) {
descriptor.globals.remove(model);
descriptor.globals.add(model);
}
}
return this;
}
@Override
public DeploymentDescriptorBuilder addEventListener(ObjectModel model) {
if (handler.accepted(model)) {
if (!descriptor.eventListeners.add(model)) {
descriptor.eventListeners.remove(model);
descriptor.eventListeners.add(model);
}
}
return this;
}
@Override
public DeploymentDescriptorBuilder addEnvironmentEntry(NamedObjectModel model) {
if (handler.accepted(model)) {
if (!descriptor.environmentEntries.add(model)) {
descriptor.environmentEntries.remove(model);
descriptor.environmentEntries.add(model);
}
}
return this;
}
@Override
public DeploymentDescriptorBuilder addConfiguration(NamedObjectModel model) {
if (handler.accepted(model)) {
if (!descriptor.configuration.add(model)) {
descriptor.configuration.remove(model);
descriptor.configuration.add(model);
}
}
return this;
}
@Override
public DeploymentDescriptorBuilder addRequiredRole(String role) {
if (handler.accepted(role)) {
descriptor.requiredRoles.add(role);
}
return this;
}
@Override
public DeploymentDescriptorBuilder addClass(String clazz) {
if (handler.accepted(clazz)) {
descriptor.classes.add(clazz);
}
return this;
}
@Override
public DeploymentDescriptorBuilder setConfiguration(List<NamedObjectModel> models) {
if (handler.accepted(models)) {
descriptor.setConfiguration(models);
}
return this;
}
@Override
public DeploymentDescriptorBuilder setEnvironmentEntries(List<NamedObjectModel> models) {
if (handler.accepted(models)) {
descriptor.setEnvironmentEntries(models);
}
return this;
}
@Override
public DeploymentDescriptorBuilder setWorkItemHandlers(List<NamedObjectModel> models) {
if (handler.accepted(models)) {
descriptor.setWorkItemHandlers(models);
}
return this;
}
@Override
public DeploymentDescriptorBuilder setGlobals(List<NamedObjectModel> models) {
if (handler.accepted(models)) {
descriptor.setGlobals(models);
}
return this;
}
@Override
public DeploymentDescriptorBuilder setEventListeners(List<ObjectModel> models) {
if (handler.accepted(models)) {
descriptor.setEventListeners(models);
}
return this;
}
@Override
public DeploymentDescriptorBuilder setTaskEventListeners(List<ObjectModel> models) {
if (handler.accepted(models)) {
descriptor.setTaskEventListeners(models);
}
return this;
}
@Override
public DeploymentDescriptorBuilder setMarshalingStrategies(List<ObjectModel> models) {
if (handler.accepted(models)) {
descriptor.setMarshallingStrategies(models);
}
return this;
}
@Override
public DeploymentDescriptorBuilder setRequiredRoles(List<String> roles) {
if (handler.accepted(roles)) {
descriptor.setRequiredRoles(roles);
}
return this;
}
@Override
public DeploymentDescriptorBuilder setClasses(List<String> classes) {
if (handler.accepted(classes)) {
descriptor.setClasses(classes);
}
return this;
}
@Override
public DeploymentDescriptorBuilder setLimitSerializationClasses(Boolean limit) {
if (handler.accepted(limit)) {
descriptor.setLimitSerializationClasses(limit);
}
return this;
}
@Override
public void setBuildHandler(BuilderHandler handler) {
this.handler = handler;
}
@Override
public DeploymentDescriptor get() {
return descriptor;
}
};
}
Aggregations