package com.sample;
/**
* This is a sample file to launch a process.
*/
public class ProcessTest {
public static final void main(String[] args) {
try {
//start humantask component
startHumanTaskComponent();
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new WSHumanTaskHandler());
// start a new process instance
Map<String, Object> params = new HashMap<String, Object>();
params.put("employee", "Administrator");
ksession.startProcess("com.sample.evaluation", params);
} catch (Throwable t) {
t.printStackTrace();
}
}
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilderConfiguration conf = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
// ((PackageBuilderConfiguration) conf).initSemanticModules();
// ((PackageBuilderConfiguration) conf).loadSemanticModule("BPMN2SemanticModule.conf");
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(conf);
// kbuilder.add(ResourceFactory.newClassPathResource("hellowWorld.bpmn"), ResourceType.DRF);
kbuilder.add(ResourceFactory.newClassPathResource("HelloWorldSample.rf"), ResourceType.DRF);
kbuilder.add(ResourceFactory.newClassPathResource("assignment.dsl"), ResourceType.DSL);
kbuilder.add(ResourceFactory.newClassPathResource("assignment.dslr"), ResourceType.DSLR);
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());
return kbase;
}
private static void startHumanTaskComponent(){
EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.drools.task");
TaskService taskService = new TaskService(emf,SystemEventListenerFactory.getSystemEventListener());
User a = new User("john");
User b = new User("mary");
TaskServiceSession taskSession = taskService.createSession();
taskSession.addUser(new User("Administrator"));
taskSession.addUser(a);
taskSession.addUser(b);
MinaTaskServer server = new MinaTaskServer( taskService );
Thread thread = new Thread( server );
thread.start();
}
}