From a052b950531fb0152bbb0bb2ef50633349a34173 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Sun, 16 Jul 2006 04:22:43 +0000
Subject: [PATCH] Update the task backend to change the format of the ds-cfg-task-retention-time configuration attribute from an integer (with the value specified in seconds) to an integer with unit (specified as an integer value followed by a unit of "seconds", "minutes", "hours", "days", or "weeks").  Also change the syntax of the attribute in the schema from integer to directory string.

---
 opendj-sdk/opends/resource/config/config.ldif                                 |    2 
 opendj-sdk/opends/src/server/org/opends/server/backends/task/TaskBackend.java |   68 +++++++++++++++++++++++----------
 opendj-sdk/opends/resource/schema/02-config.ldif                              |    2 
 3 files changed, 49 insertions(+), 23 deletions(-)

diff --git a/opendj-sdk/opends/resource/config/config.ldif b/opendj-sdk/opends/resource/config/config.ldif
index 1f26876..f685f39 100644
--- a/opendj-sdk/opends/resource/config/config.ldif
+++ b/opendj-sdk/opends/resource/config/config.ldif
@@ -233,7 +233,7 @@
 ds-cfg-backend-writability-mode: enabled
 ds-cfg-backend-base-dn: cn=tasks
 ds-cfg-task-backing-file: config/tasks.ldif
-ds-cfg-task-retention-time: 86400
+ds-cfg-task-retention-time: 24 hours
 
 dn: cn=Connection Handlers,cn=config
 objectClass: top
