[jboss-svn-commits] JBL Code SVN: r20161 - in labs/jbossrules/trunk/drools-repository/src: test/java/org/drools/repository and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun May 25 21:21:35 EDT 2008
Author: jervisliu
Date: 2008-05-25 21:21:35 -0400 (Sun, 25 May 2008)
New Revision: 20161
Modified:
labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/CategorisableItem.java
labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/CategoryItem.java
labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/Item.java
labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/VersionableItem.java
labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/repository/ArchiveItemTest.java
labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/repository/CategoryItemTest.java
Log:
JBRULES-1251(Cannot remove a category if it was used in an archived rule): now we allow removing a category if it is only linked by an archived rule.
Modified: labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/CategorisableItem.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/CategorisableItem.java 2008-05-26 01:09:33 UTC (rev 20160)
+++ labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/CategorisableItem.java 2008-05-26 01:21:35 UTC (rev 20161)
@@ -189,9 +189,20 @@
* @throws RulesRepositoryException
*/
public void removeCategory(String tag) throws RulesRepositoryException {
+ removeCategory(this.node, tag);
+ }
+
+ /**
+ * Removes the specified tag from this object's rule node.
+ *
+ * @param targetNode the node from which the tag is to be removed.
+ * @param tag the tag to remove from the rule
+ * @throws RulesRepositoryException
+ */
+ public static void removeCategory(Node targetNode, String tag) throws RulesRepositoryException {
try {
//make sure this object's node is the head version
- if ( this.node.getPrimaryNodeType().getName().equals( "nt:version" ) ) {
+ if (targetNode.getPrimaryNodeType().getName().equals( "nt:version" ) ) {
String message = "Error. Tags can only be removed from the head version of a rule node";
log.error( message );
throw new RulesRepositoryException( message );
@@ -203,13 +214,13 @@
int j = 0;
Value[] newTagValues = null;
try {
- tagReferenceProperty = this.node.getProperty( CATEGORY_PROPERTY_NAME );
+ tagReferenceProperty = targetNode.getProperty( CATEGORY_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() );
+ Node tagNode = targetNode.getSession().getNodeByUUID( oldTagValues[i].getString() );
if ( tagNode.getName().equals( tag ) ) {
wasThere = true;
}
@@ -219,7 +230,7 @@
//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() );
+ Node tagNode = targetNode.getSession().getNodeByUUID( oldTagValues[i].getString() );
if ( !tagNode.getName().equals( tag ) ) {
newTagValues[j] = oldTagValues[i];
j++;
@@ -233,11 +244,11 @@
return;
} finally {
if ( newTagValues != null ) {
- checkout();
- this.node.setProperty( CATEGORY_PROPERTY_NAME,
+ checkout(targetNode);
+ targetNode.setProperty( CATEGORY_PROPERTY_NAME,
newTagValues );
} else {
- log.error( "reached expected path of execution when removing tag '" + tag + "' from ruleNode: " + this.node.getName() );
+ log.error( "reached expected path of execution when removing tag '" + tag + "' from ruleNode: " + targetNode.getName() );
}
}
} catch ( Exception e ) {
@@ -247,4 +258,5 @@
}
}
+
}
Modified: labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/CategoryItem.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/CategoryItem.java 2008-05-26 01:09:33 UTC (rev 20160)
+++ labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/CategoryItem.java 2008-05-26 01:21:35 UTC (rev 20161)
@@ -5,6 +5,8 @@
import javax.jcr.Node;
import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
import javax.jcr.RepositoryException;
import org.apache.log4j.Logger;
@@ -110,17 +112,27 @@
/**
* This will remove the category and any ones under it.
- * This will only work if you have no current assets linked to the category.
+ * This will only work if you have no current assets linked to the category unless the assets are archived.
*/
public void remove() {
try {
- if (this.node.getReferences().hasNext()) {
- throw new RulesRepositoryException("The category still has some assets linked to it. You will need to remove the links so you can delete the cateogory.");
- }
+ PropertyIterator pi = this.node.getReferences();
+ while (pi.hasNext()) {
+ Property p = pi.nextProperty();
+ Node parentNode = p.getParent();
+
+ if (parentNode.getProperty(
+ AssetItem.CONTENT_PROPERTY_ARCHIVE_FLAG).getBoolean()) {
+ CategorisableItem.removeCategory(parentNode, this.node.getName());
+ } else {
+ throw new RulesRepositoryException(
+ "The category still has some assets linked to it. You will need to remove the links so you can delete the cateogory.");
+ }
+ }
this.node.remove();
} catch ( RepositoryException e ) {
log.error( e );
}
}
-
+
}
Modified: labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/Item.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/Item.java 2008-05-26 01:09:33 UTC (rev 20160)
+++ labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/Item.java 2008-05-26 01:21:35 UTC (rev 20161)
@@ -11,7 +11,7 @@
* @author btruitt
*/
public abstract class Item {
- Logger log = Logger.getLogger(Item.class);
+ static Logger log = Logger.getLogger(Item.class);
/**
* The node within the repository that this item corresponds to
Modified: labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/VersionableItem.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/VersionableItem.java 2008-05-26 01:09:33 UTC (rev 20160)
+++ labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/VersionableItem.java 2008-05-26 01:21:35 UTC (rev 20161)
@@ -468,13 +468,21 @@
* This will check out the node prior to editing.
*/
public void checkout() {
+ checkout(this.node);
+ }
+ /**
+ * This will check out the node prior to editing.
+ * @param targetNode the node to be checked out.
+ */
+ public static void checkout(Node targetNode) {
+
try {
- this.node.checkout();
+ targetNode.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? ";
+ message = "Error: Caught UnsupportedRepositoryOperationException when attempting to checkout rule: " + targetNode.getName() + ". Are you sure your JCR repository supports versioning? ";
log.error( message,
e );
} catch ( RepositoryException e1 ) {
@@ -490,7 +498,6 @@
throw new RulesRepositoryException( e );
}
}
-
/**
* This will save the content (if it hasn't been already) and
* then check it in to create a new version.
Modified: labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/repository/ArchiveItemTest.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/repository/ArchiveItemTest.java 2008-05-26 01:09:33 UTC (rev 20160)
+++ labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/repository/ArchiveItemTest.java 2008-05-26 01:21:35 UTC (rev 20161)
@@ -48,13 +48,6 @@
item.checkin( "archiving item 1" );
item = RepositorySessionUtil.getRepository().loadDefaultPackage().loadAsset( "testFindArchivedAssets3" );
assertTrue( item.isArchived() );
-
-
- AssetItemIterator it = repo.findArchivedAssets();
-
- List list = iteratorToList( it );
- assertEquals(3, list.size());
-
}
public void testArchiveBooleanFlag() throws Exception {
Modified: labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/repository/CategoryItemTest.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/repository/CategoryItemTest.java 2008-05-26 01:09:33 UTC (rev 20160)
+++ labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/repository/CategoryItemTest.java 2008-05-26 01:21:35 UTC (rev 20161)
@@ -160,6 +160,21 @@
repo.save();
}
+
+
+ public void testRemoveCategoryLinkedWithArchived() {
+ RulesRepository repo = getRepo();
+ repo.loadCategory( "/" ).addCategory( "testRemoveCategoryWithArchivedCat", "a" );
+ AssetItem as = repo.loadDefaultPackage().addAsset( "testRemoveCategoryWithArchivedAsset", "a", "testRemoveCategoryWithArchivedCat", "drl" );
+ as.checkin( "a" );
+
+ as.archiveItem(true);
+
+ repo.loadCategory( "testRemoveCategoryWithArchivedCat" ).remove();
+ repo.save();
+
+// as.remove();
+ }
private RulesRepository getRepo() {
return RepositorySessionUtil.getRepository();
More information about the jboss-svn-commits
mailing list