Search in sources :

Example 1 with WorkflowProcessImpl

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();
}
Also used : DynamicNode(org.jbpm.workflow.core.node.DynamicNode) StartNode(org.jbpm.workflow.core.node.StartNode) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) StateNode(org.jbpm.workflow.core.node.StateNode) MilestoneNode(org.jbpm.workflow.core.node.MilestoneNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) EventNode(org.jbpm.workflow.core.node.EventNode) Node(org.kie.api.definition.process.Node) WorkflowProcessImpl(org.jbpm.workflow.core.impl.WorkflowProcessImpl) Map(java.util.Map)

Example 2 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 3 with WorkflowProcessImpl

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;
}
Also used : Bpmn2Import(org.jbpm.bpmn2.core.Bpmn2Import) QName(javax.xml.namespace.QName) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) List(java.util.List) Client(org.apache.cxf.endpoint.Client) WorkflowProcessImpl(org.jbpm.workflow.core.impl.WorkflowProcessImpl)

Example 4 with WorkflowProcessImpl

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);
}
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 5 with 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));
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) DroolsAction(org.jbpm.workflow.core.DroolsAction) Action(org.jbpm.process.instance.impl.Action) 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) ArrayList(java.util.ArrayList) ProcessDescr(org.drools.compiler.lang.descr.ProcessDescr) ProcessDialect(org.jbpm.process.builder.dialect.ProcessDialect) WorkflowProcessImpl(org.jbpm.workflow.core.impl.WorkflowProcessImpl) JavaDialect(org.drools.compiler.rule.builder.dialect.java.JavaDialect) 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)

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