Skip to content

Commit

Permalink
Fix retrieval options support in task manager
Browse files Browse the repository at this point in the history
1) getTask method now respects the retrieval options
2) searchObjects now implements subtasks retrieval

Also,
- TaskType.F_SUBTASK was removed (replaced by F_SUBTASK_REF)
- TestQuartzTaskManagerContract was renamed to TestTaskManagerContract

This fixes MID-5374 and relates to MID-2353.
  • Loading branch information
mederly committed Mar 9, 2020
1 parent 924b656 commit b0f9223
Show file tree
Hide file tree
Showing 19 changed files with 233 additions and 128 deletions.
Expand Up @@ -117,7 +117,7 @@ protected Collection<SelectorOptions<GetOperationOptions>> buildGetOptions() {

return getOperationOptionsBuilder()
// retrieve
.item(TaskType.F_SUBTASK).retrieve()
.item(TaskType.F_SUBTASK_REF).retrieve()
.item(TaskType.F_NODE_AS_OBSERVED).retrieve()
.item(TaskType.F_NEXT_RUN_START_TIMESTAMP).retrieve()
.item(TaskType.F_NEXT_RETRY_TIMESTAMP).retrieve()
Expand Down
Expand Up @@ -186,7 +186,7 @@ private Collection<SelectorOptions<GetOperationOptions>> createOperationOptions(
propertiesToGet.add(TaskType.F_NODE_AS_OBSERVED);
propertiesToGet.add(TaskType.F_NEXT_RUN_START_TIMESTAMP);
propertiesToGet.add(TaskType.F_NEXT_RETRY_TIMESTAMP);
propertiesToGet.add(TaskType.F_SUBTASK);
propertiesToGet.add(TaskType.F_SUBTASK_REF);

GetOperationOptionsBuilder getOperationOptionsBuilder = getSchemaHelper().getOperationOptionsBuilder();
getOperationOptionsBuilder = getOperationOptionsBuilder.resolveNames();
Expand Down
Expand Up @@ -125,7 +125,7 @@ private void resolveSubTasks(TaskType subTask, boolean alreadyLoaded, List<TaskT
subTaskWithLoadedSubtasks = subTask.asPrismObject();
} else {
subTaskWithLoadedSubtasks = WebModelServiceUtils.loadObject(TaskType.class, subTask.getOid(),
getSchemaHelper().getOperationOptionsBuilder().item(TaskType.F_SUBTASK).retrieve().build(), getPageBase(), task, result);
getSchemaHelper().getOperationOptionsBuilder().item(TaskType.F_SUBTASK_REF).retrieve().build(), getPageBase(), task, result);
}

if (subTaskWithLoadedSubtasks == null) {
Expand Down
Expand Up @@ -74,7 +74,7 @@ public boolean computeSubtasksAndThreadsVisible(PageTask parentPage, PrismObject
subtasksAndThreadsVisible = configuresWorkerThreads(task) && isThreadsReadable;
} else if (!parentPage.isAdd() && !WebComponentUtil.isWorkflowTask(taskWrapper.getObject().asObjectable())) {
subtasksAndThreadsVisible = configuresWorkerThreads(task) && isThreadsReadable
|| !CollectionUtils.isNotEmpty(task.getSubtask());
|| !CollectionUtils.isNotEmpty(task.getSubtaskRef());
} else {
subtasksAndThreadsVisible = false;
}
Expand Down
Expand Up @@ -175,7 +175,7 @@ public boolean isRoot() {
private static final Set<ItemPath> PATHS_NOT_RETURNED_BY_DEFAULT = new HashSet<>(Arrays.asList(
ItemPath.create(UserType.F_JPEG_PHOTO),
ItemPath.create(TaskType.F_RESULT),
ItemPath.create(TaskType.F_SUBTASK),
ItemPath.create(TaskType.F_SUBTASK_REF),
ItemPath.create(TaskType.F_NODE_AS_OBSERVED),
ItemPath.create(TaskType.F_NEXT_RUN_START_TIMESTAMP),
ItemPath.create(TaskType.F_NEXT_RETRY_TIMESTAMP),
Expand Down
Expand Up @@ -117,4 +117,13 @@ public static OperationStatsType getAggregatedOperationStats(TaskType task, Pris
.synchronizationInformation(synchronizationInformation)
.actionsExecutedInformation(actionsExecutedInformation);
}

public static TaskType findChild(TaskType parent, String childOid) {
for (TaskType subtask : getResolvedSubtasks(parent)) {
if (childOid.equals(subtask.getOid())) {
return subtask;
}
}
return null;
}
}
Expand Up @@ -2617,18 +2617,6 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="subtask" type="tns:TaskType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Set of task's subtasks.
TRANSIENT attribute. In the repository the parent-child relationship is stored using "parent" property.
TODO: do we still need this?
</xsd:documentation>
<xsd:appinfo>
<a:objectReference>tns:subtaskRef</a:objectReference>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="subtaskRef" type="c:ObjectReferenceType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Expand Down
Expand Up @@ -102,7 +102,7 @@ private void executeReconciliation(TestResource reconciliationTask, String accou

System.out.println("Task tree suspended.");
Collection<SelectorOptions<GetOperationOptions>> getSubtasks = getOperationOptionsBuilder()
.item(TaskType.F_SUBTASK).retrieve()
.item(TaskType.F_SUBTASK_REF).retrieve()
.build();
PrismObject<TaskType> rootAfterSuspension1 = taskManager.getObject(TaskType.class, reconciliationTask.oid, getSubtasks, result);
display("Tree after suspension", TaskDebugUtil.dumpTaskTree(rootAfterSuspension1.asObjectable()));
Expand Down Expand Up @@ -189,7 +189,7 @@ private void executeRecomputation(TestResource recomputationTask, String rolePre

System.out.println("Task tree suspended.");
Collection<SelectorOptions<GetOperationOptions>> getSubtasks = getOperationOptionsBuilder()
.item(TaskType.F_SUBTASK).retrieve()
.item(TaskType.F_SUBTASK_REF).retrieve()
.build();
PrismObject<TaskType> rootAfterSuspension1 = taskManager.getObject(TaskType.class, recomputationTask.oid, getSubtasks, result);
display("Tree after suspension", TaskDebugUtil.dumpTaskTree(rootAfterSuspension1.asObjectable()));
Expand Down
Expand Up @@ -3130,7 +3130,7 @@ protected void dumpTaskTree(String oid, OperationResult result)
throws ObjectNotFoundException,
SchemaException {
Collection<SelectorOptions<GetOperationOptions>> options = schemaHelper.getOperationOptionsBuilder()
.item(TaskType.F_SUBTASK).retrieve()
.item(TaskType.F_SUBTASK_REF).retrieve()
.build();
PrismObject<TaskType> task = taskManager.getObject(TaskType.class, oid, options, result);
dumpTaskAndSubtasks(task.asObjectable(), 0);
Expand Down Expand Up @@ -3822,7 +3822,7 @@ protected PrismObject<TaskType> getTask(String taskOid)
protected PrismObject<TaskType> getTaskTree(String taskOid) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
Task task = createPlainTask("getTaskTree");
OperationResult result = task.getResult();
PrismObject<TaskType> retTask = modelService.getObject(TaskType.class, taskOid, retrieveItemsNamed(TaskType.F_RESULT, TaskType.F_SUBTASK), task, result);
PrismObject<TaskType> retTask = modelService.getObject(TaskType.class, taskOid, retrieveItemsNamed(TaskType.F_RESULT, TaskType.F_SUBTASK_REF), task, result);
result.computeStatus();
TestUtil.assertSuccess("getObject(Task) result not success", result);
return retTask;
Expand Down
Expand Up @@ -264,10 +264,6 @@ void modifyTask(String oid, Collection<? extends ItemDelta> modifications, Opera
@NotNull
Task getTaskWithResult(String taskOid, OperationResult parentResult) throws ObjectNotFoundException, SchemaException;

/**
* BEWARE: This method does not obey taskManager-related options, e.g. retrieve(F_SUBTASK). If you need to apply them,
* use getTaskObject instead. See MID-5374.
*/
@NotNull
Task getTask(String taskOid, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult parentResult) throws ObjectNotFoundException, SchemaException;

Expand Down

0 comments on commit b0f9223

Please sign in to comment.