[jboss-svn-commits] JBL Code SVN: r29100 - in labs/jbossrules/trunk: drools-repository/src/main/java/org/drools/repository and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Aug 27 23:50:15 EDT 2009
Author: jervisliu
Date: 2009-08-27 23:50:15 -0400 (Thu, 27 Aug 2009)
New Revision: 29100
Modified:
labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/ServiceImplementationTest.java
labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/CategorisableItem.java
Log:
https://jira.jboss.org/jira/browse/GUVNOR-444: Duplicate category can be added
Modified: labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/ServiceImplementationTest.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/ServiceImplementationTest.java 2009-08-28 03:32:47 UTC (rev 29099)
+++ labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/ServiceImplementationTest.java 2009-08-28 03:50:15 UTC (rev 29100)
@@ -2567,7 +2567,33 @@
assertEquals(null, res.errors);
}
+ public void testAddCategories() throws Exception {
+ ServiceImplementation impl = getService();
+ impl.repository.createPackage("testAddCategoriesPackage", "desc");
+ impl.createCategory("", "testAddCategoriesCat1", "this is a cat");
+ impl.createCategory("", "testAddCategoriesCat2", "this is a cat");
+ String uuid = impl.createNewRule("testCreateNewRuleName",
+ "an initial desc", "testAddCategoriesCat1", "testAddCategoriesPackage",
+ AssetFormats.DSL_TEMPLATE_RULE);
+
+ AssetItem dtItem = impl.repository.loadAssetByUUID(uuid);
+ dtItem.addCategory("testAddCategoriesCat1");
+ impl.repository.save();
+
+ AssetItem dtItem1 = impl.repository.loadAssetByUUID(uuid);
+ assertEquals(1, dtItem1.getCategories().size());
+ assertTrue(dtItem1.getCategorySummary().contains("testAddCategoriesCat1"));
+
+ AssetItem dtItem2 = impl.repository.loadAssetByUUID(uuid);
+ dtItem2.addCategory("testAddCategoriesCat2");
+ impl.repository.save();
+
+ AssetItem dtItem3 = impl.repository.loadAssetByUUID(uuid);
+ assertEquals(2, dtItem3.getCategories().size());
+ assertTrue(dtItem3.getCategorySummary().contains("testAddCategoriesCat2"));
+ }
+
/**
* Set up enough of the Seam environment to test it.
*/
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 2009-08-28 03:32:47 UTC (rev 29099)
+++ labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/CategorisableItem.java 2009-08-28 03:50:15 UTC (rev 29100)
@@ -47,35 +47,32 @@
checkIsUpdateable();
CategoryItem tagItem = this.rulesRepository.loadCategory( tag );
+ String tagItemUUID = this.node.getSession().getValueFactory().createValue( tagItem.getNode() ).getString();
//now set the tag property of the rule
- Property tagReferenceProperty;
- int i = 0;
- Value[] newTagValues = null;
try {
- tagReferenceProperty = this.node.getProperty( CATEGORY_PROPERTY_NAME );
+ Property tagReferenceProperty = this.node.getProperty( CATEGORY_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 ) ) {
+ for ( int j = 0; j < oldTagValues.length; j++ ) {
+ if ( oldTagValues[j].getString().equals( tagItemUUID ) ) {
log.info( "tag '" + tag + "' already existed for rule node: " + this.node.getName() );
return;
}
+ }
+
+ Value[] newTagValues = new Value[oldTagValues.length + 1];
+ for ( int i = 0; i < oldTagValues.length; i++ ) {
newTagValues[i] = oldTagValues[i];
}
+ newTagValues[oldTagValues.length] = this.node.getSession().getValueFactory().createValue( tagItem.getNode() );
+ updateCategories( newTagValues );
} 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() );
- updateCategories( newTagValues );
- } else {
- log.error( "reached expected path of execution when adding tag '" + tag + "' to ruleNode: " + this.node.getName() );
- }
- }
+ //the property doesn't exist yet
+ Value[] newTagValues = new Value[1];
+ newTagValues[0] = this.node.getSession().getValueFactory().createValue( tagItem.getNode() );
+ updateCategories( newTagValues );
+ }
} catch ( Exception e ) {
log.error( "Caught exception",
e );
More information about the jboss-svn-commits
mailing list