diff --git a/opendj-sdk/opends/resource/schema/02-config.ldif b/opendj-sdk/opends/resource/schema/02-config.ldif
index 755bff3..4feba6d 100644
--- a/opendj-sdk/opends/resource/schema/02-config.ldif
+++ b/opendj-sdk/opends/resource/schema/02-config.ldif
@@ -355,7 +355,7 @@
   NAME 'ds-task-notify-on-error' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
   X-ORIGIN 'OpenDS Directory Server' )
 attributeTypes: ( 1.3.6.1.4.1.26027.1.1.106
-  NAME 'ds-cfg-task-retention-time' SYNTAX 1.3.6.1.4.1.1466.115.121.1.27
+  NAME 'ds-cfg-task-retention-time' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
   X-ORIGIN 'OpenDS Directory Server' )
 attributeTypes: ( 1.3.6.1.4.1.26027.1.1.107
   NAME 'ds-task-scheduled-start-time' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
diff --git a/opendj-sdk/opends/src/server/org/opends/server/backends/task/TaskBackend.java b/opendj-sdk/opends/src/server/org/opends/server/backends/task/TaskBackend.java
index 02463c0..7096611 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/backends/task/TaskBackend.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/backends/task/TaskBackend.java
@@ -31,6 +31,7 @@
 import java.io.File;
 import java.util.ArrayList;
 import java.util.HashSet;
+import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -39,7 +40,7 @@
 import org.opends.server.config.ConfigAttribute;
 import org.opends.server.config.ConfigEntry;
 import org.opends.server.config.ConfigException;
-import org.opends.server.config.IntegerConfigAttribute;
+import org.opends.server.config.IntegerWithUnitConfigAttribute;
 import org.opends.server.config.StringConfigAttribute;
 import org.opends.server.core.AddOperation;
 import org.opends.server.core.CancelledOperationException;
@@ -88,6 +89,15 @@
 
 
 
+  /**
+   * The set of time units that will be used for expressing the task retention
+   * time.
+   */
+  private static final LinkedHashMap<String,Double> timeUnits =
+       new LinkedHashMap<String,Double>();
+
+
+
   // The DN of the configuration entry for this backend.
   private DN configEntryDN;
 
@@ -124,6 +134,17 @@
 
 
 
+  static
+  {
+    timeUnits.put("seconds", 1.0);
+    timeUnits.put("minutes", 60.0);
+    timeUnits.put("hours", (60.0*60.0));
+    timeUnits.put("days", (24.0*60.0*60.0));
+    timeUnits.put("weeks", (7.0*24.0*60.0*60.0));
+  }
+
+
+
   /**
    * Creates a new backend with the provided information.  All backend
    * implementations must implement a default constructor that use
@@ -237,13 +258,14 @@
     // Get the retention time that will be used to determine how long task
     // information stays around once the associated task is completed.
     int msgID = MSGID_TASKBE_DESCRIPTION_RETENTION_TIME;
-    IntegerConfigAttribute retentionStub =
-         new IntegerConfigAttribute(ATTR_TASK_RETENTION_TIME, getMessage(msgID),
-                                    true, false, false, true, 0, false, 0);
+    IntegerWithUnitConfigAttribute retentionStub =
+         new IntegerWithUnitConfigAttribute(ATTR_TASK_RETENTION_TIME,
+                                            getMessage(msgID), false, timeUnits,
+                                            true, 0, false, 0);
     try
     {
-      IntegerConfigAttribute retentionAttr =
-           (IntegerConfigAttribute)
+      IntegerWithUnitConfigAttribute retentionAttr =
+           (IntegerWithUnitConfigAttribute)
            configEntry.getConfigAttribute(retentionStub);
       if (retentionAttr == null)
       {
@@ -251,7 +273,7 @@
       }
       else
       {
-        retentionTime = retentionAttr.activeValue();
+        retentionTime = retentionAttr.activeCalculatedValue();
       }
     }
     catch (Exception e)
@@ -1260,9 +1282,11 @@
                                            taskBackingFile));
 
     description = getMessage(MSGID_TASKBE_DESCRIPTION_RETENTION_TIME);
-    attrList.add(new IntegerConfigAttribute(ATTR_TASK_RETENTION_TIME,
-                                            description, true, false, false,
-                                            true, 0, false, 0, retentionTime));
+    attrList.add(new IntegerWithUnitConfigAttribute(ATTR_TASK_RETENTION_TIME,
+                                                    description, false,
+                                                    timeUnits, true, 0, false,
+                                                    0, retentionTime,
+                                                    "seconds"));
 
     return attrList;
   }
@@ -1363,13 +1387,14 @@
 
 
     description = getMessage(MSGID_TASKBE_DESCRIPTION_RETENTION_TIME);
-    IntegerConfigAttribute retentionStub =
-         new IntegerConfigAttribute(ATTR_TASK_RETENTION_TIME, description,
-                                    true, false, false, true, 0, false, 0);
+    IntegerWithUnitConfigAttribute retentionStub =
+         new IntegerWithUnitConfigAttribute(ATTR_TASK_RETENTION_TIME,
+                                            description, false, timeUnits,
+                                            true, 0, false, 0);
     try
     {
-      IntegerConfigAttribute retentionAttr =
-           (IntegerConfigAttribute)
+      IntegerWithUnitConfigAttribute retentionAttr =
+           (IntegerWithUnitConfigAttribute)
            configEntry.getConfigAttribute(retentionStub);
       if (retentionAttr == null)
       {
@@ -1494,13 +1519,14 @@
 
     long tmpRetentionTime = retentionTime;
     description = getMessage(MSGID_TASKBE_DESCRIPTION_RETENTION_TIME);
-    IntegerConfigAttribute retentionStub =
-         new IntegerConfigAttribute(ATTR_TASK_RETENTION_TIME, description,
-                                    true, false, false, true, 0, false, 0);
+    IntegerWithUnitConfigAttribute retentionStub =
+         new IntegerWithUnitConfigAttribute(ATTR_TASK_RETENTION_TIME,
+                                            description, false, timeUnits,
+                                            true, 0, false, 0);
     try
     {
-      IntegerConfigAttribute retentionAttr =
-           (IntegerConfigAttribute)
+      IntegerWithUnitConfigAttribute retentionAttr =
+           (IntegerWithUnitConfigAttribute)
            configEntry.getConfigAttribute(retentionStub);
       if (retentionAttr == null)
       {
@@ -1514,7 +1540,7 @@
       }
       else
       {
-        tmpRetentionTime = retentionTime;
+        tmpRetentionTime = retentionAttr.activeCalculatedValue();
       }
     }
     catch (Exception e)

--
Gitblit v1.10.0