Search in sources :

Example 11 with WorkflowProcessImpl

use of org.jbpm.workflow.core.impl.WorkflowProcessImpl in project jbpm by kiegroup.

the class SwimlaneHandler 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");
    emptyAttributeCheck(localName, "name", name, parser);
    SwimlaneContext swimlaneContext = (SwimlaneContext) process.getDefaultContext(SwimlaneContext.SWIMLANE_SCOPE);
    if (swimlaneContext != null) {
        Swimlane swimlane = new Swimlane();
        swimlane.setName(name);
        swimlaneContext.addSwimlane(swimlane);
    } else {
        throw new SAXParseException("Could not find default swimlane context.", parser.getLocator());
    }
    return null;
}
Also used : SwimlaneContext(org.jbpm.process.core.context.swimlane.SwimlaneContext) Swimlane(org.jbpm.process.core.context.swimlane.Swimlane) SAXParseException(org.xml.sax.SAXParseException) WorkflowProcessImpl(org.jbpm.workflow.core.impl.WorkflowProcessImpl)

Example 12 with WorkflowProcessImpl

use of org.jbpm.workflow.core.impl.WorkflowProcessImpl in project jbpm by kiegroup.

the class ProcessInstanceResolverStrategyTest method testAccept.

@Test
public void testAccept() {
    KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    WorkflowProcessImpl process = new WorkflowProcessImpl();
    RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance();
    processInstance.setState(ProcessInstance.STATE_ACTIVE);
    processInstance.setProcess(process);
    processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) ksession);
    ProcessInstanceResolverStrategy strategy = new ProcessInstanceResolverStrategy();
    assertTrue(strategy.accept(processInstance));
    Object object = new Object();
    assertTrue(!strategy.accept(object));
}
Also used : RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) KieBase(org.kie.api.KieBase) ProcessInstanceResolverStrategy(org.jbpm.marshalling.impl.ProcessInstanceResolverStrategy) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessImpl(org.jbpm.workflow.core.impl.WorkflowProcessImpl) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 13 with WorkflowProcessImpl

use of org.jbpm.workflow.core.impl.WorkflowProcessImpl in project jbpm by kiegroup.

the class JavaReturnValueConstraintEvaluatorBuilderTest method testSimpleReturnValueConstraintEvaluator.

@Test
public void testSimpleReturnValueConstraintEvaluator() throws Exception {
    final InternalKnowledgePackage pkg = new KnowledgePackageImpl("pkg1");
    ProcessDescr processDescr = new ProcessDescr();
    processDescr.setClassName("Process1");
    processDescr.setName("Process1");
    WorkflowProcessImpl process = new WorkflowProcessImpl();
    process.setName("Process1");
    process.setPackageName("pkg1");
    ReturnValueDescr descr = new ReturnValueDescr();
    descr.setText("return value;");
    KnowledgeBuilderImpl pkgBuilder = new KnowledgeBuilderImpl(pkg);
    DialectCompiletimeRegistry dialectRegistry = pkgBuilder.getPackageRegistry(pkg.getName()).getDialectCompiletimeRegistry();
    JavaDialect javaDialect = (JavaDialect) dialectRegistry.getDialect("java");
    ProcessBuildContext context = new ProcessBuildContext(pkgBuilder, pkg, process, processDescr, dialectRegistry, javaDialect);
    pkgBuilder.addPackageFromDrl(new StringReader("package pkg1;\nglobal Boolean value;"));
    ReturnValueConstraintEvaluator node = new ReturnValueConstraintEvaluator();
    final JavaReturnValueEvaluatorBuilder builder = new JavaReturnValueEvaluatorBuilder();
    builder.build(context, node, descr, null);
    ProcessDialectRegistry.getDialect(JavaDialect.ID).addProcess(context);
    javaDialect.compileAll();
    assertEquals(0, javaDialect.getResults().size());
    final InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addPackages(Arrays.asList(pkgBuilder.getPackages()));
    final KieSession ksession = kbase.newKieSession();
    ksession.setGlobal("value", true);
    RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance();
    processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) ksession);
    SplitInstance splitInstance = new SplitInstance();
    splitInstance.setProcessInstance(processInstance);
    assertTrue(node.evaluate(splitInstance, null, null));
    ksession.setGlobal("value", false);
    assertFalse(node.evaluate(splitInstance, null, null));
}
Also used : RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) ReturnValueDescr(org.drools.compiler.compiler.ReturnValueDescr) DialectCompiletimeRegistry(org.drools.compiler.compiler.DialectCompiletimeRegistry) ProcessDescr(org.drools.compiler.lang.descr.ProcessDescr) ReturnValueConstraintEvaluator(org.jbpm.process.instance.impl.ReturnValueConstraintEvaluator) WorkflowProcessImpl(org.jbpm.workflow.core.impl.WorkflowProcessImpl) JavaDialect(org.drools.compiler.rule.builder.dialect.java.JavaDialect) SplitInstance(org.jbpm.workflow.instance.node.SplitInstance) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) StringReader(java.io.StringReader) JavaReturnValueEvaluatorBuilder(org.jbpm.process.builder.dialect.java.JavaReturnValueEvaluatorBuilder) 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 14 with WorkflowProcessImpl

use of org.jbpm.workflow.core.impl.WorkflowProcessImpl in project jbpm by kiegroup.

the class EndNodeInstanceTest method testEndNode.

@Test
public void testEndNode() {
    KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    MockNode mockNode = new MockNode();
    MockNodeInstanceFactory factory = new MockNodeInstanceFactory(new MockNodeInstance(mockNode));
    NodeInstanceFactoryRegistry.getInstance(ksession.getEnvironment()).register(mockNode.getClass(), factory);
    WorkflowProcessImpl process = new WorkflowProcessImpl();
    Node endNode = new EndNode();
    endNode.setId(1);
    endNode.setName("end node");
    mockNode.setId(2);
    new ConnectionImpl(mockNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
    process.addNode(mockNode);
    process.addNode(endNode);
    RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance();
    processInstance.setState(ProcessInstance.STATE_ACTIVE);
    processInstance.setProcess(process);
    processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) ksession);
    MockNodeInstance mockNodeInstance = (MockNodeInstance) processInstance.getNodeInstance(mockNode);
    mockNodeInstance.triggerCompleted();
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) EndNode(org.jbpm.workflow.core.node.EndNode) KieBase(org.kie.api.KieBase) EndNode(org.jbpm.workflow.core.node.EndNode) Node(org.jbpm.workflow.core.Node) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessImpl(org.jbpm.workflow.core.impl.WorkflowProcessImpl) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 15 with WorkflowProcessImpl

use of org.jbpm.workflow.core.impl.WorkflowProcessImpl in project jbpm by kiegroup.

the class FunctionImportHandler 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");
    emptyAttributeCheck(localName, "name", name, parser);
    java.util.List<String> list = process.getFunctionImports();
    if (list == null) {
        list = new ArrayList<String>();
        process.setFunctionImports(list);
    }
    list.add(name);
    return null;
}
Also used : 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