use of org.jbpm.workflow.core.impl.WorkflowProcessImpl in project jbpm by kiegroup.
the class JavaScriptActionBuilderTest method testSimpleAction.
@Test
public void testSimpleAction() throws Exception {
final InternalKnowledgePackage pkg = new KnowledgePackageImpl("pkg1");
ActionDescr actionDescr = new ActionDescr();
actionDescr.setText("var testString; print('Hello')");
KnowledgeBuilderImpl pkgBuilder = new KnowledgeBuilderImpl(pkg);
DialectCompiletimeRegistry dialectRegistry = pkgBuilder.getPackageRegistry(pkg.getName()).getDialectCompiletimeRegistry();
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, null);
context.init(pkgBuilder, pkg, null, dialectRegistry, null, null);
pkgBuilder.addPackageFromDrl(new StringReader("package pkg1;\nglobal String testField;\n"));
ActionNode actionNode = new ActionNode();
DroolsAction action = new DroolsConsequenceAction("JavaScript", null);
actionNode.setAction(action);
ProcessDialect dialect = ProcessDialectRegistry.getDialect("JavaScript");
dialect.getActionBuilder().build(context, action, actionDescr, actionNode);
dialect.addProcess(context);
final JavaScriptActionBuilder builder = new JavaScriptActionBuilder();
builder.build(context, action, actionDescr, actionNode);
final InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(Arrays.asList(pkgBuilder.getPackages()));
final KieSession wm = kbase.newKieSession();
wm.setGlobal("testField", "vagon");
ProcessContext processContext = new ProcessContext(((InternalWorkingMemory) wm).getKnowledgeRuntime());
((Action) actionNode.getAction().getMetaData("Action")).execute(processContext);
assertEquals("vagon", wm.getGlobal("testField").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 ImportHandler 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 name = attrs.getValue("name");
final String type = attrs.getValue("importType");
final String location = attrs.getValue("location");
final String namespace = attrs.getValue("namespace");
emptyAttributeCheck(localName, "name", name, parser);
if (type != null && location != null && namespace != null) {
Map<String, String> typedImports = (Map<String, String>) process.getMetaData(type);
if (typedImports == null) {
typedImports = new HashMap<String, String>();
process.setMetaData(type, typedImports);
}
typedImports.put(namespace, location);
} else {
java.util.Set<String> list = process.getImports();
if (list == null) {
list = new HashSet<String>();
process.setImports(list);
}
list.add(name);
}
return null;
}
use of org.jbpm.workflow.core.impl.WorkflowProcessImpl in project jbpm by kiegroup.
the class PackageBuilderTest method testRuleFlowUpgrade.
@Test
public void testRuleFlowUpgrade() throws Exception {
// Set the system property so that automatic conversion can happen
System.setProperty("drools.ruleflow.port", "true");
InputStream in = this.getClass().getResourceAsStream("/org/jbpm/integrationtests/ruleflow40.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);
// Reset the system property so that automatic conversion should not happen
System.setProperty("drools.ruleflow.port", "false");
}
use of org.jbpm.workflow.core.impl.WorkflowProcessImpl in project jbpm by kiegroup.
the class StoreHandler method start.
public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser xmlPackageReader) throws SAXException {
xmlPackageReader.startElementBuilder(localName, attrs);
WorkflowProcessImpl process = (WorkflowProcessImpl) xmlPackageReader.getParent();
ActionNode actionNode = new ActionNode();
final String name = attrs.getValue("name");
emptyAttributeCheck(localName, "name", name, xmlPackageReader);
actionNode.setName(name);
final String id = attrs.getValue("id");
emptyAttributeCheck(localName, "id", name, xmlPackageReader);
actionNode.setId(new Long(id));
process.addNode(actionNode);
((ProcessBuildData) xmlPackageReader.getData()).addNode(actionNode);
return actionNode;
}
Aggregations