| 
     
      
      
      From: <ssk...@re...> - 2005-03-14 13:22:17
      
     
   | 
Author: sskracic
Date: 2005-03-14 14:20:07 +0100 (Mon, 14 Mar 2005)
New Revision: 316
Modified:
   ccm-ldn-terms/trunk/src/com/arsdigita/london/terms/Term.java
Log:
  A patch supplied by Christopher Gilbert from WS-GfL, retrieves the
collection of narrower terms for which this term is the default parent.
Modified: ccm-ldn-terms/trunk/src/com/arsdigita/london/terms/Term.java
===================================================================
--- ccm-ldn-terms/trunk/src/com/arsdigita/london/terms/Term.java	2005-03-11 19:04:37 UTC (rev 315)
+++ ccm-ldn-terms/trunk/src/com/arsdigita/london/terms/Term.java	2005-03-14 13:20:07 UTC (rev 316)
@@ -5,12 +5,12 @@
  * modify it under the terms of the GNU Lesser General Public License
  * as published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -34,17 +34,17 @@
 /**
  * Instances of this class represent entries in a domain
  * of terms.
- * 
- * Although terms are currently modelled using the 
+ *
+ * Although terms are currently modelled using the
  * categorization service, it is not neccessarily going
- * remain this way, hence the getModel() method is 
- * protected. 
+ * remain this way, hence the getModel() method is
+ * protected.
  */
 public class Term extends ACSObject {
 
     private static final Logger s_log = Logger.getLogger(Term.class);
 
-    public static final String BASE_DATA_OBJECT_TYPE = 
+    public static final String BASE_DATA_OBJECT_TYPE =
         "com.arsdigita.london.terms.Term";
 
     public static final String UNIQUE_ID = "uniqueID";
@@ -60,7 +60,7 @@
     Term() {
         this(BASE_DATA_OBJECT_TYPE);
     }
-    
+
     protected Term(String type) {
         super(type);
     }
@@ -71,12 +71,12 @@
 
     public void initialize() {
         super.initialize();
-        
+
         if (isNew()) {
             set(MODEL, new Category());
         }
     }
-    
+
     /**
      * Creates a new term within a domain. All
      * parameters are required except for shortcut
@@ -99,29 +99,29 @@
         term.setName(name);
 
         term.setInAtoZ(inAtoZ);
-        term.setShortcut(shortcut);        
+        term.setShortcut(shortcut);
 
         if (s_log.isDebugEnabled()) {
-            s_log.debug("Created term " + term.getID() + " with unique id " + 
+            s_log.debug("Created term " + term.getID() + " with unique id " +
                         uniqueID + " and name " + name + " in domain " +
                         domain);
         }
-        
+
         return term;
     }
-    
+
     private void setUniqueID(Integer uniqueID) {
         Assert.exists(uniqueID, Integer.class);
         set(UNIQUE_ID, uniqueID);
     }
-    
+
     /**
      * Retrieves the unique identifier for this term.
      */
     public Integer getUniqueID() {
         return (Integer)get(UNIQUE_ID);
     }
-    
+
     /**
      * Updates the name of this term
      * @param name the term's new name
@@ -131,7 +131,7 @@
         getModel().setName(name);
         getModel().setURL(cleanURL(name));
     }
-    
+
     /**
      * Retrieves the name of this term
      * @return the name of the term
@@ -139,7 +139,7 @@
     public String getName() {
         return getModel().getName();
     }
-    
+
     /**
      * Updates the description of this term
      * @param description the term's new description
@@ -148,7 +148,7 @@
         Assert.exists(description, String.class);
         getModel().setDescription(description);
     }
-    
+
     /**
      * Retrieves the description of this term
      * @return the description of the term
@@ -156,7 +156,7 @@
     public String getDescription() {
         return getModel().getDescription();
     }
-    
+
     /**
      * Update the flag indicating whether this
      * term is suitable for inclusion in an A-Z
@@ -165,7 +165,7 @@
     public void setInAtoZ(boolean inAtoZ) {
         set(IN_ATOZ, new Boolean(inAtoZ));
     }
-    
+
     /**
      * Determines whether the term is suitable
      * for inclusion in an A-Z
@@ -181,7 +181,7 @@
     public void setShortcut(String shortcut) {
         set(SHORTCUT, shortcut);
     }
-    
+
     /**
      * Retrieves the URL fragment forming a shortcut
      * to this term
@@ -189,12 +189,12 @@
     public String getShortcut() {
         return (String)get(SHORTCUT);
     }
-    
+
     private void setDomain(Domain domain) {
         Assert.exists(domain, Domain.class);
         setAssociation(DOMAIN, domain);
     }
-    
+
     /**
      * Retrieves the domain containing this term
      * @return the domain containing this term
@@ -203,13 +203,13 @@
         return (Domain)DomainObjectFactory
             .newInstance((DataObject)get(DOMAIN));
     }
-    
+
     public Category getModel() {
         return (Category)DomainObjectFactory
             .newInstance((DataObject)get(MODEL));
     }
 
-    
+
     /**
      * Adds a narrower term to this term
      * @param term the narrower term
@@ -222,28 +222,28 @@
         //             "narrower term is in this domain");
 
         if (s_log.isDebugEnabled()) {
-            s_log.debug("Adding narrower term " + term + " to " + 
+            s_log.debug("Adding narrower term " + term + " to " +
                         this + " isDefault?" + isDefault);
         }
 
         getModel().addChild(term.getModel());
         term.getModel().setEnabled(isPreferred);
-        
+
         if (isDefault) {
             term.getModel().setDefaultParentCategory(getModel());
         }
     }
-    
+
     /**
      * Removes a narrower term from this term
      * @param term the narrower term to remove
      */
     public void removeNarrowerTerm(Term term) {
         if (s_log.isDebugEnabled()) {
-            s_log.debug("Removing narrower term " + term + " from " + 
+            s_log.debug("Removing narrower term " + term + " from " +
                         this);
         }
-        
+
         getModel().removeChild(term.getModel());
     }
 
@@ -257,8 +257,22 @@
         terms.addEqualsFilter("model.parents.link.relationType", "child");
         return terms;
     }
-    
+
+
     /**
+     * Retrieves the collection of narrower terms
+     * for which this term is the default parent
+     * @return a collection of narrower terms
+     *
+     */
+    public DomainCollection getDefaultNarrowerTerms() {
+        DomainCollection terms = getNarrowerTerms();
+        terms.addEqualsFilter("model.parents.link.isDefault", Boolean.TRUE);
+        return terms;
+    }
+
+
+    /**
      * Retrieves the collection of broader terms
      * @return a collection of broader terms
      */
@@ -266,9 +280,9 @@
         DomainCollection terms = getDomain().getTerms();
         terms.addEqualsFilter("model.related.id", getModel().getID());
         terms.addEqualsFilter("model.related.link.relationType", "child");
-        return terms;        
+        return terms;
     }
