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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Sep 13 05:15:33 EDT 2006


Author: michael.neale at jboss.com
Date: 2006-09-13 05:15:29 -0400 (Wed, 13 Sep 2006)
New Revision: 6192

Modified:
   labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/FunctionItem.java
   labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/RulesRepository.java
   labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/repository/FunctionItemTestCase.java
Log:
simplified the categories

Modified: labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/FunctionItem.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/FunctionItem.java	2006-09-13 09:10:22 UTC (rev 6191)
+++ labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/FunctionItem.java	2006-09-13 09:15:29 UTC (rev 6192)
@@ -165,177 +165,8 @@
         }
     }            
     
-    /**
-     * Adds the specified tag to this object's function 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.
-     *  
-     * @param tag the tag to add to the function. functions can have multiple tags
-     * @throws RulesRepositoryException 
-     */
-    public void addTag(String tag) throws RulesRepositoryException {
-        try {
-            //make sure this object's node is the head version
-            if(this.node.getPrimaryNodeType().getName().equals("nt:version")) {
-                String message = "Error. Tags can only be added to the head version of a function node";
-                log.error(message);
-                throw new RulesRepositoryException(message);
-            }                                       
-            
-            CategoryItem tagItem = this.rulesRepository.getOrCreateCategory(tag);
-                                    
-            //now set the tag property of the node
-            Property tagReferenceProperty;
-            int i = 0;
-            Value[] newTagValues = null;
-            try {
-                tagReferenceProperty = this.node.getProperty(TAG_PROPERTY_NAME);
-                Value[] oldTagValues = tagReferenceProperty.getValues();
-                
-                //first, make sure this tag wasn't already there. while we're at it, lets copy the array
-                newTagValues = new Value[oldTagValues.length + 1];                
-                for(i=0; i<oldTagValues.length; i++) {
-                    if(oldTagValues[i].getString().equals(tag)) {
-                        log.info("tag '" + tag + "' already existed for function node: " + this.node.getName());
-                        return;
-                    }
-                    newTagValues[i] = oldTagValues[i];
-                }
-            }
-            catch(PathNotFoundException e) {
-                //the property doesn't exist yet, so create it in the finally block
-                newTagValues = new Value[1];                 
-            }
-            finally {   
-                if(newTagValues != null) {
-                    newTagValues[i] = this.node.getSession().getValueFactory().createValue(tagItem.getNode());
-                    this.node.checkout();
-                    this.node.setProperty(TAG_PROPERTY_NAME, newTagValues);
-                    this.node.getSession().save();
-                    this.node.checkin();
-                }
-                else {
-                    log.error("reached expected path of execution when adding tag '" + tag + "' to functionNode: " + this.node.getName());
-                }
-            }
-        }
-        catch(Exception e) {
-            log.error("Caught exception", e);
-            throw new RulesRepositoryException(e);
-        }
-    }
-
-    /**
-     * Removes the specified tag from this object's function node.
-     * 
-     * @param tag the tag to remove from the node
-     * @throws RulesRepositoryException 
-     */
-    public void removeTag(String tag) throws RulesRepositoryException {
-        //TODO: implement if the removed tag no longer has anyone referencing it, remove the tag (are we sure we want to do this, for versioning's sake?)
-        try {
-            //make sure this object's node is the head version
-            if(this.node.getPrimaryNodeType().getName().equals("nt:version")) {
-                String message = "Error. Tags can only be removed from the head version of a function node";
-                log.error(message);
-                throw new RulesRepositoryException(message);
-            }                                                   
-                                    
-            //now set the tag property of the rule
-            Property tagReferenceProperty;
-            int i = 0;
-            int j = 0;
-            Value[] newTagValues = null;
-            try {
-                tagReferenceProperty = this.node.getProperty(TAG_PROPERTY_NAME);
-                Value[] oldTagValues = tagReferenceProperty.getValues();
-                
-                //see if the tag was even there
-                boolean wasThere = false;
-                for(i=0; i<oldTagValues.length; i++) {
-                    Node tagNode = this.node.getSession().getNodeByUUID(oldTagValues[i].getString());
-                    if(tagNode.getName().equals(tag)) {                                                
-                        wasThere = true;
-                    }
-                }
-                
-                if(wasThere) {
-                    //copy the array, minus the specified tag
-                    newTagValues = new Value[oldTagValues.length + 1];                
-                    for(i=0; i<oldTagValues.length; i++) {
-                        Node tagNode = this.node.getSession().getNodeByUUID(oldTagValues[i].getString());
-                        if(!tagNode.getName().equals(tag)) {                                                         
-                            newTagValues[j] = oldTagValues[i];
-                            j++;
-                        }
-                    }
-                }
-                else {
-                    //TODO: remove the tag if it isn't used by anyone else
-                    return;
-                }
-            }
-            catch(PathNotFoundException e) {
-                //the property doesn't exist yet
-                //TODO: first remove the tag if it isn't used by anyone else
-                return;             
-            }
-            finally {   
-                if(newTagValues != null) {
-                    this.node.checkout();
-                    this.node.setProperty(TAG_PROPERTY_NAME, newTagValues);
-                    this.node.getSession().save();
-                    this.node.checkin();
-                }
-                else {
-                    log.error("reached expected path of execution when removing tag '" + tag + "' from functionNode: " + this.node.getName());
-                }
-            }
-        }
-        catch(Exception e) {
-            log.error("Caught exception", e);
-            throw new RulesRepositoryException(e);
-        }
-    }
     
     /**
-     * Gets a list of TagItem objects for this object's function node.
-     * 
-     * @return a list of TagItem objects for each tag on the node. If there are no tags, an empty list. 
-     * @throws RulesRepositoryException
-     */
-    public List getTags() throws RulesRepositoryException {
-        try {                            
-            Node functionNode;
-            if(this.node.getPrimaryNodeType().getName().equals("nt:version")) {
-                functionNode = this.node.getNode("jcr:frozenNode");
-            }
-            else {
-                functionNode = this.node;
-            }
-            
-            List returnList = new ArrayList();
-            try {
-                Property tagReferenceProperty = functionNode.getProperty(TAG_PROPERTY_NAME);
-                Value[] tagValues = tagReferenceProperty.getValues();                
-                for(int i=0; i<tagValues.length; i++) {
-                    Node tagNode = this.node.getSession().getNodeByUUID(tagValues[i].getString());
-                    CategoryItem tagItem = new CategoryItem(this.rulesRepository, tagNode);
-                    returnList.add(tagItem);
-                }
-            }
-            catch(PathNotFoundException e) {
-                //the property doesn't even exist yet, so just return nothing
-            }
-            return returnList;
-        }
-        catch(Exception e) {
-            log.error("Caught exception", e);
-            throw new RulesRepositoryException(e);
-        }
-    }
-    
-    /**
      * Sets this object's function node's state property to refer to the specified state node
      * 
      * @param stateName the name of the state to set the function node to
@@ -427,12 +258,6 @@
             }            
             returnString.append("------\n");
             
-            returnString.append("Categories:\n");
-            for(Iterator it=this.getTags().iterator(); it.hasNext();) {
-                CategoryItem currentTag = (CategoryItem)it.next();
-                returnString.append(currentTag.getName() + "\n");
-            }
-            returnString.append("--------------\n");
             return returnString.toString();
         }
         catch(Exception e) {         

Modified: labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/RulesRepository.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/RulesRepository.java	2006-09-13 09:10:22 UTC (rev 6191)
+++ labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/RulesRepository.java	2006-09-13 09:15:29 UTC (rev 6192)
@@ -725,31 +725,6 @@
         }
     }
 
-    /**
-     * This will retrieve a list of FunctionItem objects - that are allocated to the 
-     * provided category.
-     * Only the latest versions of each FunctionItem will be returned (you will have 
-     * to delve into the functions' deepest darkest history yourself... mahahahaha).
-     */
-    public List findFunctionsByTag(String categoryTag) throws RulesRepositoryException {        
-        CategoryItem item = this.getOrCreateCategory( categoryTag );
-        List results = new ArrayList();
-        try {
-            PropertyIterator it = item.getNode().getReferences();
-            while(it.hasNext()) {
-                Property ruleLink = (Property) it.next();
-                Node parentNode = ruleLink.getParent();
-                if(parentNode.getPrimaryNodeType().getName().equals(FunctionItem.FUNCTION_NODE_TYPE_NAME) ||
-                   (parentNode.getPrimaryNodeType().getName().equals("nt:version") && 
-                    parentNode.getProperty(VersionableItem.FORMAT_PROPERTY_NAME).getString().equals(VersionableItem.FUNCTION_FORMAT))) {
-                    results.add(new FunctionItem(this, parentNode));
-                }
-            }
-            return results;
-        } catch (RepositoryException e) {            
-            throw new RulesRepositoryException(e);
-        }        
-    }
     
     /**
      * This will retrieve a list of RuleItem objects - that are allocated to the 
@@ -766,9 +741,7 @@
             while(it.hasNext()) {
                 Property ruleLink = (Property) it.next();
                 Node parentNode = ruleLink.getParent();
-                if(parentNode.getPrimaryNodeType().getName().equals(RuleItem.RULE_NODE_TYPE_NAME) ||
-                   (parentNode.getPrimaryNodeType().getName().equals("nt:version") && 
-                    parentNode.getProperty(VersionableItem.FORMAT_PROPERTY_NAME).getString().equals(VersionableItem.RULE_FORMAT))) {
+                if(parentNode.getPrimaryNodeType().getName().equals(RuleItem.RULE_NODE_TYPE_NAME)) {
                     results.add(new RuleItem(this, parentNode));
                 }
             }

Modified: labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/repository/FunctionItemTestCase.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/repository/FunctionItemTestCase.java	2006-09-13 09:10:22 UTC (rev 6191)
+++ labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/repository/FunctionItemTestCase.java	2006-09-13 09:15:29 UTC (rev 6192)
@@ -57,55 +57,8 @@
             
             assertEquals("new content", functionItem1.getContent());
     }
-        
-    public void testAddCategory() {
-            FunctionItem functionItem1 = this.getRepo().addFunction("testAddCategory", "test content");
-            
-            functionItem1.addTag("testAddCategoryTestTag");
-            List tags = functionItem1.getTags();
-            assertEquals(1, tags.size());
-            assertEquals("testAddCategoryTestTag", ((CategoryItem)tags.get(0)).getName());
-            
-            functionItem1.addTag("testAddCategoryTestTag2");
-            tags = functionItem1.getTags();
-            assertEquals(2, tags.size());   
-                        
-            //now test retrieve by tags
-            List result = this.getRepo().findFunctionsByTag("testAddCategoryTestTag");            
-            assertEquals(1, result.size());            
-            FunctionItem retItem = (FunctionItem) result.get(0);
-            assertEquals("testAddCategory", retItem.getName());            
-    }
 
-    public void testRemoveTag() {
-            FunctionItem functionItem1 = this.getRepo().addFunction("testRemoveTag", "test content");
-            
-            functionItem1.addTag("TestTag");                                    
-            functionItem1.removeTag("TestTag");
-            List tags = functionItem1.getTags();
-            assertEquals(0, tags.size());
-            
-            functionItem1.addTag("TestTag2");                                    
-            functionItem1.addTag("TestTag3");
-            functionItem1.removeTag("TestTag2");
-            tags = functionItem1.getTags();
-            assertEquals(1, tags.size());
-            assertEquals("TestTag3", ((CategoryItem)tags.get(0)).getName());            
-    }
 
-    public void testGetTags() {
-            FunctionItem functionItem1 = this.getRepo().addFunction("testGetTags", "test content");
-           
-            List tags = functionItem1.getTags();
-            assertNotNull(tags);
-            assertEquals(0, tags.size());
-            
-            functionItem1.addTag("TestTag");                                    
-            tags = functionItem1.getTags();
-            assertEquals(1, tags.size());
-            assertEquals("TestTag", ((CategoryItem)tags.get(0)).getName());
-    }
-
     public void testSetStateString() {
             FunctionItem functionItem1 = this.getRepo().addFunction("testSetStateString", "test content");
            




More information about the jboss-svn-commits mailing list