-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support activities in their own subtasks
Now we can delegate activity execution to a (physical) subtask by specifying distribution/subtask item. This execution is handled by special DelegatedActivityExecution (as opposed to newly created LocalActivityExecution covering all the standard cases). Also implemented overview of the whole tree execution status in the root task ($task/activityState/treeOverview).
- Loading branch information
Showing
46 changed files
with
1,697 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...chema/src/main/java/com/evolveum/midpoint/schema/util/task/ActivityStateOverviewUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright (C) 2010-2021 Evolveum and contributors | ||
* | ||
* This work is dual-licensed under the Apache License 2.0 | ||
* and European Union Public License. See LICENSE file for details. | ||
*/ | ||
|
||
package com.evolveum.midpoint.schema.util.task; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
import com.evolveum.midpoint.prism.path.ItemPath; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.*; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class ActivityStateOverviewUtil { | ||
|
||
public static final ItemPath ACTIVITY_TREE_STATE_OVERVIEW_PATH = | ||
ItemPath.create(TaskType.F_ACTIVITY_STATE, TaskActivityStateType.F_TREE_OVERVIEW); | ||
|
||
public static @NotNull ActivityStateOverviewType findOrCreateEntry(@NotNull ActivityStateOverviewType current, | ||
@NotNull ActivityPath path) { | ||
if (path.isEmpty()) { | ||
return current; | ||
} | ||
return findOrCreateEntry( | ||
findOrCreateEntry(current, path.first()), | ||
path.rest()); | ||
} | ||
|
||
public static @NotNull ActivityStateOverviewType findOrCreateEntry(@NotNull ActivityStateOverviewType current, | ||
String identifier) { | ||
List<ActivityStateOverviewType> matching = current.getActivity().stream() | ||
.filter(a -> Objects.equals(a.getIdentifier(), identifier)) | ||
.collect(Collectors.toList()); | ||
if (matching.isEmpty()) { | ||
ActivityStateOverviewType newEntry = new ActivityStateOverviewType() | ||
.identifier(identifier); | ||
current.getActivity().add(newEntry); | ||
return newEntry; | ||
} else if (matching.size() == 1) { | ||
return matching.get(0); | ||
} else { | ||
throw new IllegalStateException("State overview entry " + current + " contains " + matching.size() + " entries " + | ||
"for activity identifier '" + identifier + "': " + matching); | ||
} | ||
} | ||
|
||
public static boolean containsFailedExecution(@NotNull TaskType task) { | ||
return task.getActivityState() != null && | ||
containsFailedExecution(task.getActivityState().getTreeOverview()); | ||
} | ||
|
||
public static boolean containsFailedExecution(@Nullable ActivityStateOverviewType stateOverview) { | ||
return stateOverview != null && | ||
(isExecutionFailed(stateOverview) || | ||
stateOverview.getActivity().stream().anyMatch(ActivityStateOverviewUtil::containsFailedExecution)); | ||
} | ||
|
||
private static boolean isExecutionFailed(@NotNull ActivityStateOverviewType stateOverview) { | ||
return stateOverview.getExecutionState() == ActivityExecutionStateType.NOT_EXECUTING && | ||
(stateOverview.getResultStatus() == OperationResultStatusType.FATAL_ERROR || | ||
stateOverview.getResultStatus() == OperationResultStatusType.PARTIAL_ERROR); | ||
} | ||
|
||
@NotNull | ||
public static ActivityStateOverviewType getOrCreateTreeOverview(@NotNull TaskType taskBean) { | ||
return taskBean.getActivityState() != null && taskBean.getActivityState().getTreeOverview() != null ? | ||
taskBean.getActivityState().getTreeOverview() : new ActivityStateOverviewType(); | ||
} | ||
|
||
public static ActivityStateOverviewType getTreeOverview(@NotNull TaskType taskBean) { | ||
return taskBean.getActivityState() != null ? taskBean.getActivityState().getTreeOverview() : null; | ||
} | ||
|
||
public static void clearFailedState(@NotNull ActivityStateOverviewType state) { | ||
doClearFailedState(state); | ||
state.getActivity().forEach(ActivityStateOverviewUtil::clearFailedState); | ||
} | ||
|
||
private static void doClearFailedState(@NotNull ActivityStateOverviewType state) { | ||
if (isExecutionFailed(state)) { | ||
state.setExecutionState(null); | ||
state.setResultStatus(null); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.