Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[incubator-kie-issues-1439] UserTask Decouple codegen and interface from engine #2009

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading