org.kie.api.runtime.process.WorkItem Java Examples
The following examples show how to use
org.kie.api.runtime.process.WorkItem.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ActivityGenerationModelTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test public void testUserTaskWithParamProcess() throws Exception { BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTaskWithParametrizedInput.bpmn2")).get(0); ProcessMetaData metaData = ProcessToExecModelGenerator.INSTANCE.generate((WorkflowProcess) process.legacyProcess()); String content = metaData.getGeneratedClassModel().toString(); assertThat(content).isNotNull(); log(content); Map<String, String> classData = new HashMap<>(); classData.put("org.drools.bpmn2.UserTaskProcess", content); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); Map<String, BpmnProcess> processes = createProcesses(classData, Collections.singletonMap("Human Task", workItemHandler)); ProcessInstance<BpmnVariables> processInstance = processes.get("UserTask").createInstance(); processInstance.start(); assertEquals(STATE_ACTIVE, processInstance.status()); WorkItem workItem = workItemHandler.getWorkItem(); assertNotNull(workItem); assertEquals("Executing task of process instance " + processInstance.id() + " as work item with Hello", workItem.getParameter("Description").toString().trim()); processInstance.completeWorkItem(workItem.getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john"))); assertEquals(STATE_COMPLETED, processInstance.status()); }
Example #2
Source File: StandaloneBPMNProcessTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test @Disabled("Process does not complete.") public void testAdHocSubProcess() throws Exception { KieBase kbase = createKnowledgeBase("BPMN2-AdHocSubProcess.bpmn2"); KieSession ksession = createKnowledgeSession(kbase); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); ProcessInstance processInstance = ksession.startProcess("AdHocSubProcess"); assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE); WorkItem workItem = workItemHandler.getWorkItem(); assertThat(workItem).isNull(); ksession = restoreSession(ksession); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); ksession.fireAllRules(); ksession.signalEvent("Hello2", null, processInstance.getId()); workItem = workItemHandler.getWorkItem(); assertThat(workItem).isNotNull(); ksession = restoreSession(ksession); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null); assertProcessInstanceCompleted(processInstance.getId(), ksession); }
Example #3
Source File: ProtobufProcessMarshaller.java From kogito-runtimes with Apache License 2.0 | 6 votes |
public static WorkItem readWorkItem(MarshallerReaderContext context, JBPMMessages.WorkItem _workItem, boolean includeVariables) throws IOException { WorkItemImpl workItem = new WorkItemImpl(); workItem.setId( _workItem.getId() ); workItem.setProcessInstanceId( _workItem.getProcessInstancesId() ); workItem.setName( _workItem.getName() ); workItem.setState( _workItem.getState() ); workItem.setDeploymentId(_workItem.getDeploymentId()); workItem.setNodeId(_workItem.getNodeId()); workItem.setNodeInstanceId(_workItem.getNodeInstanceId()); if ( includeVariables ) { for ( JBPMMessages.Variable _variable : _workItem.getVariableList() ) { try { Object value = unmarshallVariableValue( context, _variable ); workItem.setParameter( _variable.getName(), value ); } catch ( ClassNotFoundException e ) { throw new IllegalArgumentException( "Could not reload parameter " + _variable.getName() + " for work item " + _workItem ); } } } return workItem; }
Example #4
Source File: ActivityTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test public void testCallActivityWithSubProcessWaitState() throws Exception { KieBase kbase = createKnowledgeBase( "BPMN2-CallActivity.bpmn2", "BPMN2-CallActivitySubProcessWithBoundaryEvent.bpmn2"); ksession = createKnowledgeSession(kbase); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); Map<String, Object> params = new HashMap<String, Object>(); ProcessInstance processInstance = ksession.startProcess("ParentProcess", params); assertProcessInstanceActive(processInstance.getId(), ksession); WorkItem wi = workItemHandler.getWorkItem(); assertNotNull(wi); ksession.getWorkItemManager().completeWorkItem(wi.getId(), null); assertProcessInstanceFinished(processInstance, ksession); // first check the parent process executed nodes assertNodeTriggered(processInstance.getId(), "StartProcess", "CallActivity", "EndProcess"); // then check child process executed nodes - is there better way to get child process id than simply increment? assertNodeTriggered(processInstance.getId() + 1, "StartProcess2", "User Task", "EndProcess"); }
Example #5
Source File: IntermediateEventTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test @Disabled("Transfomer has been disabled") public void testMessageIntermediateThrowWithTransformation() throws Exception { KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2"); ksession = createKnowledgeSession(kbase); final StringBuffer messageContent = new StringBuffer(); ksession.getWorkItemManager().registerWorkItemHandler("Send Task", new SendTaskHandler(){ @Override public void executeWorkItem(WorkItem workItem, WorkItemManager manager) { // collect message content for verification messageContent.append(workItem.getParameter("Message")); super.executeWorkItem(workItem, manager); } }); Map<String, Object> params = new HashMap<String, Object>(); params.put("x", "MyValue"); ProcessInstance processInstance = ksession.startProcess( "MessageIntermediateEvent", params); assertProcessInstanceCompleted(processInstance); assertThat(messageContent.toString()).isEqualTo("MYVALUE"); }
Example #6
Source File: ActivityTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test public void testUserTaskParametrizedInput() throws Exception { KieBase kbase = createKnowledgeBase("BPMN2-UserTaskWithParametrizedInput.bpmn2"); KieSession ksession = createKnowledgeSession(kbase); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); ProcessInstance processInstance = ksession.startProcess("UserTask"); assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE); ksession = restoreSession(ksession, true); WorkItem workItem = workItemHandler.getWorkItem(); assertNotNull(workItem); assertEquals("Executing task of process instance " + processInstance.getId() + " as work item with Hello", workItem.getParameter("Description").toString().trim()); ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null); assertProcessInstanceFinished(processInstance, ksession); ksession.dispose(); }
Example #7
Source File: IntermediateEventTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test public void testIntermediateCatchEventSignalAndBoundarySignalEvent() throws Exception { KieBase kbase = createKnowledgeBase("BPMN2-BoundaryEventWithSignals.bpmn2"); ksession = createKnowledgeSession(kbase); TestWorkItemHandler handler = new TestWorkItemHandler(); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler); ProcessInstance processInstance = ksession.startProcess("boundaryeventtest"); assertProcessInstanceActive(processInstance); ksession = restoreSession(ksession, true); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler); // now signal process instance ksession.signalEvent("moveon", "", processInstance.getId()); assertProcessInstanceActive(processInstance); WorkItem wi = handler.getWorkItem(); assertThat(wi).isNotNull(); // signal boundary event on user task ksession.signalEvent("moveon", "", processInstance.getId()); assertProcessInstanceFinished(processInstance, ksession); }
Example #8
Source File: ActivityTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test public void testUserTask() throws Exception { KieBase kbase = createKnowledgeBase("BPMN2-UserTask.bpmn2"); KieSession ksession = createKnowledgeSession(kbase); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); ProcessInstance processInstance = ksession.startProcess("UserTask"); assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE); ksession = restoreSession(ksession, true); WorkItem workItem = workItemHandler.getWorkItem(); assertNotNull(workItem); assertEquals("john", workItem.getParameter("ActorId")); ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null); assertProcessInstanceFinished(processInstance, ksession); ksession.dispose(); }
Example #9
Source File: GetExistingPastebinWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 6 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); Map<String, Object> results = new HashMap<String, Object>(); String pastebinKey = (String) workItem.getParameter("PastebinKey"); PastebinLink pastebinLink = (PastebinLink) workItem.getParameter("PastebinLink"); if (pastebinLink == null) { pastebinLink = Pastebin.getPaste(pastebinKey); } pastebinLink.fetchContent(); results.put(RESULTS_VALUE, pastebinLink.getPaste().getContents()); workItemManager.completeWorkItem(workItem.getId(), results); } catch (Exception e) { handleException(e); } }
Example #10
Source File: IntermediateEventTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test @Timeout(10) public void testTimerMultipleInstances() throws Exception { NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 3); KieBase kbase = createKnowledgeBase("BPMN2-MultiInstanceLoopBoundaryTimer.bpmn2"); ksession = createKnowledgeSession(kbase); ksession.addEventListener(countDownListener); TestWorkItemHandler handler = new TestWorkItemHandler(); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler); ProcessInstance processInstance = ksession.startProcess("boundaryTimerMultipleInstances"); assertProcessInstanceActive(processInstance); countDownListener.waitTillCompleted(); List<WorkItem> workItems = handler.getWorkItems(); assertThat(workItems).isNotNull(); assertThat(workItems.size()).isEqualTo(3); for (WorkItem wi : workItems) { ksession.getWorkItemManager().completeWorkItem(wi.getId(), null); } assertProcessInstanceFinished(processInstance, ksession); }
Example #11
Source File: KillContainerWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 6 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); String containerId = (String) workItem.getParameter("ContainerId"); if (dockerClient == null) { DockerClientConnector connector = new DockerClientConnector(); dockerClient = connector.getDockerClient(); } dockerClient.killContainerCmd(containerId).exec(); workItemManager.completeWorkItem(workItem.getId(), null); } catch (Exception e) { logger.error("Unable to kill container: " + e.getMessage()); handleException(e); } }
Example #12
Source File: WorkItemHandlerExceptionHandlingTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test public void testErrornousHandlerWithStrategyRetryWaitState() throws Exception { KieBase kbase = createKnowledgeBaseWithoutDumper("handler/BPMN2-UserTaskWithBooleanOutput.bpmn2", "handler/BPMN2-ReceiveTask.bpmn2"); KieSession ksession = createKnowledgeSession(kbase); ErrornousWorkItemHandler workItemHandler = new ErrornousWorkItemHandler("ReceiveTask", HandlingStrategy.RETRY); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); TestWorkItemHandler testHandler = new TestWorkItemHandler(); ksession.getWorkItemManager().registerWorkItemHandler("Receive Task", testHandler); Map<String, Object> params = new HashMap<>(); params.put("isChecked", false); ProcessInstance processInstance = ksession.startProcess("com.sample.boolean", params); assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState()); WorkItem receiveWorkItem = testHandler.getWorkItem(); Map<String, Object> results = new HashMap<>(); results.put("Message", true); ksession.getWorkItemManager().completeWorkItem(receiveWorkItem.getId(), results); assertProcessVarValue(processInstance, "isChecked", "true"); }
Example #13
Source File: StandaloneBPMNProcessTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test public void testUserTask() throws Exception { KieBase kbase = createKnowledgeBase("BPMN2-UserTask.bpmn2"); KieSession ksession = createKnowledgeSession(kbase); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); Map<String, Object> params = new HashMap<String, Object>(); String varId = "s"; String varValue = "initialValue"; params.put(varId, varValue); ProcessInstance processInstance = ksession.startProcess("UserTask", params); assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE); ksession = restoreSession(ksession, true); WorkItem workItem = workItemHandler.getWorkItem(); assertThat(workItem).isNotNull(); assertThat(workItem.getParameter("ActorId")).isEqualTo("john"); ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null); assertProcessInstanceCompleted(processInstance.getId(), ksession); }
Example #14
Source File: EscalationEventTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test @Disabled("Non interrupting escalation has not yet been implemented.") // TODO: implement non-interrupting escalation public void testNonInterruptingEscalationBoundaryEventOnTask() throws Exception { KieBase kbase = createKnowledgeBase("escalation/BPMN2-EscalationBoundaryEventOnTask.bpmn2"); ksession = createKnowledgeSession(kbase); TestWorkItemHandler handler = new TestWorkItemHandler(); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler); ksession.addEventListener(LOGGING_EVENT_LISTENER); ProcessInstance processInstance = ksession.startProcess("non-interrupting-escalation"); List<WorkItem> workItems = handler.getWorkItems(); assertEquals(2, workItems.size()); WorkItem johnsWork = workItems.get(0); WorkItem marysWork = workItems.get(1); if (!"john".equalsIgnoreCase((String) johnsWork.getParameter("ActorId"))) { marysWork = johnsWork; johnsWork = workItems.get(1); } // end event after task triggers escalation ksession.getWorkItemManager().completeWorkItem(johnsWork.getId(), null); // escalation should have run.. // should finish process ksession.getWorkItemManager().completeWorkItem(marysWork.getId(), null); assertProcessInstanceCompleted(processInstance); }
Example #15
Source File: ProcessEventSupport.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public void fireAfterWorkItemTransition(final ProcessInstance instance, WorkItem workitem, Transition<?> transition, KieRuntime kruntime) { final Iterator<ProcessEventListener> iter = getEventListenersIterator(); final ProcessWorkItemTransitionEvent event = new ProcessWorkItemTransitionEventImpl(instance, workitem, transition, kruntime, true); unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, (e) -> { if (iter.hasNext()) { do { iter.next().afterWorkItemTransition(e); } while (iter.hasNext()); } })); }
Example #16
Source File: UploadFileWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 5 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); if (auth == null) { auth = new DropboxAuth(); } client = auth.authorize(clientIdentifier, accessToken); String dropboxPath = (String) workItem.getParameter("Path"); Document documentToUpload = (Document) workItem.getParameter("Document"); ByteArrayInputStream docStream = new ByteArrayInputStream(documentToUpload.getContent()); client.files().uploadBuilder(dropboxPath + "/" + documentToUpload.getName()) .withMode(WriteMode.ADD) .withClientModified(documentToUpload.getLastModified()) .uploadAndFinish(docStream); workItemManager.completeWorkItem(workItem.getId(), null); } catch (Exception e) { logger.error("Unable to upload file: " + e.getMessage()); handleException(e); } }
Example #17
Source File: SummonerInfoWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 5 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); String summonerName = (String) workItem.getParameter("SummonerName"); String summonerPlatform = (String) workItem.getParameter("SummonerPlatform"); Map<String, Object> results = new HashMap<String, Object>(); Platform platform = RiotUtils.getPlatform(summonerPlatform); if (riotAuth == null) { riotAuth = new RiotAuth(); } riotApi = riotAuth.getRiotApi(apiKey); Summoner summoner = riotApi.getSummonerByName(platform, summonerName); if (summoner != null) { results.put(RESULTS_VALUE, summoner); workItemManager.completeWorkItem(workItem.getId(), results); } else { throw new IllegalArgumentException("Could not find summoner with name: " + summonerName + " and platform: " + summonerPlatform); } } catch (Exception e) { handleException(e); } }
Example #18
Source File: ActivityGenerationModelTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test public void testWorkItemProcessWithVariableMapping() throws Exception { BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-ServiceProcess.bpmn2")).get(0); ProcessMetaData metaData = ProcessToExecModelGenerator.INSTANCE.generate((WorkflowProcess) process.legacyProcess()); String content = metaData.getGeneratedClassModel().toString(); assertThat(content).isNotNull(); log(content); Map<String, String> classData = new HashMap<>(); classData.put("org.drools.bpmn2.ServiceProcessProcess", content); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); Map<String, Object> params = new HashMap<String, Object>(); params.put("s", "john"); Map<String, BpmnProcess> processes = createProcesses(classData, Collections.singletonMap("org.jbpm.bpmn2.objects.HelloService_hello_2_Handler", workItemHandler)); ProcessInstance<BpmnVariables> processInstance = processes.get("ServiceProcess").createInstance(BpmnVariables.create(params)); processInstance.start(); assertEquals(STATE_ACTIVE, processInstance.status()); WorkItem workItem = workItemHandler.getWorkItem(); assertNotNull(workItem); assertEquals("john", workItem.getParameter("Parameter")); processInstance.completeWorkItem(workItem.getId(), Collections.singletonMap("Result", "john doe")); assertEquals(STATE_COMPLETED, processInstance.status()); }
Example #19
Source File: FlowTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test public void testTimerAndGateway() throws Exception { NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 1); KieBase kbase = createKnowledgeBase("timer/BPMN2-ParallelSplitWithTimerProcess.bpmn2"); ksession = createKnowledgeSession(kbase); ksession.addEventListener(countDownListener); TestWorkItemHandler handler1 = new TestWorkItemHandler(); TestWorkItemHandler handler2 = new TestWorkItemHandler(); ksession.getWorkItemManager().registerWorkItemHandler("task1", handler1); ksession.getWorkItemManager().registerWorkItemHandler("task2", handler2); ProcessInstance instance = ksession.createProcessInstance("timer-process", new HashMap<String, Object>()); ksession.startProcessInstance(instance.getId()); WorkItem workItem1 = handler1.getWorkItem(); assertNotNull(workItem1); assertNull(handler1.getWorkItem()); //first safe state: task1 completed ksession.getWorkItemManager().completeWorkItem(workItem1.getId(), null); ksession = restoreSession(ksession, true); ksession.addEventListener(countDownListener); ksession.getWorkItemManager().registerWorkItemHandler("task1", handler1); ksession.getWorkItemManager().registerWorkItemHandler("task2", handler2); //second safe state: timer completed, waiting on task2 countDownListener.waitTillCompleted(); WorkItem workItem2 = handler2.getWorkItem(); //Both sides of the join are completed. But on the process instance, there are two //JoinInstance for the same Join, and since it is an AND join, it never reaches task2 //It fails after the next assertion assertNotNull(workItem2); assertNull(handler2.getWorkItem()); ksession.getWorkItemManager().completeWorkItem(workItem2.getId(), null); assertProcessInstanceCompleted(instance); }
Example #20
Source File: UIWorkItemHandler.java From kogito-runtimes with Apache License 2.0 | 5 votes |
private void select() { WorkItem workItem = getSelectedWorkItem(); if (workItem != null) { UIWorkItemHandlerDialog dialog = new UIWorkItemHandlerDialog(UIWorkItemHandler.this, workItem); dialog.setVisible(true); } }
Example #21
Source File: UIWorkItemHandler.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public WorkItem getSelectedWorkItem() { int index = workItemsList.getSelectedIndex(); if (index != -1) { Object selected = workItemsList.getModel().getElementAt(index); if (selected instanceof WorkItemWrapper) { return ((WorkItemWrapper) selected).getWorkItem(); } } return null; }
Example #22
Source File: UIWorkItemHandler.java From kogito-runtimes with Apache License 2.0 | 5 votes |
private void reloadWorkItemsList() { List<WorkItemWrapper> result = new ArrayList<WorkItemWrapper>(); for (Iterator<WorkItem> iterator = workItems.keySet().iterator(); iterator.hasNext(); ) { WorkItem workItem = iterator.next(); result.add(new WorkItemWrapper(workItem)); } workItemsList.setListData(result.toArray()); }
Example #23
Source File: Complete.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Override public void apply(WorkItem workitem, Transition<?> transition) { if (workitem instanceof HumanTaskWorkItem) { if (transition.policies() != null) { for (Policy<?> policy : transition.policies()) { if (policy instanceof SecurityPolicy) { ((HumanTaskWorkItemImpl) workitem).setActualOwner(((SecurityPolicy) policy).value().getName()); break; } } } workitem.getResults().put("ActorId", ((HumanTaskWorkItem) workitem).getActualOwner()); } }
Example #24
Source File: ForkRepositoryWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 5 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); Map<String, Object> results = new HashMap<String, Object>(); String repoOwner = (String) workItem.getParameter("RepoOwner"); String repoName = (String) workItem.getParameter("RepoName"); String organization = (String) workItem.getParameter("Organization"); Repository forkedRepository; RepositoryService repoService = auth.getRespositoryService(this.userName, this.password); RepositoryId toBeForkedRepo = new RepositoryId(repoOwner, repoName); if (StringUtils.isNotEmpty(organization)) { forkedRepository = repoService.forkRepository(toBeForkedRepo, organization); } else { forkedRepository = repoService.forkRepository(toBeForkedRepo); } results.put(RESULTS_VALUE, new RepositoryInfo(forkedRepository)); workItemManager.completeWorkItem(workItem.getId(), results); } catch (Exception e) { handleException(e); } }
Example #25
Source File: InspectContainerWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 5 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { Map<String, Object> results = new HashMap<String, Object>(); try { RequiredParameterValidator.validate(this.getClass(), workItem); String containerId = (String) workItem.getParameter("ContainerId"); if (dockerClient == null) { DockerClientConnector connector = new DockerClientConnector(); dockerClient = connector.getDockerClient(); } InspectContainerResponse containerResponse = dockerClient.inspectContainerCmd(containerId).exec(); results.put(RESULTS_DOCUMENT, new SerializableInspectContainerResponse(containerResponse)); workItemManager.completeWorkItem(workItem.getId(), results); } catch (Exception e) { logger.error("Unable to inspect container: " + e.getMessage()); handleException(e); } }
Example #26
Source File: EscalationEventTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test public void testEventSubprocessEscalation() throws Exception { KieBase kbase = createKnowledgeBase("escalation/BPMN2-EventSubprocessEscalation.bpmn2"); final List<String> executednodes = new ArrayList<>(); ProcessEventListener listener = new DefaultProcessEventListener() { @Override public void afterNodeLeft(ProcessNodeLeftEvent event) { if (event.getNodeInstance().getNodeName() .equals("Script Task 1")) { executednodes.add(event.getNodeInstance().getId()); } } }; ksession = createKnowledgeSession(kbase); ksession.addEventListener(listener); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); ProcessInstance processInstance = ksession .startProcess("BPMN2-EventSubprocessEscalation"); assertProcessInstanceActive(processInstance); ksession = restoreSession(ksession, true); ksession.addEventListener(listener); WorkItem workItem = workItemHandler.getWorkItem(); assertNotNull(workItem); ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null); assertProcessInstanceFinished(processInstance, ksession); assertNodeTriggered(processInstance.getId(), "start", "User Task 1", "end", "Sub Process 1", "start-sub", "Script Task 1", "end-sub"); assertEquals(1, executednodes.size()); }
Example #27
Source File: FlowTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test public void testInclusiveSplitAndJoinWithEnd() throws Exception { KieBase kbase = createKnowledgeBase("BPMN2-InclusiveSplitAndJoinWithEnd.bpmn2"); ksession = createKnowledgeSession(kbase); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); Map<String, Object> params = new HashMap<String, Object>(); params.put("x", 25); ProcessInstance processInstance = ksession.startProcess( "com.sample.test", params); List<WorkItem> activeWorkItems = workItemHandler.getWorkItems(); assertEquals(3, activeWorkItems.size()); ksession = restoreSession(ksession, true); for (int i = 0; i < 2; i++) { ksession.getWorkItemManager().completeWorkItem( activeWorkItems.get(i).getId(), null); } assertProcessInstanceActive(processInstance); ksession.getWorkItemManager().completeWorkItem( activeWorkItems.get(2).getId(), null); assertProcessInstanceFinished(processInstance, ksession); }
Example #28
Source File: FlowTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test public void testMultiInstanceLoopNumberTest() throws Exception { KieBase kbase = createKnowledgeBase("BPMN2-MultiInstanceLoop-Numbering.bpmn2"); ksession = createKnowledgeSession(kbase); Map<String, Object> params = new HashMap<String, Object>(); final Map<String, String> nodeIdNodeNameMap = new HashMap<String, String>(); ksession.addEventListener(new DefaultProcessEventListener() { @Override public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) { NodeInstance nodeInstance = event.getNodeInstance(); String uniqId = ((NodeInstanceImpl) nodeInstance).getUniqueId(); String nodeName = ((NodeInstanceImpl) nodeInstance).getNode().getName(); String prevNodeName = nodeIdNodeNameMap.put( uniqId, nodeName ); if( prevNodeName != null ) { assertEquals(uniqId + " is used for more than one node instance: ", prevNodeName, nodeName); } } }); TestWorkItemHandler handler = new TestWorkItemHandler(); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler); ProcessInstance processInstance = ksession.startProcess("Test.MultipleInstancesBug", params); List<WorkItem> workItems = handler.getWorkItems(); logger.debug( "COMPLETING TASKS."); ksession.getWorkItemManager().completeWorkItem(workItems.remove(0).getId(), null); ksession.getWorkItemManager().completeWorkItem(workItems.remove(0).getId(), null); assertProcessInstanceCompleted(processInstance); }
Example #29
Source File: SignallingTaskHandlerDecorator.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Override public void handleAbortException(Throwable cause, WorkItem workItem, WorkItemManager manager) { if( getAndIncreaseExceptionCount(workItem.getProcessInstanceId()) < exceptionCountLimit ) { workItem.getParameters().put(this.workItemExceptionParameterName, cause); ((org.drools.core.process.instance.WorkItemManager) manager).signalEvent(this.eventType, (org.drools.core.process.instance.WorkItem) workItem, workItem.getProcessInstanceId()); } }
Example #30
Source File: Skip.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Override public void apply(WorkItem workitem, Transition<?> transition) { if (transition.policies() != null) { for (Policy<?> policy : transition.policies()) { if (policy instanceof SecurityPolicy) { ((HumanTaskWorkItemImpl) workitem).setActualOwner(((SecurityPolicy)policy).value().getName()); break; } } } workitem.getResults().put("ActorId", ((HumanTaskWorkItem) workitem).getActualOwner()); }