From 02e05c396c23a35dcb105c29f36be883bd3f6576 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Wed, 25 Mar 2009 12:22:05 +0000
Subject: [PATCH] Fix for issue 3528 (A scheduled task should check that the start time has not passed)
---
opends/src/server/org/opends/server/tools/ExportLDIF.java | 10 ++++
opends/src/messages/messages/tools.properties | 7 ++-
opends/src/server/org/opends/server/tools/tasks/TaskTool.java | 19 +++++++--
opends/src/server/org/opends/server/tools/RestoreDB.java | 10 ++++
opends/src/server/org/opends/server/tools/BackUpDB.java | 10 ++++
opends/src/server/org/opends/server/tools/ImportLDIF.java | 8 ++++
6 files changed, 54 insertions(+), 10 deletions(-)
diff --git a/opends/src/messages/messages/tools.properties b/opends/src/messages/messages/tools.properties
index a420be9..61103a3 100644
--- a/opends/src/messages/messages/tools.properties
+++ b/opends/src/messages/messages/tools.properties
@@ -2453,12 +2453,13 @@
INFO_LDIFEXPORT_PATH_TO_LDIF_FILE_1662=Exporting to %s
#
-# These are the localized version of the answers that the user can provide in
-# interactive tools.
+# These are the localized version of the answers that the user can provide in
+# interactive tools.
#
INFO_PROMPT_YES_COMPLETE_ANSWER_1663=yes
INFO_PROMPT_YES_FIRST_LETTER_ANSWER_1664=y
INFO_PROMPT_NO_COMPLETE_ANSWER_1665=no
INFO_PROMPT_NO_FIRST_LETTER_ANSWER_1666=n
-
+SEVERE_ERR_START_DATETIME_ALREADY_PASSED_1667=The specified start time '%s' \
+ has already passed
diff --git a/opends/src/server/org/opends/server/tools/BackUpDB.java b/opends/src/server/org/opends/server/tools/BackUpDB.java
index 2a0416a..24f09b2 100644
--- a/opends/src/server/org/opends/server/tools/BackUpDB.java
+++ b/opends/src/server/org/opends/server/tools/BackUpDB.java
@@ -22,7 +22,7 @@
* CDDL HEADER END
*
*
- * Copyright 2006-2008 Sun Microsystems, Inc.
+ * Copyright 2006-2009 Sun Microsystems, Inc.
*/
package org.opends.server.tools;
import org.opends.messages.Message;
@@ -60,6 +60,7 @@
import org.opends.server.util.args.BooleanArgument;
import org.opends.server.util.args.StringArgument;
import org.opends.server.util.args.LDAPConnectionArgumentParser;
+import org.opends.server.util.cli.CLIException;
import static org.opends.messages.ToolMessages.*;
import static org.opends.server.util.ServerConstants.*;
@@ -299,6 +300,13 @@
err.println(argParser.getUsage());
return 1;
}
+ catch (CLIException ce)
+ {
+ // No need to display the usage since the problem comes with a provided
+ // value.
+ err.println(wrapText(ce.getMessageObject(), MAX_LINE_WIDTH));
+ return 1;
+ }
// If we should just display usage or version information,
diff --git a/opends/src/server/org/opends/server/tools/ExportLDIF.java b/opends/src/server/org/opends/server/tools/ExportLDIF.java
index debea69..c010e2a 100644
--- a/opends/src/server/org/opends/server/tools/ExportLDIF.java
+++ b/opends/src/server/org/opends/server/tools/ExportLDIF.java
@@ -22,7 +22,7 @@
* CDDL HEADER END
*
*
- * Copyright 2006-2008 Sun Microsystems, Inc.
+ * Copyright 2006-2009 Sun Microsystems, Inc.
*/
package org.opends.server.tools;
@@ -53,6 +53,7 @@
import org.opends.server.util.args.IntegerArgument;
import org.opends.server.util.args.StringArgument;
import org.opends.server.util.args.LDAPConnectionArgumentParser;
+import org.opends.server.util.cli.CLIException;
import org.opends.messages.Message;
import static org.opends.messages.ToolMessages.*;
@@ -330,6 +331,13 @@
err.println(argParser.getUsage());
return 1;
}
+ catch (CLIException ce)
+ {
+ // No need to display the usage since the problem comes with a provided
+ // value.
+ err.println(wrapText(ce.getMessageObject(), MAX_LINE_WIDTH));
+ return 1;
+ }
// If we should just display usage or version information,
diff --git a/opends/src/server/org/opends/server/tools/ImportLDIF.java b/opends/src/server/org/opends/server/tools/ImportLDIF.java
index d4f8859..3b96cd6 100644
--- a/opends/src/server/org/opends/server/tools/ImportLDIF.java
+++ b/opends/src/server/org/opends/server/tools/ImportLDIF.java
@@ -79,6 +79,7 @@
import org.opends.server.util.args.IntegerArgument;
import org.opends.server.util.args.LDAPConnectionArgumentParser;
import org.opends.server.util.args.StringArgument;
+import org.opends.server.util.cli.CLIException;
@@ -405,6 +406,13 @@
err.println(argParser.getUsage());
return 1;
}
+ catch (CLIException ce)
+ {
+ // No need to display the usage since the problem comes with a provided
+ // value.
+ err.println(wrapText(ce.getMessageObject(), MAX_LINE_WIDTH));
+ return 1;
+ }
// If we should just display usage or version information,
diff --git a/opends/src/server/org/opends/server/tools/RestoreDB.java b/opends/src/server/org/opends/server/tools/RestoreDB.java
index 8ea79db..e7308139 100644
--- a/opends/src/server/org/opends/server/tools/RestoreDB.java
+++ b/opends/src/server/org/opends/server/tools/RestoreDB.java
@@ -22,7 +22,7 @@
* CDDL HEADER END
*
*
- * Copyright 2006-2008 Sun Microsystems, Inc.
+ * Copyright 2006-2009 Sun Microsystems, Inc.
*/
package org.opends.server.tools;
import org.opends.messages.Message;
@@ -57,6 +57,7 @@
import org.opends.server.util.args.BooleanArgument;
import org.opends.server.util.args.StringArgument;
import org.opends.server.util.args.LDAPConnectionArgumentParser;
+import org.opends.server.util.cli.CLIException;
import static org.opends.server.loggers.ErrorLogger.*;
import static org.opends.messages.ToolMessages.*;
@@ -244,6 +245,13 @@
err.println(argParser.getUsage());
return 1;
}
+ catch (CLIException ce)
+ {
+ // No need to display the usage since the problem comes with a provided
+ // value.
+ err.println(wrapText(ce.getMessageObject(), MAX_LINE_WIDTH));
+ return 1;
+ }
// If we should just display usage or version information,
diff --git a/opends/src/server/org/opends/server/tools/tasks/TaskTool.java b/opends/src/server/org/opends/server/tools/tasks/TaskTool.java
index 344f22e..4eb7c89 100644
--- a/opends/src/server/org/opends/server/tools/tasks/TaskTool.java
+++ b/opends/src/server/org/opends/server/tools/tasks/TaskTool.java
@@ -22,7 +22,7 @@
* CDDL HEADER END
*
*
- * Copyright 2007-2008 Sun Microsystems, Inc.
+ * Copyright 2007-2009 Sun Microsystems, Inc.
*/
package org.opends.server.tools.tasks;
@@ -32,6 +32,8 @@
import org.opends.server.util.args.ArgumentException;
import org.opends.server.util.args.StringArgument;
import org.opends.server.util.args.ArgumentGroup;
+import org.opends.server.util.cli.CLIException;
+
import static org.opends.server.util.StaticUtils.wrapText;
import static org.opends.server.util.StaticUtils.getExceptionMessage;
import static org.opends.server.util.ServerConstants.MAX_LINE_WIDTH;
@@ -233,12 +235,21 @@
* called after the <code>ArgumentParser.parseArguments</code> has
* been called.
*
- * @throws ArgumentException if there is a problem with the arguments
+ * @throws ArgumentException if there is a problem with the arguments.
+ * @throws CLIException if there is a problem with one of the values provided
+ * by the user.
*/
- protected void validateTaskArgs() throws ArgumentException {
+ protected void validateTaskArgs() throws ArgumentException, CLIException {
if (startArg.isPresent() && !NOW.equals(startArg.getValue())) {
try {
- StaticUtils.parseDateTimeString(startArg.getValue());
+ Date date = StaticUtils.parseDateTimeString(startArg.getValue());
+ // Check that the provided date is not previous to the current date.
+ Date currentDate = new Date(System.currentTimeMillis());
+ if (currentDate.after(date))
+ {
+ throw new CLIException(ERR_START_DATETIME_ALREADY_PASSED.get(
+ startArg.getValue()));
+ }
} catch (ParseException pe) {
throw new ArgumentException(ERR_START_DATETIME_FORMAT.get());
}
--
Gitblit v1.10.0