use of org.jbpm.workflow.core.impl.WorkflowProcessImpl in project jbpm by kiegroup.
the class ProcessBuilderImpl method generateRules.
private String generateRules(final Process process) {
StringBuffer builder = new StringBuffer();
if (process instanceof WorkflowProcessImpl) {
WorkflowProcessImpl ruleFlow = (WorkflowProcessImpl) process;
builder.append("package " + ruleFlow.getPackageName() + "\n");
Set<String> imports = ruleFlow.getImports();
if (imports != null) {
for (String importString : imports) {
builder.append("import " + importString + ";\n");
}
}
List<String> functionImports = ruleFlow.getFunctionImports();
if (functionImports != null) {
for (String importString : functionImports) {
builder.append("import function " + importString + ";\n");
}
}
Map<String, String> globals = ruleFlow.getGlobals();
if (globals != null) {
for (Map.Entry<String, String> entry : globals.entrySet()) {
builder.append("global " + entry.getValue() + " " + entry.getKey() + ";\n");
}
}
Node[] nodes = ruleFlow.getNodes();
generateRules(nodes, process, builder);
}
return builder.toString();
}
use of org.jbpm.workflow.core.impl.WorkflowProcessImpl in project jbpm by kiegroup.
the class GlobalHandler method start.
public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
parser.startElementBuilder(localName, attrs);
WorkflowProcessImpl process = (WorkflowProcessImpl) parser.getParent();
final String identifier = attrs.getValue("identifier");
final String type = attrs.getValue("type");
emptyAttributeCheck(localName, "identifier", identifier, parser);
emptyAttributeCheck(localName, "type", type, parser);
Map<String, String> map = process.getGlobals();
if (map == null) {
map = new HashMap<String, String>();
process.setGlobals(map);
}
map.put(identifier, type);
return null;
}
use of org.jbpm.workflow.core.impl.WorkflowProcessImpl in project jbpm by kiegroup.
the class WebServiceWorkItemHandler method getWSClient.
@SuppressWarnings("unchecked")
protected Client getWSClient(WorkItem workItem, String interfaceRef) {
if (clients.containsKey(interfaceRef)) {
return clients.get(interfaceRef);
}
synchronized (this) {
if (clients.containsKey(interfaceRef)) {
return clients.get(interfaceRef);
}
String importLocation = (String) workItem.getParameter("Url");
String importNamespace = (String) workItem.getParameter("Namespace");
if (importLocation != null && importLocation.trim().length() > 0 && importNamespace != null && importNamespace.trim().length() > 0) {
Client client = getDynamicClientFactory().createClient(importLocation, new QName(importNamespace, interfaceRef), getInternalClassLoader(), null);
clients.put(interfaceRef, client);
return client;
}
long processInstanceId = ((WorkItemImpl) workItem).getProcessInstanceId();
WorkflowProcessImpl process = ((WorkflowProcessImpl) ksession.getProcessInstance(processInstanceId).getProcess());
List<Bpmn2Import> typedImports = (List<Bpmn2Import>) process.getMetaData("Bpmn2Imports");
if (typedImports != null) {
Client client = null;
for (Bpmn2Import importObj : typedImports) {
if (WSDL_IMPORT_TYPE.equalsIgnoreCase(importObj.getType())) {
try {
client = getDynamicClientFactory().createClient(importObj.getLocation(), new QName(importObj.getNamespace(), interfaceRef), getInternalClassLoader(), null);
clients.put(interfaceRef, client);
return client;
} catch (Exception e) {
logger.error("Error when creating WS Client", e);
continue;
}
}
}
}
}
return null;
}
use of org.jbpm.workflow.core.impl.WorkflowProcessImpl in project jbpm by kiegroup.
the class PackageBuilderTest method testRuleFlow.
@Test
public void testRuleFlow() throws Exception {
InputStream in = this.getClass().getResourceAsStream("/org/jbpm/integrationtests/ruleflow.rfm");
assertNotNull(in);
builder.addPackage(new PackageDescr("com.sample"));
builder.addRuleFlow(new InputStreamReader(in));
InternalKnowledgePackage pkg = builder.getPackage("com.sample");
assertNotNull(pkg);
Map<String, Process> flows = pkg.getRuleFlows();
assertNotNull(flows);
assertEquals(1, flows.size());
assertTrue(flows.containsKey("0"));
Process p = (Process) flows.get("0");
assertTrue(p instanceof WorkflowProcessImpl);
// now serialization
InternalKnowledgePackage pkg2 = (InternalKnowledgePackage) DroolsStreamUtils.streamIn(DroolsStreamUtils.streamOut(pkg));
assertNotNull(pkg2);
flows = pkg2.getRuleFlows();
assertNotNull(flows);
assertEquals(1, flows.size());
assertTrue(flows.containsKey("0"));
p = (Process) flows.get("0");
assertTrue(p instanceof WorkflowProcessImpl);
}
use of org.jbpm.workflow.core.impl.WorkflowProcessImpl in project jbpm by kiegroup.
the class JavaActionBuilderTest method testSimpleAction.
@Test
public void testSimpleAction() throws Exception {
final InternalKnowledgePackage pkg = new KnowledgePackageImpl("pkg1");
ActionDescr actionDescr = new ActionDescr();
actionDescr.setText("list.add( \"hello world\" );");
KnowledgeBuilderImpl pkgBuilder = new KnowledgeBuilderImpl(pkg);
DialectCompiletimeRegistry dialectRegistry = pkgBuilder.getPackageRegistry(pkg.getName()).getDialectCompiletimeRegistry();
JavaDialect javaDialect = (JavaDialect) dialectRegistry.getDialect("java");
ProcessDescr processDescr = new ProcessDescr();
processDescr.setClassName("Process1");
processDescr.setName("Process1");
WorkflowProcessImpl process = new WorkflowProcessImpl();
process.setName("Process1");
process.setPackageName("pkg1");
ProcessBuildContext context = new ProcessBuildContext(pkgBuilder, pkgBuilder.getPackage("pkg1"), null, processDescr, dialectRegistry, javaDialect);
context.init(pkgBuilder, pkg, null, dialectRegistry, javaDialect, null);
pkgBuilder.addPackageFromDrl(new StringReader("package pkg1;\nglobal java.util.List list;\n"));
ActionNode actionNode = new ActionNode();
DroolsAction action = new DroolsConsequenceAction("java", null);
actionNode.setAction(action);
ProcessDialect dialect = ProcessDialectRegistry.getDialect("java");
dialect.getActionBuilder().build(context, action, actionDescr, actionNode);
dialect.addProcess(context);
javaDialect.compileAll();
assertEquals(0, javaDialect.getResults().size());
final InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(Arrays.asList(pkgBuilder.getPackages()));
final KieSession wm = kbase.newKieSession();
List<String> list = new ArrayList<String>();
wm.setGlobal("list", list);
ProcessContext processContext = new ProcessContext(((InternalWorkingMemory) wm).getKnowledgeRuntime());
((Action) actionNode.getAction().getMetaData("Action")).execute(processContext);
assertEquals("hello world", list.get(0));
}
Aggregations