valueIter = keyValues.iterator();
+ while (keyIter.hasNext() && valueIter.hasNext()) {
+ builder.append(keyIter.next()).append("=")
+ .append(valueIter.next()).append(", ");
}
+ }
- if (isDeltaSpecified()) {
- getVersionsClause(builder);
- builder.append("at ")
- .append(this.getTimeDescription(delta))
- .append("intervals ");
- getRoundClause(builder);
- getPeriodClause(builder);
- } else if (!isDeltaSpecified() && isVersionsToKeepSpecified()) {
- getVersionsClause(builder);
- getPeriodClause(builder);
- } else if (!isDeltaSpecified() && !isVersionsToKeepSpecified()
- && isPeriodSpecified()) {
- getVersionsClause(builder);
- getPeriodClause(builder);
- } else {
- builder.append("keep all data.");
- }
- if (isModTimeToWaitSpecified()) {
- builder.append(
- " Do not purge if most recent version has been modified in the last ")
- .append(this.getModTimeToWaitDescription());
- }
+ if (isDeltaSpecified()) {
+ getVersionsClause(builder);
+ builder.append("at ").append(this.getTimeDescription(delta))
+ .append("intervals ");
+ getRoundClause(builder);
+ getPeriodClause(builder);
+ } else if (!isDeltaSpecified() && isVersionsToKeepSpecified()) {
+ getVersionsClause(builder);
+ getPeriodClause(builder);
+ } else if (!isDeltaSpecified() && !isVersionsToKeepSpecified()
+ && isPeriodSpecified()) {
+ getVersionsClause(builder);
+ getPeriodClause(builder);
+ } else {
+ builder.append("keep all data.");
+ }
+ if (isModTimeToWaitSpecified()) {
+ builder.append(
+ " Do not purge if most recent version has been modified in the last ")
+ .append(this.getModTimeToWaitDescription());
}
ruleDescription = builder.toString();
}
@@ -578,26 +570,6 @@ public class PurgeRule implements IPersistableDataObject, Serializable,
return builder.toString();
}
- @Override
- public Object getIdentifier() {
- return id;
- }
-
- /**
- * @return the id
- */
- public PurgeRulePK getId() {
- return id;
- }
-
- /**
- * @param id
- * the id to set
- */
- public void setId(PurgeRulePK id) {
- this.id = id;
- }
-
/**
* @return the versionsToKeep
*/
@@ -687,40 +659,4 @@ public class PurgeRule implements IPersistableDataObject, Serializable,
public void setLogOnly(boolean logOnly) {
this.logOnly = logOnly;
}
-
- public Object clone() {
- PurgeRule rval = new PurgeRule();
- rval.id = (PurgeRulePK) id.clone();
- rval.delta = delta;
- rval.logOnly = logOnly;
- rval.period = period;
- rval.round = round;
- rval.versionsToKeep = versionsToKeep;
-
- return rval;
- }
-
- public boolean equals(Object obj) {
-
- if (!(obj instanceof PurgeRule)) {
- return false;
- }
- PurgeRule rhs = (PurgeRule) obj;
- return this.id.equals(rhs.getId()) && this.delta.equals(rhs.getDelta())
- && this.logOnly == rhs.isLogOnly()
- && this.period.equals(rhs.getPeriod())
- && this.round.equals(rhs.getRound())
- && this.versionsToKeep == rhs.getVersionsToKeep();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Comparable#compareTo(java.lang.Object)
- */
- @Override
- public int compareTo(PurgeRule o) {
- return this.id.getPluginName().compareTo(o.getId().getPluginName());
- }
-
}
diff --git a/edexOsgi/com.raytheon.uf.edex.database/src/com/raytheon/uf/edex/database/purge/PurgeRulePK.java b/edexOsgi/com.raytheon.uf.edex.database/src/com/raytheon/uf/edex/database/purge/PurgeRulePK.java
deleted file mode 100644
index c1f83c9443..0000000000
--- a/edexOsgi/com.raytheon.uf.edex.database/src/com/raytheon/uf/edex/database/purge/PurgeRulePK.java
+++ /dev/null
@@ -1,209 +0,0 @@
-/**
- * This software was developed and / or modified by Raytheon Company,
- * pursuant to Contract DG133W-05-CQ-1067 with the US Government.
- *
- * U.S. EXPORT CONTROLLED TECHNICAL DATA
- * This software product contains export-restricted data whose
- * export/transfer/disclosure is restricted by U.S. law. Dissemination
- * to non-U.S. persons whether in the United States or abroad requires
- * an export license or other authorization.
- *
- * Contractor Name: Raytheon Company
- * Contractor Address: 6825 Pine Street, Suite 340
- * Mail Stop B8
- * Omaha, NE 68106
- * 402.291.0100
- *
- * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
- * further licensing information.
- **/
-
-package com.raytheon.uf.edex.database.purge;
-
-import java.io.Serializable;
-
-import javax.persistence.Embeddable;
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-
-import org.apache.commons.lang.builder.HashCodeBuilder;
-
-import com.raytheon.uf.common.serialization.ISerializableObject;
-import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
-import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
-
-/**
- * This class defines the primary key for data purge rules stored in the
- * database. This key consists of a sequence number, the pluginName to which
- * this rule applies and the key to which this rule applies.
- *
- * The sequence number is a number obtained from the hibernate_sequence on the
- * database. This number has no significance other than to distinguish two rules
- * which may have the the same pluginName and same key values. The pluginName is
- * the plugin to which this purge rule applies. The key servers as a filter for
- * purging. The key value corresponds to the productKey field in the plugin data
- * object.
- *
- *
- *
- *
- * SOFTWARE HISTORY
- *
- * Date Ticket# Engineer Description
- * ------------ ---------- ----------- --------------------------
- * 2/15/11 #2469 bphillip Initial creation
- *
- *
- *
- * @author bphillip
- * @version 1
- */
-@Embeddable
-@XmlRootElement
-@XmlAccessorType(XmlAccessType.NONE)
-@DynamicSerialize
-public class PurgeRulePK implements ISerializableObject, Serializable,
- Cloneable {
-
- /** The serial number */
- private static final long serialVersionUID = 3400703274820497880L;
-
- /**
- * A sequence number defined by the database for uniquely identifying this
- * rule
- */
- @XmlElement
- @DynamicSerializeElement
- private Long id;
-
- /** The plugin associated with this rule */
- @XmlElement
- @DynamicSerializeElement
- private String pluginName;
-
- /** The key used by this rule for purging */
- @XmlElement
- @DynamicSerializeElement
- private String key;
-
- /**
- * Creates a new PurgeRulePK object
- */
- public PurgeRulePK() {
- }
-
- /**
- * Creates a new plugin rule with the given plugin name and an empty key.
- *
- * @param pluginName
- * The plugin to which this purge rule applies
- */
- public PurgeRulePK(String pluginName) {
- this.pluginName = pluginName;
- this.key = "";
- }
-
- /**
- * Creates a new plugin rule with the given plugin name and key
- *
- * @param pluginName
- * The plugin to which this purge rule applies
- * @param key
- * The key to use when applying this rule
- */
- public PurgeRulePK(String pluginName, String key) {
- this(pluginName);
- this.key = key;
- }
-
- /**
- * Creates a new plugin rule with the given plugin name key, and id value
- *
- * @param pluginName
- * The plugin to which this purge rule applies
- * @param key
- * The key to use when applying this rule
- * @param id
- * An identifying number
- */
- public PurgeRulePK(String pluginName, String key, long id) {
- this(pluginName, key);
- this.id = id;
- }
-
- public String toString() {
- return "Plugin:" + pluginName + " Key:" + key;
- }
-
- public int hashCode() {
- HashCodeBuilder builder = new HashCodeBuilder();
- builder.append(pluginName);
- builder.append(key);
- return builder.toHashCode();
- }
-
- public boolean equals(Object rval) {
- if (!(rval instanceof PurgeRulePK)) {
- return false;
- }
- PurgeRulePK rhs = (PurgeRulePK) rval;
-
- return this.pluginName.equals(rhs.getPluginName())
- && this.key.equals(rhs.getKey());
-
- }
-
- /**
- * @return the pluginName
- */
- public String getPluginName() {
- return pluginName;
- }
-
- /**
- * @param pluginName
- * the pluginName to set
- */
- public void setPluginName(String pluginName) {
- this.pluginName = pluginName;
- }
-
- /**
- * @return the key
- */
- public String getKey() {
- return key;
- }
-
- /**
- * @param key
- * the key to set
- */
- public void setKey(String key) {
- this.key = key;
- }
-
- public Object clone() {
- PurgeRulePK rval = new PurgeRulePK(this.pluginName, this.key);
- rval.setId(this.id);
- return rval;
- }
-
- /**
- * @return the id
- */
- public Long getId() {
- return id;
- }
-
- /**
- * @param id
- * the id to set
- */
- public void setId(Long id) {
- this.id = id;
- }
-
-}
diff --git a/edexOsgi/com.raytheon.uf.edex.database/src/com/raytheon/uf/edex/database/purge/PurgeRuleSet.java b/edexOsgi/com.raytheon.uf.edex.database/src/com/raytheon/uf/edex/database/purge/PurgeRuleSet.java
index f2a72131a2..b1b6532c25 100644
--- a/edexOsgi/com.raytheon.uf.edex.database/src/com/raytheon/uf/edex/database/purge/PurgeRuleSet.java
+++ b/edexOsgi/com.raytheon.uf.edex.database/src/com/raytheon/uf/edex/database/purge/PurgeRuleSet.java
@@ -21,7 +21,7 @@
package com.raytheon.uf.edex.database.purge;
import java.util.ArrayList;
-import java.util.Collection;
+import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@@ -33,8 +33,8 @@ import com.raytheon.uf.common.serialization.ISerializableObject;
/**
* A container class used for unmarshalling purge rules. The purge rules are
- * stored in xml files in the edex_static/base/purge directory. The rules are
- * unmarshalled into this object before being persisted to the database.
+ * stored in xml files in the common_static/base/purge directory. The rules are
+ * then organized into a tree for easy look up of closest matching rule.
*
*
*
@@ -52,14 +52,35 @@ import com.raytheon.uf.common.serialization.ISerializableObject;
@XmlRootElement(name = "purgeRuleSet")
@XmlAccessorType(XmlAccessType.NONE)
public class PurgeRuleSet implements ISerializableObject {
+
+ @XmlElements({ @XmlElement(name = "key", type = String.class) })
+ private List keys;
+
+ @XmlElement
+ private PurgeRule defaultRule;
+
/**
* List of purge rules for/from the XML.
*/
@XmlElements({ @XmlElement(name = "rule", type = PurgeRule.class) })
private ArrayList rules;
+ private PurgeRuleTree purgeTree = null;
+
public PurgeRuleSet() {
- rules = new ArrayList();
+ }
+
+ /**
+ * Returns the default rule.
+ *
+ * @return
+ */
+ public PurgeRule getDefaultRule() {
+ return defaultRule;
+ }
+
+ public void setDefaultRule(PurgeRule defaultRule) {
+ this.defaultRule = defaultRule;
}
/**
@@ -71,32 +92,36 @@ public class PurgeRuleSet implements ISerializableObject {
return rules;
}
- /**
- * Set the list of purge rules.
- *
- * @param models
- */
- public void setModels(ArrayList rules) {
+ public void setRules(ArrayList rules) {
this.rules = rules;
}
/**
- * Add a purge rule to this set
+ * Returns the list of purge keys.
*
- * @param rule
- * The rule to add
+ * @return
*/
- public void addRule(PurgeRule rule) {
- this.rules.add(rule);
+ public List getKeys() {
+ return keys;
+ }
+
+ public void setKeys(List keys) {
+ this.keys = keys;
}
/**
- * Adds purge rules to this set
+ * Returns the purge rule associated with the passed key values.
*
- * @param rules
- * The rules to add
+ * @param keyValues
+ * The values associated with the plugin purge keys to check for
+ * a purge rule for.
+ * @return
*/
- public void addRules(Collection rules) {
- this.rules.addAll(rules);
+ public PurgeRule getRuleForKeys(String[] keyValues) {
+ if (purgeTree == null) {
+ purgeTree = new PurgeRuleTree(this);
+ }
+
+ return purgeTree.getRuleForKeys(keyValues);
}
}
diff --git a/edexOsgi/com.raytheon.uf.edex.database/src/com/raytheon/uf/edex/database/purge/PurgeRuleTree.java b/edexOsgi/com.raytheon.uf.edex.database/src/com/raytheon/uf/edex/database/purge/PurgeRuleTree.java
new file mode 100644
index 0000000000..caadc1ee75
--- /dev/null
+++ b/edexOsgi/com.raytheon.uf.edex.database/src/com/raytheon/uf/edex/database/purge/PurgeRuleTree.java
@@ -0,0 +1,132 @@
+/**
+ * This software was developed and / or modified by Raytheon Company,
+ * pursuant to Contract DG133W-05-CQ-1067 with the US Government.
+ *
+ * U.S. EXPORT CONTROLLED TECHNICAL DATA
+ * This software product contains export-restricted data whose
+ * export/transfer/disclosure is restricted by U.S. law. Dissemination
+ * to non-U.S. persons whether in the United States or abroad requires
+ * an export license or other authorization.
+ *
+ * Contractor Name: Raytheon Company
+ * Contractor Address: 6825 Pine Street, Suite 340
+ * Mail Stop B8
+ * Omaha, NE 68106
+ * 402.291.0100
+ *
+ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
+ * further licensing information.
+ */
+package com.raytheon.uf.edex.database.purge;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Tree representation of the purge rules. Each Node can contain a PurgeRule as
+ * well as a collection of other Nodes. Each Node should be a specific purge key
+ * value based on the PurgeRuleSet keys. A given set of key/value pairs will
+ * return the most significant purge key that matches.
+ *
+ *
+ *
+ * SOFTWARE HISTORY
+ *
+ * Date Ticket# Engineer Description
+ * ------------ ---------- ----------- --------------------------
+ * Oct 29, 2012 rjpeter Initial creation
+ *
+ *
+ *
+ * @author rjpeter
+ * @version 1.0
+ */
+public class PurgeRuleTree {
+ private final PurgeNode root;
+
+ public PurgeRuleTree(PurgeRuleSet ruleSet) {
+ root = new PurgeNode();
+ root.setRule(ruleSet.getDefaultRule());
+ ArrayList rules = ruleSet.getRules();
+ if (rules != null) {
+ for (PurgeRule rule : rules) {
+ PurgeNode curNode = root;
+ List values = rule.getKeyValues();
+ if (values != null) {
+ // descend purge tree
+ for (String val : values) {
+ Map childNodes = curNode
+ .getChildNodes();
+ curNode = childNodes.get(val);
+ if (curNode == null) {
+ curNode = new PurgeNode();
+ childNodes.put(val, curNode);
+ }
+ }
+
+ // set the rule on the leaf node defined by key values
+ curNode.setRule(rule);
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns the purge rule associated with the given key value list.
+ *
+ * @param keyValues
+ * @return
+ */
+ public PurgeRule getRuleForKeys(String[] keyValues) {
+ // default rule is initial closest rule
+ PurgeRule closestRule = root.getRule();
+ PurgeNode currentNode = root;
+
+ if ((keyValues != null) && (keyValues.length > 0)) {
+ // iterate over key values, descending tree as far as possible,
+ // keeping track of closest matching rule.
+ for (String value : keyValues) {
+ currentNode = currentNode.getChildNode(value);
+
+ // descend node
+ if (currentNode != null) {
+ // check node for rule
+ PurgeRule rule = currentNode.getRule();
+
+ if (rule != null) {
+ // current closest rule
+ closestRule = rule;
+ }
+ } else {
+ break;
+ }
+ }
+ }
+
+ return closestRule;
+ }
+
+ private class PurgeNode {
+ private PurgeRule rule;
+
+ private final Map childNodes = new HashMap();
+
+ public void setRule(PurgeRule rule) {
+ this.rule = rule;
+ }
+
+ public PurgeRule getRule() {
+ return rule;
+ }
+
+ public Map getChildNodes() {
+ return childNodes;
+ }
+
+ public PurgeNode getChildNode(String keyValue) {
+ return childNodes.get(keyValue);
+ }
+ }
+}
diff --git a/edexOsgi/com.raytheon.uf.edex.database/utility/common_static/base/purge/defaultPurgeRules.xml b/edexOsgi/com.raytheon.uf.edex.database/utility/common_static/base/purge/defaultPurgeRules.xml
index de1d772210..d8401ec954 100644
--- a/edexOsgi/com.raytheon.uf.edex.database/utility/common_static/base/purge/defaultPurgeRules.xml
+++ b/edexOsgi/com.raytheon.uf.edex.database/utility/common_static/base/purge/defaultPurgeRules.xml
@@ -1,10 +1,6 @@
-
-
-
- default
- default
-
+
+
01-00:00:00
-
-
\ No newline at end of file
+
+