Skip to content

Commit

Permalink
[incubator-kie-issues-1439] UserTask Decouple codegen and interface f…
Browse files Browse the repository at this point in the history
…rom engine
  • Loading branch information
elguardian committed Sep 11, 2024
1 parent 8f1a822 commit ad6bef1
Show file tree
Hide file tree
Showing 30 changed files with 331 additions and 696 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.kie.kogito.addons.k8s.LocalEndpointDiscovery;
import org.kie.kogito.addons.quarkus.k8s.workitems.QuarkusDiscoveredEndpointCaller;
import org.kie.kogito.examples.onboarding.DecisionTaskWorkItemHandler;
import org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler;
import org.kie.kogito.internal.process.workitem.KogitoWorkItemHandler;
import org.kie.kogito.process.impl.DefaultWorkItemHandlerConfig;

import jakarta.annotation.PostConstruct;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@
package org.kie.kogito.examples.onboarding;

import java.util.Map;
import java.util.Optional;

import org.kie.kogito.addons.quarkus.k8s.workitems.QuarkusDiscoveredEndpointCaller;
import org.kie.kogito.internal.process.runtime.KogitoWorkItem;
import org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler;
import org.kie.kogito.internal.process.runtime.KogitoWorkItemManager;
import org.kie.kogito.internal.process.workitem.KogitoWorkItem;
import org.kie.kogito.internal.process.workitem.KogitoWorkItemHandler;
import org.kie.kogito.internal.process.workitem.KogitoWorkItemManager;
import org.kie.kogito.internal.process.workitem.WorkItemTransition;
import org.kie.kogito.process.workitems.impl.DefaultKogitoWorkItemHandler;

import jakarta.ws.rs.HttpMethod;

