[rules-users] How to execute a Process API result?

Scott Stevenson scott.stevenson at datacert.com
Fri Nov 20 08:58:14 EST 2009


This is how I ran my dynamic process:

Public static final void main(String[] args) {
	String xml =
XmlRuleFlowProcessDumper.INSTANCE.dump(createProcess());
	System.out.println(xml);
	KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
	kbuilder.add(
ResourceFactory.newByteArrayResource(xml.getBytes()), ResourceType.DRF
);
	KnowledgeBuilderErrors errors = kbuilder.getErrors();
	if (errors.size() > 0) {
		for (KnowledgeBuilderError error: errors) {
			System.err.println(error);
		}
		throw new IllegalArgumentException("Could not parse
knowledge.");
	}
	
	KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
	kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
		
	StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession();
	
	WorkflowProcessInstance pi = (WorkflowProcessInstance)
ksession.startProcess("com.datacert.workflow.dynamic");
}

-Scott



-----Original Message-----
From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of ramram8
Sent: Friday, November 20, 2009 3:19 AM
To: rules-users at lists.jboss.org
Subject: Re: [rules-users] How to execute a Process API result?


Hi All

I am also trying to build a dynamic process to be used. I am having some
difficulties in the build where I having this exception below is the
sample
code that I am using:

java.lang.NoClassDefFoundError: sample/Process_sample_0
	at
sample.Process_sample_0Action0Invoker.execute(Process_sample_0Action0Inv
oker.java:20)

Also I have a question can I use this dynamic process inside the GWT web
console? and How?

Please help in this issue

public static final void main(String[] args) 
	{
		try 
		{
			KnowledgeBase kbase =
KnowledgeBaseFactory.newKnowledgeBase();

            org.drools.rule.Package p = new
org.drools.rule.Package("sample");
            RuleFlowProcess process = createProcess();
            p.addProcess(process);

            KnowledgePackageImp kpi = new KnowledgePackageImp();
            kpi.pkg = p;

            List<KnowledgePackage> list = new
ArrayList<KnowledgePackage>();
            list.add(kpi);

            org.drools.compiler.PackageBuilder pbuilder = new
PackageBuilder();
            pbuilder.addPackage(p);
            org.drools.compiler.ProcessBuilder builder = new
ProcessBuilder(pbuilder);
            builder.buildProcess(process, null);
            
            kbase.addKnowledgePackages(list);

            StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession();

            System.out.println("=======>>> process.getId()
["+process.getId()+"]");

			// starting the process
			ksession.startProcess( process.getId() );
			ksession.fireAllRules();
		} 
		catch (Throwable t) 
		{
			t.printStackTrace();
		}
	}
	
	
	public static RuleFlowProcess createProcess()
	{
		String processName = "org.drools.HelloWorldJoinSplit";
		RuleFlowProcessFactory factory =
		    RuleFlowProcessFactory.createProcess(processName);
		factory
		    // Header
		    .name("HelloWorldJoinSplit")
		    .version("1.0")
		    .packageName("sample")
		    // Nodes
		    .startNode(1).name("Start").done()
		    .actionNode(2).name("Action 1")
		        .action("java", "System.out.println(\"Inside
Action 1\")").done()
		    .endNode(3).name("End").done()
		    // Connections
		    .connection(1, 2)
		    .connection(2, 3);
		RuleFlowProcess process =
factory.validate().getProcess();
		
		System.out.println(" ====== >> ["+process.getId()+"]");
		return process;
	}
-- 
View this message in context:
http://old.nabble.com/How-to-execute-a-Process-API-result--tp26169577p26
433405.html
Sent from the drools - user mailing list archive at Nabble.com.

_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users




More information about the rules-users mailing list