Search in sources :

Example 11 with WorkItemDto

use of com.evolveum.midpoint.web.page.admin.workflow.dto.WorkItemDto in project midpoint by Evolveum.

the class PageWorkItem method loadWorkItemDtoIfNecessary.

private WorkItemDto loadWorkItemDtoIfNecessary() {
    if (workItemDtoModel.isLoaded()) {
        return workItemDtoModel.getObject();
    }
    Task task = createSimpleTask(OPERATION_LOAD_WORK_ITEM);
    OperationResult result = task.getResult();
    WorkItemDto workItemDto = null;
    try {
        final ObjectQuery query = QueryBuilder.queryFor(WorkItemType.class, getPrismContext()).item(F_EXTERNAL_ID).eq(taskId).build();
        final Collection<SelectorOptions<GetOperationOptions>> options = resolveItemsNamed(F_ASSIGNEE_REF, F_ORIGINAL_ASSIGNEE_REF);
        List<WorkItemType> workItems = getModelService().searchContainers(WorkItemType.class, query, options, task, result);
        if (workItems.size() > 1) {
            throw new SystemException("More than one work item with ID of " + taskId);
        } else if (workItems.size() == 0) {
            throw new SystemException("No work item with ID of " + taskId);
        }
        final WorkItemType workItem = workItems.get(0);
        //final String taskOid = workItem.getTaskRef() != null ? workItem.getTaskRef().getOid() : null;
        final String taskOid = WfContextUtil.getTask(workItem).getOid();
        TaskType taskType = null;
        List<TaskType> relatedTasks = new ArrayList<>();
        if (taskOid != null) {
            final Collection<SelectorOptions<GetOperationOptions>> getTaskOptions = resolveItemsNamed(new ItemPath(F_WORKFLOW_CONTEXT, F_REQUESTER_REF));
            getTaskOptions.addAll(retrieveItemsNamed(new ItemPath(F_WORKFLOW_CONTEXT, F_WORK_ITEM)));
            try {
                taskType = getModelService().getObject(TaskType.class, taskOid, getTaskOptions, task, result).asObjectable();
            } catch (AuthorizationException e) {
                LoggingUtils.logExceptionOnDebugLevel(LOGGER, "Access to the task {} was denied", e, taskOid);
            }
            if (taskType != null && taskType.getParent() != null) {
                final ObjectQuery relatedTasksQuery = QueryBuilder.queryFor(TaskType.class, getPrismContext()).item(F_PARENT).eq(taskType.getParent()).build();
                List<PrismObject<TaskType>> relatedTaskObjects = getModelService().searchObjects(TaskType.class, relatedTasksQuery, null, task, result);
                for (PrismObject<TaskType> relatedObject : relatedTaskObjects) {
                    relatedTasks.add(relatedObject.asObjectable());
                }
            }
        }
        workItemDto = new WorkItemDto(workItem, taskType, relatedTasks);
        workItemDto.prepareDeltaVisualization("pageWorkItem.delta", getPrismContext(), getModelInteractionService(), task, result);
        result.recordSuccessIfUnknown();
    } catch (CommonException | RuntimeException ex) {
        result.recordFatalError("Couldn't get work item.", ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get work item.", ex);
    }
    showResult(result, false);
    if (!result.isSuccess()) {
        throw getRestartResponseException(PageDashboard.class);
    }
    return workItemDto;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) PrismObject(com.evolveum.midpoint.prism.PrismObject) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) WorkItemDto(com.evolveum.midpoint.web.page.admin.workflow.dto.WorkItemDto) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 12 with WorkItemDto

use of com.evolveum.midpoint.web.page.admin.workflow.dto.WorkItemDto in project midpoint by Evolveum.

the class PageWorkItems method releaseWorkItemsPerformed.

private void releaseWorkItemsPerformed(AjaxRequestTarget target) {
    List<WorkItemDto> workItemDtoList = getWorkItemsPanel().getSelectedWorkItems();
    if (!isSomeItemSelected(workItemDtoList, target)) {
        return;
    }
    OperationResult mainResult = new OperationResult(OPERATION_RELEASE_ITEMS);
    WorkflowService workflowService = getWorkflowService();
    for (WorkItemDto workItemDto : workItemDtoList) {
        OperationResult result = mainResult.createSubresult(OPERATION_RELEASE_ITEM);
        try {
            workflowService.releaseWorkItem(workItemDto.getWorkItemId(), result);
            result.computeStatusIfUnknown();
        } catch (ObjectNotFoundException | SecurityViolationException | RuntimeException e) {
            result.recordPartialError("Couldn't release work item due to an unexpected exception.", e);
        }
    }
    if (mainResult.isUnknown()) {
        mainResult.recomputeStatus();
    }
    if (mainResult.isSuccess()) {
        mainResult.recordStatus(OperationResultStatus.SUCCESS, "The work item(s) have been successfully released.");
    }
    showResult(mainResult);
    resetWorkItemCountModel();
    target.add(this);
}
Also used : SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) WorkflowService(com.evolveum.midpoint.model.api.WorkflowService) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) WorkItemDto(com.evolveum.midpoint.web.page.admin.workflow.dto.WorkItemDto) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 13 with WorkItemDto

