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

Sync main branch with Apache main branch #68

Merged
merged 22 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b2f1afc
[incubator-kie-issues-1516] Remove obsolete code in process service (…
elguardian Oct 11, 2024
054085c
[incubator-kie-issues-1508] GraphQL external reference id retrieve in…
elguardian Oct 11, 2024
8b5cf4b
[incubator-kie-issues-1519] Clean Up Task Model (#3704)
elguardian Oct 11, 2024
aab0ffb
[incubator-kie-issues-1521] Move user task work item handler to its o…
elguardian Oct 11, 2024
702f76d
[incubator-kie-issues-1520] Proper user task exception handling (#3705)
elguardian Oct 11, 2024
995646c
[incubator-kie-issues-1518] Testing external reference between user t…
elguardian Oct 14, 2024
f77dc94
[incubator-kie-issues-1517] Add Transactional Rest endpoints to UserT…
elguardian Oct 14, 2024
4219f42
[Fix #3717] Switching kogito.events.grouping from buildtime to runtim…
fjtirado Oct 15, 2024
74d3c9e
[incubator-kie-issues#1539] Fix PIP on CI (#3729)
fjtirado Oct 15, 2024
c644dd8
[Fix #3725] Setting leaveTime in Split and Fault node instance (#3726)
fjtirado Oct 15, 2024
245c449
Rename DISCLAIMER file to DISCLAIMER-WIP
LightGuard Oct 15, 2024
12d5506
[incubator-kie-issues#1528] Adapt tracing code. Fix tests (#3727)
gitgabrio Oct 16, 2024
343f086
[Fix #3719] Unmarshall return ObjectNode that is event sensitive (#3720)
fjtirado Oct 16, 2024
a423367
[Fix #3728] Fixing number casting issues (#3730)
fjtirado Oct 16, 2024
38d2208
[incubator-kie-issues#1497] Using the getSerializableNodeInstances in…
gitgabrio Oct 18, 2024
ee521df
[incubator-kie-issues-1522] Transition object to make extensible user…
elguardian Oct 21, 2024
517e403
Revert "[incubator-kie-issues#1539] Fix PIP on CI (#3729)" (#3741)
fjtirado Oct 21, 2024
b8fbf12
[incubator-kie-issues-1529] Avoid concurrency test execution in jbpm-…
elguardian Oct 22, 2024
37eda3e
[incubator-kie-issues-1485] Reenable event test in ProcessTestEvents …
elguardian Oct 22, 2024
3eafc77
Fixing flaky test failing in multiple PRs (#3747)
fjtirado Oct 23, 2024
6b7e7e0
[incubator-kie-issues-1556] Unify task parameters in jbpm-flow (#3746)
elguardian Oct 24, 2024
f670acc
update pr-kogito-runtimes.yml workflow to reflect upstream changes
rgdoliveira Oct 24, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/pr-kogito-runtimes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
github-token: "${{ secrets.GITHUB_TOKEN }}"
definition-file: https://raw.githubusercontent.com/${GROUP:kiegroup}/kogito-pipelines/${BRANCH:main}/.ci/pull-request-config.yaml
env:
BUILD_MVN_OPTS_CURRENT: '-T 1.5C'
BUILD_MVN_OPTS_CURRENT: '-Dvalidate-formatting'
- name: Junit Report
uses: kiegroup/kogito-pipelines/.ci/actions/action-junit-report@main
if: ${{ always() }}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void beforeNodeLeft(ProcessNodeLeftEvent event) {
}

private void recordNodeDuration(DistributionSummary summary, KogitoNodeInstance instance, TimeUnit target) {
if (instance.getTriggerTime() != null) {
if (instance.getTriggerTime() != null && instance.getLeaveTime() != null) {
double duration = target.convert(instance.getLeaveTime().getTime() - instance.getTriggerTime().getTime(), TimeUnit.MILLISECONDS);
summary.record(duration);
LOGGER.debug("Recorded {} {} because of node {} for summary {}", duration, target, instance.getNode().getName(), summary.getId().getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
import org.kie.kogito.process.ProcessInstanceExecutionException;
import org.kie.kogito.process.ProcessInstanceNotFoundException;
import org.kie.kogito.process.VariableViolationException;
import org.kie.kogito.usertask.UserTaskInstanceNotAuthorizedException;
import org.kie.kogito.usertask.UserTaskInstanceNotFoundException;
import org.kie.kogito.usertask.lifecycle.UserTaskTransitionException;

public abstract class BaseExceptionsHandler<T> {

Expand Down Expand Up @@ -74,6 +77,15 @@ protected BaseExceptionsHandler() {
mapper.put(InvalidLifeCyclePhaseException.class, new FunctionHolder<>(
ex -> Collections.singletonMap(MESSAGE, ex.getMessage()), ex -> BaseExceptionsHandler.this::badRequest));

mapper.put(UserTaskTransitionException.class, new FunctionHolder<>(
ex -> Collections.singletonMap(MESSAGE, ex.getMessage()), ex -> BaseExceptionsHandler.this::badRequest));

mapper.put(UserTaskInstanceNotFoundException.class, new FunctionHolder<>(
ex -> Collections.singletonMap(MESSAGE, ex.getMessage()), ex -> BaseExceptionsHandler.this::notFound));

mapper.put(UserTaskInstanceNotAuthorizedException.class, new FunctionHolder<>(
ex -> Collections.singletonMap(MESSAGE, ex.getMessage()), ex -> BaseExceptionsHandler.this::forbidden));

mapper.put(InvalidTransitionException.class, new FunctionHolder<>(
ex -> Collections.singletonMap(MESSAGE, ex.getMessage()), ex -> BaseExceptionsHandler.this::badRequest));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.kie.kogito.task.management.service;

import java.util.Map;
import java.util.Objects;
import java.util.Set;

public class TaskInfo {
Expand Down Expand Up @@ -112,6 +113,25 @@ public void setInputParams(Map<String, Object> inputParams) {
this.inputParams = inputParams;
}

@Override
public int hashCode() {
return Objects.hash(adminGroups, adminUsers, description, excludedUsers, inputParams, potentialGroups, potentialUsers, priority);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TaskInfo other = (TaskInfo) obj;
return Objects.equals(adminGroups, other.adminGroups) && Objects.equals(adminUsers, other.adminUsers) && Objects.equals(description, other.description)
&& Objects.equals(excludedUsers, other.excludedUsers) && Objects.equals(inputParams, other.inputParams) && Objects.equals(potentialGroups, other.potentialGroups)
&& Objects.equals(potentialUsers, other.potentialUsers) && Objects.equals(priority, other.priority);
}

@Override
public String toString() {
return "TaskInfo [description=" + description + ", priority=" + priority + ", potentialUsers=" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,9 @@
*/
package org.kie.kogito.task.management.service;

import org.kie.kogito.internal.process.workitem.Policy;

public interface TaskManagementOperations {

TaskInfo updateTask(String processId,
String processInstanceId,
String taskId,
TaskInfo taskInfo,
boolean replace,
Policy... policies);
TaskInfo updateTask(String taskId, TaskInfo taskInfo, boolean replace);

TaskInfo getTask(String processId, String processInstanceId, String taskId, Policy... policies);
TaskInfo getTask(String taskId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,63 @@
*/
package org.kie.kogito.task.management.service;

import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Supplier;

import org.kie.kogito.internal.process.workitem.KogitoWorkItem;
import org.kie.kogito.internal.process.workitem.Policy;
import org.kie.kogito.process.Process;
import org.kie.kogito.process.ProcessConfig;
import org.kie.kogito.process.ProcessInstance;
import org.kie.kogito.process.ProcessInstanceNotFoundException;
import org.kie.kogito.process.Processes;
import org.kie.kogito.process.WorkItem;
import org.kie.kogito.process.workitems.InternalKogitoWorkItem;
import org.kie.kogito.services.uow.UnitOfWorkExecutor;
import org.kie.kogito.usertask.UserTaskConfig;
import org.kie.kogito.usertask.UserTaskInstance;
import org.kie.kogito.usertask.UserTaskInstanceNotFoundException;
import org.kie.kogito.usertask.UserTasks;
import org.kie.kogito.usertask.impl.DefaultUserTaskInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TaskManagementService implements TaskManagementOperations {

private Processes processes;
private ProcessConfig processConfig;
private static final Logger LOG = LoggerFactory.getLogger(TaskManagementService.class);

public TaskManagementService(Processes processes, ProcessConfig processConfig) {
this.processes = processes;
this.processConfig = processConfig;
private UserTasks userTasks;
// unit of work needs to add the publisher and this is not shared.
private UserTaskConfig userTaskConfig;
private ProcessConfig processesConfig;

public TaskManagementService(UserTasks userTasks, UserTaskConfig userTaskConfig, ProcessConfig processConfig) {
this.userTasks = userTasks;
this.userTaskConfig = userTaskConfig;
this.processesConfig = processConfig;
}

@Override
public TaskInfo updateTask(String processId,
String processInstanceId,
String taskId,
TaskInfo taskInfo,
boolean shouldReplace,
Policy... policies) {
ProcessInstance<?> pi = getProcessInstance(processId, processInstanceId, taskId);
KogitoWorkItem workItem = UnitOfWorkExecutor.executeInUnitOfWork(processConfig.unitOfWorkManager(),
() -> pi.updateWorkItem(taskId,
wi -> {
InternalKogitoWorkItem task = (InternalKogitoWorkItem) wi;
setMap(task::setParameters, task::setParameter, taskInfo.getInputParams(), shouldReplace);
return wi;
}, policies));
return convert(workItem);
public TaskInfo updateTask(String taskId, TaskInfo taskInfo, boolean shouldReplace) {
UserTaskInstance userTaskInstance = UnitOfWorkExecutor.executeInUnitOfWork(processesConfig.unitOfWorkManager(), () -> {
DefaultUserTaskInstance ut = (DefaultUserTaskInstance) getUserTaskInstance(taskId);
setField(ut::setTaskDescription, taskInfo::getDescription, shouldReplace);
setField(ut::setTaskPriority, taskInfo::getPriority, shouldReplace);
setField(ut::setAdminGroups, taskInfo::getAdminGroups, shouldReplace);
setField(ut::setAdminUsers, taskInfo::getAdminUsers, shouldReplace);
setField(ut::setExcludedUsers, taskInfo::getExcludedUsers, shouldReplace);
setField(ut::setPotentialUsers, taskInfo::getPotentialUsers, shouldReplace);
setField(ut::setPotentialGroups, taskInfo::getPotentialGroups, shouldReplace);
setMap(ut::setInputs, ut::setInput, taskInfo.getInputParams(), shouldReplace);
return ut;
});
LOG.trace("updated task through management endpoint to {}", userTaskInstance);
return convert(userTaskInstance);
}

private <T> boolean setField(Consumer<T> consumer, Supplier<T> supplier, boolean shouldReplace) {
T value = supplier.get();
boolean result = shouldReplace || value != null;
if (result) {
consumer.accept(value);
}
return result;
}

private void setMap(Consumer<Map<String, Object>> allConsumer,
Expand All @@ -80,61 +93,31 @@ private void setMap(Consumer<Map<String, Object>> allConsumer,
}

@Override
public TaskInfo getTask(String processId, String processInstanceId, String taskId, Policy... policies) {
WorkItem workItem = getProcessInstance(processId, processInstanceId, taskId).workItem(taskId, policies);
return convert(workItem);
}

private TaskInfo convert(WorkItem workItem) {
return new TaskInfo(
(String) workItem.getParameters().get("Description"),
(String) workItem.getParameters().get("Priority"),
toSet(workItem.getParameters().get("ActorId")),
toSet(workItem.getParameters().get("GroupId")),
toSet(workItem.getParameters().get("ExcludedUsersId")),
toSet(workItem.getParameters().get("BusinessAdministratorId")),
toSet(workItem.getParameters().get("BusinessGroupsId")),
workItem.getParameters());
public TaskInfo getTask(String taskId) {
return convert(getUserTaskInstance(taskId));
}

private TaskInfo convert(KogitoWorkItem workItem) {
private TaskInfo convert(UserTaskInstance userTaskInstance) {
return new TaskInfo(
(String) workItem.getParameter("Description"),
(String) workItem.getParameter("Priority"),
toSet(workItem.getParameter("ActorId")),
toSet(workItem.getParameter("GroupId")),
toSet(workItem.getParameter("ExcludedUsersId")),
toSet(workItem.getParameter("BusinessAdministratorId")),
toSet(workItem.getParameter("BusinessGroupsId")),
workItem.getParameters());
userTaskInstance.getTaskDescription(),
userTaskInstance.getTaskPriority(),
userTaskInstance.getPotentialUsers(),
userTaskInstance.getPotentialGroups(),
userTaskInstance.getExcludedUsers(),
userTaskInstance.getAdminUsers(),
userTaskInstance.getAdminGroups(),
userTaskInstance.getInputs());
}

private Set<String> toSet(Object value) {
if (value == null) {
return Collections.emptySet();
}
if (value instanceof String string) {
return Set.of(string.split(","));
}
return Collections.emptySet();
}

private ProcessInstance<?> getProcessInstance(String processId, String processInstanceId, String taskId) {
if (processId == null) {
throw new IllegalArgumentException("Process id must be given");
}
if (processInstanceId == null) {
throw new IllegalArgumentException("Process instance id must be given");
}
private UserTaskInstance getUserTaskInstance(String taskId) {
if (taskId == null) {
throw new IllegalArgumentException("Task id must be given");
}
Process<?> process = processes.processById(processId);
if (process == null) {
throw new IllegalArgumentException(String.format("Process with id %s not found", processId));
Optional<UserTaskInstance> userTaskInstance = userTasks.instances().findById(taskId);
if (userTaskInstance.isEmpty()) {
throw new UserTaskInstanceNotFoundException(String.format("user task instance with id %s not found", taskId));
}
return process.instances().findById(processInstanceId).orElseThrow(
() -> new ProcessInstanceNotFoundException(processInstanceId));
return userTaskInstance.get();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import org.kie.kogito.tracing.event.trace.TraceExecutionStepType;

public enum EvaluateEventType {
AFTER_CONDITIONAL_EVALUATION(false),
BEFORE_EVALUATE_ALL(true),
AFTER_EVALUATE_ALL(false),
BEFORE_EVALUATE_BKM(true),
AFTER_EVALUATE_BKM(false),
AFTER_EVALUATE_CONDITIONAL(false),
BEFORE_EVALUATE_CONTEXT_ENTRY(true),
AFTER_EVALUATE_CONTEXT_ENTRY(false),
BEFORE_EVALUATE_DECISION(true),
Expand Down Expand Up @@ -52,6 +54,10 @@ public boolean isAfter() {

public TraceExecutionStepType toTraceExecutionStepType() {
switch (this) {
case AFTER_CONDITIONAL_EVALUATION:
case AFTER_EVALUATE_CONDITIONAL:
return TraceExecutionStepType.DMN_CONDITIONAL_INVOCATION;

case BEFORE_EVALUATE_CONTEXT_ENTRY:
case AFTER_EVALUATE_CONTEXT_ENTRY:
return TraceExecutionStepType.DMN_CONTEXT_ENTRY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import java.util.Optional;

import org.junit.jupiter.api.Test;
import org.kie.dmn.api.core.event.AfterConditionalEvaluationEvent;
import org.kie.dmn.api.core.event.AfterEvaluateAllEvent;
import org.kie.dmn.api.core.event.AfterEvaluateBKMEvent;
import org.kie.dmn.api.core.event.AfterEvaluateConditionalEvent;
import org.kie.dmn.api.core.event.AfterEvaluateContextEntryEvent;
import org.kie.dmn.api.core.event.AfterEvaluateDecisionEvent;
import org.kie.dmn.api.core.event.AfterEvaluateDecisionServiceEvent;
Expand Down Expand Up @@ -67,6 +69,8 @@ class EvaluateEventTypeTest {
put(EvaluateEventType.AFTER_EVALUATE_DECISION_TABLE, new Pair<>("afterEvaluateDecisionTable", AfterEvaluateDecisionTableEvent.class));
put(EvaluateEventType.BEFORE_INVOKE_BKM, new Pair<>("beforeInvokeBKM", BeforeInvokeBKMEvent.class));
put(EvaluateEventType.AFTER_INVOKE_BKM, new Pair<>("afterInvokeBKM", AfterInvokeBKMEvent.class));
put(EvaluateEventType.AFTER_CONDITIONAL_EVALUATION, new Pair<>("afterConditionalEvaluation", AfterConditionalEvaluationEvent.class));
put(EvaluateEventType.AFTER_EVALUATE_CONDITIONAL, new Pair<>("afterEvaluateConditional", AfterEvaluateConditionalEvent.class));
}
};
private static final Class<DMNRuntimeEventListener> LISTENER_CLASS = DMNRuntimeEventListener.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
public enum TraceExecutionStepType {
DMN_BKM_EVALUATION,
DMN_BKM_INVOCATION,
DMN_CONDITIONAL_INVOCATION,
DMN_CONTEXT_ENTRY,
DMN_DECISION,
DMN_DECISION_SERVICE,
Expand Down
Loading
Loading