[jboss-svn-commits] JBL Code SVN: r5936 - in labs/jbossrules/trunk/drools-repository/src: java/org/drools/repository java/org/drools/repository/test node_type_definitions

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Aug 18 00:16:24 EDT 2006


Author: bentruitt
Date: 2006-08-18 00:16:20 -0400 (Fri, 18 Aug 2006)
New Revision: 5936

Modified:
   labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RuleItem.java
   labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/RuleItemTestCase.java
   labs/jbossrules/trunk/drools-repository/src/node_type_definitions/rule_node_type.cnd
Log:
Added description to rule node type.

Modified: labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RuleItem.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RuleItem.java	2006-08-17 20:26:32 UTC (rev 5935)
+++ labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RuleItem.java	2006-08-18 04:16:20 UTC (rev 5936)
@@ -2,6 +2,7 @@
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Iterator;
@@ -76,6 +77,17 @@
     public static final String DATE_EXPIRED_PROPERTY_NAME = "drools:date_expired";
     
     /**
+     * The name of the description property on the rule node type
+     */
+    public static final String DESCRIPTION_PROPERTY_NAME = "drools:description";    
+        
+    /**
+     * The name of the additional docuementation child node on the rule node type
+     */
+    public static final String ADDITIONAL_DOCUMENTATION_NODE_NAME = "drools:additional_documentation";
+    
+    
+    /**
      * Constructs a RuleItem object, setting its node attribute to the specified node.
      * 
      * @param rulesRepository the rulesRepository that instantiated this object
@@ -153,6 +165,36 @@
     }
     
     /**
+     * returns the description of this object's rule node
+     * 
+     * @return the description of this object's rule node
+     * @throws RulesRepositoryException
+     */
+    public String getDescription() throws RulesRepositoryException {
+        try {                        
+            Node ruleNode;
+            if(this.node.getPrimaryNodeType().getName().equals("nt:version")) {
+                ruleNode = this.node.getNode("jcr:frozenNode");
+            }
+            else {
+                ruleNode = this.node;
+            }
+            
+            //grab the description of the node and dump it into a string            
+            Property data = ruleNode.getProperty(DESCRIPTION_PROPERTY_NAME);
+            return data.getValue().getString();
+        }
+        catch(PathNotFoundException e) {
+            //no description set yet
+            return null;
+        }
+        catch(Exception e) {
+            log.error("Caught Exception", e);
+            throw new RulesRepositoryException(e);
+        }
+    }       
+    
+    /**
      * @return the date the rule node (this version) was last modified
      * @throws RulesRepositoryException
      */
@@ -429,6 +471,50 @@
     }
     
     /**
+     * Creates a new version of this object's rule node, updating the description content 
+     * for the rule node. 
+     * 
+     * @param newDescriptionContent the new description content for the rule
+     * @throws RulesRepositoryException
+     */
+    public void updateDescription(String newDescriptionContent) throws RulesRepositoryException {
+        try {
+            this.node.checkout();
+        }
+        catch(UnsupportedRepositoryOperationException e) {
+            String message = "";
+            try {
+                message = "Error: Caught UnsupportedRepositoryOperationException when attempting to checkout rule: " + this.node.getName() + ". Are you sure your JCR repository supports versioning? ";
+                log.error(message + e);
+            }
+            catch (RepositoryException e1) {
+                log.error("Caught Exception", e);
+                throw new RulesRepositoryException(e1);
+            }
+            throw new RulesRepositoryException(message, e);
+        }
+        catch(Exception e) {
+            log.error("Caught Exception", e);
+            throw new RulesRepositoryException(e);
+        }
+        
+        try {                                    
+            this.node.setProperty(DESCRIPTION_PROPERTY_NAME, newDescriptionContent);
+            
+            Calendar lastModified = Calendar.getInstance();
+            this.node.setProperty(LAST_MODIFIED_PROPERTY_NAME, lastModified);
+            
+            this.node.getSession().save();
+            
+            this.node.checkin();
+        }
+        catch(Exception e) {
+            log.error("Caught Exception", e);
+            throw new RulesRepositoryException(e);
+        }
+    }
+    
+    /**
      * Adds the specified tag to this object's rule node. Tags are stored as nodes in a tag area of
      * the repository. If the specified tag does not already have a corresponding node, a node is 
      * created for it.

Modified: labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/RuleItemTestCase.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/RuleItemTestCase.java	2006-08-17 20:26:32 UTC (rev 5935)
+++ labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/RuleItemTestCase.java	2006-08-18 04:16:20 UTC (rev 5936)
@@ -305,4 +305,19 @@
             fail("Caught unexpected exception: " + e);
         }
     }
+    
+    public void testGetDescription() {
+        try {
+            RuleItem ruleItem1 = this.rulesRepository.addRule("test rule", "test lhs content", "test rhs content");
+            
+            //it should be null to begin with
+            assertTrue(ruleItem1.getDescription() == null);
+            
+            ruleItem1.updateDescription("test description");
+            assertEquals("test description", ruleItem1.getDescription());
+        }
+        catch(Exception e) {
+            fail("Caught unexpected exception: " + e);
+        }
+    }
 }

Modified: labs/jbossrules/trunk/drools-repository/src/node_type_definitions/rule_node_type.cnd
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/node_type_definitions/rule_node_type.cnd	2006-08-17 20:26:32 UTC (rev 5935)
+++ labs/jbossrules/trunk/drools-repository/src/node_type_definitions/rule_node_type.cnd	2006-08-18 04:16:20 UTC (rev 5936)
@@ -33,6 +33,8 @@
 - drools:rule_language (string)
   = 'DRL'
   mandatory autocreated
+  
+- drools:description (string)
 
 - drools:dsl_reference (reference)
   copy 




More information about the jboss-svn-commits mailing list