use of com.evolveum.midpoint.web.page.admin.workflow.dto.WorkItemDto in project midpoint by Evolveum.

the class PageWorkItems method approveOrRejectWorkItemsPerformed.

private void approveOrRejectWorkItemsPerformed(AjaxRequestTarget target, boolean approve) {
    List<WorkItemDto> workItemDtoList = getWorkItemsPanel().getSelectedWorkItems();
    if (!isSomeItemSelected(workItemDtoList, target)) {
        return;
    }
    OperationResult mainResult = new OperationResult(OPERATION_APPROVE_OR_REJECT_ITEMS);
    WorkflowService workflowService = getWorkflowService();
    for (WorkItemDto workItemDto : workItemDtoList) {
        OperationResult result = mainResult.createSubresult(OPERATION_APPROVE_OR_REJECT_ITEM);
        try {
            workflowService.completeWorkItem(workItemDto.getWorkItemId(), approve, null, null, result);
            result.computeStatus();
        } catch (Exception e) {
            result.recordPartialError("Couldn't approve/reject work item due to an unexpected exception.", e);
        }
    }
    if (mainResult.isUnknown()) {
        mainResult.recomputeStatus();
    }
    if (mainResult.isSuccess()) {
        mainResult.recordStatus(OperationResultStatus.SUCCESS, "The work item(s) have been successfully " + (approve ? "approved." : "rejected."));
    }
    showResult(mainResult);
    resetWorkItemCountModel();
    target.add(this);
}
Also used : WorkflowService(com.evolveum.midpoint.model.api.WorkflowService) WorkItemDto(com.evolveum.midpoint.web.page.admin.workflow.dto.WorkItemDto) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException)

Example 14 with WorkItemDto

use of com.evolveum.midpoint.web.page.admin.workflow.dto.WorkItemDto in project midpoint by Evolveum.

the class PageWorkItems method claimWorkItemsPerformed.

private void claimWorkItemsPerformed(AjaxRequestTarget target) {
    List<WorkItemDto> workItemDtoList = getWorkItemsPanel().getSelectedWorkItems();
    if (!isSomeItemSelected(workItemDtoList, target)) {
        return;
    }
    OperationResult mainResult = new OperationResult(OPERATION_CLAIM_ITEMS);
    WorkflowService workflowService = getWorkflowService();
    for (WorkItemDto workItemDto : workItemDtoList) {
        OperationResult result = mainResult.createSubresult(OPERATION_CLAIM_ITEM);
        try {
            workflowService.claimWorkItem(workItemDto.getWorkItemId(), result);
            result.computeStatusIfUnknown();
        } catch (ObjectNotFoundException | SecurityViolationException | RuntimeException e) {
            result.recordPartialError("Couldn't claim work item due to an unexpected exception.", e);
        }
    }
    if (mainResult.isUnknown()) {
        mainResult.recomputeStatus();
    }
    if (mainResult.isSuccess()) {
        mainResult.recordStatus(OperationResultStatus.SUCCESS, "The work item(s) have been successfully claimed.");
    }
    showResult(mainResult);
    resetWorkItemCountModel();
    target.add(this);
}
Also used : SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) WorkflowService(com.evolveum.midpoint.model.api.WorkflowService) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) WorkItemDto(com.evolveum.midpoint.web.page.admin.workflow.dto.WorkItemDto) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Aggregations

WorkItemDto (com.evolveum.midpoint.web.page.admin.workflow.dto.WorkItemDto)14 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)7 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)4 IModel (org.apache.wicket.model.IModel)4 WorkflowService (com.evolveum.midpoint.model.api.WorkflowService)3 Task (com.evolveum.midpoint.task.api.Task)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)3 ListDataProvider (com.evolveum.midpoint.web.component.util.ListDataProvider)3 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)3 WorkItemsPanel (com.evolveum.midpoint.web.component.wf.WorkItemsPanel)3 ProcessInstanceDto (com.evolveum.midpoint.web.page.admin.workflow.dto.ProcessInstanceDto)3 ArrayList (java.util.ArrayList)3 PropertyModel (org.apache.wicket.model.PropertyModel)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)2 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)2 LinkColumn (com.evolveum.midpoint.web.component.data.column.LinkColumn)2 ItemApprovalHistoryPanel (com.evolveum.midpoint.web.component.wf.processes.itemApproval.ItemApprovalHistoryPanel)2