Exemple #1
0
    /** {@inheritDoc} */
    @Override
    public MenuResult<Void> invoke(ManageTasks app) throws ClientException {
      if (taskIds != null && !taskIds.isEmpty()) {
        if (cancelableIndices != null && !cancelableIndices.isEmpty()) {

          // Prompt for the task number
          Integer index = null;
          String line =
              app.readLineOfInput(
                  INFO_TASKINFO_CMD_CANCEL_NUMBER_PROMPT.get(cancelableIndices.get(0)));
          if (line.length() == 0) {
            line = String.valueOf(cancelableIndices.get(0));
          }
          try {
            int i = Integer.parseInt(line);
            if (!cancelableIndices.contains(i)) {
              app.println(ERR_TASKINFO_NOT_CANCELABLE_TASK_INDEX.get(i));
            } else {
              index = i - 1;
            }
          } catch (NumberFormatException nfe) {
            // ignore;
          }
          if (index != null) {
            String taskId = taskIds.get(index);
            try {
              CancelTask ct = new CancelTask(taskId);
              MenuResult<TaskEntry> result = ct.invoke(app);
              if (result.isSuccess()) {
                return MenuResult.success();
              } else {
                return MenuResult.again();
              }
            } catch (Exception e) {
              app.println(ERR_TASKINFO_CANCELING_TASK.get(taskId, e.getMessage()));
              return MenuResult.again();
            }
          } else {
            app.println(ERR_TASKINFO_INVALID_MENU_KEY.get(line));
            return MenuResult.again();
          }
        } else {
          app.println(INFO_TASKINFO_NO_CANCELABLE_TASKS.get());
          return MenuResult.cancel();
        }
      } else {
        app.println(INFO_TASKINFO_NO_TASKS.get());
        return MenuResult.cancel();
      }
    }
Exemple #2
0
 /** {@inheritDoc} */
 @Override
 public MenuResult<TaskEntry> invoke(ManageTasks app) throws ClientException {
   try {
     TaskEntry entry = app.getTaskClient().getTaskEntry(taskId);
     if (entry.isCancelable()) {
       app.getTaskClient().cancelTask(taskId);
       app.println(INFO_TASKINFO_CMD_CANCEL_SUCCESS.get(taskId));
       return MenuResult.success(entry);
     } else {
       app.println(ERR_TASKINFO_TASK_NOT_CANCELABLE_TASK.get(taskId));
       return MenuResult.again();
     }
   } catch (Exception e) {
     app.println(ERR_TASKINFO_CANCELING_TASK.get(taskId, e.getMessage()));
     return MenuResult.again();
   }
 }