Пример #1
0
  private void savePerformed(AjaxRequestTarget target, boolean decision) {
    LOGGER.debug("Saving work item changes.");

    OperationResult result = new OperationResult(OPERATION_SAVE_WORK_ITEM);

    try {
      WorkItemDto dto = workItemDtoModel.getObject();
      getWorkflowService()
          .approveOrRejectWorkItem(dto.getWorkItemId(), decision, dto.getApproverComment(), result);
    } catch (Exception ex) {
      result.recordFatalError("Couldn't save work item.", ex);
      LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save work item", ex);
    }

    result.computeStatusIfUnknown();

    if (!result.isSuccess()) {
      showResult(result, false);
      target.add(getFeedbackPanel());
    } else {
      showResult(result);
      redirectBack();
    }
  }
Пример #2
0
  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_WORK_ITEM_ID)
              .eq(taskId)
              .build();
      final Collection<SelectorOptions<GetOperationOptions>> options =
          resolveItemsNamed(F_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;
      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;
  }