/** * Creates the summary table. * * @return list of strings of IDs of all the tasks in the table in order of the indexes printed in * the table * @throws IOException if there is a problem with screen I/O * @throws LDAPException if there is a problem getting information out to the directory * @throws DecodeException if there is a problem with the encoding */ private Menu<Void> getSummaryMenu() throws LDAPException, IOException, DecodeException { List<String> taskIds = new ArrayList<>(); List<Integer> cancelableIndices = new ArrayList<>(); List<TaskEntry> entries = taskClient.getTaskEntries(); MenuBuilder<Void> menuBuilder = new MenuBuilder<>(this); if (!entries.isEmpty()) { Map<String, TaskEntry> mapIdToEntry = new TreeMap<>(); for (TaskEntry entry : entries) { String taskId = entry.getId(); if (taskId != null) { mapIdToEntry.put(taskId, entry); } } menuBuilder.setColumnHeadings( INFO_TASKINFO_FIELD_ID.get(), INFO_TASKINFO_FIELD_TYPE.get(), INFO_TASKINFO_FIELD_STATUS.get()); menuBuilder.setColumnWidths(null, null, 0); int index = 0; for (final String taskId : mapIdToEntry.keySet()) { taskIds.add(taskId); final TaskEntry taskEntry = mapIdToEntry.get(taskId); menuBuilder.addNumberedOption( LocalizableMessage.raw(taskEntry.getId()), new TaskDrilldownMenu(taskId), taskEntry.getType(), taskEntry.getState()); index++; if (taskEntry.isCancelable()) { cancelableIndices.add(index); } } } else { getOutputStream().println(INFO_TASKINFO_NO_TASKS.get()); getOutputStream().println(); } menuBuilder.addCharOption( INFO_TASKINFO_CMD_REFRESH_CHAR.get(), INFO_TASKINFO_CMD_REFRESH.get(), new PrintSummaryTop()); if (!cancelableIndices.isEmpty()) { menuBuilder.addCharOption( INFO_TASKINFO_CMD_CANCEL_CHAR.get(), INFO_TASKINFO_CMD_CANCEL.get(), new CancelTaskTop(taskIds, cancelableIndices)); } menuBuilder.addQuitOption(); return menuBuilder.toMenu(); }
/** {@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(); } }
/** {@inheritDoc} */ @Override public MenuResult<Void> invoke(ManageTasks app) throws ClientException { MenuResult<TaskEntry> res = new PrintTaskInfo(taskId).invoke(app); TaskEntry taskEntry = res.getValue(); if (taskEntry != null) { while (true) { try { taskEntry = app.getTaskClient().getTaskEntry(taskId); // Show the menu MenuBuilder<TaskEntry> menuBuilder = new MenuBuilder<>(app); menuBuilder.addBackOption(true); menuBuilder.addCharOption( INFO_TASKINFO_CMD_REFRESH_CHAR.get(), INFO_TASKINFO_CMD_REFRESH.get(), new PrintTaskInfo(taskId)); List<LocalizableMessage> logs = taskEntry.getLogMessages(); if (logs != null && !logs.isEmpty()) { menuBuilder.addCharOption( INFO_TASKINFO_CMD_VIEW_LOGS_CHAR.get(), INFO_TASKINFO_CMD_VIEW_LOGS.get(), new ViewTaskLogs(taskId)); } if (taskEntry.isCancelable() && !taskEntry.isDone()) { menuBuilder.addCharOption( INFO_TASKINFO_CMD_CANCEL_CHAR.get(), INFO_TASKINFO_CMD_CANCEL.get(), new CancelTask(taskId)); } menuBuilder.addQuitOption(); Menu<TaskEntry> menu = menuBuilder.toMenu(); MenuResult<TaskEntry> result = menu.run(); if (result.isCancel()) { break; } else if (result.isQuit()) { System.exit(0); } } catch (Exception e) { app.println(LocalizableMessage.raw(StaticUtils.getExceptionMessage(e))); } } } else { app.println(ERR_TASKINFO_UNKNOWN_TASK_ENTRY.get(taskId)); } return MenuResult.success(); }