public class DecisionTaskWorkItemHandler implements KogitoWorkItemHandler {
public class DecisionTaskWorkItemHandler extends DefaultKogitoWorkItemHandler {

private QuarkusDiscoveredEndpointCaller endpointCaller;

Expand All @@ -36,14 +39,9 @@ public DecisionTaskWorkItemHandler(QuarkusDiscoveredEndpointCaller endpointCalle
}

@Override
public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager manager) {
public Optional<WorkItemTransition> activateWorkItemHandler(KogitoWorkItemManager manager, KogitoWorkItemHandler handler, KogitoWorkItem workItem, WorkItemTransition transition) {
Map<String, Object> results = endpointCaller.discoverAndCall(workItem, System.getenv("NAMESPACE"), "Decision", HttpMethod.POST);
manager.completeWorkItem(workItem.getStringId(), results);
}

@Override
public void abortWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager manager) {

return Optional.of(handler.completeTransition(workItem.getPhaseStatus(), results));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.kie.kogito.examples;

import org.kie.kogito.examples.test.RecordedOutputWorkItemHandler;
import org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler;
import org.kie.kogito.internal.process.workitem.KogitoWorkItemHandler;

public class WorkItemHandlerConfig extends BaseWorkItemHandlerConfig {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

import org.junit.jupiter.api.Test;
import org.kie.kogito.examples.test.RecordedOutputWorkItemHandler;
import org.kie.kogito.internal.process.runtime.KogitoWorkItem;
import org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler;
import org.kie.kogito.internal.process.workitem.KogitoWorkItem;
import org.kie.kogito.internal.process.workitem.KogitoWorkItemHandler;
import org.kie.kogito.process.ProcessConfig;
import org.kie.kogito.testcontainers.quarkus.InfinispanQuarkusTestResource;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,23 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

import org.kie.kogito.internal.process.runtime.KogitoWorkItem;
import org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler;
import org.kie.kogito.internal.process.runtime.KogitoWorkItemManager;
import org.kie.kogito.internal.process.workitem.KogitoWorkItem;
import org.kie.kogito.internal.process.workitem.KogitoWorkItemHandler;
import org.kie.kogito.internal.process.workitem.KogitoWorkItemManager;
import org.kie.kogito.internal.process.workitem.WorkItemTransition;
import org.kie.kogito.process.workitems.impl.DefaultKogitoWorkItemHandler;

public class RecordedOutputWorkItemHandler implements KogitoWorkItemHandler {
public class RecordedOutputWorkItemHandler extends DefaultKogitoWorkItemHandler {

private Map<String, Function<KogitoWorkItem, Map<String, Object>>> recorded = new HashMap<>();

@Override
public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager manager) {
public Optional<WorkItemTransition> activateWorkItemHandler(KogitoWorkItemManager manager, KogitoWorkItemHandler handler, KogitoWorkItem workItem, WorkItemTransition transition) {
Map<String, Object> results = recorded.remove(workItem.getParameter("TaskName")).apply(workItem);

manager.completeWorkItem(workItem.getStringId(), results);
}

@Override
public void abortWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager manager) {

return Optional.of(handler.completeTransition(workItem.getPhaseStatus(), results));
}

public void record(String name, Function<KogitoWorkItem, Map<String, Object>> item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,23 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import org.kie.api.runtime.process.ProcessWorkItemHandlerException;
import org.kie.kogito.internal.process.runtime.KogitoWorkItem;
import org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler;
import org.kie.kogito.internal.process.runtime.KogitoWorkItemManager;
import org.kie.kogito.internal.process.workitem.KogitoWorkItem;
import org.kie.kogito.internal.process.workitem.KogitoWorkItemHandler;
import org.kie.kogito.internal.process.workitem.KogitoWorkItemManager;
import org.kie.kogito.internal.process.workitem.WorkItemTransition;
import org.kie.kogito.process.workitems.impl.DefaultKogitoWorkItemHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CustomTaskWorkItemHandler implements KogitoWorkItemHandler {
public class CustomTaskWorkItemHandler extends DefaultKogitoWorkItemHandler {

private static final Logger LOG = LoggerFactory.getLogger(CustomTaskWorkItemHandler.class);

@Override
public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager manager) {
public Optional<WorkItemTransition> activateWorkItemHandler(KogitoWorkItemManager manager, KogitoWorkItemHandler handler, KogitoWorkItem workItem, WorkItemTransition transition) {
LOG.debug("start");
LOG.debug("Passed parameters:");

Expand All @@ -51,15 +54,22 @@ public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager manag
if (input.matches("(RETRY|COMPLETE|RETHROW)")) {
handleError(input);
} else if (input.contentEquals("ABORT")) {
manager.abortWorkItem(workItem.getStringId());
return Optional.of(handler.abortTransition(workItem.getPhaseStatus()));
} else {
// Don’t forget to finish the work item otherwise the process
// will be active infinitely and never will pass the flow
// to the next node.
manager.completeWorkItem(workItem.getStringId(), results);
return Optional.of(handler.completeTransition(workItem.getPhaseStatus(), results));
}

LOG.debug("end");
return Optional.empty();
}

@Override
public Optional<WorkItemTransition> abortWorkItemHandler(KogitoWorkItemManager manager, KogitoWorkItemHandler handler, KogitoWorkItem workitem, WorkItemTransition transition) {
LOG.debug("ABORT!");
return Optional.empty();
}

private void handleError(String strategy) {
Expand All @@ -68,9 +78,4 @@ private void handleError(String strategy) {
new IllegalStateException(strategy + " strategy test"));
}

@Override
public void abortWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager manager) {
LOG.debug("ABORT!");
manager.abortWorkItem(workItem.getStringId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
*/
package org.acme.travels.config;

import org.acme.travels.usertasks.CustomHumanTaskLifeCycle;
import org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemHandler;
import org.acme.travels.usertasks.CustomHumanTaskWorkItemHandler;
import org.kie.kogito.process.impl.DefaultWorkItemHandlerConfig;

import jakarta.enterprise.context.ApplicationScoped;
Expand All @@ -37,6 +36,6 @@
@ApplicationScoped
public class CustomWorkItemHandlerConfig extends DefaultWorkItemHandlerConfig {
{
register("Human Task", new HumanTaskWorkItemHandler(new CustomHumanTaskLifeCycle()));
register("Human Task", new CustomHumanTaskWorkItemHandler());
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit ad6bef1

Please sign in to comment.