Search in sources :

Example 1 with ChecklistManager

use of org.jbpm.examples.checklist.ChecklistManager in project jbpm by kiegroup.

the class ChecklistExample method main.

public static void main(String[] args) {
    try {
        JBPMHelper.startH2Server();
        JBPMHelper.setupDataSource();
        RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(new UserGroupCallback() {

            public List<String> getGroupsForUser(String userId) {
                List<String> result = new ArrayList<String>();
                if ("actor4".equals(userId)) {
                    result.add("group1");
                }
                return result;
            }

            public boolean existsUser(String arg0) {
                return true;
            }

            public boolean existsGroup(String arg0) {
                return true;
            }
        }).addAsset(KieServices.Factory.get().getResources().newClassPathResource("checklist/SampleChecklistProcess.bpmn"), ResourceType.BPMN2).get();
        ChecklistManager checklistManager = new DefaultChecklistManager(environment);
        long c1 = checklistManager.createContext("org.jbpm.examples.checklist.sample1", "actor1");
        List<ChecklistItem> items = checklistManager.getTasks(c1, null);
        printChecklistItems(items, c1);
        System.out.println("Completing Task1");
        ChecklistItem item1 = findChecklistItem(items, "Task1");
        checklistManager.completeTask("actor1", item1.getTaskId());
        items = checklistManager.getTasks(c1, null);
        printChecklistItems(items, c1);
        System.out.println("Adding Extra Task");
        String[] actorIds = new String[] { "actor5" };
        ChecklistItem itemExtra = checklistManager.addTask("actor5", actorIds, new String[0], "TaskExtra", "2+", c1);
        items = checklistManager.getTasks(c1, null);
        printChecklistItems(items, c1);
        System.out.println("Completing Task2");
        ChecklistItem item2 = findChecklistItem(items, "Task2");
        checklistManager.claimTask("actor4", item2.getTaskId());
        checklistManager.completeTask("actor4", item2.getTaskId());
        items = checklistManager.getTasks(c1, null);
        printChecklistItems(items, c1);
        System.out.println("Completing Task3b");
        ChecklistItem item3b = findChecklistItem(items, "Task3b");
        checklistManager.claimTask("actor3", item3b.getTaskId());
        checklistManager.completeTask("actor3", item3b.getTaskId());
        items = checklistManager.getTasks(c1, null);
        printChecklistItems(items, c1);
        System.out.println("Completing Task3a");
        ChecklistItem item3a = findChecklistItem(items, "Task3a");
        checklistManager.completeTask("actor1", item3a.getTaskId());
        items = checklistManager.getTasks(c1, null);
        printChecklistItems(items, c1);
        System.out.println("Completing Extra Task");
        itemExtra = findChecklistItem(items, "TaskExtra");
        checklistManager.completeTask("actor5", itemExtra.getTaskId());
        items = checklistManager.getTasks(c1, null);
        printChecklistItems(items, c1);
        System.out.println("Completing Task4");
        ChecklistItem item4 = findChecklistItem(items, "Task4");
        checklistManager.completeTask("actor1", item4.getTaskId());
        items = checklistManager.getTasks(c1, null);
        printChecklistItems(items, c1);
    } catch (Throwable t) {
        t.printStackTrace();
    }
    System.exit(0);
}
Also used : RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) ChecklistManager(org.jbpm.examples.checklist.ChecklistManager) ChecklistItem(org.jbpm.examples.checklist.ChecklistItem) List(java.util.List) ArrayList(java.util.ArrayList) UserGroupCallback(org.kie.api.task.UserGroupCallback)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 ChecklistItem (org.jbpm.examples.checklist.ChecklistItem)1 ChecklistManager (org.jbpm.examples.checklist.ChecklistManager)1 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)1 UserGroupCallback (org.kie.api.task.UserGroupCallback)1