TaskScheduleInteraction.java revision a23343e9e4e0b555b1bcfa99a7455e0e28117a3d
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * CDDL HEADER START
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * The contents of this file are subject to the terms of the
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * Common Development and Distribution License, Version 1.0 only
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * (the "License"). You may not use this file except in compliance
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * with the License.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * or http://forgerock.org/license/CDDLv1.0.html.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * See the License for the specific language governing permissions
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * and limitations under the License.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * When distributing Covered Code, include this CDDL HEADER in each
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * file and include the License file at legal-notices/CDDLv1_0.txt.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * If applicable, add the following below this CDDL HEADER, with the
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * fields enclosed by brackets "[]" replaced with your own identifying
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * information:
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * Portions Copyright [yyyy] [name of copyright owner]
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * CDDL HEADER END
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * Copyright 2010 Sun Microsystems, Inc.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * Portions Copyright 2014-2015 ForgeRock AS
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkimport static org.opends.messages.AdminToolMessages.*;
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkimport static org.opends.messages.ToolMessages.*;
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkimport org.opends.quicksetup.util.PlainTextProgressMessageFormatter;
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkimport org.opends.quicksetup.util.ProgressMessageFormatter;
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkimport org.opends.server.admin.client.cli.TaskScheduleArgs;
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkimport org.opends.server.backends.task.FailedDependencyAction;
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkimport org.opends.server.backends.task.RecurringTask;
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkimport org.opends.server.types.DirectoryException;
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenkimport com.forgerock.opendj.cli.ConsoleApplication;
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * A class that is in charge of interacting with the user to ask about
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * scheduling options for a task.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * It takes as argument an {@link TaskScheduleArgs} object with the arguments
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * provided by the user and updates the provided {@link TaskScheduleUserData}
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * with the information provided by the user.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk private boolean headerDisplayed;
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * The enumeration used by the menu displayed to ask the user about the
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * type of scheduling (if any) to be done.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk private ScheduleOption(LocalizableMessage prompt)
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * The default option to be proposed to the user.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * @return the default option to be proposed to the user.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * Default constructor.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * @param uData the task schedule user data.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * @param args the object with the arguments provided by the user. The code
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * assumes that the arguments have already been parsed.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * @param app the console application object used to prompt for data.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * @param taskName the name of the task to be used in the prompt messages.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk public TaskScheduleInteraction(TaskScheduleUserData uData,
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * Executes the interaction with the user.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * @throws ClientException if there is an error prompting the user.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * Returns the task entries that are defined in the server. These are
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * used to prompt the user about the task dependencies.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * @return the task entries that are defined in the server.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk public List<? extends TaskEntry> getTaskEntries()
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * Sets the task entries that are defined in the server. These are
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * used to prompt the user about the task dependencies. If no task entries
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * are provided, the user will not be prompted for task dependencies.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * @param taskEntries the task entries that are defined in the server.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk public void setTaskEntries(List<? extends TaskEntry> taskEntries)
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * Returns the formatter that is used to generate messages.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * @return the formatter that is used to generate messages.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * Sets the formatter that is used to generate messages.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk * @param formatter the formatter that is used to generate messages.
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk public void setFormatter(ProgressMessageFormatter formatter)
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk private void runFailedDependencyAction() throws ClientException
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk uData.setFailedDependencyAction(args.getFailedDependencyAction());
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk private void askForFailedDependencyAction() throws ClientException
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk MenuBuilder<FailedDependencyAction> builder = new MenuBuilder<>(app);
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk builder.setPrompt(INFO_TASK_FAILED_DEPENDENCY_ACTION_PROMPT.get());
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk for (FailedDependencyAction choice : FailedDependencyAction.values())
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk MenuResult<FailedDependencyAction> result = MenuResult.success(choice);
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk builder.addNumberedOption(choice.getDisplayName(), result);
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk if (choice.equals(FailedDependencyAction.defaultValue()))
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk builder.setDefault(choice.getDisplayName(), result);
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk MenuResult<FailedDependencyAction> m = builder.toMenu().run();
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk throw new ClientException(ReturnCode.ERROR_UNEXPECTED, LocalizableMessage.EMPTY);
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk private void runDependency() throws ClientException
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk uData.setDependencyIds(args.getDependencyIds());
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk private void askForDependency() throws ClientException
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk app.confirmAction(INFO_TASK_HAS_DEPENDENCIES_PROMPT.get(), false);
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk while (true)
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk app.readLineOfInput(INFO_TASK_DEPENDENCIES_PROMPT.get());
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk if (dependencyID != null && !dependencyID.isEmpty())
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk uData.setDependencyIds(new ArrayList<String>(dependencies));
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk private void printAvailableDependencyTaskMessage()
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk String separator = formatter.getLineBreak().toString() + formatter.getTab();
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk app.print(INFO_AVAILABLE_DEFINED_TASKS.get(sb));
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk private void printTaskIDNotDefinedMessage(String dependencyID)
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk app.println(ERR_DEPENDENCY_TASK_NOT_DEFINED.get(dependencyID));
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk private boolean isTaskIDDefined(String dependencyID)
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk boolean taskIDDefined = false;
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk if (dependencyID.equalsIgnoreCase(entry.getId()))
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk private void runErrorNotification() throws ClientException
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk private void askForErrorNotification() throws ClientException
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk askForEmailNotification(INFO_HAS_ERROR_NOTIFICATION_PROMPT.get(),
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk uData.setNotifyUponErrorEmailAddresses(addresses);
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk private List<String> askForEmailNotification(LocalizableMessage hasNotificationPrompt,
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk LocalizableMessage emailAddressPrompt) throws ClientException
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk app.confirmAction(hasNotificationPrompt, false);
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk while (true)
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk String address = app.readLineOfInput(emailAddressPrompt);
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk app.println(ERR_INVALID_EMAIL_ADDRESS.get(address));
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk private void runCompletionNotification() throws ClientException
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk private void askForCompletionNotification() throws ClientException
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk askForEmailNotification(INFO_HAS_COMPLETION_NOTIFICATION_PROMPT.get(),
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk uData.setNotifyUponCompletionEmailAddresses(addresses);
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk private void runStartNowOrSchedule() throws ClientException
4b8d88eb610aa1e0bb6ec632f792744b3d6b5f22jeff.schenk uData.setRecurringDateTime(args.getRecurringDateTime());
if (m.isSuccess())
switch (m.getValue())
case RUN_NOW:
case RUN_LATER:
case SCHEDULE_TASK:
null);
private void checkHeaderDisplay()
if (!headerDisplayed)
headerDisplayed = true;