Skip to content

Commit

Permalink
Merge pull request #68 from rgdoliveira/sync_main
Browse files Browse the repository at this point in the history
Sync main branch with Apache main branch
  • Loading branch information
rgdoliveira authored Oct 25, 2024
2 parents 6376ae8 + f670acc commit 4152095
Show file tree
Hide file tree
Showing 98 changed files with 2,201 additions and 727 deletions.
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

0 comments on commit 4152095

Please sign in to comment.