private PasswordQuestionsDto loadPageModel() {
    LOGGER.debug("Loading user for Security Question Page.");

    PasswordQuestionsDto dto = new PasswordQuestionsDto();
    OperationResult result = new OperationResult(OPERATION_LOAD_USER);
    try {

      String userOid = SecurityUtils.getPrincipalUser().getOid();
      Task task = createSimpleTask(OPERATION_LOAD_USER);
      OperationResult subResult = result.createSubresult(OPERATION_LOAD_USER);

      PrismObject<UserType> user =
          getModelService().getObject(UserType.class, userOid, null, task, subResult);

      dto.setSecurityAnswers(createUsersSecurityQuestionsList(user));

      subResult.recordSuccessIfUnknown();

    } catch (Exception ex) {
      LoggingUtils.logExceptionOnDebugLevel(
          LOGGER, "Couldn't get user Questions, Probably not set yet", ex);

    } finally {
      result.recomputeStatus();
    }
    return dto;
  }
Exemple #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;
  }