Search in sources :

Example 96 with TaskType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType in project midpoint by Evolveum.

the class ProcessInstanceProvider method augmentTaskObject.

// doesn't throw any exceptions - these are logged and stored into the operation result
public <T extends ObjectType> void augmentTaskObject(PrismObject<T> object, Collection<SelectorOptions<GetOperationOptions>> options, Task opTask, OperationResult parentResult) {
    final OperationResult result = parentResult.createSubresult(OPERATION_AUGMENT_TASK_OBJECT);
    result.addParam("object", ObjectTypeUtil.toShortString(object));
    result.addCollectionOfSerializablesAsParam("options", options);
    if (!(object.asObjectable() instanceof TaskType)) {
        result.recordNotApplicableIfUnknown();
        return;
    }
    final TaskType taskType = (TaskType) object.asObjectable();
    try {
        if (taskType.getWorkflowContext() == null) {
            return;
        }
        final String instanceId = taskType.getWorkflowContext().getProcessInstanceId();
        if (instanceId == null) {
            return;
        }
        final boolean retrieveWorkItems = SelectorOptions.hasToLoadPath(new ItemPath(F_WORKFLOW_CONTEXT, F_WORK_ITEM), options);
        if (!retrieveWorkItems) {
            // We assume that everything (except work items) is already stored in repo.
            return;
        }
        final List<WorkItemType> workItems = workItemProvider.getWorkItemsForProcessInstanceId(instanceId, result);
        taskType.getWorkflowContext().getWorkItem().addAll(CloneUtil.cloneCollectionMembers(workItems));
    } catch (RuntimeException e) {
        result.recordFatalError(e.getMessage(), e);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't prepare wf-related information for {}", e, ObjectTypeUtil.toShortString(object));
    } finally {
        result.computeStatusIfUnknown();
    }
    if (!result.isSuccess()) {
        taskType.setFetchResult(result.createOperationResultType());
    }
}
Also used : TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) WorkItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemType)

Example 97 with TaskType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType in project midpoint by Evolveum.

the class ProcessInstanceManager method getProcessInstancesToKeep.

private Set<String> getProcessInstancesToKeep(OperationResult result) throws SchemaException {
    ObjectQuery query = QueryBuilder.queryFor(TaskType.class, prismContext).not().item(TaskType.F_WORKFLOW_CONTEXT, WfContextType.F_PROCESS_INSTANCE_ID).isNull().build();
    SearchResultList<PrismObject<TaskType>> tasks = taskManager.searchObjects(TaskType.class, query, null, result);
    return tasks.stream().map(t -> t.asObjectable().getWorkflowContext().getProcessInstanceId()).collect(Collectors.toSet());
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) java.util(java.util) WfContextType(com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType) TaskService(org.activiti.engine.TaskService) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) WorkflowManager(com.evolveum.midpoint.wf.api.WorkflowManager) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Autowired(org.springframework.beans.factory.annotation.Autowired) Trace(com.evolveum.midpoint.util.logging.Trace) TaskManager(com.evolveum.midpoint.task.api.TaskManager) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) PrismContext(com.evolveum.midpoint.prism.PrismContext) CommonProcessVariableNames(com.evolveum.midpoint.wf.impl.processes.common.CommonProcessVariableNames) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoryService(org.activiti.engine.HistoryService) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) Collectors(java.util.stream.Collectors) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) QueryBuilder(com.evolveum.midpoint.prism.query.builder.QueryBuilder) ActivitiEngine(com.evolveum.midpoint.wf.impl.activiti.ActivitiEngine) Component(org.springframework.stereotype.Component) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 98 with TaskType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType in project midpoint by Evolveum.

the class ProcessInstanceManager method getMidpointToActiviti.

private Map<String, String> getMidpointToActiviti(OperationResult result) throws SchemaException {
    final Map<String, String> rv = new HashMap<>();
    final List<PrismObject<TaskType>> tasks = taskManager.searchObjects(TaskType.class, null, null, result);
    int tasksWithProcessId = 0;
    for (PrismObject<TaskType> taskObject : tasks) {
        final TaskType task = taskObject.asObjectable();
        final WfContextType wfc = task.getWorkflowContext();
        final String pid = wfc != null ? wfc.getProcessInstanceId() : null;
        rv.put(task.getOid(), pid);
        if (pid != null) {
            tasksWithProcessId++;
        }
    }
    LOGGER.info("Found {} tasks; among these, {} have a pointer to process instance id", rv.size(), tasksWithProcessId);
    return rv;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) WfContextType(com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType)

Aggregations

TaskType (com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType)88 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)63 Test (org.testng.annotations.Test)50 Task (com.evolveum.midpoint.task.api.Task)47 PrismObject (com.evolveum.midpoint.prism.PrismObject)30 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)25 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)23 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)19 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)18 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)17 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)16 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)15 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)15 ArrayList (java.util.ArrayList)14 QName (javax.xml.namespace.QName)13 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)11 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)10 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)8 Checker (com.evolveum.midpoint.test.Checker)8 ObjectChecker (com.evolveum.midpoint.test.ObjectChecker)8