-    
+
     /**
      * Retrieves the default broader term
      * @return the default broader term
@@ -284,33 +298,33 @@
         throw new DataObjectNotFoundException(
             "No default broader term for " + getID());
     }
-    
+
     /**
      * Adds a related term to this term
      * @param term the related term
      */
     public void addRelatedTerm(Term term) {
         if (s_log.isDebugEnabled()) {
-            s_log.debug("Adding related term " + term + " to " + 
+            s_log.debug("Adding related term " + term + " to " +
                         this);
         }
 
         getModel().addRelatedCategory(term.getModel());
     }
-    
+
     /**
      * Removes a related term to this term
      * @param term the related term
      */
     public void removeRelatedTerm(Term term) {
         if (s_log.isDebugEnabled()) {
-            s_log.debug("Removing related term " + term + "from " + 
+            s_log.debug("Removing related term " + term + "from " +
                         this);
         }
 
         getModel().removeRelatedCategory(term.getModel());
     }
-    
+
     /**
      * Retrieves the related terms within this terms
      * domain
@@ -322,7 +336,7 @@
         terms.addEqualsFilter("model.parents.link.relationType", "related");
         return terms;
     }
-    
+
     /**
      * Retrieves the related terms within this terms
      * domain
@@ -355,7 +369,7 @@
     public void addObject(ACSObject obj) {
         getModel().addChild(obj);
     }
-    
+
     /**
      * Unclassifies an object against this term
      * @param obj the object to unclassify
 |