Search in sources :

Example 6 with WorkflowProcessImpl

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());
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) Action(org.jbpm.process.instance.impl.Action) DroolsAction(org.jbpm.workflow.core.DroolsAction) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) DialectCompiletimeRegistry(org.drools.compiler.compiler.DialectCompiletimeRegistry) ActionDescr(org.drools.compiler.lang.descr.ActionDescr) ActionNode(org.jbpm.workflow.core.node.ActionNode) ProcessDescr(org.drools.compiler.lang.descr.ProcessDescr) ProcessDialect(org.jbpm.process.builder.dialect.ProcessDialect) WorkflowProcessImpl(org.jbpm.workflow.core.impl.WorkflowProcessImpl) JavaScriptActionBuilder(org.jbpm.process.builder.dialect.javascript.JavaScriptActionBuilder) ProcessContext(org.drools.core.spi.ProcessContext) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) StringReader(java.io.StringReader) KieSession(org.kie.api.runtime.KieSession) KnowledgePackageImpl(org.drools.core.definitions.impl.KnowledgePackageImpl) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 7 with WorkflowProcessImpl

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;
}
Also used : WorkflowProcessImpl(org.jbpm.workflow.core.impl.WorkflowProcessImpl)

Example 8 with WorkflowProcessImpl

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;
}
Also used : WorkflowProcessImpl(org.jbpm.workflow.core.impl.WorkflowProcessImpl) Map(java.util.Map) HashMap(java.util.HashMap)

Example 9 with WorkflowProcessImpl

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");
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Process(org.kie.api.definition.process.Process) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) WorkflowProcessImpl(org.jbpm.workflow.core.impl.WorkflowProcessImpl) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 10 with WorkflowProcessImpl

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;
}
Also used : ActionNode(org.jbpm.workflow.core.node.ActionNode) WorkflowProcessImpl(org.jbpm.workflow.core.impl.WorkflowProcessImpl)

Aggregations

WorkflowProcessImpl (org.jbpm.workflow.core.impl.WorkflowProcessImpl)18 Test (org.junit.Test)8 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)7 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)6 KieSession (org.kie.api.runtime.KieSession)6 StringReader (java.io.StringReader)4 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)4 DialectCompiletimeRegistry (org.drools.compiler.compiler.DialectCompiletimeRegistry)4 ProcessDescr (org.drools.compiler.lang.descr.ProcessDescr)4 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)4 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)4 RuleFlowProcessInstance (org.jbpm.ruleflow.instance.RuleFlowProcessInstance)4 ActionNode (org.jbpm.workflow.core.node.ActionNode)3 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 List (java.util.List)2 Map (java.util.Map)2 QName (javax.xml.namespace.QName)2 Client (org.apache.cxf.endpoint.Client)2 ReturnValueDescr (org.drools.compiler.compiler.ReturnValueDescr)2