You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(233) |
Sep
(199) |
Oct
(206) |
Nov
(185) |
Dec
(270) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(232) |
Feb
(426) |
Mar
(623) |
Apr
(592) |
May
(506) |
Jun
(389) |
Jul
(160) |
Aug
(3) |
Sep
(1) |
Oct
(1) |
Nov
(2) |
Dec
(5) |
2007 |
Jan
(1) |
Feb
(1) |
Mar
(2) |
Apr
(2) |
May
(4) |
Jun
(2) |
Jul
|
Aug
(3) |
Sep
(5) |
Oct
(9) |
Nov
(6) |
Dec
(6) |
2008 |
Jan
(3) |
Feb
|
Mar
(1) |
Apr
(3) |
May
(3) |
Jun
(5) |
Jul
(10) |
Aug
(2) |
Sep
(12) |
Oct
(10) |
Nov
(54) |
Dec
(49) |
2009 |
Jan
(19) |
Feb
(13) |
Mar
(20) |
Apr
(24) |
May
(44) |
Jun
(29) |
Jul
(32) |
Aug
(10) |
Sep
(7) |
Oct
(10) |
Nov
(4) |
Dec
(17) |
2010 |
Jan
(14) |
Feb
(5) |
Mar
(23) |
Apr
(50) |
May
(31) |
Jun
(9) |
Jul
(5) |
Aug
(4) |
Sep
(7) |
Oct
(5) |
Nov
(2) |
Dec
(3) |
2011 |
Jan
(12) |
Feb
(5) |
Mar
(5) |
Apr
(3) |
May
(4) |
Jun
(3) |
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
2012 |
Jan
(1) |
Feb
(2) |
Mar
|
Apr
(1) |
May
(1) |
Jun
(2) |
Jul
(4) |
Aug
(1) |
Sep
|
Oct
(1) |
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(2) |
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(3) |
Sep
|
Oct
|
Nov
|
Dec
(1) |
2015 |
Jan
|
Feb
|
Mar
(2) |
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2016 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <jbo...@li...> - 2006-04-23 01:55:29
|
Author: mic...@jb... Date: 2006-04-22 21:55:22 -0400 (Sat, 22 Apr 2006) New Revision: 3909 Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/lang/or_binding_with_brackets.drl Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/RuleParserTest.java Log: JBRULES-197 Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/RuleParserTest.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/RuleParserTest.java 2006-04-23 01:34:43 UTC (rev 3908) +++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/RuleParserTest.java 2006-04-23 01:55:22 UTC (rev 3909) @@ -903,6 +903,35 @@ assertFalse( parser.hasErrors() ); } + public void testOrBindingWithBrackets() throws Exception { + RuleParser parser = parseResource( "or_binding_with_brackets.drl" ); + parser.compilation_unit(); + + PackageDescr pack = parser.getPackageDescr(); + assertEquals(1, pack.getRules().size()); + RuleDescr rule = (RuleDescr) pack.getRules().get( 0 ); + assertEquals(1, rule.getLhs().getDescrs().size()); + + assertEquals(1, rule.getLhs().getDescrs().size()); + + OrDescr or = (OrDescr) rule.getLhs().getDescrs().get( 0 ); + assertEquals( 2, or.getDescrs().size() ); + + //first fact + ColumnDescr firstFact = (ColumnDescr) or.getDescrs().get( 0 ); + assertEquals("Person", firstFact.getObjectType()); + assertEquals("foo", firstFact.getIdentifier()); + + //second "option" + ColumnDescr secondFact = (ColumnDescr) or.getDescrs().get( 0 ); + assertEquals("Person", secondFact.getObjectType()); + assertEquals( "foo", secondFact.getIdentifier() ); + + assertEqualsIgnoreWhitespace( "System.out.println( \"Mark and Michael\" + bar );", rule.getConsequence()); + + assertFalse( parser.hasErrors() ); + } + /** */ public void testBracketsPrecedence() throws Exception { RuleParser parser = parseResource( "brackets_precedence.drl" ); Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/lang/or_binding_with_brackets.drl =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/lang/or_binding_with_brackets.drl 2006-04-23 01:34:43 UTC (rev 3908) +++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/lang/or_binding_with_brackets.drl 2006-04-23 01:55:22 UTC (rev 3909) @@ -0,0 +1,6 @@ +rule simple_rule + when + foo : ( Person(name == "mark") or Person(type == "fan") ) + then + System.out.println( "Mark and Michael" + bar ); +end \ No newline at end of file Property changes on: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/lang/or_binding_with_brackets.drl ___________________________________________________________________ Name: svn:eol-style + native |
Author: tirelli Date: 2006-04-22 14:06:35 -0400 (Sat, 22 Apr 2006) New Revision: 3907 Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsNotPingPong.drl Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/LeapsTest.java labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TupleSource.java Log: JBRULES-233: * Fixing looping test cases on logical assertions * Overriding failed test cases on LeapsTest class Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java 2006-04-22 09:30:19 UTC (rev 3906) +++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java 2006-04-22 18:06:35 UTC (rev 3907) @@ -1455,7 +1455,7 @@ workingMemory.getObjects().size() ); } - public void xxxtestLogicalAssertionsBacking() throws Exception { + public void testLogicalAssertionsBacking() throws Exception { PackageBuilder builder = new PackageBuilder(); builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_LogicalAssertionsBacking.drl" ) ) ); Package pkg = builder.getPackage(); @@ -1494,7 +1494,7 @@ assertEquals("cheese-type " + cheese1.getType() + " was not retracted, but should have. Neither cheese1 => type nor cheese2 => type is true.", 0, list.size()); } - public void xxxtestLogicalAssertionsSelfreferencing() throws Exception { + public void testLogicalAssertionsSelfreferencing() throws Exception { PackageBuilder builder = new PackageBuilder(); builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_LogicalAssertionsSelfreferencing.drl" ) ) ); Package pkg = builder.getPackage(); @@ -1530,7 +1530,7 @@ assertEquals(0, list.size()); } - public void xxxtestLogicalAssertionsLoop() throws Exception { + public void testLogicalAssertionsLoop() throws Exception { PackageBuilder builder = new PackageBuilder(); builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_LogicalAssertionsLoop.drl" ) ) ); Package pkg = builder.getPackage(); @@ -1552,7 +1552,7 @@ assertEquals("Rule has not fired (looped) expected number of times", 10, l.size()); } - public void xxxtestLogicalAssertionsNoLoop() throws Exception { + public void testLogicalAssertionsNoLoop() throws Exception { PackageBuilder builder = new PackageBuilder(); builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_LogicalAssertionsNoLoop.drl" ) ) ); Package pkg = builder.getPackage(); @@ -1570,12 +1570,11 @@ workingMemory.fireAllRules(); list = workingMemory.getObjects(a.getClass()); - assertEquals("a not asserted.", 1, list.size()); - assertEquals("a not asserted", a, list.get(0)); + assertEquals("a still in WM", 0, list.size()); assertEquals("Rule should not loop", 1, l.size()); } - public void xxxtestLogicalAssertions2() throws Exception { + public void testLogicalAssertions2() throws Exception { PackageBuilder builder = new PackageBuilder(); builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_LogicalAssertions2.drl" ) ) ); Package pkg = builder.getPackage(); @@ -1609,7 +1608,7 @@ assertEquals("Exactly six events", 6, events.size()); } - public void xxxtestLogicalAssertionsNot() throws Exception { + public void testLogicalAssertionsNot() throws Exception { PackageBuilder builder = new PackageBuilder(); builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_LogicalAssertionsNot.drl" ) ) ); Package pkg = builder.getPackage(); @@ -1647,6 +1646,34 @@ assertEquals("i was not asserted by not a => i.", 1, list.size()); assertEquals("i was not asserted by not a => i.", i, list.get(0)); } + + public void testLogicalAssertionsNotPingPong() throws Exception { + PackageBuilder builder = new PackageBuilder(); + builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_LogicalAssertionsNotPingPong.drl" ) ) ); + Package pkg = builder.getPackage(); + + RuleBase ruleBase = getRuleBase(); + ruleBase.addPackage( pkg ); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + + //workingMemory.addEventListener(new DebugAgendaEventListener()); + //workingMemory.addEventListener(new DebugWorkingMemoryEventListener()); + + List list; + + List l = new ArrayList(); + + String s = new String("s"); + Integer i = new Integer(1); + workingMemory.setGlobal( "i", i ); + workingMemory.setGlobal( "s", s ); + workingMemory.setGlobal( "l", l ); + + workingMemory.fireAllRules(); + + //not sure about desired state of working memory. + assertEquals("Rules have not fired (looped) expected number of times", 10, l.size()); + } private Object serializeIn(byte[] bytes) throws IOException, ClassNotFoundException { Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/LeapsTest.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/LeapsTest.java 2006-04-22 09:30:19 UTC (rev 3906) +++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/LeapsTest.java 2006-04-22 18:06:35 UTC (rev 3907) @@ -22,8 +22,10 @@ import java.util.List; import org.drools.Cheese; +import org.drools.FactHandle; import org.drools.QueryResults; import org.drools.RuleBase; +import org.drools.Sensor; import org.drools.WorkingMemory; import org.drools.compiler.PackageBuilder; import org.drools.rule.Package; @@ -114,13 +116,39 @@ workingMemory.fireAllRules(); assertEquals(4, list.size()); - assertEquals("group2", list.get(3)); + assertEquals("group2", list.get(3)); } public void testLogicalAssertions() throws Exception { // Not working in leaps - } + public void testLogicalAssertionsBacking() throws Exception { + // Not working in leaps + } + + public void testLogicalAssertionsSelfreferencing() throws Exception { + // Not working in leaps + } + + public void testLogicalAssertionsLoop() throws Exception { + // Not working in leaps + } + + public void testLogicalAssertionsNoLoop() throws Exception { + // Not working in leaps + } + + public void testLogicalAssertions2() throws Exception { + // Not working in leaps + } + + public void testLogicalAssertionsNot() throws Exception { + // Not working in leaps + } + + public void testLogicalAssertionsNotPingPong() throws Exception { + // Not working in leaps + } } \ No newline at end of file Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsNotPingPong.drl =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsNotPingPong.drl 2006-04-22 09:30:19 UTC (rev 3906) +++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsNotPingPong.drl 2006-04-22 18:06:35 UTC (rev 3907) @@ -0,0 +1,28 @@ +package org.drools.test; + +import java.lang.String; +import java.lang.Integer; +import java.util.List; + +global java.lang.Integer i; +global java.lang.String s; +global java.util.List l; + +rule "not s then i" + when + not String() + then + if (l.size() < 10) { + l.add(new Integer(0)); + assertLogical(i); + } +end +rule "i then s" + when + Integer() + then + if (l.size() < 10) { + l.add(new Integer(0)); + assertLogical(s); + } +end \ No newline at end of file Property changes on: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsNotPingPong.drl ___________________________________________________________________ Name: svn:executable + * Name: svn:eol-style + native Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TupleSource.java =================================================================== --- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TupleSource.java 2006-04-22 09:30:19 UTC (rev 3906) +++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TupleSource.java 2006-04-22 18:06:35 UTC (rev 3907) @@ -18,6 +18,7 @@ import java.io.Serializable; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import org.drools.common.BetaNodeBinder; @@ -174,9 +175,15 @@ PropagationContext context, WorkingMemoryImpl workingMemory) { LinkedList list = tuple.getLinkedTuples(); + if ( list != null && !list.isEmpty() ) { - int i = 0; - for ( LinkedListNode node = list.removeFirst(); node != null; node = list.removeFirst() ) { + LinkedListNode[] clone = new LinkedListNode[list.size()]; + int i=0; + for( LinkedListNode node = list.removeFirst(); node != null; node = list.removeFirst()) { + clone[i++] = node; + } + for(i = 0; i < clone.length; i++) { + LinkedListNode node = clone[i]; ((TupleSink) getTupleSinks().get( i++ )).retractTuple( (ReteTuple) ((LinkedListNodeWrapper) node).getNode(), context, workingMemory ); |
From: <jbo...@li...> - 2006-04-22 09:30:26
|
Author: mic...@jb... Date: 2006-04-22 05:30:19 -0400 (Sat, 22 Apr 2006) New Revision: 3906 Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/XmlPackageReader.java Log: JBRULES-235 Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/XmlPackageReader.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/XmlPackageReader.java 2006-04-22 08:38:12 UTC (rev 3905) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/XmlPackageReader.java 2006-04-22 09:30:19 UTC (rev 3906) @@ -17,6 +17,7 @@ */ import java.io.BufferedInputStream; +import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; @@ -662,54 +663,64 @@ } // Try looking in META-INF - try { - return new InputSource( cl.getResourceAsStream( "META-INF/" + xsd ) ); - } catch ( Exception e ) { + + { + InputStream is = cl.getResourceAsStream( "META-INF/" + xsd ); + if ( is != null ) { + return new InputSource( is ); + } } // Try looking in /META-INF - try { - return new InputSource( cl.getResourceAsStream( "/META-INF/" + xsd ) ); - } catch ( Exception e ) { + { + InputStream is = cl.getResourceAsStream( "/META-INF/" + xsd ); + if ( is != null ) { + return new InputSource( is ); + } } // Try looking at root of classpath - try { - return new InputSource( cl.getResourceAsStream( "/" + xsd ) ); - } catch ( Exception e ) { + { + InputStream is = cl.getResourceAsStream( "/" + xsd ); + if ( is != null ) { + return new InputSource( is ); + } } // Try current working directory - try { - return new InputSource( new BufferedInputStream( new FileInputStream( xsd ) ) ); - } catch ( Exception e ) { + { + File file = new File( xsd ); + if ( file.exists() ) { + return new InputSource( new BufferedInputStream( new FileInputStream( file ) ) ); + } } cl = ClassLoader.getSystemClassLoader(); // Try looking in META-INF - try { - return new InputSource( cl.getResourceAsStream( "META-INF/" + xsd ) ); - } catch ( Exception e ) { + { + InputStream is = cl.getResourceAsStream( "META-INF/" + xsd ); + if ( is != null ) { + return new InputSource( is ); + } } // Try looking in /META-INF - try { - return new InputSource( cl.getResourceAsStream( "/META-INF/" + xsd ) ); - } catch ( Exception e ) { + { + InputStream is = cl.getResourceAsStream( "/META-INF/" + xsd ); + if ( is != null ) { + return new InputSource( is ); + } } // Try looking at root of classpath - try { - return new InputSource( cl.getResourceAsStream( "/" + xsd ) ); - } catch ( Exception e ) { + { + InputStream is = cl.getResourceAsStream( "/" + xsd ); + if ( is != null ) { + return new InputSource( is ); + } } - // Try current working directory - try { - return new InputSource( new BufferedInputStream( new FileInputStream( xsd ) ) ); - } catch ( Exception e ) { - } return null; } |
From: <jbo...@li...> - 2006-04-22 05:00:58
|
Author: woolfel Date: 2006-04-22 01:00:49 -0400 (Sat, 22 Apr 2006) New Revision: 3904 Added: labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/models/Address.java labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/models/GroupTransaction.java labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/models/Security.java labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/models/SubTransaction.java labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/models/Transaction.java Log: adding a bunch of sample objects for testing purposes. I plan to write more rule generators to use these objects. peter Added: labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/models/Address.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/models/Address.java 2006-04-22 04:58:09 UTC (rev 3903) +++ labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/models/Address.java 2006-04-22 05:00:49 UTC (rev 3904) @@ -0,0 +1,177 @@ +package com.sample.benchmark.models; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeEvent; +import java.io.Serializable; +import java.util.ArrayList; + +/** + * @author Peter Lin + * + * A simple address class that represents a house a person owns. + */ +public class Address implements Serializable { + + protected String title = null; + protected String accountId = null; + protected String street = null; + protected String street2 = null; + protected String status = null; + protected String city = null; + protected String state = null; + protected String postalCode = null; + protected String houseType = null; + protected String country = null; + + protected ArrayList listeners = new ArrayList(); + + /** + * + */ + public Address() { + super(); + } + + public void setTitle(String val){ + if (!val.equals(this.title)){ + String old = this.title; + this.title = val; + notifyListener("title",old,this.title); + } + } + + public String getTitle(){ + return this.title; + } + + public void setState(String val){ + if (!val.equals(this.state)){ + String old = this.state; + this.state = val; + notifyListener("officeCode",old,this.state); + } + } + + public String getState(){ + return this.state; + } + + public void setCity(String val){ + if (!val.equals(this.city)){ + String old = this.city; + this.city = val; + notifyListener("regionCode",old,this.city); + } + } + + public String getCity(){ + return this.city; + } + + public void setStreet2(String val){ + if (!val.equals(this.street2)){ + String old = this.street2; + this.street2 = val; + notifyListener("status",old,this.street2); + } + } + + public String getStreet2(){ + return this.street2; + } + + public void setAccountId(String val){ + if (!val.equals(this.accountId)){ + String old = this.accountId; + this.accountId = val; + notifyListener("accountId",old,this.accountId); + } + } + + public String getAccountId(){ + return this.accountId; + } + + public void setStreet(String val){ + if (!val.equals(this.street)){ + String old = this.street; + this.street = val; + notifyListener("accountType",old,this.street); + } + } + + public String getStreet(){ + return this.street; + } + + public void setStatus(String val){ + if (!val.equals(this.status)){ + String old = this.status; + this.status = val; + notifyListener("username",old,this.status); + } + } + + public String getStatus(){ + return this.status; + } + + public String getPostalCode() { + return this.postalCode; + } + + public void setPostalCode(String val) { + if (!val.equals(this.postalCode)){ + String old = this.postalCode; + this.postalCode = val; + notifyListener("areaCode",old,this.postalCode); + } + } + + public String getHouseType() { + return this.houseType; + } + + public void setHouseType(String val) { + if (!val.equals(this.houseType)){ + String old = this.houseType; + this.houseType = val; + notifyListener("exchange",old,this.houseType); + } + } + + public String getCountry() { + return this.country; + } + + public void setCountry(String val) { + if (!val.equals(this.country)){ + String old = this.country; + this.country = val; + notifyListener("number",old,this.country); + } + } + + public void addPropertyChangeListener(PropertyChangeListener listener){ + this.listeners.add(listener); + } + + public void removePropertyChangeListener(PropertyChangeListener listener){ + this.listeners.remove(listener); + } + + protected void notifyListener(String field, Object oldValue, Object newValue){ + if (listeners == null || listeners.size() == 0) { + return; + } else { + PropertyChangeEvent event = new PropertyChangeEvent(this, field, + oldValue, newValue); + + for (int i = 0; i < listeners.size(); i++) { + ((java.beans.PropertyChangeListener) listeners.get(i)) + .propertyChange(event); + } + } + + } +} Added: labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/models/GroupTransaction.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/models/GroupTransaction.java 2006-04-22 04:58:09 UTC (rev 3903) +++ labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/models/GroupTransaction.java 2006-04-22 05:00:49 UTC (rev 3904) @@ -0,0 +1,121 @@ +package com.sample.benchmark.models; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.Serializable; +import java.util.ArrayList; + +/** + * @author Peter Lin + * + */ +public class GroupTransaction extends Security { + + protected String[] accountIds = null; + protected double buyPrice; + protected String purchaseDate = null; + protected double shares; + protected double total; + protected String transactionId = null; + + protected ArrayList listeners = new ArrayList(); + + public GroupTransaction() { + super(); + } + + public void setAccountIds(String[] id) { + if (id != this.accountIds) { + String[] old = this.accountIds; + this.accountIds = id; + this.notifyListener("accountIds",old,this.accountIds); + } + } + + public String[] getAccountIds() { + return this.accountIds; + } + + public void setBuyPrice(double price) { + if (price != this.buyPrice) { + Double old = new Double(this.buyPrice); + this.buyPrice = price; + this.notifyListener("buyPrice",old,new Double(this.buyPrice)); + } + } + + public double getBuyPrice() { + return this.buyPrice; + } + + public void setPurchaseDate(String date) { + if (!date.equals(this.purchaseDate)) { + String old = this.purchaseDate; + this.purchaseDate = date; + this.notifyListener("purchaseDate",old,this.purchaseDate); + } + } + + public String getPurchaseDate() { + return this.purchaseDate; + } + + public void setShares(double shares) { + if (shares != this.shares) { + Double old = new Double(this.shares); + this.shares = shares; + this.notifyListener("shares",old,new Double(this.shares)); + } + } + + public double getShares() { + return this.shares; + } + + public void setTotal(double value) { + if (value != this.total) { + Double old = new Double(this.total); + this.total = value; + this.notifyListener("total",old,new Double(this.total)); + } + } + + public double getTotal() { + return this.total; + } + + public void setTransactionId(String id) { + if (!id.equals(this.transactionId)) { + String old = this.transactionId; + this.transactionId = id; + this.notifyListener("transactionId",old,this.transactionId); + } + } + + public String getTransactionId() { + return this.transactionId; + } + + public void addPropertyChangeListener(PropertyChangeListener listener){ + this.listeners.add(listener); + } + + public void removePropertyChangeListener(PropertyChangeListener listener){ + this.listeners.remove(listener); + } + + protected void notifyListener(String field, Object oldValue, Object newValue){ + if (listeners == null || listeners.size() == 0) { + return; + } else { + PropertyChangeEvent event = new PropertyChangeEvent(this, field, + oldValue, newValue); + + for (int i = 0; i < listeners.size(); i++) { + ((java.beans.PropertyChangeListener) listeners.get(i)) + .propertyChange(event); + } + } + + } +} Added: labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/models/Security.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/models/Security.java 2006-04-22 04:58:09 UTC (rev 3903) +++ labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/models/Security.java 2006-04-22 05:00:49 UTC (rev 3904) @@ -0,0 +1,177 @@ +package com.sample.benchmark.models; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.Serializable; +import java.util.ArrayList; + +/** + * @author Peter Lin + * + */ +public class Security implements Serializable{ + + protected String countryCode = null; + protected double currentPrice; + protected int cusip; + protected String exchange = null; + protected int industryGroupID; + protected int industryID; + protected String issuer = null; + protected double lastPrice; + protected int sectorID; + protected int subIndustryID; + + protected ArrayList listeners = new ArrayList(); + + public Security() { + super(); + } + + public void setCountryCode(String code) { + if (!code.equals(this.countryCode)) { + String old = this.countryCode; + this.countryCode = code; + this.notifyListener("countryCode",old,this.countryCode); + } + } + + public String getCountryCode() { + return this.countryCode; + } + + public void setCurrentPrice(double price) { + if (price != this.currentPrice) { + Double old = new Double(this.currentPrice); + this.currentPrice = price; + this.notifyListener("currentPrice",old,new Double(this.currentPrice)); + } + } + + public double getCurrentPrice() { + return this.currentPrice; + } + + public void setCusip(int value) { + if (value != this.cusip) { + Integer old = new Integer(this.cusip); + this.cusip = value; + this.notifyListener("cusip",old,new Integer(this.cusip)); + } + } + + public int getCusip() { + return this.cusip; + } + + public void setExchange(String exc) { + if (!exc.equals(this.exchange)) { + String old = this.exchange; + this.exchange = exc; + this.notifyListener("exchange",old,this.exchange); + } + } + + public String getExchange() { + return this.exchange; + } + + public void setIndustryGroupID(int id) { + if (id != this.industryGroupID) { + int old = this.industryGroupID; + this.industryGroupID = id; + this.notifyListener("industryGroupID", + new Integer(old), new Integer(this.industryGroupID)); + } + } + + public int getIndustryGroupID() { + return this.industryGroupID; + } + + public void setIndustryID(int id) { + if (id != this.industryID) { + int old = this.industryID; + this.industryID = id; + this.notifyListener("industryID", + new Integer(old), new Integer(this.industryID)); + } + } + + public int getIndustryID() { + return this.industryID; + } + + public void setIssuer(String name) { + if (!name.equals(this.issuer)) { + String old = this.issuer; + this.issuer = name; + this.notifyListener("issuer", old, this.issuer); + } + } + + public String getIssuer() { + return this.issuer; + } + + public void setLastPrice(double price) { + if (price != this.lastPrice) { + Double old = new Double(this.lastPrice); + this.lastPrice = price; + this.notifyListener("lastPrice",old,new Double(this.lastPrice)); + } + } + + public double getLastPrice() { + return this.lastPrice; + } + + public void setSectorID(int id) { + if (id != this.sectorID) { + int old = this.sectorID; + this.sectorID = id; + this.notifyListener("sectorID", + new Integer(old), new Integer(this.sectorID)); + } + } + + public int getSectorID() { + return this.sectorID; + } + + public void setSubIndustryID(int id) { + if (id != this.subIndustryID) { + int old = this.subIndustryID; + this.subIndustryID = id; + this.notifyListener("subIndustryID", + new Integer(old), new Integer(this.subIndustryID)); + } + } + + public int getSubIndustryID() { + return this.subIndustryID; + } + + public void addPropertyChangeListener(PropertyChangeListener listener){ + this.listeners.add(listener); + } + + public void removePropertyChangeListener(PropertyChangeListener listener){ + this.listeners.remove(listener); + } + + protected void notifyListener(String field, Object oldValue, Object newValue){ + if (listeners == null || listeners.size() == 0) { + return; + } else { + PropertyChangeEvent event = new PropertyChangeEvent(this, field, + oldValue, newValue); + + for (int i = 0; i < listeners.size(); i++) { + ((java.beans.PropertyChangeListener) listeners.get(i)) + .propertyChange(event); + } + } + + } +} Added: labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/models/SubTransaction.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/models/SubTransaction.java 2006-04-22 04:58:09 UTC (rev 3903) +++ labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/models/SubTransaction.java 2006-04-22 05:00:49 UTC (rev 3904) @@ -0,0 +1,55 @@ +package com.sample.benchmark.models; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.Serializable; +import java.util.ArrayList; + +/** + * @author Peter Lin + * + */ +public class SubTransaction extends Security { + + protected String[] transactionSet = null; + protected ArrayList listeners = new ArrayList(); + + public SubTransaction() { + super(); + } + + public void setTransactionSet(String[] ids) { + if (ids != this.transactionSet) { + String[] old = this.transactionSet; + this.transactionSet = ids; + this.notifyListener("transactionSet", old, this.transactionSet); + } + } + + public String[] getTransactionSet() { + return this.transactionSet; + } + + public void addPropertyChangeListener(PropertyChangeListener listener){ + this.listeners.add(listener); + } + + public void removePropertyChangeListener(PropertyChangeListener listener){ + this.listeners.remove(listener); + } + + protected void notifyListener(String field, Object oldValue, Object newValue){ + if (listeners == null || listeners.size() == 0) { + return; + } else { + PropertyChangeEvent event = new PropertyChangeEvent(this, field, + oldValue, newValue); + + for (int i = 0; i < listeners.size(); i++) { + ((java.beans.PropertyChangeListener) listeners.get(i)) + .propertyChange(event); + } + } + + } +} Added: labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/models/Transaction.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/models/Transaction.java 2006-04-22 04:58:09 UTC (rev 3903) +++ labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/models/Transaction.java 2006-04-22 05:00:49 UTC (rev 3904) @@ -0,0 +1,121 @@ +package com.sample.benchmark.models; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.Serializable; +import java.util.ArrayList; + +/** + * @author Peter Lin + * + */ +public class Transaction extends Security { + + protected String accountId = null; + protected double buyPrice; + protected String purchaseDate = null; + protected double shares; + protected double total; + protected String transactionId = null; + + protected ArrayList listeners = new ArrayList(); + + public Transaction() { + super(); + } + + public void setAccountId(String id) { + if (!id.equals(this.accountId)) { + String old = this.accountId; + this.accountId = id; + this.notifyListener("accountId",old,this.accountId); + } + } + + public String getAccountId() { + return this.accountId; + } + + public void setBuyPrice(double price) { + if (price != this.buyPrice) { + Double old = new Double(this.buyPrice); + this.buyPrice = price; + this.notifyListener("buyPrice",old,new Double(this.buyPrice)); + } + } + + public double getBuyPrice() { + return this.buyPrice; + } + + public void setPurchaseDate(String date) { + if (!date.equals(this.purchaseDate)) { + String old = this.purchaseDate; + this.purchaseDate = date; + this.notifyListener("purchaseDate",old,this.purchaseDate); + } + } + + public String getPurchaseDate() { + return this.purchaseDate; + } + + public void setShares(double shares) { + if (shares != this.shares) { + Double old = new Double(this.shares); + this.shares = shares; + this.notifyListener("shares",old,new Double(this.shares)); + } + } + + public double getShares() { + return this.shares; + } + + public void setTotal(double value) { + if (value != this.total) { + Double old = new Double(this.total); + this.total = value; + this.notifyListener("total",old,new Double(this.total)); + } + } + + public double getTotal() { + return this.total; + } + + public void setTransactionId(String id) { + if (!id.equals(this.transactionId)) { + String old = this.transactionId; + this.transactionId = id; + this.notifyListener("transactionId",old,this.transactionId); + } + } + + public String getTransactionId() { + return this.transactionId; + } + + public void addPropertyChangeListener(PropertyChangeListener listener){ + this.listeners.add(listener); + } + + public void removePropertyChangeListener(PropertyChangeListener listener){ + this.listeners.remove(listener); + } + + protected void notifyListener(String field, Object oldValue, Object newValue){ + if (listeners == null || listeners.size() == 0) { + return; + } else { + PropertyChangeEvent event = new PropertyChangeEvent(this, field, + oldValue, newValue); + + for (int i = 0; i < listeners.size(); i++) { + ((java.beans.PropertyChangeListener) listeners.get(i)) + .propertyChange(event); + } + } + + } +} |
From: <jbo...@li...> - 2006-04-22 04:58:12
|
Author: woolfel Date: 2006-04-22 00:58:09 -0400 (Sat, 22 Apr 2006) New Revision: 3903 Added: labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformanceTest.java Log: re-adding the performance test now the rule files have been renamed to .rule. thanks to mike for the suggestion. peter Added: labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformanceTest.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformanceTest.java 2006-04-22 04:56:41 UTC (rev 3902) +++ labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformanceTest.java 2006-04-22 04:58:09 UTC (rev 3903) @@ -0,0 +1,406 @@ +package com.sample.benchmark; + +import junit.framework.TestCase; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.ArrayList; +import java.util.Iterator; + +import org.drools.PackageIntegrationException; +import org.drools.RuleBase; +import org.drools.RuleIntegrationException; +import org.drools.WorkingMemory; +import org.drools.compiler.DrlParser; +import org.drools.compiler.DroolsParserException; +import org.drools.compiler.PackageBuilder; +import org.drools.lang.descr.PackageDescr; +import org.drools.reteoo.RuleBaseImpl; +import org.drools.rule.InvalidPatternException; +import org.drools.rule.Package; + +import com.sample.benchmark.models.Account; + +/** + * @author Peter Lin + * + */ +public class RuleSetPerformanceTest extends TestCase { + public RuleSetPerformanceTest() { + super(); + } + + public void setUp() { + + } + + public void tearDown() { + + } + + private static RuleBase readRule(String file) throws IOException, DroolsParserException, RuleIntegrationException, PackageIntegrationException, InvalidPatternException { + //read in the source + Reader reader = + new InputStreamReader( + RuleSetPerformanceTest.class.getResourceAsStream( file ) ); + DrlParser parser = new DrlParser(); + PackageDescr packageDescr = parser.parse( reader ); + + //pre build the package + PackageBuilder builder = new PackageBuilder(); + builder.addPackage( packageDescr ); + Package pkg = builder.getPackage(); + + //add the package to a rulebase + RuleBaseImpl ruleBase = new RuleBaseImpl(); + ruleBase.addPackage( pkg ); + return ruleBase; + } + + /** + * test the performance with 50 facts and 5 rules. The test measures + * the load, assert and fire time. + */ + public void testFiveRuleFire() { + try { + int factCount = 50000; + String file = "5_rules.drl"; + int loop = 5; + long totalload = 0; + long totalassert = 0; + long totalfire = 0; + for (int c=0; c < loop; c++) { + long loadStart = System.currentTimeMillis(); + RuleBase ruleBase = readRule(file); + long loadEnd = System.currentTimeMillis(); + long loadet = loadEnd - loadStart; + totalload += loadet; + System.out.println("time to load " + file + + " " + loadet + "ms"); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + ArrayList objects = new ArrayList(); + // create the objects + for (int idx=0; idx < factCount; idx++) { + Account acc = new Account(); + acc.setAccountId("acc"+idx); + acc.setTitle("mr"); + acc.setStatus("standard"); + objects.add(acc); + } + Iterator itr = objects.iterator(); + long assertStart = System.currentTimeMillis(); + while( itr.hasNext() ) { + workingMemory.assertObject(itr.next()); + } + long assertEnd = System.currentTimeMillis(); + long assertet = assertEnd - assertStart; + totalassert += assertet; + System.out.println("time to assert " + assertet + + " ms"); + long fireStart = System.currentTimeMillis(); + workingMemory.fireAllRules(); + long fireEnd = System.currentTimeMillis(); + long fireet = fireEnd - fireStart; + totalfire += fireet; + System.out.println("time to fireAllRules " + fireet + + " ms"); + workingMemory.dispose(); + } + System.out.println(file); + System.out.println("number of objects asserted " + factCount); + System.out.println("average load " + (totalload/loop) + " ms"); + System.out.println("average assert " + (totalassert/loop) + " ms"); + System.out.println("average fire " + (totalfire/loop) + " ms"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * + * + */ + public void testFiftyRuleFire() { + try { + int factCount = 50000; + String file = "50_rules.drl"; + int loop = 5; + long totalload = 0; + long totalassert = 0; + long totalfire = 0; + for (int c=0; c < loop; c++) { + long loadStart = System.currentTimeMillis(); + RuleBase ruleBase = readRule(file); + long loadEnd = System.currentTimeMillis(); + long loadet = loadEnd - loadStart; + totalload += loadet; + System.out.println("time to load " + file + + " " + loadet + "ms"); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + ArrayList objects = new ArrayList(); + // create the objects + for (int idx=0; idx < factCount; idx++) { + Account acc = new Account(); + acc.setAccountId("acc"+idx); + acc.setTitle("mr"); + acc.setStatus("standard"); + objects.add(acc); + } + Iterator itr = objects.iterator(); + long assertStart = System.currentTimeMillis(); + while( itr.hasNext() ) { + workingMemory.assertObject(itr.next()); + } + long assertEnd = System.currentTimeMillis(); + long assertet = assertEnd - assertStart; + totalassert += assertet; + System.out.println("time to assert " + assertet + + " ms"); + long fireStart = System.currentTimeMillis(); + workingMemory.fireAllRules(); + long fireEnd = System.currentTimeMillis(); + long fireet = fireEnd - fireStart; + totalfire += fireet; + System.out.println("time to fireAllRules " + fireet + + " ms"); + workingMemory.dispose(); + } + System.out.println(file); + System.out.println("number of objects asserted " + factCount); + System.out.println("average load " + (totalload/loop) + " ms"); + System.out.println("average assert " + (totalassert/loop) + " ms"); + System.out.println("average fire " + (totalfire/loop) + " ms"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * + * + */ + public void testFiveHundredRuleFire() { + try { + int factCount = 50000; + String file = "500_rules.drl"; + int loop = 5; + long totalload = 0; + long totalassert = 0; + long totalfire = 0; + for (int c=0; c < loop; c++) { + long loadStart = System.currentTimeMillis(); + RuleBase ruleBase = readRule(file); + long loadEnd = System.currentTimeMillis(); + long loadet = loadEnd - loadStart; + totalload += loadet; + System.out.println("time to load " + file + + " " + loadet + "ms"); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + ArrayList objects = new ArrayList(); + // create the objects + for (int idx=0; idx < factCount; idx++) { + Account acc = new Account(); + acc.setAccountId("acc"+idx); + acc.setTitle("mr"); + acc.setStatus("standard"); + objects.add(acc); + } + Iterator itr = objects.iterator(); + long assertStart = System.currentTimeMillis(); + while( itr.hasNext() ) { + workingMemory.assertObject(itr.next()); + } + long assertEnd = System.currentTimeMillis(); + long assertet = assertEnd - assertStart; + totalassert += assertet; + System.out.println("time to assert " + assertet + + " ms"); + long fireStart = System.currentTimeMillis(); + workingMemory.fireAllRules(); + long fireEnd = System.currentTimeMillis(); + long fireet = fireEnd - fireStart; + totalfire += fireet; + System.out.println("time to fireAllRules " + fireet + + " ms"); + workingMemory.dispose(); + } + System.out.println(file); + System.out.println("number of objects asserted " + factCount); + System.out.println("average load " + (totalload/loop) + " ms"); + System.out.println("average assert " + (totalassert/loop) + " ms"); + System.out.println("average fire " + (totalfire/loop) + " ms"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * + * + */ + public void test2KRuleFire() { + try { + int factCount = 50000; + String file = "2000_rules_1condition.rule"; + int loop = 5; + long totalload = 0; + long totalassert = 0; + long totalfire = 0; + for (int c=0; c < loop; c++) { + long loadStart = System.currentTimeMillis(); + RuleBase ruleBase = readRule(file); + long loadEnd = System.currentTimeMillis(); + long loadet = loadEnd - loadStart; + totalload += loadet; + System.out.println("time to load " + file + + " " + loadet + "ms"); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + ArrayList objects = new ArrayList(); + // create the objects + for (int idx=0; idx < factCount; idx++) { + Account acc = new Account(); + acc.setAccountId("acc"+idx); + acc.setTitle("mr"); + acc.setStatus("standard"); + objects.add(acc); + } + Iterator itr = objects.iterator(); + long assertStart = System.currentTimeMillis(); + while( itr.hasNext() ) { + workingMemory.assertObject(itr.next()); + } + long assertEnd = System.currentTimeMillis(); + long assertet = assertEnd - assertStart; + totalassert += assertet; + System.out.println("time to assert " + assertet + + " ms"); + long fireStart = System.currentTimeMillis(); + workingMemory.fireAllRules(); + long fireEnd = System.currentTimeMillis(); + long fireet = fireEnd - fireStart; + totalfire += fireet; + System.out.println("time to fireAllRules " + fireet + + " ms"); + workingMemory.dispose(); + } + System.out.println(file); + System.out.println("number of objects asserted " + factCount); + System.out.println("average load " + (totalload/loop) + " ms"); + System.out.println("average assert " + (totalassert/loop) + " ms"); + System.out.println("average fire " + (totalfire/loop) + " ms"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void test2KRuleFire2Conditions() { + try { + int factCount = 50000; + String file = "2000_rules_2condition.rule"; + int loop = 5; + long totalload = 0; + long totalassert = 0; + long totalfire = 0; + for (int c=0; c < loop; c++) { + long loadStart = System.currentTimeMillis(); + RuleBase ruleBase = readRule(file); + long loadEnd = System.currentTimeMillis(); + long loadet = loadEnd - loadStart; + totalload += loadet; + System.out.println("time to load " + file + + " " + loadet + "ms"); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + ArrayList objects = new ArrayList(); + // create the objects + for (int idx=0; idx < factCount; idx++) { + Account acc = new Account(); + acc.setAccountId("acc"+idx); + acc.setTitle("mr"); + acc.setStatus("standard"); + objects.add(acc); + } + Iterator itr = objects.iterator(); + long assertStart = System.currentTimeMillis(); + while( itr.hasNext() ) { + workingMemory.assertObject(itr.next()); + } + long assertEnd = System.currentTimeMillis(); + long assertet = assertEnd - assertStart; + totalassert += assertet; + System.out.println("time to assert " + assertet + + " ms"); + long fireStart = System.currentTimeMillis(); + workingMemory.fireAllRules(); + long fireEnd = System.currentTimeMillis(); + long fireet = fireEnd - fireStart; + totalfire += fireet; + System.out.println("time to fireAllRules " + fireet + + " ms"); + workingMemory.dispose(); + } + System.out.println(file); + System.out.println("number of objects asserted " + factCount); + System.out.println("average load " + (totalload/loop) + " ms"); + System.out.println("average assert " + (totalassert/loop) + " ms"); + System.out.println("average fire " + (totalfire/loop) + " ms"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void test2KRuleFire3Conditions() { + try { + int factCount = 50000; + String file = "2000_rules_3condition.rule"; + int loop = 5; + long totalload = 0; + long totalassert = 0; + long totalfire = 0; + for (int c=0; c < loop; c++) { + long loadStart = System.currentTimeMillis(); + RuleBase ruleBase = readRule(file); + long loadEnd = System.currentTimeMillis(); + long loadet = loadEnd - loadStart; + totalload += loadet; + System.out.println("time to load " + file + + " " + loadet + "ms"); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + ArrayList objects = new ArrayList(); + // create the objects + for (int idx=0; idx < factCount; idx++) { + Account acc = new Account(); + acc.setAccountId("acc"+idx); + acc.setTitle("mr"); + acc.setStatus("standard"); + objects.add(acc); + } + Iterator itr = objects.iterator(); + long assertStart = System.currentTimeMillis(); + while( itr.hasNext() ) { + workingMemory.assertObject(itr.next()); + } + long assertEnd = System.currentTimeMillis(); + long assertet = assertEnd - assertStart; + totalassert += assertet; + System.out.println("time to assert " + assertet + + " ms"); + long fireStart = System.currentTimeMillis(); + workingMemory.fireAllRules(); + long fireEnd = System.currentTimeMillis(); + long fireet = fireEnd - fireStart; + totalfire += fireet; + System.out.println("time to fireAllRules " + fireet + + " ms"); + workingMemory.dispose(); + } + System.out.println(file); + System.out.println("number of objects asserted " + factCount); + System.out.println("average load " + (totalload/loop) + " ms"); + System.out.println("average assert " + (totalassert/loop) + " ms"); + System.out.println("average fire " + (totalfire/loop) + " ms"); + } catch (Exception e) { + e.printStackTrace(); + } + } +} |
Author: mic...@jb... Date: 2006-04-22 00:35:00 -0400 (Sat, 22 Apr 2006) New Revision: 3901 Added: labs/jbossrules/trunk/drools-ide/icons/dsl_expression.gif Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/DroolsPluginImages.java labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/DSLEditor.java labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProcessor.java labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProposal.java Log: tidy up, ad some more icons Added: labs/jbossrules/trunk/drools-ide/icons/dsl_expression.gif =================================================================== (Binary files differ) Property changes on: labs/jbossrules/trunk/drools-ide/icons/dsl_expression.gif ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/DroolsPluginImages.java =================================================================== --- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/DroolsPluginImages.java 2006-04-22 03:27:01 UTC (rev 3900) +++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/DroolsPluginImages.java 2006-04-22 04:35:00 UTC (rev 3901) @@ -46,6 +46,7 @@ public static final String PACKAGE = "Package"; public static final String METHOD = "Method"; public static final String DROOLS = "Drools"; + public static final String DSL_EXPRESSION = "DslExpression"; private static ImageRegistry imageRegistry; private static final String PATH_SUFFIX = "/icons/"; @@ -70,6 +71,7 @@ declareRegistryImage(PACKAGE, "package_obj.gif"); declareRegistryImage(METHOD, "methpub_obj.gif"); declareRegistryImage(DROOLS, "drools.gif"); + declareRegistryImage(DSL_EXPRESSION, "dsl_expression.gif"); } /** Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/DSLEditor.java =================================================================== --- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/DSLEditor.java 2006-04-22 03:27:01 UTC (rev 3900) +++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/dsl/editor/DSLEditor.java 2006-04-22 04:35:00 UTC (rev 3901) @@ -107,7 +107,7 @@ .createMarker(IDroolsModelMarker.DROOLS_MODEL_PROBLEM_MARKER); marker.setAttribute(IMarker.MESSAGE, message); marker.setAttribute(IMarker.SEVERITY, - IMarker.SEVERITY_ERROR); + IMarker.SEVERITY_WARNING); marker.setAttribute(IMarker.LINE_NUMBER, lineNumber); } }; Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProcessor.java =================================================================== --- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProcessor.java 2006-04-22 03:27:01 UTC (rev 3900) +++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProcessor.java 2006-04-22 04:35:00 UTC (rev 3901) @@ -31,14 +31,18 @@ * * This also handles queries, as they are just a type of rule essentially. * - * @author Michael Neale + * @author Michael Neale, Kris Verlanen */ public class RuleCompletionProcessor extends DefaultCompletionProcessor { private static final Pattern condition = Pattern.compile(".*\\Wwhen\\W.*", Pattern.DOTALL); private static final Pattern consequence = Pattern.compile(".*\\Wthen\\W.*", Pattern.DOTALL); private static final Pattern query = Pattern.compile(".*\\Wquery\\W.*", Pattern.DOTALL); - + private static final Image droolsIcon = DroolsPluginImages.getImage(DroolsPluginImages.DROOLS); + private static final Image dslIcon = DroolsPluginImages.getImage( DroolsPluginImages.DSL_EXPRESSION ); + private static final Image methodIcon = DroolsPluginImages.getImage(DroolsPluginImages.METHOD); + private static final Image classIcon = DroolsPluginImages.getImage(DroolsPluginImages.CLASS); + public RuleCompletionProcessor(DRLRuleEditor editor) { super(editor); } @@ -56,28 +60,26 @@ String backText = readBackwards(documentOffset, doc); final String prefix = stripWhiteSpace(backText); - + + if (query.matcher(backText).matches()) { list.addAll(adapter.listConditionItems()); } else if (consequence.matcher(backText).matches()) { List dslConsequences = adapter.listConsequenceItems(); - Iterator iterator = dslConsequences.iterator(); - while (iterator.hasNext()) { - String consequence = (String) iterator.next(); - list.add(new RuleCompletionProposal(prefix.length(), consequence)); - // TODO prefix should be from beginning of line, not just last word ? - filterProposalsOnPrefix(prefix, list); - } + Iterator iterator; + addDSLProposals( list, + prefix, + dslConsequences ); if (!adapter.hasConsequences()) { - Image image = DroolsPluginImages.getImage(DroolsPluginImages.DROOLS); + RuleCompletionProposal prop = new RuleCompletionProposal(prefix.length(), "modify", "modify();", 7); - prop.setImage(image); + prop.setImage(droolsIcon); list.add(prop); prop = new RuleCompletionProposal(prefix.length(), "retract", "retract();", 8); - prop.setImage(image); + prop.setImage(droolsIcon); list.add(prop); prop = new RuleCompletionProposal(prefix.length(), "assert", "assert();", 7); - prop.setImage(image); + prop.setImage(droolsIcon); list.add(prop); List functions = getFunctions(viewer); @@ -86,62 +88,25 @@ String name = (String) iterator.next() + "()"; prop = new RuleCompletionProposal(prefix.length(), name, name + ";", name.length() - 1); prop.setPriority(-1); - prop.setImage(DroolsPluginImages.getImage(DroolsPluginImages.METHOD)); + prop.setImage(methodIcon); list.add(prop); } - - filterProposalsOnPrefix(prefix, list); - -// IEditorInput input = getEditor().getEditorInput(); -// if (input instanceof IFileEditorInput) { -// IProject project = ((IFileEditorInput) input).getFile().getProject(); -// IJavaProject javaProject = JavaCore.create(project); -// -// CompletionRequestor requestor = new CompletionRequestor() { -// public void accept(org.eclipse.jdt.core.CompletionProposal proposal) { -// String display = new String(proposal.getCompletion()); -// String completion = display; -// if (prefix.lastIndexOf(".") != -1) { -// completion = prefix.substring(0, prefix.lastIndexOf(".") + 1) + completion; -// } -// System.out.println(completion); -// list.add(new RuleCompletionProposal(documentOffset, prefix.length(), display, completion)); -// } -// }; -// -// try { -// javaProject.newEvaluationContext().codeComplete(backText, backText.length(), requestor); -// } catch (Throwable t) { -// DroolsIDEPlugin.log(t); -// } -// } } } else if (condition.matcher(backText).matches()) { List dslConditions = adapter.listConditionItems(); - Iterator iterator = dslConditions.iterator(); - while (iterator.hasNext()) { - String condition = (String) iterator.next(); - list.add(new RuleCompletionProposal(prefix.length(), condition)); - // TODO prefix should be from beginning of line, not just last word ? - filterProposalsOnPrefix(prefix, list); - } - Image image = DroolsPluginImages.getImage(DroolsPluginImages.DROOLS); + Iterator iterator; + addDSLProposals( list, + prefix, + dslConditions ); + Image droolsIcon = DroolsPluginImages.getImage(DroolsPluginImages.DROOLS); if (!adapter.hasConditions()) { - RuleCompletionProposal prop = new RuleCompletionProposal(prefix.length(), "exists", "exists "); - prop.setImage(image); + list.add( new RuleCompletionProposal(prefix.length(), "exists", "exists ", droolsIcon)); + list.add( new RuleCompletionProposal(prefix.length(), "not", "not ", droolsIcon)); + list.add( new RuleCompletionProposal(prefix.length(), "and", "and ", droolsIcon)); + list.add( new RuleCompletionProposal(prefix.length(), "or", "or ", droolsIcon)); + RuleCompletionProposal prop = new RuleCompletionProposal(prefix.length(), "eval", "eval()", 5); + prop.setImage(droolsIcon); list.add(prop); - prop = new RuleCompletionProposal(prefix.length(), "not", "not "); - prop.setImage(image); - list.add(prop); - prop = new RuleCompletionProposal(prefix.length(), "and", "and "); - prop.setImage(image); - list.add(prop); - prop = new RuleCompletionProposal(prefix.length(), "or", "or "); - prop.setImage(image); - list.add(prop); - prop = new RuleCompletionProposal(prefix.length(), "eval", "eval()", 5); - prop.setImage(image); - list.add(prop); List imports = getImports(viewer); iterator = imports.iterator(); @@ -150,41 +115,26 @@ int index = name.lastIndexOf("."); if (index != -1) { String className = name.substring(index + 1); - prop = new RuleCompletionProposal(prefix.length(), className, className + "()", className.length() + 1); - prop.setPriority(-1); - prop.setImage(DroolsPluginImages.getImage(DroolsPluginImages.CLASS)); - list.add(prop); + RuleCompletionProposal p = new RuleCompletionProposal(prefix.length(), className, className + "()", className.length() + 1); + p.setPriority(-1); + p.setImage(classIcon); + list.add(p); } } -// if (true) { -// String className = ""; -// ClassTypeResolver resolver = new ClassTypeResolver(imports); -// Class conditionClass = resolver.resolveType(className); -// ClassFieldInspector inspector = new ClassFieldInspector(conditionClass); -// Map fields = inspector.getFieldNames(); -// Iterator iterator2 = fields.keySet().iterator(); -// while (iterator2.hasNext()) { -// String varName = (String) iterator2.next(); -// list.add(new RuleCompletionProposal(prefix.length(), varName, varName + " ")); -// } -// } } RuleCompletionProposal prop = new RuleCompletionProposal(prefix.length(), "then", "then\n\t"); - prop.setImage(image); + prop.setImage(droolsIcon); list.add(prop); - filterProposalsOnPrefix(prefix, list); + } else { //we are in rule header - list.add(new RuleCompletionProposal(prefix.length(), "salience", "salience ")); - list.add(new RuleCompletionProposal(prefix.length(), "no-loop", "no-loop ")); - list.add(new RuleCompletionProposal(prefix.length(), "agenda-group", "agenda-group ")); - list.add(new RuleCompletionProposal(prefix.length(), "duration", "duration ")); - list.add(new RuleCompletionProposal(prefix.length(), "auto-focus", "auto-focus ")); - list.add(new RuleCompletionProposal(prefix.length(), "when", "when\n\t ")); - filterProposalsOnPrefix(prefix, list); + addRuleHeaderItems( list, + prefix ); } + + filterProposalsOnPrefix(prefix, list); return list; } catch (Throwable t) { DroolsIDEPlugin.log(t); @@ -192,6 +142,28 @@ return null; } + private void addRuleHeaderItems(final List list, + final String prefix) { + list.add(new RuleCompletionProposal(prefix.length(), "salience", "salience ", droolsIcon)); + list.add(new RuleCompletionProposal(prefix.length(), "no-loop", "no-loop ", droolsIcon)); + list.add(new RuleCompletionProposal(prefix.length(), "agenda-group", "agenda-group ", droolsIcon)); + list.add(new RuleCompletionProposal(prefix.length(), "duration", "duration ", droolsIcon)); + list.add(new RuleCompletionProposal(prefix.length(), "auto-focus", "auto-focus ", droolsIcon)); + list.add(new RuleCompletionProposal(prefix.length(), "when", "when\n\t ", droolsIcon)); + } + + private void addDSLProposals(final List list, + final String prefix, + List dslItems) { + Iterator iterator = dslItems.iterator(); + while (iterator.hasNext()) { + String consequence = (String) iterator.next(); + RuleCompletionProposal p = new RuleCompletionProposal(prefix.length(), consequence); + p.setImage( dslIcon ); + list.add(p); + } + } + /** * Lazily get the adapter for DSLs, and cache it with the editor for future reference. * If it is unable to load a DSL, it will try again next time. Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProposal.java =================================================================== --- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProposal.java 2006-04-22 03:27:01 UTC (rev 3900) +++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProposal.java 2006-04-22 04:35:00 UTC (rev 3901) @@ -28,6 +28,13 @@ public RuleCompletionProposal(int replacementLength, String display, String content) { this(replacementLength, display, content, content.length()); } + + /** Also allows an icon to be used */ + public RuleCompletionProposal(int replacementLength, String display, String content, Image icon) { + this(replacementLength, display, content, content.length()); + this.image = icon; + + } /** This is used when a different display value is shown to what is put in when selected. */ public RuleCompletionProposal(int replacementLength, String display, String content, int cursorPosition) { |
From: <jbo...@li...> - 2006-04-22 03:26:27
|
Author: woolfel Date: 2006-04-21 23:26:20 -0400 (Fri, 21 Apr 2006) New Revision: 3899 Removed: labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformanceTest.java Log: I'm deleting the class, since the large 2K rule files cause eclipse to hang on build. I'm also removing those files, so eclipse can open the example project without hanging. peter Deleted: labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformanceTest.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformanceTest.java 2006-04-22 03:18:28 UTC (rev 3898) +++ labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformanceTest.java 2006-04-22 03:26:20 UTC (rev 3899) @@ -1,406 +0,0 @@ -package com.sample.benchmark; - -import junit.framework.TestCase; - -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.util.ArrayList; -import java.util.Iterator; - -import org.drools.PackageIntegrationException; -import org.drools.RuleBase; -import org.drools.RuleIntegrationException; -import org.drools.WorkingMemory; -import org.drools.compiler.DrlParser; -import org.drools.compiler.DroolsParserException; -import org.drools.compiler.PackageBuilder; -import org.drools.lang.descr.PackageDescr; -import org.drools.reteoo.RuleBaseImpl; -import org.drools.rule.InvalidPatternException; -import org.drools.rule.Package; - -import com.sample.benchmark.models.Account; - -/** - * @author Peter Lin - * - */ -public class RuleSetPerformanceTest extends TestCase { - public RuleSetPerformanceTest() { - super(); - } - - public void setUp() { - - } - - public void tearDown() { - - } - - private static RuleBase readRule(String file) throws IOException, DroolsParserException, RuleIntegrationException, PackageIntegrationException, InvalidPatternException { - //read in the source - Reader reader = - new InputStreamReader( - RuleSetPerformanceTest.class.getResourceAsStream( file ) ); - DrlParser parser = new DrlParser(); - PackageDescr packageDescr = parser.parse( reader ); - - //pre build the package - PackageBuilder builder = new PackageBuilder(); - builder.addPackage( packageDescr ); - Package pkg = builder.getPackage(); - - //add the package to a rulebase - RuleBaseImpl ruleBase = new RuleBaseImpl(); - ruleBase.addPackage( pkg ); - return ruleBase; - } - - /** - * test the performance with 50 facts and 5 rules. The test measures - * the load, assert and fire time. - */ - public void testFiveRuleFire() { - try { - int factCount = 50000; - String file = "5_rules.drl"; - int loop = 5; - long totalload = 0; - long totalassert = 0; - long totalfire = 0; - for (int c=0; c < loop; c++) { - long loadStart = System.currentTimeMillis(); - RuleBase ruleBase = readRule(file); - long loadEnd = System.currentTimeMillis(); - long loadet = loadEnd - loadStart; - totalload += loadet; - System.out.println("time to load " + file + - " " + loadet + "ms"); - WorkingMemory workingMemory = ruleBase.newWorkingMemory(); - ArrayList objects = new ArrayList(); - // create the objects - for (int idx=0; idx < factCount; idx++) { - Account acc = new Account(); - acc.setAccountId("acc"+idx); - acc.setTitle("mr"); - acc.setStatus("standard"); - objects.add(acc); - } - Iterator itr = objects.iterator(); - long assertStart = System.currentTimeMillis(); - while( itr.hasNext() ) { - workingMemory.assertObject(itr.next()); - } - long assertEnd = System.currentTimeMillis(); - long assertet = assertEnd - assertStart; - totalassert += assertet; - System.out.println("time to assert " + assertet + - " ms"); - long fireStart = System.currentTimeMillis(); - workingMemory.fireAllRules(); - long fireEnd = System.currentTimeMillis(); - long fireet = fireEnd - fireStart; - totalfire += fireet; - System.out.println("time to fireAllRules " + fireet + - " ms"); - workingMemory.dispose(); - } - System.out.println(file); - System.out.println("number of objects asserted " + factCount); - System.out.println("average load " + (totalload/loop) + " ms"); - System.out.println("average assert " + (totalassert/loop) + " ms"); - System.out.println("average fire " + (totalfire/loop) + " ms"); - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * - * - */ - public void testFiftyRuleFire() { - try { - int factCount = 50000; - String file = "50_rules.drl"; - int loop = 5; - long totalload = 0; - long totalassert = 0; - long totalfire = 0; - for (int c=0; c < loop; c++) { - long loadStart = System.currentTimeMillis(); - RuleBase ruleBase = readRule(file); - long loadEnd = System.currentTimeMillis(); - long loadet = loadEnd - loadStart; - totalload += loadet; - System.out.println("time to load " + file + - " " + loadet + "ms"); - WorkingMemory workingMemory = ruleBase.newWorkingMemory(); - ArrayList objects = new ArrayList(); - // create the objects - for (int idx=0; idx < factCount; idx++) { - Account acc = new Account(); - acc.setAccountId("acc"+idx); - acc.setTitle("mr"); - acc.setStatus("standard"); - objects.add(acc); - } - Iterator itr = objects.iterator(); - long assertStart = System.currentTimeMillis(); - while( itr.hasNext() ) { - workingMemory.assertObject(itr.next()); - } - long assertEnd = System.currentTimeMillis(); - long assertet = assertEnd - assertStart; - totalassert += assertet; - System.out.println("time to assert " + assertet + - " ms"); - long fireStart = System.currentTimeMillis(); - workingMemory.fireAllRules(); - long fireEnd = System.currentTimeMillis(); - long fireet = fireEnd - fireStart; - totalfire += fireet; - System.out.println("time to fireAllRules " + fireet + - " ms"); - workingMemory.dispose(); - } - System.out.println(file); - System.out.println("number of objects asserted " + factCount); - System.out.println("average load " + (totalload/loop) + " ms"); - System.out.println("average assert " + (totalassert/loop) + " ms"); - System.out.println("average fire " + (totalfire/loop) + " ms"); - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * - * - */ - public void testFiveHundredRuleFire() { - try { - int factCount = 50000; - String file = "500_rules.drl"; - int loop = 5; - long totalload = 0; - long totalassert = 0; - long totalfire = 0; - for (int c=0; c < loop; c++) { - long loadStart = System.currentTimeMillis(); - RuleBase ruleBase = readRule(file); - long loadEnd = System.currentTimeMillis(); - long loadet = loadEnd - loadStart; - totalload += loadet; - System.out.println("time to load " + file + - " " + loadet + "ms"); - WorkingMemory workingMemory = ruleBase.newWorkingMemory(); - ArrayList objects = new ArrayList(); - // create the objects - for (int idx=0; idx < factCount; idx++) { - Account acc = new Account(); - acc.setAccountId("acc"+idx); - acc.setTitle("mr"); - acc.setStatus("standard"); - objects.add(acc); - } - Iterator itr = objects.iterator(); - long assertStart = System.currentTimeMillis(); - while( itr.hasNext() ) { - workingMemory.assertObject(itr.next()); - } - long assertEnd = System.currentTimeMillis(); - long assertet = assertEnd - assertStart; - totalassert += assertet; - System.out.println("time to assert " + assertet + - " ms"); - long fireStart = System.currentTimeMillis(); - workingMemory.fireAllRules(); - long fireEnd = System.currentTimeMillis(); - long fireet = fireEnd - fireStart; - totalfire += fireet; - System.out.println("time to fireAllRules " + fireet + - " ms"); - workingMemory.dispose(); - } - System.out.println(file); - System.out.println("number of objects asserted " + factCount); - System.out.println("average load " + (totalload/loop) + " ms"); - System.out.println("average assert " + (totalassert/loop) + " ms"); - System.out.println("average fire " + (totalfire/loop) + " ms"); - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * - * - */ - public void test2KRuleFire() { - try { - int factCount = 50000; - String file = "2000_rules_1condition.drl"; - int loop = 5; - long totalload = 0; - long totalassert = 0; - long totalfire = 0; - for (int c=0; c < loop; c++) { - long loadStart = System.currentTimeMillis(); - RuleBase ruleBase = readRule(file); - long loadEnd = System.currentTimeMillis(); - long loadet = loadEnd - loadStart; - totalload += loadet; - System.out.println("time to load " + file + - " " + loadet + "ms"); - WorkingMemory workingMemory = ruleBase.newWorkingMemory(); - ArrayList objects = new ArrayList(); - // create the objects - for (int idx=0; idx < factCount; idx++) { - Account acc = new Account(); - acc.setAccountId("acc"+idx); - acc.setTitle("mr"); - acc.setStatus("standard"); - objects.add(acc); - } - Iterator itr = objects.iterator(); - long assertStart = System.currentTimeMillis(); - while( itr.hasNext() ) { - workingMemory.assertObject(itr.next()); - } - long assertEnd = System.currentTimeMillis(); - long assertet = assertEnd - assertStart; - totalassert += assertet; - System.out.println("time to assert " + assertet + - " ms"); - long fireStart = System.currentTimeMillis(); - workingMemory.fireAllRules(); - long fireEnd = System.currentTimeMillis(); - long fireet = fireEnd - fireStart; - totalfire += fireet; - System.out.println("time to fireAllRules " + fireet + - " ms"); - workingMemory.dispose(); - } - System.out.println(file); - System.out.println("number of objects asserted " + factCount); - System.out.println("average load " + (totalload/loop) + " ms"); - System.out.println("average assert " + (totalassert/loop) + " ms"); - System.out.println("average fire " + (totalfire/loop) + " ms"); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void test2KRuleFire2Conditions() { - try { - int factCount = 50000; - String file = "2000_rules_2condition.drl"; - int loop = 5; - long totalload = 0; - long totalassert = 0; - long totalfire = 0; - for (int c=0; c < loop; c++) { - long loadStart = System.currentTimeMillis(); - RuleBase ruleBase = readRule(file); - long loadEnd = System.currentTimeMillis(); - long loadet = loadEnd - loadStart; - totalload += loadet; - System.out.println("time to load " + file + - " " + loadet + "ms"); - WorkingMemory workingMemory = ruleBase.newWorkingMemory(); - ArrayList objects = new ArrayList(); - // create the objects - for (int idx=0; idx < factCount; idx++) { - Account acc = new Account(); - acc.setAccountId("acc"+idx); - acc.setTitle("mr"); - acc.setStatus("standard"); - objects.add(acc); - } - Iterator itr = objects.iterator(); - long assertStart = System.currentTimeMillis(); - while( itr.hasNext() ) { - workingMemory.assertObject(itr.next()); - } - long assertEnd = System.currentTimeMillis(); - long assertet = assertEnd - assertStart; - totalassert += assertet; - System.out.println("time to assert " + assertet + - " ms"); - long fireStart = System.currentTimeMillis(); - workingMemory.fireAllRules(); - long fireEnd = System.currentTimeMillis(); - long fireet = fireEnd - fireStart; - totalfire += fireet; - System.out.println("time to fireAllRules " + fireet + - " ms"); - workingMemory.dispose(); - } - System.out.println(file); - System.out.println("number of objects asserted " + factCount); - System.out.println("average load " + (totalload/loop) + " ms"); - System.out.println("average assert " + (totalassert/loop) + " ms"); - System.out.println("average fire " + (totalfire/loop) + " ms"); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void test2KRuleFire3Conditions() { - try { - int factCount = 50000; - String file = "2000_rules_3condition.drl"; - int loop = 5; - long totalload = 0; - long totalassert = 0; - long totalfire = 0; - for (int c=0; c < loop; c++) { - long loadStart = System.currentTimeMillis(); - RuleBase ruleBase = readRule(file); - long loadEnd = System.currentTimeMillis(); - long loadet = loadEnd - loadStart; - totalload += loadet; - System.out.println("time to load " + file + - " " + loadet + "ms"); - WorkingMemory workingMemory = ruleBase.newWorkingMemory(); - ArrayList objects = new ArrayList(); - // create the objects - for (int idx=0; idx < factCount; idx++) { - Account acc = new Account(); - acc.setAccountId("acc"+idx); - acc.setTitle("mr"); - acc.setStatus("standard"); - objects.add(acc); - } - Iterator itr = objects.iterator(); - long assertStart = System.currentTimeMillis(); - while( itr.hasNext() ) { - workingMemory.assertObject(itr.next()); - } - long assertEnd = System.currentTimeMillis(); - long assertet = assertEnd - assertStart; - totalassert += assertet; - System.out.println("time to assert " + assertet + - " ms"); - long fireStart = System.currentTimeMillis(); - workingMemory.fireAllRules(); - long fireEnd = System.currentTimeMillis(); - long fireet = fireEnd - fireStart; - totalfire += fireet; - System.out.println("time to fireAllRules " + fireet + - " ms"); - workingMemory.dispose(); - } - System.out.println(file); - System.out.println("number of objects asserted " + factCount); - System.out.println("average load " + (totalload/loop) + " ms"); - System.out.println("average assert " + (totalassert/loop) + " ms"); - System.out.println("average fire " + (totalfire/loop) + " ms"); - } catch (Exception e) { - e.printStackTrace(); - } - } -} |
From: <jbo...@li...> - 2006-04-22 03:18:34
|
Author: mic...@jb... Date: 2006-04-21 23:18:28 -0400 (Fri, 21 Apr 2006) New Revision: 3898 Removed: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/helloworld/ Log: not needed |
From: <jbo...@li...> - 2006-04-22 03:18:16
|
Author: mic...@jb... Date: 2006-04-21 23:18:00 -0400 (Fri, 21 Apr 2006) New Revision: 3897 Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/LeapsTest.java Log: stubbed out failing test Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/LeapsTest.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/LeapsTest.java 2006-04-22 03:06:44 UTC (rev 3896) +++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/LeapsTest.java 2006-04-22 03:18:00 UTC (rev 3897) @@ -116,4 +116,11 @@ assertEquals(4, list.size()); assertEquals("group2", list.get(3)); } + + public void testLogicalAssertions() throws Exception { + // Not working in leaps + + } + + } \ No newline at end of file |
Author: mic...@jb... Date: 2006-04-21 23:06:44 -0400 (Fri, 21 Apr 2006) New Revision: 3896 Added: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/descr/ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/descr/AndDescrTest.java labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/HelloWorld.drl labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/lang/multiple_bindings.drl Removed: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/helloworld/HelloWorldLeapsTest.java labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/helloworld/HelloWorldTest.java Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/descr/AndDescr.java labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/template/MappingError.java labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/RuleParserTest.java labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/template/NLExpressionCompilerTest.java labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/template/NLGrammarTest.java Log: refactored helloworld into integration tests Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/descr/AndDescr.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/descr/AndDescr.java 2006-04-21 23:26:33 UTC (rev 3895) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/descr/AndDescr.java 2006-04-22 03:06:44 UTC (rev 3896) @@ -1,4 +1,5 @@ package org.drools.lang.descr; + /* * Copyright 2005 JBoss Inc * @@ -15,26 +16,69 @@ * limitations under the License. */ - - import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; import java.util.List; +import java.util.Map; -public class AndDescr extends PatternDescr - implements ConditionalElementDescr { - private List descrs = Collections.EMPTY_LIST; - +public class AndDescr extends PatternDescr + implements + ConditionalElementDescr { + private List descrs = Collections.EMPTY_LIST; + private Map boundColumns = new HashMap(); + public AndDescr() { } - + public void addDescr(PatternDescr patternDescr) { if ( this.descrs == Collections.EMPTY_LIST ) { - this.descrs = new ArrayList(1); + this.descrs = new ArrayList( 1 ); } - this.descrs.add( patternDescr ); +//MN: No pattern combining just yet +// if ( patternDescr instanceof ColumnDescr ) { +// addColumn( (ColumnDescr) patternDescr ); +// } else { + this.descrs.add( patternDescr ); +// } } - + + /** + * NOTE: to be used possibly in a future version... wire in above... + * This will check the column binding, and add the patterns + * to a previously bound column + * if one exists. + * If its not a bound column, or it is a unique bound variable column, + * it will just add it to the list of children descrs. + */ + private void addColumn(ColumnDescr col) { + String identifier = col.getIdentifier(); + if ( identifier == null || "".equals( identifier ) ) { + this.descrs.add( col ); + } else { + if (boundColumns.containsKey( identifier )) { + ColumnDescr existingCol = (ColumnDescr) boundColumns.get( identifier ); + if (existingCol.getObjectType().equals( col.getObjectType() )) { + combinePatterns(existingCol, col.getDescrs()); + } else { + this.descrs.add( col ); + } + } else { + boundColumns.put( identifier, col ); + this.descrs.add( col ); + } + } + } + + private void combinePatterns(ColumnDescr existingCol, + List newColPatterns) { + for ( Iterator iter = newColPatterns.iterator(); iter.hasNext(); ) { + existingCol.addDescr( (PatternDescr) iter.next() ); + } + + } + public List getDescrs() { return this.descrs; } Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/template/MappingError.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/template/MappingError.java 2006-04-21 23:26:33 UTC (rev 3895) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/template/MappingError.java 2006-04-22 03:06:44 UTC (rev 3896) @@ -92,9 +92,9 @@ public String getMessage() { switch(this.errorCode) { case ERROR_UNUSED_TOKEN: - return "Token "+this.token+" not used in the mapping."; + return "Warning, the token "+this.token+" not used in the mapping."; case ERROR_UNDECLARED_TOKEN: - return "Token "+this.token+" not found in the expression."; + return "Warning, the token "+this.token+" not found in the expression. (May not be a problem)."; case ERROR_INVALID_TOKEN: return "Invalid token declaration at offset "+this.offset+": "+this.token; case ERROR_UNMATCHED_BRACES: Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java 2006-04-21 23:26:33 UTC (rev 3895) +++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java 2006-04-22 03:06:44 UTC (rev 3896) @@ -52,6 +52,8 @@ import org.drools.event.AgendaEventListener; import org.drools.event.BeforeActivationFiredEvent; import org.drools.event.DefaultAgendaEventListener; +import org.drools.integrationtests.helloworld.Message; +import org.drools.lang.descr.PackageDescr; import org.drools.rule.Package; import org.drools.rule.Rule; @@ -87,6 +89,37 @@ list.get( 0 ) ); } + public void testHelloWorld() throws Exception { + + //read in the source + Reader reader = new InputStreamReader( getClass().getResourceAsStream( "HelloWorld.drl" ) ); + DrlParser parser = new DrlParser(); + PackageDescr packageDescr = parser.parse( reader ); + + //pre build the package + PackageBuilder builder = new PackageBuilder(); + builder.addPackage( packageDescr ); + Package pkg = builder.getPackage(); + + //add the package to a rulebase + RuleBase ruleBase = getRuleBase(); + ruleBase.addPackage( pkg ); + //load up the rulebase + + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + + //go ! + Message message = new Message( "hola" ); + message.addToList( "hello" ); + message.setNumber( 42 ); + + workingMemory.assertObject( message ); + workingMemory.assertObject( "boo" ); + workingMemory.fireAllRules(); + assertTrue( message.isFired() ); + + } + public void testLiteral() throws Exception { PackageBuilder builder = new PackageBuilder(); builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "literal_rule_test.drl" ) ) ); @@ -156,22 +189,23 @@ } public void testCell() throws Exception { - Cell cell1 = new Cell(9); - Cell cell = new Cell(0); - + Cell cell1 = new Cell( 9 ); + Cell cell = new Cell( 0 ); + PackageBuilder builder = new PackageBuilder(); - builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "evalmodify.drl" )) ); - + builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "evalmodify.drl" ) ) ); + RuleBase ruleBase = getRuleBase(); ruleBase.addPackage( builder.getPackage() ); - + WorkingMemory memory = ruleBase.newWorkingMemory(); - memory.assertObject(cell1); - memory.assertObject(cell); + memory.assertObject( cell1 ); + memory.assertObject( cell ); memory.fireAllRules(); - assertEquals(9, cell.getValue()); + assertEquals( 9, + cell.getValue() ); } - + public void testOr() throws Exception { PackageBuilder builder = new PackageBuilder(); builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "or_test.drl" ) ) ); @@ -439,7 +473,7 @@ workingMemory.fireAllRules(); } - + public void testNullConstraint() throws Exception { PackageBuilder builder = new PackageBuilder(); builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "null_constraint.drl" ) ) ); @@ -449,8 +483,9 @@ ruleBase.addPackage( pkg ); WorkingMemory workingMemory = ruleBase.newWorkingMemory(); List foo = new ArrayList(); - workingMemory.setGlobal( "messages", foo ); - + workingMemory.setGlobal( "messages", + foo ); + Person p1 = new Person( null, "food", 40 ); @@ -458,11 +493,11 @@ workingMemory.assertObject( p1 ); workingMemory.fireAllRules(); - assertEquals(1, foo.size()); + assertEquals( 1, + foo.size() ); + } - } - public void testExists() throws Exception { PackageBuilder builder = new PackageBuilder(); builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "exists_rule_test.drl" ) ) ); @@ -1211,13 +1246,11 @@ assertEquals( "stilton", list.get( 0 ) ); - - assertTrue("cheddar".equals(list.get(1)) - || "cheddar".equals(list.get(2))); - - assertTrue("stilton".equals(list.get(1)) - || "stilton".equals(list.get(2))); + assertTrue( "cheddar".equals( list.get( 1 ) ) || "cheddar".equals( list.get( 2 ) ) ); + + assertTrue( "stilton".equals( list.get( 1 ) ) || "stilton".equals( list.get( 2 ) ) ); + list.clear(); reader = new InputStreamReader( getClass().getResourceAsStream( "test_Dynamic3.drl" ) ); @@ -1267,7 +1300,7 @@ builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_Dynamic4.drl" ) ) ); Package pkg = builder.getPackage(); - org.drools.reteoo.RuleBaseImpl ruleBase = new org.drools.reteoo.RuleBaseImpl(); + org.drools.reteoo.RuleBaseImpl ruleBase = new org.drools.reteoo.RuleBaseImpl(); ruleBase.addPackage( pkg ); WorkingMemory workingMemory = ruleBase.newWorkingMemory(); @@ -1338,7 +1371,7 @@ null ); bob.setStatus( "P1" ); Person pete = new Person( null, - null ); + null ); bob.setStatus( "P2" ); workingMemory.assertObject( bob ); workingMemory.assertObject( pete ); @@ -1346,9 +1379,11 @@ workingMemory.fireAllRules(); Assert.assertEquals( "Indexing with null values is not working correctly.", - "OK", bob.getStatus() ); + "OK", + bob.getStatus() ); Assert.assertEquals( "Indexing with null values is not working correctly.", - "OK", pete.getStatus() ); + "OK", + pete.getStatus() ); } @@ -1361,19 +1396,23 @@ assertEquals( 0, builder.getErrors().length ); - + RuleBase ruleBase = getRuleBase();//RuleBaseFactory.newRuleBase(); - + ruleBase.addPackage( pkg ); - + byte[] ast = serializeOut( ruleBase ); - ruleBase = ( RuleBase ) serializeIn( ast ); + ruleBase = (RuleBase) serializeIn( ast ); Rule[] rules = ruleBase.getPackages()[0].getRules(); - assertEquals( 3, rules.length ); - - assertEquals( "match Person 1", rules[0].getName() ); - assertEquals( "match Person 2", rules[1].getName() ); - assertEquals( "match Person 3", rules[2].getName() ); + assertEquals( 3, + rules.length ); + + assertEquals( "match Person 1", + rules[0].getName() ); + assertEquals( "match Person 2", + rules[1].getName() ); + assertEquals( "match Person 3", + rules[2].getName() ); } public void testLogicalAssertions() throws Exception { @@ -1630,8 +1669,3 @@ } } - - - - - Deleted: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/helloworld/HelloWorldLeapsTest.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/helloworld/HelloWorldLeapsTest.java 2006-04-21 23:26:33 UTC (rev 3895) +++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/helloworld/HelloWorldLeapsTest.java 2006-04-22 03:06:44 UTC (rev 3896) @@ -1,88 +0,0 @@ -package org.drools.integrationtests.helloworld; -/* - * Copyright 2005 JBoss Inc - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - - -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; - -import junit.framework.TestCase; - -import org.drools.PackageIntegrationException; -import org.drools.RuleBase; -import org.drools.RuleIntegrationException; -import org.drools.WorkingMemory; -import org.drools.compiler.DrlParser; -import org.drools.compiler.DroolsParserException; -import org.drools.compiler.PackageBuilder; -import org.drools.lang.descr.PackageDescr; - -import org.drools.reteoo.RuleBaseImpl; -import org.drools.rule.InvalidPatternException; -import org.drools.rule.Package; - - - -/** - * This shows how it all works with Leaps, identically. - */ -public class HelloWorldLeapsTest extends TestCase { - - public void testSomething() { - try { - - //load up the rulebase - RuleBase ruleBase = readRule(); - WorkingMemory workingMemory = ruleBase.newWorkingMemory(); - - //go ! - Message message = new Message("hola"); - message.addToList( "hello" ); - message.setNumber( 42 ); - - workingMemory.assertObject( message ); - - workingMemory.fireAllRules(); - assertTrue( message.isFired() ); - } catch (Throwable t) { - t.printStackTrace(); - fail(t.getMessage()); - } - } - - /** - * Please note that this is the "low level" rule assembly API. - */ - private static RuleBase readRule() throws Exception { - //read in the source - Reader reader = new InputStreamReader( HelloWorldLeapsTest.class.getResourceAsStream( "HelloWorld.drl" ) ); - DrlParser parser = new DrlParser(); - PackageDescr packageDescr = parser.parse( reader ); - - //pre build the package - PackageBuilder builder = new PackageBuilder(); - builder.addPackage( packageDescr ); - Package pkg = builder.getPackage(); - - //add the package to a rulebase - RuleBase ruleBase = new RuleBaseImpl(); - ruleBase.addPackage( pkg ); - return ruleBase; - } - -} \ No newline at end of file Deleted: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/helloworld/HelloWorldTest.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/helloworld/HelloWorldTest.java 2006-04-21 23:26:33 UTC (rev 3895) +++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/helloworld/HelloWorldTest.java 2006-04-22 03:06:44 UTC (rev 3896) @@ -1,83 +0,0 @@ -package org.drools.integrationtests.helloworld; -/* - * Copyright 2005 JBoss Inc - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - - -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; - -import junit.framework.TestCase; - -import org.drools.PackageIntegrationException; -import org.drools.RuleBase; -import org.drools.RuleIntegrationException; -import org.drools.WorkingMemory; -import org.drools.compiler.DrlParser; -import org.drools.compiler.DroolsParserException; -import org.drools.compiler.PackageBuilder; -import org.drools.lang.descr.PackageDescr; -import org.drools.reteoo.RuleBaseImpl; -import org.drools.rule.InvalidPatternException; -import org.drools.rule.Package; - - - -/** - * This is a sample file to launch a rule package from a rule source file. - */ -public class HelloWorldTest extends TestCase { - - public void testSomething() throws Exception { - - //load up the rulebase - RuleBase ruleBase = readRule(); - WorkingMemory workingMemory = ruleBase.newWorkingMemory(); - - //go ! - Message message = new Message("hola"); - message.addToList( "hello" ); - message.setNumber( 42 ); - - workingMemory.assertObject( message ); - workingMemory.assertObject( "boo" ); - workingMemory.fireAllRules(); - assertTrue( message.isFired() ); - - } - - /** - * Please note that this is the "low level" rule assembly API. - */ - private static RuleBase readRule() throws IOException, DroolsParserException, RuleIntegrationException, PackageIntegrationException, InvalidPatternException { - //read in the source - Reader reader = new InputStreamReader( HelloWorldTest.class.getResourceAsStream( "HelloWorld.drl" ) ); - DrlParser parser = new DrlParser(); - PackageDescr packageDescr = parser.parse( reader ); - - //pre build the package - PackageBuilder builder = new PackageBuilder(); - builder.addPackage( packageDescr ); - Package pkg = builder.getPackage(); - - //add the package to a rulebase - RuleBaseImpl ruleBase = new RuleBaseImpl(); - ruleBase.addPackage( pkg ); - return ruleBase; - } - -} \ No newline at end of file Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/RuleParserTest.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/RuleParserTest.java 2006-04-21 23:26:33 UTC (rev 3895) +++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/RuleParserTest.java 2006-04-22 03:06:44 UTC (rev 3896) @@ -19,8 +19,10 @@ import java.io.InputStream; import java.io.InputStreamReader; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import junit.framework.TestCase; @@ -41,6 +43,7 @@ import org.drools.lang.descr.NotDescr; import org.drools.lang.descr.OrDescr; import org.drools.lang.descr.PackageDescr; +import org.drools.lang.descr.PatternDescr; import org.drools.lang.descr.PredicateDescr; import org.drools.lang.descr.QueryDescr; import org.drools.lang.descr.ReturnValueDescr; @@ -327,6 +330,19 @@ assertFalse( parser.hasErrors() ); } + + /** Note this is only to be enabled if we agree to combine patterns from columns bound to the same var. + * At present, not a valid test. Refer to AndDescr and AndDescrTest (Michael Neale). + */ + public void xxxtestMultiBindings() throws Exception { + RuleDescr rule = parseResource( "multiple_bindings.drl" ).rule(); + assertNotNull( rule ); + assertEquals( "simple_rule", rule.getName() ); + + assertEquals(1, rule.getLhs().getDescrs().size()); + + } + public void testLhsSemicolonDelim() throws Exception { RuleDescr rule = parseResource( "lhs_semicolon_delim.drl" ).rule(); Added: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/descr/AndDescrTest.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/descr/AndDescrTest.java 2006-04-21 23:26:33 UTC (rev 3895) +++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/descr/AndDescrTest.java 2006-04-22 03:06:44 UTC (rev 3896) @@ -0,0 +1,49 @@ +package org.drools.lang.descr; + +import junit.framework.TestCase; + +public class AndDescrTest extends TestCase { + + public void testAddUnboundColumnsEtc() { + AndDescr and = new AndDescr(); + and.addDescr( new NotDescr() ); + and.addDescr( new ColumnDescr("Foo") ); + and.addDescr( new NotDescr() ); + + assertEquals(3, and.getDescrs().size()); + } + + /** This is for combining bound columns with the same name patterns together */ + public void xxtestAddBoundCols() { + AndDescr and = new AndDescr(); + ColumnDescr col1 = new ColumnDescr("Foo"); + col1.setIdentifier( "foo" ); + col1.addDescr( new BoundVariableDescr("foo", "==", "bar") ); + and.addDescr( col1 ); + + ColumnDescr col2 = new ColumnDescr("Foo"); + col2.setIdentifier( "foo" ); + col2.addDescr( new BoundVariableDescr("bar", "==", "baz") ); + and.addDescr( col2 ); + + and.addDescr( new NotDescr() ); + + ColumnDescr col3 = new ColumnDescr("Foo"); + and.addDescr( col3 ); //will not be combined, as not bound + + ColumnDescr col4 = new ColumnDescr("Bar"); + col4.setIdentifier( "foo" ); + and.addDescr( col4 ); //even though has a name, should be left alone + + assertEquals(4, and.getDescrs().size()); + assertEquals(col1, and.getDescrs().get( 0 )); + assertTrue(and.getDescrs().get( 1 ) instanceof NotDescr); + assertEquals(col3, and.getDescrs().get( 2 )); + assertEquals(col4, and.getDescrs().get( 3 )); + + assertEquals(2, col1.getDescrs().size()); + assertEquals("bar", ((BoundVariableDescr)col1.getDescrs().get( 0 )).getIdentifier() ); + assertEquals("baz", ((BoundVariableDescr)col1.getDescrs().get( 1 )).getIdentifier() ); + } + +} Property changes on: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/descr/AndDescrTest.java ___________________________________________________________________ Name: svn:eol-style + native Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/template/NLExpressionCompilerTest.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/template/NLExpressionCompilerTest.java 2006-04-21 23:26:33 UTC (rev 3895) +++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/template/NLExpressionCompilerTest.java 2006-04-22 03:06:44 UTC (rev 3896) @@ -139,4 +139,13 @@ assertEquals( "something boo eee fa", result ); } + public void testWithCurliesInTarget() { + NLGrammar g = new NLGrammar(); + g.addNLItem( new NLMappingItem("foo {bar}", "if ({bar}) { doSomething(); }", "when") ); + NLExpressionCompiler compiler = new NLExpressionCompiler(g); + String result = compiler.compile( "foo bar", "when"); + assertEquals("if (bar) { doSomething(); }", result); + + } + } \ No newline at end of file Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/template/NLGrammarTest.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/template/NLGrammarTest.java 2006-04-21 23:26:33 UTC (rev 3895) +++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/template/NLGrammarTest.java 2006-04-22 03:06:44 UTC (rev 3896) @@ -184,6 +184,12 @@ Assert.assertEquals( "Error list should have 1 error", 1, errors.size() ); error = (MappingError) errors.get( 0 ); Assert.assertEquals( "Wrong reported error", MappingError.ERROR_UNMATCHED_BRACES, error.getErrorCode()); + +//TODO: really should stop the following from barfing... +// item = new NLMappingItem("this is something {here}", "yeah here is {here} and { doSomething(); }", "*"); +// errors = g.validateMapping( item ); +// Assert.assertEquals( 0, errors.size() ); + } } \ No newline at end of file Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/HelloWorld.drl =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/HelloWorld.drl 2006-04-21 23:26:33 UTC (rev 3895) +++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/HelloWorld.drl 2006-04-22 03:06:44 UTC (rev 3896) @@ -0,0 +1,15 @@ +package HelloWorld + +import org.drools.integrationtests.helloworld.Message + +rule "Hello World" + when + $m : Message(list contains "hello", + text:message == "hola", + number > 40, + birthday > "10-Jul-1974", + message matches ".*ho.*") + then + System.out.println("hello world with collections " + $m.getMessage()); + $m.setFired(true); +end Property changes on: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/HelloWorld.drl ___________________________________________________________________ Name: svn:eol-style + native Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/lang/multiple_bindings.drl =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/lang/multiple_bindings.drl 2006-04-21 23:26:33 UTC (rev 3895) +++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/lang/multiple_bindings.drl 2006-04-22 03:06:44 UTC (rev 3896) @@ -0,0 +1,8 @@ +#trying to show how it will normalise biondings +rule simple_rule + when + foo : Bar(a==3) + foo : Bar(a!=4) + then + Baz(); +end \ No newline at end of file Property changes on: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/lang/multiple_bindings.drl ___________________________________________________________________ Name: svn:eol-style + native |
Author: KrisVerlaenen Date: 2006-04-21 19:26:33 -0400 (Fri, 21 Apr 2006) New Revision: 3895 Added: labs/jbossrules/trunk/drools-ide/icons/methpub_obj.gif Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/DroolsPluginImages.java labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/DRLRuleEditor.java labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProcessor.java Log: fixed JBRULES-152 - rule completion now also suggests function names in drl Added: labs/jbossrules/trunk/drools-ide/icons/methpub_obj.gif =================================================================== (Binary files differ) Property changes on: labs/jbossrules/trunk/drools-ide/icons/methpub_obj.gif ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/DroolsPluginImages.java =================================================================== --- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/DroolsPluginImages.java 2006-04-21 23:00:46 UTC (rev 3894) +++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/DroolsPluginImages.java 2006-04-21 23:26:33 UTC (rev 3895) @@ -44,6 +44,7 @@ public static final String EXECUTE_ACTIVATION = "ExecuteActivation"; public static final String CLASS = "Class"; public static final String PACKAGE = "Package"; + public static final String METHOD = "Method"; public static final String DROOLS = "Drools"; private static ImageRegistry imageRegistry; @@ -67,6 +68,7 @@ declareRegistryImage(EXECUTE_ACTIVATION, "bluediamond.GIF"); declareRegistryImage(CLASS, "class_obj.gif"); declareRegistryImage(PACKAGE, "package_obj.gif"); + declareRegistryImage(METHOD, "methpub_obj.gif"); declareRegistryImage(DROOLS, "drools.gif"); } Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/DRLRuleEditor.java =================================================================== --- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/DRLRuleEditor.java 2006-04-21 23:00:46 UTC (rev 3894) +++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/DRLRuleEditor.java 2006-04-21 23:26:33 UTC (rev 3895) @@ -22,6 +22,7 @@ //used to provide additional content assistance/popups when DSLs are used. private DSLAdapter dslAdapter; private List imports; + private List functions; private RuleContentOutlinePage ruleContentOutline = null; @@ -72,6 +73,14 @@ return imports; } + public void setFunctions(List functions) { + this.functions = functions; + } + + public List getFunctions() { + return functions; + } + public Object getAdapter(Class adapter) { if ( adapter.equals( IContentOutlinePage.class ) ) { return getContentOutline(); @@ -94,6 +103,7 @@ } dslAdapter = null; imports = null; + functions = null; } } Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProcessor.java =================================================================== --- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProcessor.java 2006-04-21 23:00:46 UTC (rev 3894) +++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProcessor.java 2006-04-21 23:26:33 UTC (rev 3895) @@ -13,6 +13,7 @@ import org.drools.ide.builder.DroolsBuilder; import org.drools.ide.editors.DRLRuleEditor; import org.drools.ide.editors.DSLAdapter; +import org.drools.lang.descr.FunctionDescr; import org.drools.lang.descr.PackageDescr; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.text.IDocument; @@ -68,9 +69,27 @@ filterProposalsOnPrefix(prefix, list); } if (!adapter.hasConsequences()) { - list.add(new RuleCompletionProposal(prefix.length(), "modify", "modify();", 7)); - list.add(new RuleCompletionProposal(prefix.length(), "retract", "retract();", 8)); - list.add(new RuleCompletionProposal(prefix.length(), "assert", "assert();", 7)); + Image image = DroolsPluginImages.getImage(DroolsPluginImages.DROOLS); + RuleCompletionProposal prop = new RuleCompletionProposal(prefix.length(), "modify", "modify();", 7); + prop.setImage(image); + list.add(prop); + prop = new RuleCompletionProposal(prefix.length(), "retract", "retract();", 8); + prop.setImage(image); + list.add(prop); + prop = new RuleCompletionProposal(prefix.length(), "assert", "assert();", 7); + prop.setImage(image); + list.add(prop); + + List functions = getFunctions(viewer); + iterator = functions.iterator(); + while (iterator.hasNext()) { + String name = (String) iterator.next() + "()"; + prop = new RuleCompletionProposal(prefix.length(), name, name + ";", name.length() - 1); + prop.setPriority(-1); + prop.setImage(DroolsPluginImages.getImage(DroolsPluginImages.METHOD)); + list.add(prop); + } + filterProposalsOnPrefix(prefix, list); // IEditorInput input = getEditor().getEditorInput(); @@ -199,15 +218,36 @@ private List getImports(ITextViewer viewer) throws CoreException, DroolsParserException { List imports = getDRLEditor().getImports(); if (imports == null) { - String content = viewer.getDocument().get(); - Reader dslReader = DSLAdapter.getDSLContent(content, ((FileEditorInput) getEditor().getEditorInput()).getFile()); - DrlParser parser = new DrlParser(); - PackageDescr descr = DroolsBuilder.parsePackage(content, parser, dslReader); - imports = descr.getImports(); - getDRLEditor().setImports(imports); + loadImportsAndFunctions(viewer); + imports = getDRLEditor().getFunctions(); } return imports; } + + private void loadImportsAndFunctions(ITextViewer viewer) throws CoreException, DroolsParserException { + String content = viewer.getDocument().get(); + Reader dslReader = DSLAdapter.getDSLContent(content, ((FileEditorInput) getEditor().getEditorInput()).getFile()); + DrlParser parser = new DrlParser(); + PackageDescr descr = DroolsBuilder.parsePackage(content, parser, dslReader); + // imports + getDRLEditor().setImports(descr.getImports()); + // functions + List functionDescrs = descr.getFunctions(); + List functions = new ArrayList(functionDescrs.size()); + Iterator iterator = functionDescrs.iterator(); + while (iterator.hasNext()) { + functions.add(((FunctionDescr) iterator.next()).getName()); + } + getDRLEditor().setFunctions(functions); + } + private List getFunctions(ITextViewer viewer) throws CoreException, DroolsParserException { + List functions = getDRLEditor().getFunctions(); + if (functions == null) { + loadImportsAndFunctions(viewer); + functions = getDRLEditor().getFunctions(); + } + return functions; + } } |
From: <jbo...@li...> - 2006-04-21 23:00:51
|
Author: KrisVerlaenen Date: 2006-04-21 19:00:46 -0400 (Fri, 21 Apr 2006) New Revision: 3894 Modified: labs/jbossrules/trunk/drools-ide/help/debug/agenda.html labs/jbossrules/trunk/drools-ide/help/debug/applicationData.html labs/jbossrules/trunk/drools-ide/help/debug/workingMemory.html labs/jbossrules/trunk/drools-ide/help/drools.html labs/jbossrules/trunk/drools-ide/help/editor/editor.html Log: fixed JBRULES-201 - updated help so images are showing correctly Modified: labs/jbossrules/trunk/drools-ide/help/debug/agenda.html =================================================================== --- labs/jbossrules/trunk/drools-ide/help/debug/agenda.html 2006-04-21 22:38:40 UTC (rev 3893) +++ labs/jbossrules/trunk/drools-ide/help/debug/agenda.html 2006-04-21 23:00:46 UTC (rev 3894) @@ -1,6 +1,6 @@ <HTML> <H1>The Agenda View</H1> - <IMG src="./agenda.gif"/> + <IMG src="./agenda.GIF"/> <P/> The Agenda View shows all elements on the agenda. For each rule on the agenda, the rule name and bound variables are shown. <P/> Modified: labs/jbossrules/trunk/drools-ide/help/debug/applicationData.html =================================================================== --- labs/jbossrules/trunk/drools-ide/help/debug/applicationData.html 2006-04-21 22:38:40 UTC (rev 3893) +++ labs/jbossrules/trunk/drools-ide/help/debug/applicationData.html 2006-04-21 23:00:46 UTC (rev 3894) @@ -1,6 +1,6 @@ <HTML> <H1>The Global Data View</H1> - <IMG src="./applicationData.gif"/> + <IMG src="./applicationData.GIF"/> <P/> The Global Data View shows all global data currently defined in the Drools engine. <P/> Modified: labs/jbossrules/trunk/drools-ide/help/debug/workingMemory.html =================================================================== --- labs/jbossrules/trunk/drools-ide/help/debug/workingMemory.html 2006-04-21 22:38:40 UTC (rev 3893) +++ labs/jbossrules/trunk/drools-ide/help/debug/workingMemory.html 2006-04-21 23:00:46 UTC (rev 3894) @@ -1,6 +1,6 @@ <HTML> <H1>The Working Memory View</H1> - <IMG src="./workingMemory.gif"/> + <IMG src="./workingMemory.GIF"/> <P/> The Working Memory shows all elements in the working memory of the Drools engine. <P/> Modified: labs/jbossrules/trunk/drools-ide/help/drools.html =================================================================== --- labs/jbossrules/trunk/drools-ide/help/drools.html 2006-04-21 22:38:40 UTC (rev 3893) +++ labs/jbossrules/trunk/drools-ide/help/drools.html 2006-04-21 23:00:46 UTC (rev 3894) @@ -6,7 +6,7 @@ <P/> You can create a new Drools Project by selecting File -> New -> Project ... which pops up a 'New Project'-dialog. Select the New Rule Project item in the JBoss Rules folder and click Next. Fill in a name and click Finish. The new Drools Project should have been created. <P/> - <IMG src="./DroolsProject.gif"/> + <IMG src="./DroolsProject.GIF"/> <P/> The newly created contains an example rule file (Sample.drl) in the src/rules dir and an example java file (DroolsTest.java) that can be used to execute the rules in a Drools engine in the folder src/java, in the com.sample package. All the others jars that are necessary during execution are also added to the classpath in a custom classpath container called Drools Library [3.0]. <P/> Modified: labs/jbossrules/trunk/drools-ide/help/editor/editor.html =================================================================== --- labs/jbossrules/trunk/drools-ide/help/editor/editor.html 2006-04-21 22:38:40 UTC (rev 3893) +++ labs/jbossrules/trunk/drools-ide/help/editor/editor.html 2006-04-21 23:00:46 UTC (rev 3894) @@ -8,5 +8,5 @@ <P/> The following picture shows the syntax colouring and syntax checking in action. <P/> - <IMG src="editor.gif"/> + <IMG src="editor.GIF"/> </html> \ No newline at end of file |
From: <jbo...@li...> - 2006-04-21 22:38:43
|
Author: KrisVerlaenen Date: 2006-04-21 18:38:40 -0400 (Fri, 21 Apr 2006) New Revision: 3893 Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/ReteViewer.java Log: fixed JBRULES-234 - Rete viewer now also takes expander into account Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/ReteViewer.java =================================================================== --- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/ReteViewer.java 2006-04-21 19:36:49 UTC (rev 3892) +++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/ReteViewer.java 2006-04-21 22:38:40 UTC (rev 3893) @@ -2,6 +2,7 @@ import java.awt.BorderLayout; import java.awt.Frame; +import java.io.Reader; import org.drools.RuleBase; import org.drools.compiler.DrlParser; @@ -91,11 +92,19 @@ newLoader = ProjectClassLoader.getProjectClassLoader(project); } + Reader dslReader = DSLAdapter.getDSLContent(contents, file); + try { Thread.currentThread().setContextClassLoader(newLoader); DrlParser parser = new DrlParser(); - PackageDescr packageDescr = parser.parse(contents); + + PackageDescr packageDescr = null; + if (dslReader == null) { + packageDescr = parser.parse(contents); + } else { + packageDescr = parser.parse(contents, dslReader); + } //pre build the package PackageBuilder builder = new PackageBuilder(); |
From: <jbo...@li...> - 2006-04-21 19:36:55
|
Author: mar...@jb... Date: 2006-04-21 15:36:49 -0400 (Fri, 21 Apr 2006) New Revision: 3892 Removed: labs/jbossrules/trunk/repository/eclipse/ Log: -jdtcore 3.2.0.v_658 has moved to ibiblio |
From: <jbo...@li...> - 2006-04-21 19:36:05
|
Author: mar...@jb... Date: 2006-04-21 15:35:56 -0400 (Fri, 21 Apr 2006) New Revision: 3891 Removed: labs/jbossrules/trunk/repository/antlr/stringtemplate/ Log: -stringtemplate 2.3b6 has moved to ibiblio |
Author: wrzep Date: 2006-04-21 13:14:54 -0400 (Fri, 21 Apr 2006) New Revision: 3890 Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/PluginConfImpl.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/PluginValuesImpl.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/PluginsValuesImpl.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/ScoresServiceImpl.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/model/ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/model/PluginConf.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/model/PluginValues.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/model/PluginsValues.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/model/ScoresService.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/model/ScoresServiceLocal.java Removed: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresService.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceImpl.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceLocal.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/PluginConf.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/PluginValues.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/PluginsValues.java Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/templates/CellTemplate.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/templates/Column.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/templates/Columns.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/templates/MatrixTemplate.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/templates/MetricTemplate.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/templates/RowTemplate.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/Plugins.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/ProjectsByScoreComparator.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/ScoresManager.java Log: JBLAB-599 more flexible ejb3 service based on interfaces instead of fixed classes Pawel Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java 2006-04-21 16:27:16 UTC (rev 3889) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java 2006-04-21 17:14:54 UTC (rev 3890) @@ -39,11 +39,12 @@ import org.jboss.forge.status.exceptions.InvalidPluginsConfigurationException; import org.jboss.forge.status.exceptions.GetScoresException; import org.jboss.forge.status.exceptions.ScoresSaveException; +import org.jboss.forge.status.service.impl.PluginConfImpl; +import org.jboss.forge.status.service.model.PluginConf; +import org.jboss.forge.status.service.model.PluginsValues; import org.jboss.forge.status.templates.Column; import org.jboss.forge.status.templates.Columns; import org.jboss.forge.status.templates.MatrixTemplate; -import org.jboss.forge.status.tools.PluginConf; -import org.jboss.forge.status.tools.PluginsValues; import org.jboss.forge.status.tools.ScoresManager; import org.jboss.forge.status.tools.Tags; @@ -137,7 +138,7 @@ } try { - PluginConf pluginConf = new PluginConf(pluginNode); + PluginConfImpl pluginConf = new PluginConfImpl(pluginNode); pluginsConfList.add(pluginConf); } catch (InvalidPluginsConfigurationException e) { log.warn(e); Deleted: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresService.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresService.java 2006-04-21 16:27:16 UTC (rev 3889) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresService.java 2006-04-21 17:14:54 UTC (rev 3890) @@ -1,49 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2005, JBoss Inc., and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This is free software; you can redistribute it and/or 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 software 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 software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ - -package org.jboss.forge.status.service; - -import java.util.Date; -import java.util.List; - -import org.jboss.forge.common.projects.Projects; -import org.jboss.forge.status.exceptions.GetScoresException; -import org.jboss.forge.status.exceptions.ScoresSaveException; -import org.jboss.forge.status.tools.PluginConf; -import org.jboss.forge.status.tools.PluginValues; -import org.jboss.forge.status.tools.PluginsValues; - - -/** -* @author Pawel Wrzeszcz (pawel.wrzeszcz [at] gmail.com) -*/ -public interface ScoresService { - - public PluginsValues getPluginsValues(String portalName, - Date date) throws GetScoresException; - - public void save(Projects projects, List<PluginConf> pluginsConf, - String portalName) throws ScoresSaveException; - - public PluginValues get(String portalName, String pluginId, Date date) - throws GetScoresException; -} \ No newline at end of file Deleted: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceImpl.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceImpl.java 2006-04-21 16:27:16 UTC (rev 3889) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceImpl.java 2006-04-21 17:14:54 UTC (rev 3890) @@ -1,341 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2005, JBoss Inc., and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This is free software; you can redistribute it and/or 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 software 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 software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ - -package org.jboss.forge.status.service; - -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.OutputStream; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.ejb.Local; - -import org.jboss.annotation.ejb.LocalBinding; -import org.jboss.annotation.ejb.Management; -import org.jboss.annotation.ejb.Service; - -import org.jboss.forge.common.projects.Projects; - -import org.jboss.forge.status.exceptions.GetScoresException; -import org.jboss.forge.status.exceptions.ScoresSaveException; -import org.jboss.forge.status.tools.PluginConf; -import org.jboss.forge.status.tools.PluginValues; -import org.jboss.forge.status.tools.Plugins; -import org.jboss.forge.status.tools.PluginsValues; -import org.jboss.forge.status.tools.Tools; - -import org.jboss.logging.Logger; -import org.jboss.shotoku.ContentManager; -import org.jboss.shotoku.Directory; -import org.jboss.shotoku.Node; -import org.jboss.shotoku.aop.Inject; -import org.jboss.shotoku.exceptions.RepositoryException; -import org.jboss.shotoku.exceptions.ResourceDoesNotExist; -import org.jboss.shotoku.exceptions.SaveException; - -/** -* @author Pawel Wrzeszcz (paw...@gm...) -*/ - -@Service(objectName=Tools.STATUS_SERVICE_NAME) -@Management(ScoresService.class) -@Local(ScoresServiceLocal.class) -@LocalBinding(jndiBinding="Status/ScoresService") -public class ScoresServiceImpl implements ScoresService, ScoresServiceLocal { - - private static Logger log = Logger.getLogger(ScoresServiceImpl.class); - - private Map<String,PluginsValues> values = new HashMap<String,PluginsValues>(); - - @Inject - private ContentManager cm; - - /** - * Saves current plugin values. - * - * @param projects Projects for which plugin values will be saved - * @param plugins Plugins for which values will be saved - * @param portalName - * @return true iff saving was successful - */ - public void save(Projects projects, List<PluginConf> pluginsConf, - String portalName) throws ScoresSaveException { - - // Get plugins from conf - Plugins plugins = new Plugins(pluginsConf, portalName, projects); - - // Get directory where we store historical scores - Directory rootDir = cm.getRootDirectory(); - String dirName = Tools.getShotokuStatusPath(portalName); - Directory dir = getDir(rootDir, dirName); - - // Get plugin values and save them in proper node - PluginsValues pluginsValues = new PluginsValues(projects, plugins); - - // Get node to store scores - String nodeName = getCurrentNodeName(); - Node node = null; - - try { - node = dir.getNode(nodeName); - } catch (RepositoryException e) { - log.error("Error while getting shotoku node: " + - dir.getFullName() + "/" + nodeName, e); - throw new ScoresSaveException(e); - } catch (ResourceDoesNotExist e) { - node = createNode(dir, nodeName); - } - - // Save values and store then in cache - values.put(getCurrentNodeName(), pluginsValues); - save(node, pluginsValues); - } - - /** - * Saves plugins values in the given Directory. - * - * @param dir Directory to save values - * @param pluginsValues PluginsValues to save - * @return true iff saving was successful - */ - private boolean save(Node node, PluginsValues pluginsValues) { - - try { - OutputStream os = node.getOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(os); - oos.writeObject((PluginsValues) pluginsValues); - oos.close(); - node.save("update"); /* os is closed inside save() */ - } catch (IOException e) { - e.printStackTrace();//TODO error messages - return false; - } catch (RepositoryException e) { - e.printStackTrace(); - return false; - } catch (SaveException e) { - e.printStackTrace(); - return false; - } - - return true; - } - - /** - * Returns historical scores from the given <code>date</code> in the past. - * - * Notice that only year, month and day matter in passed dates. - * - * @return scores from the given date - * @throws GetScoresException - */ - public PluginsValues getPluginsValues(String portalName, Date date) - throws GetScoresException { - - // null date means today - if (date == null) { - Calendar cal = Calendar.getInstance(); - date = cal.getTime(); - } - - String key = getNodeName(date); - PluginsValues v = values.get(key); - - if (v == null) { // Not in cache => get value and store it - - Directory rootDir = cm.getRootDirectory(); - - Directory dir; - try { - dir = rootDir.getDirectory(Tools.getShotokuStatusPath(portalName)); - } catch (RepositoryException e) { - throw new GetScoresException(e); - } catch (ResourceDoesNotExist e) { - throw new GetScoresException(e); - } - - if (dir != null) { - v = getPluginsValues(dir, date); - values.put(key,v); - } - } - - return v; - } - - /** - * Returns historical scores from the specified directory. - * - * @param dir Directory to read scores from - * @return - * @throws GetScoresException - */ - private PluginsValues getPluginsValues(Directory dir, Date date) - throws GetScoresException { - - // Get appropriate node - Node node = null; - String nodeName = getNodeName(date); - - try { - node = dir.getNode(nodeName); - } catch (Exception e) { - log.error("Error while getting shotoku node " + - dir.getFullName() + "/" + nodeName); - throw new GetScoresException(e); - } - - // Restore values - PluginsValues values = null; - try { - InputStream is = node.getContentInputStream(); - ObjectInputStream ois = new ObjectInputStream(is); - values = (PluginsValues) ois.readObject(); - ois.close(); - is.close(); - } catch (Exception e) { - log.error("Error while restoring scores from shotoku node " + - dir.getFullName() + "/" + nodeName); - throw new GetScoresException(e); - } - - return values; - } - - /** - * Creates new shotoku Node. - * - * @param dir Directory in which new Node will be created - * @param nodeName name of new Node - * @return Node - * @throws ScoresSaveException - */ - private Node createNode(Directory dir, String nodeName) - throws ScoresSaveException { - - Node node = null; - - try { - node = dir.newNode(nodeName); - node.save("create"); - } catch (Exception e) { - log.error("Error while creating shotoku node: " + - dir.getFullName() + "/" + nodeName, e); - throw new ScoresSaveException(e); - } - - return node; - } - - /** - * Gets shotoku Directory with name <code>dirName</code> - * from specified shotoku Directory. - * If requested Directory does not exist it is created. - * - * @param rootDir Directory where search will be performed - * @param dirName name of searched Directory - * @return Directory with the given name - * or null when creating Directory failed. - * @throws ScoresSaveException - */ - private Directory getDir(Directory rootDir, String dirName) - throws ScoresSaveException { - - Directory dir = null; - - try { - dir = rootDir.getDirectory(dirName); - } catch (RepositoryException e) { - log.error("Error while getting shotoku directory " + - rootDir.getFullName() + "/" + dirName); - throw new ScoresSaveException(e); - } catch (ResourceDoesNotExist e) { - dir = createDir(rootDir, dirName); - } - - return dir; - } - - /** - * Creates new shotoku Directory. - * - * @param rootDir Directory in which new subdirectory will be created - * @param dirName name of new Directory - * @return Directory or null if errors occured - * @throws ScoresSaveException - */ - private Directory createDir(Directory rootDir, String dirName) - throws ScoresSaveException { - - Directory dir = null; - - try { - dir = rootDir.newDirectory(dirName); - dir.save("create"); - } catch (Exception e) { - log.error("Error while creating shotoku directory: " + - rootDir.getFullName() + "/" + dirName, e); - throw new ScoresSaveException(e); - } - - return dir; - } - - /** - * Gets name of Node containing saved data from specified datestamp. - * Notice that only year, month and day matter in passed <code>date</code>. - * - * @param date datestamp - * @return Node name - */ - private String getNodeName(Date date) { - - SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); - - return df.format(date); - } - - /** - * @return name of Node containging data saved today - */ - private String getCurrentNodeName() { - - Calendar cal = Calendar.getInstance(); - Date today = cal.getTime(); - - return getNodeName(today); - } - - public PluginValues get(String portalName, String pluginId, Date date) - throws GetScoresException { - - PluginsValues pv = getPluginsValues(portalName, date); - return pv.getPluginValues(pluginId); - } - -} Deleted: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceLocal.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceLocal.java 2006-04-21 16:27:16 UTC (rev 3889) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceLocal.java 2006-04-21 17:14:54 UTC (rev 3890) @@ -1,48 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2005, JBoss Inc., and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This is free software; you can redistribute it and/or 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 software 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 software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ - -package org.jboss.forge.status.service; - -import java.util.Date; -import java.util.List; - -import org.jboss.forge.common.projects.Projects; -import org.jboss.forge.status.exceptions.GetScoresException; -import org.jboss.forge.status.exceptions.ScoresSaveException; -import org.jboss.forge.status.tools.PluginConf; -import org.jboss.forge.status.tools.PluginValues; -import org.jboss.forge.status.tools.PluginsValues; - -/** -* @author Pawel Wrzeszcz (pawel.wrzeszcz [at] gmail.com) -*/ -public interface ScoresServiceLocal { - - public PluginsValues getPluginsValues(String portalName, - Date date) throws GetScoresException; - - public void save(Projects projects, List<PluginConf> pluginsConf, - String portalName) throws ScoresSaveException; - - public PluginValues get(String portalName, String pluginId, Date date) - throws GetScoresException; -} \ No newline at end of file Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/PluginConfImpl.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/PluginConfImpl.java 2006-04-21 16:27:16 UTC (rev 3889) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/PluginConfImpl.java 2006-04-21 17:14:54 UTC (rev 3890) @@ -0,0 +1,114 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or 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 software 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 software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.forge.status.service.impl; + +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +import org.jboss.forge.common.XmlTools; +import org.jboss.forge.status.exceptions.InvalidPluginsConfigurationException; +import org.jboss.forge.status.service.model.PluginConf; +import org.jboss.forge.status.tools.Tags; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** +* @author Pawel Wrzeszcz +*/ +public class PluginConfImpl implements PluginConf { + + private static final long serialVersionUID = 8598887068548048511L; + + private Map<String,String> fields = new HashMap<String,String>(); + private Properties properties = new Properties(); + + public PluginConfImpl(Node pluginNode) + throws InvalidPluginsConfigurationException { + + // Parse plugin configuration + parseField(pluginNode, Tags.PLUGIN_ID_ELEMENT); + parseField(pluginNode, Tags.PLUGIN_CLASS_ELEMENT); + + // Parse plugin properties + Node pluginPropertiesNode = + XmlTools.getFirstNodeWithName(pluginNode, + Tags.PLUGIN_PROPERTIES_ELEMENT); + addPluginProperties(pluginPropertiesNode); + } + + public String getFieldValue(String fieldName) { + return fields.get(fieldName); + } + + public Properties getProperties() { + return properties; + } + + private void parseField(Node pluginNode, String fieldName) + throws InvalidPluginsConfigurationException { + + String fieldValue = + XmlTools.getChildNodeValue(pluginNode, fieldName); + + if (fieldValue == null) { + throw new InvalidPluginsConfigurationException( + "Missing field: " + fieldName); + } + + fields.put(fieldName, fieldValue); + } + + /** + * Computes plugin properites from given properties Node. + * + * @param propertiesNode Node containging plugin properties + * @return plugin properties or null if properties are not specified + */ + private void addPluginProperties(Node propertiesNode) { + + if (propertiesNode == null) { + return; + } + + NodeList nodes = propertiesNode.getChildNodes(); + + for (int i = 0; i < nodes.getLength(); i++) { + Node node = nodes.item(i); + + if ((node.getNodeType() == Node.ELEMENT_NODE) + && (node.getNodeName() == "property")){ + + String propertyName = + XmlTools.getChildNodeValue(node, "name"); + String propertyValue = + XmlTools.getChildNodeValue(node, "value"); + + if ((propertyName != null) && (propertyValue != null)) { + properties.setProperty(propertyName, propertyValue); + } + } + } + } + +} \ No newline at end of file Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/PluginValuesImpl.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/PluginValuesImpl.java 2006-04-21 16:27:16 UTC (rev 3889) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/PluginValuesImpl.java 2006-04-21 17:14:54 UTC (rev 3890) @@ -0,0 +1,82 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or 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 software 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 software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.forge.status.service.impl; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.jboss.forge.status.plugins.Plugin; +import org.jboss.forge.status.service.model.PluginValues; + +/** +* @author Pawel Wrzeszcz (paw...@gm...) +* A class used to store plugin values in shotoku. +*/ + +public class PluginValuesImpl implements PluginValues { + + private static final long serialVersionUID = 5196364802717262757L; + + private Map<String,Long> values = new HashMap<String,Long>(); + private Map<String,Integer> rates = new HashMap<String,Integer>(); + private Map<String,String> links = new HashMap<String,String>(); + + private String pluginId; + private String linkName; + + public PluginValuesImpl(Plugin plugin, Set<String> projectIds) { + + // Get plugin properties + pluginId = plugin.getId(); + linkName = plugin.getLinkName(); + + // Get plugin values + for (String projectId : projectIds) { + + values.put(projectId, plugin.getValue(projectId)); + rates.put(projectId, new Integer(plugin.getRate(projectId))); + links.put(projectId, plugin.getLink(projectId)); + } + } + + public String getId() { + return pluginId; + } + + public Long getValue(String projectId) { + return values.get(projectId); + } + + public Integer getRate(String projectId) { + return rates.get(projectId); + } + + public String getLink(String projectId) { + return links.get(projectId); + } + + public String getLinkName() { + return linkName; + } +} Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/PluginsValuesImpl.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/PluginsValuesImpl.java 2006-04-21 16:27:16 UTC (rev 3889) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/PluginsValuesImpl.java 2006-04-21 17:14:54 UTC (rev 3890) @@ -0,0 +1,117 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or 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 software 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 software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.forge.status.service.impl; + +import java.util.Calendar; +import java.util.Date; +import java.util.Map; +import java.util.HashMap; +import java.util.Set; + +import java.io.Serializable; + +import org.jboss.forge.common.projects.Projects; +import org.jboss.forge.common.projects.permissions.NullPermissionsChecker; + +import org.jboss.forge.status.exceptions.GetScoresException; +import org.jboss.forge.status.plugins.Plugin; +import org.jboss.forge.status.service.model.PluginsValues; +import org.jboss.forge.status.tools.Plugins; + +/** +* @author Pawel Wrzeszcz (paw...@gm...) +* A class used to store plugins values in shotoku. +*/ + +public class PluginsValuesImpl implements PluginsValues { + + private static final long serialVersionUID = -1669515339062166738L; + + /** Map : pluginId -> pluginValue */ + private Map<String,PluginValuesImpl> values; + + /** Creation date */ + private Date date; + + /** + * @param projects Projects present in the Status Matrix + * @param plugins Plugins which values will be stored + */ + public PluginsValuesImpl(Projects projects, Plugins plugins) { + + date = Calendar.getInstance().getTime(); + + values = new HashMap<String,PluginValuesImpl>(); + + Set<String> projectIds = + projects.getProjectIds(new NullPermissionsChecker(), null); + + for (Plugin plugin : plugins.getPlugins()) { + + PluginValuesImpl pluginValues = new PluginValuesImpl(plugin, projectIds); + + values.put(plugin.getId(), pluginValues); + } + } + + /** + * For the given plugin and project ids returns stored value. + * + * @param pluginId plugin id + * @param projectId project id + * @return stored plugin value for specified project + * @throws GetScoresException + * Thrown when requested value was not found + */ + public long getPluginValue(String pluginId, String projectId) + throws GetScoresException { + + Long val = null; + PluginValuesImpl pluginValues = values.get(pluginId); + + if (pluginValues != null) { + val = pluginValues.getValue(projectId); + } + + if (val == null) { + throw new GetScoresException(); + } + + return val; + } + + /** + * @return creation date + */ + public Date getDate() { + return date; + } + + public boolean hasPlugin(String pluginId) { + return values.containsKey(pluginId); + } + + public PluginValuesImpl getPluginValues(String pluginId) { + return values.get(pluginId); + } +} Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/ScoresServiceImpl.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/ScoresServiceImpl.java 2006-04-21 16:27:16 UTC (rev 3889) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/ScoresServiceImpl.java 2006-04-21 17:14:54 UTC (rev 3890) @@ -0,0 +1,341 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or 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 software 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 software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.forge.status.service.impl; + +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.OutputStream; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.ejb.Local; + +import org.jboss.annotation.ejb.LocalBinding; +import org.jboss.annotation.ejb.Management; +import org.jboss.annotation.ejb.Service; + +import org.jboss.forge.common.projects.Projects; + +import org.jboss.forge.status.exceptions.GetScoresException; +import org.jboss.forge.status.exceptions.ScoresSaveException; +import org.jboss.forge.status.service.model.PluginConf; +import org.jboss.forge.status.service.model.ScoresService; +import org.jboss.forge.status.service.model.ScoresServiceLocal; +import org.jboss.forge.status.tools.Plugins; +import org.jboss.forge.status.tools.Tools; + +import org.jboss.logging.Logger; +import org.jboss.shotoku.ContentManager; +import org.jboss.shotoku.Directory; +import org.jboss.shotoku.Node; +import org.jboss.shotoku.aop.Inject; +import org.jboss.shotoku.exceptions.RepositoryException; +import org.jboss.shotoku.exceptions.ResourceDoesNotExist; +import org.jboss.shotoku.exceptions.SaveException; + +/** +* @author Pawel Wrzeszcz (paw...@gm...) +*/ + +@Service(objectName=Tools.STATUS_SERVICE_NAME) +@Management(ScoresService.class) +@Local(ScoresServiceLocal.class) +@LocalBinding(jndiBinding="Status/ScoresService") +public class ScoresServiceImpl implements ScoresService, ScoresServiceLocal { + + private static Logger log = Logger.getLogger(ScoresServiceImpl.class); + + private Map<String,PluginsValuesImpl> values = new HashMap<String,PluginsValuesImpl>(); + + @Inject + private ContentManager cm; + + /** + * Saves current plugin values. + * + * @param projects Projects for which plugin values will be saved + * @param plugins Plugins for which values will be saved + * @param portalName + * @return true iff saving was successful + */ + public void save(Projects projects, List<PluginConf> pluginsConf, + String portalName) throws ScoresSaveException { + + // Get plugins from conf + Plugins plugins = new Plugins(pluginsConf, portalName, projects); + + // Get directory where we store historical scores + Directory rootDir = cm.getRootDirectory(); + String dirName = Tools.getShotokuStatusPath(portalName); + Directory dir = getDir(rootDir, dirName); + + // Get plugin values and save them in proper node + PluginsValuesImpl pluginsValues = new PluginsValuesImpl(projects, plugins); + + // Get node to store scores + String nodeName = getCurrentNodeName(); + Node node = null; + + try { + node = dir.getNode(nodeName); + } catch (RepositoryException e) { + log.error("Error while getting shotoku node: " + + dir.getFullName() + "/" + nodeName, e); + throw new ScoresSaveException(e); + } catch (ResourceDoesNotExist e) { + node = createNode(dir, nodeName); + } + + // Save values and store then in cache + values.put(getCurrentNodeName(), pluginsValues); + save(node, pluginsValues); + } + + /** + * Saves plugins values in the given Directory. + * + * @param dir Directory to save values + * @param pluginsValues PluginsValues to save + * @return true iff saving was successful + */ + private boolean save(Node node, PluginsValuesImpl pluginsValues) { + + try { + OutputStream os = node.getOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(os); + oos.writeObject((PluginsValuesImpl) pluginsValues); + oos.close(); + node.save("update"); /* os is closed inside save() */ + } catch (IOException e) { + e.printStackTrace();//TODO error messages + return false; + } catch (RepositoryException e) { + e.printStackTrace(); + return false; + } catch (SaveException e) { + e.printStackTrace(); + return false; + } + + return true; + } + + /** + * Returns historical scores from the given <code>date</code> in the past. + * + * Notice that only year, month and day matter in passed dates. + * + * @return scores from the given date + * @throws GetScoresException + */ + public PluginsValuesImpl getPluginsValues(String portalName, Date date) + throws GetScoresException { + + // null date means today + if (date == null) { + Calendar cal = Calendar.getInstance(); + date = cal.getTime(); + } + + String key = getNodeName(date); + PluginsValuesImpl v = values.get(key); + + if (v == null) { // Not in cache => get value and store it + + Directory rootDir = cm.getRootDirectory(); + + Directory dir; + try { + dir = rootDir.getDirectory(Tools.getShotokuStatusPath(portalName)); + } catch (RepositoryException e) { + throw new GetScoresException(e); + } catch (ResourceDoesNotExist e) { + throw new GetScoresException(e); + } + + if (dir != null) { + v = getPluginsValues(dir, date); + values.put(key,v); + } + } + + return v; + } + + /** + * Returns historical scores from the specified directory. + * + * @param dir Directory to read scores from + * @return + * @throws GetScoresException + */ + private PluginsValuesImpl getPluginsValues(Directory dir, Date date) + throws GetScoresException { + + // Get appropriate node + Node node = null; + String nodeName = getNodeName(date); + + try { + node = dir.getNode(nodeName); + } catch (Exception e) { + log.error("Error while getting shotoku node " + + dir.getFullName() + "/" + nodeName); + throw new GetScoresException(e); + } + + // Restore values + PluginsValuesImpl values = null; + try { + InputStream is = node.getContentInputStream(); + ObjectInputStream ois = new ObjectInputStream(is); + values = (PluginsValuesImpl) ois.readObject(); + ois.close(); + is.close(); + } catch (Exception e) { + log.error("Error while restoring scores from shotoku node " + + dir.getFullName() + "/" + nodeName); + throw new GetScoresException(e); + } + + return values; + } + + /** + * Creates new shotoku Node. + * + * @param dir Directory in which new Node will be created + * @param nodeName name of new Node + * @return Node + * @throws ScoresSaveException + */ + private Node createNode(Directory dir, String nodeName) + throws ScoresSaveException { + + Node node = null; + + try { + node = dir.newNode(nodeName); + node.save("create"); + } catch (Exception e) { + log.error("Error while creating shotoku node: " + + dir.getFullName() + "/" + nodeName, e); + throw new ScoresSaveException(e); + } + + return node; + } + + /** + * Gets shotoku Directory with name <code>dirName</code> + * from specified shotoku Directory. + * If requested Directory does not exist it is created. + * + * @param rootDir Directory where search will be performed + * @param dirName name of searched Directory + * @return Directory with the given name + * or null when creating Directory failed. + * @throws ScoresSaveException + */ + private Directory getDir(Directory rootDir, String dirName) + throws ScoresSaveException { + + Directory dir = null; + + try { + dir = rootDir.getDirectory(dirName); + } catch (RepositoryException e) { + log.error("Error while getting shotoku directory " + + rootDir.getFullName() + "/" + dirName); + throw new ScoresSaveException(e); + } catch (ResourceDoesNotExist e) { + dir = createDir(rootDir, dirName); + } + + return dir; + } + + /** + * Creates new shotoku Directory. + * + * @param rootDir Directory in which new subdirectory will be created + * @param dirName name of new Directory + * @return Directory or null if errors occured + * @throws ScoresSaveException + */ + private Directory createDir(Directory rootDir, String dirName) + throws ScoresSaveException { + + Directory dir = null; + + try { + dir = rootDir.newDirectory(dirName); + dir.save("create"); + } catch (Exception e) { + log.error("Error while creating shotoku directory: " + + rootDir.getFullName() + "/" + dirName, e); + throw new ScoresSaveException(e); + } + + return dir; + } + + /** + * Gets name of Node containing saved data from specified datestamp. + * Notice that only year, month and day matter in passed <code>date</code>. + * + * @param date datestamp + * @return Node name + */ + private String getNodeName(Date date) { + + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); + + return df.format(date); + } + + /** + * @return name of Node containging data saved today + */ + private String getCurrentNodeName() { + + Calendar cal = Calendar.getInstance(); + Date today = cal.getTime(); + + return getNodeName(today); + } + + public PluginValuesImpl get(String portalName, String pluginId, Date date) + throws GetScoresException { + + PluginsValuesImpl pv = getPluginsValues(portalName, date); + return pv.getPluginValues(pluginId); + } + +} Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/model/PluginConf.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/model/PluginConf.java 2006-04-21 16:27:16 UTC (rev 3889) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/model/PluginConf.java 2006-04-21 17:14:54 UTC (rev 3890) @@ -0,0 +1,38 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or 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 software 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 software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.forge.status.service.model; + +import java.io.Serializable; +import java.util.Properties; + +/** +* @author Pawel Wrzeszcz +*/ +public interface PluginConf extends Serializable { + + //TODO PluginConfImpl has constructor + + public String getFieldValue(String fieldName); + + public Properties getProperties(); +} \ No newline at end of file Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/model/PluginValues.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/model/PluginValues.java 2006-04-21 16:27:16 UTC (rev 3889) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/model/PluginValues.java 2006-04-21 17:14:54 UTC (rev 3890) @@ -0,0 +1,44 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or 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 software 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 software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.forge.status.service.model; + +import java.io.Serializable; + +/** +* @author Pawel Wrzeszcz (paw...@gm...) +* A class used to store plugin values in shotoku. +*/ + +public interface PluginValues extends Serializable { + + public String getId(); + + public Long getValue(String projectId); + + public Integer getRate(String projectId); + + public String getLink(String projectId); + + public String getLinkName(); + +} Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/model/PluginsValues.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/model/PluginsValues.java 2006-04-21 16:27:16 UTC (rev 3889) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/model/PluginsValues.java 2006-04-21 17:14:54 UTC (rev 3890) @@ -0,0 +1,63 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or 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 software 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 software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.forge.status.service.model; + +import java.util.Date; + +import java.io.Serializable; + +import org.jboss.forge.status.exceptions.GetScoresException; + + +/** +* @author Pawel Wrzeszcz (paw...@gm...) +* A class used to store plugins values in shotoku. +*/ + +public interface PluginsValues extends Serializable { + + + //TODO constructor in impl + + /** + * For the given plugin and project ids returns stored value. + * + * @param pluginId plugin id + * @param projectId project id + * @return stored plugin value for specified project + * @throws GetScoresException + * Thrown when requested value was not found + */ + public long getPluginValue(String pluginId, String projectId) + throws GetScoresException; + + /** + * @return creation date + */ + public Date getDate(); + + public boolean hasPlugin(String pluginId); + + public PluginValues getPluginValues(String pluginId); + +} Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/model/ScoresService.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/model/ScoresService.java 2006-04-21 16:27:16 UTC (rev 3889) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/model/ScoresService.java 2006-04-21 17:14:54 UTC (rev 3890) @@ -0,0 +1,45 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or 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 software 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 software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.forge.status.service.model; + +import java.util.Date; +import java.util.List; + +import org.jboss.forge.common.projects.Projects; +import org.jboss.forge.status.exceptions.GetScoresException; +import org.jboss.forge.status.exceptions.ScoresSaveException; + +/** +* @author Pawel Wrzeszcz (pawel.wrzeszcz [at] gmail.com) +*/ +public interface ScoresService { + + public PluginsValues getPluginsValues(String portalName, + Date date) throws GetScoresException; + + public void save(Projects projects, List<PluginConf> pluginsConf, + String portalName) throws ScoresSaveException; + + public PluginValues get(String portalName, String pluginId, Date date) + throws GetScoresException; +} \ No newline at end of file Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/model/ScoresServiceLocal.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/model/ScoresServiceLocal.java 2006-04-21 16:27:16 UTC (rev 3889) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/model/ScoresServiceLocal.java 2006-04-21 17:14:54 UTC (rev 3890) @@ -0,0 +1,45 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or 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 software 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 software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.forge.status.service.model; + +import java.util.Date; +import java.util.List; + +import org.jboss.forge.common.projects.Projects; +import org.jboss.forge.status.exceptions.GetScoresException; +import org.jboss.forge.status.exceptions.ScoresSaveException; + +/** +* @author Pawel Wrzeszcz (pawel.wrzeszcz [at] gmail.com) +*/ +public interface ScoresServiceLocal { + + public PluginsValues getPluginsValues(String portalName, + Date date) throws GetScoresException; + + public void save(Projects projects, List<PluginConf> pluginsConf, + String portalName) throws ScoresSaveException; + + public PluginValues get(String portalName, String pluginId, Date date) + throws GetScoresException; +} \ No newline at end of file Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/templates/CellTemplate.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/templates/CellTemplate.java 2006-04-21 16:27:16 UTC (rev 3889) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/templates/CellTemplate.java 2006-04-21 17:14:54 UTC (rev 3890) @@ -26,7 +26,7 @@ import java.util.List; import org.jboss.forge.common.XmlTools; -import org.jboss.forge.status.tools.PluginsValues; +import org.jboss.forge.status.service.model.PluginsValues; import org.jboss.forge.status.tools.Tags; import org.jboss.portal.common.context.DelegateContext; Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/templates/Column.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/templates/Column.java 2006-04-21 16:27:16 UTC (rev 3889) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/templates/Column.java 2006-04-21 17:14:54 UTC (rev 3890) @@ -28,7 +28,7 @@ import org.jboss.forge.common.projects.Projects; import org.jboss.forge.common.projects.permissions.NullPermissionsChecker; -import org.jboss.forge.status.tools.PluginValues; +import org.jboss.forge.status.service.model.PluginValues; import org.jboss.forge.status.tools.ProjectsByScoreComparator; import org.jboss.logging.Logger; import org.jboss.portal.common.context.DelegateContext; Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/templates/Columns.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/templates/Columns.java 2006-04-21 16:27:16 UTC (rev 3889) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/templates/Columns.java 2006-04-21 17:14:54 UTC (rev 3890) @@ -34,8 +34,10 @@ import org.jboss.forge.common.projects.permissions.NullPermissionsChecker; import org.jboss.forge.common.projects.permissions.PermissionsChecker; -import org.jboss.forge.status.tools.PluginValues; -import org.jboss.forge.status.tools.PluginsValues; +import org.jboss.forge.status.service.impl.PluginValuesImpl; +import org.jboss.forge.status.service.impl.PluginsValuesImpl; +import org.jboss.forge.status.service.model.PluginValues; +import org.jboss.forge.status.service.model.PluginsValues; import org.jboss.forge.status.tools.ProjectsByNameComparator; import org.jboss.forge.status.tools.ProjectsByScoreComparator; import org.jboss.forge.status.tools.Tags; Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/templates/MatrixTemplate.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/templates/MatrixTemplate.java 2006-04-21 16:27:16 UTC (rev 3889) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/templates/MatrixTemplate.java 2006-04-21 17:14:54 UTC (rev 3890) @@ -27,7 +27,7 @@ import org.jboss.forge.common.XmlTools; import org.jboss.forge.common.projects.Projects; -import org.jboss.forge.status.tools.PluginsValues; +import org.jboss.forge.status.service.model.PluginsValues; import org.jboss.forge.status.tools.Tags; import org.jboss.portal.common.context.DelegateContext; Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/templates/MetricTemplate.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/templates/MetricTemplate.java 2006-04-21 16:27:16 UTC (rev 3889) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/templates/MetricTemplate.java 2006-04-21 17:14:54 UTC (rev 3890) @@ -22,8 +22,8 @@ package org.jboss.forge.status.templates; -import org.jboss.forge.status.tools.PluginValues; -import org.jboss.forge.status.tools.PluginsValues; +import org.jboss.forge.status.service.model.PluginValues; +import org.jboss.forge.status.service.model.PluginsValues; import org.jboss.forge.status.tools.Tags; import org.jboss.forge.common.XmlTools; import org.jboss.portal.common.context.DelegateContext; Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/templates/RowTemplate.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/templates/RowTemplate.java 2006-04-21 16:27:16 UTC (rev 3889) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/templates/RowTemplate.java 2006-04-21 17:14:54 UTC (rev 3890) @@ -26,7 +26,7 @@ import java.util.ArrayList; import org.jboss.forge.common.XmlTools; -import org.jboss.forge.status.tools.PluginsValues; +import org.jboss.forge.status.service.model.PluginsValues; import org.jboss.forge.status.tools.Tags; import org.jboss.portal.common.context.DelegateContext; Deleted: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/PluginConf.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/PluginConf.java 2006-04-21 16:27:16 UTC (rev 3889) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/PluginConf.java 2006-04-21 17:14:54 UTC (rev 3890) @@ -1,113 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2005, JBoss Inc., and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This is free software; you can redistribute it and/or 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 software 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 software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ - -package org.jboss.forge.status.tools; - -import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -import org.jboss.forge.common.XmlTools; -import org.jboss.forge.status.exceptions.InvalidPluginsConfigurationException; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** -* @author Pawel Wrzeszcz -*/ -public class PluginConf implements Serializable { - - private static final long serialVersionUID = 8598887068548048511L; - - private Map<String,String> fields = new HashMap<String,String>(); - private Properties properties = new Properties(); - - public... [truncated message content] |
From: <jbo...@li...> - 2006-04-21 16:27:28
|
Author: wrzep Date: 2006-04-21 12:27:16 -0400 (Fri, 21 Apr 2006) New Revision: 3889 Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/exceptions/GetScoresException.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/exceptions/ScoresSaveException.java Removed: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/exceptions/PluginValueNotFoundException.java Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/Last7DaysStatusPlugin.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresService.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceImpl.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceLocal.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/PluginsValues.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/ScoresManager.java Log: JBLAB-599 Pawel Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java 2006-04-21 16:04:43 UTC (rev 3888) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java 2006-04-21 16:27:16 UTC (rev 3889) @@ -37,12 +37,12 @@ import org.jboss.forge.common.XmlTools; import org.jboss.forge.status.exceptions.InvalidPluginsConfigurationException; -import org.jboss.forge.status.exceptions.PluginValueNotFoundException; +import org.jboss.forge.status.exceptions.GetScoresException; +import org.jboss.forge.status.exceptions.ScoresSaveException; import org.jboss.forge.status.templates.Column; import org.jboss.forge.status.templates.Columns; import org.jboss.forge.status.templates.MatrixTemplate; import org.jboss.forge.status.tools.PluginConf; -import org.jboss.forge.status.tools.Plugins; import org.jboss.forge.status.tools.PluginsValues; import org.jboss.forge.status.tools.ScoresManager; import org.jboss.forge.status.tools.Tags; @@ -63,11 +63,8 @@ private Columns mainPageColumns; /** Matrix to display on the project specyfic page */ - private MatrixTemplate matrixTemplate; + private MatrixTemplate matrixTemplate; - /** Plugins used in the Status Matrix */ - private Plugins plugins; - /** Projects present in the Status Matrix */ private Projects projects; @@ -94,24 +91,21 @@ ScoresManager scoresManager = new ScoresManager(portalName); // Compute and save current scores - boolean b = scoresManager.save(projects, pluginsConf); + scoresManager.save(projects, pluginsConf); - // <debug> - System.out.print("save: " + b); - System.out.println("** class: " + pluginsConf); - System.out.println("** item class: " + pluginsConf.get(0)); - System.out.println("** item x: " + pluginsConf.get(0).getFieldValue("x")); - + // <debug>; long v = scoresManager.getValue("downloads", "jbosswiki", new Date(), new Date()); System.out.println("value = " + v); // </debug> pluginsValues = scoresManager.getCurrentScores(); - } catch (PluginValueNotFoundException e) { - - e.printStackTrace(); //TODO log msg + } catch (ScoresSaveException e) { + log.error("Saving scores failed ", e); return; + } catch (GetScoresException e) { + log.error("Getting computed scores failed ", e); + return; } // Get columns to display on the main page Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/exceptions/GetScoresException.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/exceptions/GetScoresException.java 2006-04-21 16:04:43 UTC (rev 3888) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/exceptions/GetScoresException.java 2006-04-21 16:27:16 UTC (rev 3889) @@ -0,0 +1,42 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or 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 software 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 software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.forge.status.exceptions; + +/** +* @author Pawel Wrzeszcz (paw...@gm...) +* Indicates that searching for saved scores failed. +*/ + +public class GetScoresException extends Exception { + + private static final long serialVersionUID = 7291136165537810321L; + + public GetScoresException() { + super(); + } + + public GetScoresException(Exception e) { + super(e); + } + +} Deleted: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/exceptions/PluginValueNotFoundException.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/exceptions/PluginValueNotFoundException.java 2006-04-21 16:04:43 UTC (rev 3888) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/exceptions/PluginValueNotFoundException.java 2006-04-21 16:27:16 UTC (rev 3889) @@ -1,38 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2005, JBoss Inc., and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This is free software; you can redistribute it and/or 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 software 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 software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ - -package org.jboss.forge.status.exceptions; - -/** -* @author Pawel Wrzeszcz (paw...@gm...) -* Indicates that searching for value stored in PluginsValues failed. -*/ - -public class PluginValueNotFoundException extends Exception { - - private static final long serialVersionUID = 1L; - - public PluginValueNotFoundException() { - super(); - } - -} Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/exceptions/ScoresSaveException.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/exceptions/ScoresSaveException.java 2006-04-21 16:04:43 UTC (rev 3888) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/exceptions/ScoresSaveException.java 2006-04-21 16:27:16 UTC (rev 3889) @@ -0,0 +1,38 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or 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 software 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 software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.forge.status.exceptions; + +/** +* @author Pawel Wrzeszcz (paw...@gm...) +* Indicates that computing or saving scores failed. +*/ + +public class ScoresSaveException extends Exception { + + private static final long serialVersionUID = 7291136165537810321L; + + public ScoresSaveException(Exception e) { + super(e); + } + +} Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/Last7DaysStatusPlugin.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/Last7DaysStatusPlugin.java 2006-04-21 16:04:43 UTC (rev 3888) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/Last7DaysStatusPlugin.java 2006-04-21 16:27:16 UTC (rev 3889) @@ -28,7 +28,7 @@ import org.jboss.forge.common.projects.Projects; import org.jboss.forge.status.exceptions.InvalidPluginPropertiesException; -import org.jboss.forge.status.exceptions.PluginValueNotFoundException; +import org.jboss.forge.status.exceptions.GetScoresException; import org.jboss.forge.status.tools.Plugins; import org.jboss.forge.status.tools.ScoresManager; @@ -85,7 +85,7 @@ try { prevValue = scoresManager.getValue( insidePlugin.getId(), projectId, prev,now); - } catch (PluginValueNotFoundException e) { + } catch (GetScoresException e) { return 0; } Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresService.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresService.java 2006-04-21 16:04:43 UTC (rev 3888) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresService.java 2006-04-21 16:27:16 UTC (rev 3889) @@ -26,7 +26,8 @@ import java.util.List; import org.jboss.forge.common.projects.Projects; -import org.jboss.forge.status.exceptions.PluginValueNotFoundException; +import org.jboss.forge.status.exceptions.GetScoresException; +import org.jboss.forge.status.exceptions.ScoresSaveException; import org.jboss.forge.status.tools.PluginConf; import org.jboss.forge.status.tools.PluginValues; import org.jboss.forge.status.tools.PluginsValues; @@ -38,11 +39,11 @@ public interface ScoresService { public PluginsValues getPluginsValues(String portalName, - Date date) throws PluginValueNotFoundException; + Date date) throws GetScoresException; - public boolean save(Projects projects, List<PluginConf> pluginsConf, - String portalName); + public void save(Projects projects, List<PluginConf> pluginsConf, + String portalName) throws ScoresSaveException; - public PluginValues get(String portalName, Date date) - throws PluginValueNotFoundException; + public PluginValues get(String portalName, String pluginId, Date date) + throws GetScoresException; } \ No newline at end of file Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceImpl.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceImpl.java 2006-04-21 16:04:43 UTC (rev 3888) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceImpl.java 2006-04-21 16:27:16 UTC (rev 3889) @@ -42,7 +42,8 @@ import org.jboss.forge.common.projects.Projects; -import org.jboss.forge.status.exceptions.PluginValueNotFoundException; +import org.jboss.forge.status.exceptions.GetScoresException; +import org.jboss.forge.status.exceptions.ScoresSaveException; import org.jboss.forge.status.tools.PluginConf; import org.jboss.forge.status.tools.PluginValues; import org.jboss.forge.status.tools.Plugins; @@ -83,27 +84,37 @@ * @param portalName * @return true iff saving was successful */ - public boolean save(Projects projects, List<PluginConf> pluginsConf, - String portalName) {//TODO exception instead of boolean - + public void save(Projects projects, List<PluginConf> pluginsConf, + String portalName) throws ScoresSaveException { + + // Get plugins from conf Plugins plugins = new Plugins(pluginsConf, portalName, projects); // Get directory where we store historical scores - Directory dir = getDir(cm.getRootDirectory(), - Tools.getShotokuStatusPath(portalName)); + Directory rootDir = cm.getRootDirectory(); + String dirName = Tools.getShotokuStatusPath(portalName); + Directory dir = getDir(rootDir, dirName); - if (dir == null) { - return false; - } - // Get plugin values and save them in proper node PluginsValues pluginsValues = new PluginsValues(projects, plugins); - Node node = getNode(dir, getCurrentNodeName(), true); + // Get node to store scores + String nodeName = getCurrentNodeName(); + Node node = null; + try { + node = dir.getNode(nodeName); + } catch (RepositoryException e) { + log.error("Error while getting shotoku node: " + + dir.getFullName() + "/" + nodeName, e); + throw new ScoresSaveException(e); + } catch (ResourceDoesNotExist e) { + node = createNode(dir, nodeName); + } + + // Save values and store then in cache values.put(getCurrentNodeName(), pluginsValues); - - return save(node, pluginsValues); + save(node, pluginsValues); } /** @@ -141,10 +152,10 @@ * Notice that only year, month and day matter in passed dates. * * @return scores from the given date - * @throws PluginValueNotFoundException + * @throws GetScoresException */ public PluginsValues getPluginsValues(String portalName, Date date) - throws PluginValueNotFoundException { + throws GetScoresException { // null date means today if (date == null) { @@ -157,8 +168,16 @@ if (v == null) { // Not in cache => get value and store it - Directory dir = getDir(cm.getRootDirectory(), - Tools.getShotokuStatusPath(portalName)); + Directory rootDir = cm.getRootDirectory(); + + Directory dir; + try { + dir = rootDir.getDirectory(Tools.getShotokuStatusPath(portalName)); + } catch (RepositoryException e) { + throw new GetScoresException(e); + } catch (ResourceDoesNotExist e) { + throw new GetScoresException(e); + } if (dir != null) { v = getPluginsValues(dir, date); @@ -174,74 +193,50 @@ * * @param dir Directory to read scores from * @return + * @throws GetScoresException */ - private PluginsValues getPluginsValues(Directory dir, Date date) { + private PluginsValues getPluginsValues(Directory dir, Date date) + throws GetScoresException { - Node node = getNode(dir, getNodeName(date), false); - if (node == null) { - return null; + // Get appropriate node + Node node = null; + String nodeName = getNodeName(date); + + try { + node = dir.getNode(nodeName); + } catch (Exception e) { + log.error("Error while getting shotoku node " + + dir.getFullName() + "/" + nodeName); + throw new GetScoresException(e); } + // Restore values PluginsValues values = null; - try { InputStream is = node.getContentInputStream(); ObjectInputStream ois = new ObjectInputStream(is); values = (PluginsValues) ois.readObject(); ois.close(); is.close(); - } catch (IOException e) { - e.printStackTrace(); - } catch (ClassNotFoundException e) { - e.printStackTrace(); + } catch (Exception e) { + log.error("Error while restoring scores from shotoku node " + + dir.getFullName() + "/" + nodeName); + throw new GetScoresException(e); } return values; } /** - * Gets shotoku Node with name <code>nodeName</code> from specified - * shotoku Directory. - * If <code>createIdNotExist</code> flag is set, - * when node does not exist it is created. - * - * @param dir Directory where search will be performed - * @param nodeName name of searched Node - * @param createIfNotExist If this flag is set, new Node is created, - * when node with specified name does not exist. - * @return Node with the given name - * or null if such Node does not exist - * and <code>createIfNotExist</code> was not set. - * Null is also returned when creating Node failed. - */ - private Node getNode(Directory dir, String nodeName, - boolean createIfNotExist) { - - Node node = null; - - try { - node = dir.getNode(nodeName); - } catch (RepositoryException e) { - log.error("Failed to get shotoku node: " + - dir.getFullName() + "/" + nodeName, e); - } catch (ResourceDoesNotExist e) { - - if (createIfNotExist) { - node = createNode(dir, nodeName); - } - } - - return node; - } - - /** * Creates new shotoku Node. * * @param dir Directory in which new Node will be created * @param nodeName name of new Node - * @return Node or null if errors occured + * @return Node + * @throws ScoresSaveException */ - private Node createNode(Directory dir, String nodeName) { + private Node createNode(Directory dir, String nodeName) + throws ScoresSaveException { Node node = null; @@ -251,6 +246,7 @@ } catch (Exception e) { log.error("Error while creating shotoku node: " + dir.getFullName() + "/" + nodeName, e); + throw new ScoresSaveException(e); } return node; @@ -265,8 +261,10 @@ * @param dirName name of searched Directory * @return Directory with the given name * or null when creating Directory failed. + * @throws ScoresSaveException */ - private Directory getDir(Directory rootDir, String dirName) { + private Directory getDir(Directory rootDir, String dirName) + throws ScoresSaveException { Directory dir = null; @@ -275,6 +273,7 @@ } catch (RepositoryException e) { log.error("Error while getting shotoku directory " + rootDir.getFullName() + "/" + dirName); + throw new ScoresSaveException(e); } catch (ResourceDoesNotExist e) { dir = createDir(rootDir, dirName); } @@ -288,8 +287,10 @@ * @param rootDir Directory in which new subdirectory will be created * @param dirName name of new Directory * @return Directory or null if errors occured + * @throws ScoresSaveException */ - private Directory createDir(Directory rootDir, String dirName) { + private Directory createDir(Directory rootDir, String dirName) + throws ScoresSaveException { Directory dir = null; @@ -299,6 +300,7 @@ } catch (Exception e) { log.error("Error while creating shotoku directory: " + rootDir.getFullName() + "/" + dirName, e); + throw new ScoresSaveException(e); } return dir; @@ -329,8 +331,11 @@ return getNodeName(today); } - public PluginValues get(String portalName, Date date) throws PluginValueNotFoundException { - return ((PluginsValues)getPluginsValues(portalName, date)).getPluginValues("downloads"); + public PluginValues get(String portalName, String pluginId, Date date) + throws GetScoresException { + + PluginsValues pv = getPluginsValues(portalName, date); + return pv.getPluginValues(pluginId); } } Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceLocal.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceLocal.java 2006-04-21 16:04:43 UTC (rev 3888) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceLocal.java 2006-04-21 16:27:16 UTC (rev 3889) @@ -26,7 +26,8 @@ import java.util.List; import org.jboss.forge.common.projects.Projects; -import org.jboss.forge.status.exceptions.PluginValueNotFoundException; +import org.jboss.forge.status.exceptions.GetScoresException; +import org.jboss.forge.status.exceptions.ScoresSaveException; import org.jboss.forge.status.tools.PluginConf; import org.jboss.forge.status.tools.PluginValues; import org.jboss.forge.status.tools.PluginsValues; @@ -37,11 +38,11 @@ public interface ScoresServiceLocal { public PluginsValues getPluginsValues(String portalName, - Date date) throws PluginValueNotFoundException; + Date date) throws GetScoresException; - public boolean save(Projects projects, List<PluginConf> pluginsConf, - String portalName); + public void save(Projects projects, List<PluginConf> pluginsConf, + String portalName) throws ScoresSaveException; - public PluginValues get(String portalName, Date date) - throws PluginValueNotFoundException; + public PluginValues get(String portalName, String pluginId, Date date) + throws GetScoresException; } \ No newline at end of file Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/PluginsValues.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/PluginsValues.java 2006-04-21 16:04:43 UTC (rev 3888) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/PluginsValues.java 2006-04-21 16:27:16 UTC (rev 3889) @@ -33,7 +33,7 @@ import org.jboss.forge.common.projects.Projects; import org.jboss.forge.common.projects.permissions.NullPermissionsChecker; -import org.jboss.forge.status.exceptions.PluginValueNotFoundException; +import org.jboss.forge.status.exceptions.GetScoresException; import org.jboss.forge.status.plugins.Plugin; /** @@ -80,11 +80,11 @@ * @param pluginId plugin id * @param projectId project id * @return stored plugin value for specified project - * @throws PluginValueNotFoundException + * @throws GetScoresException * Thrown when requested value was not found */ public long getPluginValue(String pluginId, String projectId) - throws PluginValueNotFoundException { + throws GetScoresException { Long val = null; PluginValues pluginValues = values.get(pluginId); @@ -94,7 +94,7 @@ } if (val == null) { - throw new PluginValueNotFoundException(); + throw new GetScoresException(); } return val; Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/ScoresManager.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/ScoresManager.java 2006-04-21 16:04:43 UTC (rev 3888) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/ScoresManager.java 2006-04-21 16:27:16 UTC (rev 3889) @@ -26,10 +26,13 @@ import java.util.List; import javax.management.MBeanServer; +import javax.management.MalformedObjectNameException; import org.jboss.forge.common.projects.Projects; -import org.jboss.forge.status.exceptions.PluginValueNotFoundException; +import org.jboss.forge.status.exceptions.GetScoresException; +import org.jboss.forge.status.exceptions.ScoresSaveException; import org.jboss.forge.status.service.ScoresService; + import org.jboss.mx.util.MBeanProxyExt; import org.jboss.mx.util.MBeanServerLocator; @@ -40,32 +43,33 @@ public class ScoresManager { private String portalName; - + public ScoresManager(String portalName) { this.portalName = portalName; } - public boolean save(Projects projects, List<PluginConf> pluginsConf) { + public void save(Projects projects, List<PluginConf> pluginsConf) + throws ScoresSaveException { - try { + MBeanServer server = MBeanServerLocator.locate(); - ScoresService service = (ScoresService) MBeanProxyExt.create( - ScoresService.class, - Tools.STATUS_SERVICE_NAME, - server); + ScoresService service; + try { + service = (ScoresService) MBeanProxyExt.create( + ScoresService.class, + Tools.STATUS_SERVICE_NAME, + server); + } catch (MalformedObjectNameException e) { + throw new ScoresSaveException(e); + } - return service.save(projects, pluginsConf, portalName); + service.save(projects, pluginsConf, portalName); - } catch (Exception e) { - e.printStackTrace (); //TODO log msg - } - - return false; } public PluginsValues getScores(Date date, Date toDate) - throws PluginValueNotFoundException { + throws GetScoresException { PluginsValues pluginsValues = null; @@ -84,10 +88,10 @@ } if (pluginsValues == null) { - throw new PluginValueNotFoundException(); + throw new GetScoresException(); } - return null; + return pluginsValues; } /** @@ -100,11 +104,11 @@ * Notice that only year, month and day matter in passed dates. * * @return project score from the given date for specified plugin - * @throws PluginValueNotFoundException + * @throws GetScoresException */ public long getValue(String pluginId, String projectId, Date date, Date toDate) - throws PluginValueNotFoundException { + throws GetScoresException { PluginsValues pluginsValues = getScores(date, toDate); @@ -112,7 +116,7 @@ } public PluginsValues getCurrentScores() - throws PluginValueNotFoundException { + throws GetScoresException { Date now = new Date(); |
From: <jbo...@li...> - 2006-04-21 16:05:10
|
Author: adamw Date: 2006-04-21 12:04:43 -0400 (Fri, 21 Apr 2006) New Revision: 3888 Added: labs/jbosslabs/trunk/portal-extensions/forge-theme/jbossForgeLayout.war/WEB-INF/layout/portal-strategies.xml labs/jbosslabs/trunk/portal-extensions/forge-theme/src/java/org/jboss/portal/core/theme/render/impl/JBFStrategyImpl.java Modified: labs/jbosslabs/trunk/portal-extensions/forge-theme/jbossForgeLayout.war/WEB-INF/portal-layouts.xml labs/jbosslabs/trunk/portal-extensions/portal-default/src/web/WEB-INF/default-object.xml Log: http://jira.jboss.com/jira/browse/JBLAB-656 Administration fix Added: labs/jbosslabs/trunk/portal-extensions/forge-theme/jbossForgeLayout.war/WEB-INF/layout/portal-strategies.xml =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-theme/jbossForgeLayout.war/WEB-INF/layout/portal-strategies.xml 2006-04-21 15:01:45 UTC (rev 3887) +++ labs/jbosslabs/trunk/portal-extensions/forge-theme/jbossForgeLayout.war/WEB-INF/layout/portal-strategies.xml 2006-04-21 16:04:43 UTC (rev 3888) @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<portal-strategies> + <set name="jbfStrategy"> + <strategy content-type="text/html"> + <implementation>org.jboss.portal.theme.impl.strategy.JBFStrategyImpl</implementation> + </strategy> + </set> +</portal-strategies> Modified: labs/jbosslabs/trunk/portal-extensions/forge-theme/jbossForgeLayout.war/WEB-INF/portal-layouts.xml =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-theme/jbossForgeLayout.war/WEB-INF/portal-layouts.xml 2006-04-21 15:01:45 UTC (rev 3887) +++ labs/jbosslabs/trunk/portal-extensions/forge-theme/jbossForgeLayout.war/WEB-INF/portal-layouts.xml 2006-04-21 16:04:43 UTC (rev 3888) @@ -2,5 +2,13 @@ <layout> <name>JBossForge</name> <uri>/layouts/jbossForge.jsp</uri> + <uri state="maximized">/layouts/jbossForge.jsp</uri> + <regions> + <region name="left"/> + <region name="center"/> + <region name="right"/> + <region name="innerleft"/> + <region name="innerright"/> + </regions> </layout> </layouts> \ No newline at end of file Added: labs/jbosslabs/trunk/portal-extensions/forge-theme/src/java/org/jboss/portal/core/theme/render/impl/JBFStrategyImpl.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-theme/src/java/org/jboss/portal/core/theme/render/impl/JBFStrategyImpl.java 2006-04-21 15:01:45 UTC (rev 3887) +++ labs/jbosslabs/trunk/portal-extensions/forge-theme/src/java/org/jboss/portal/core/theme/render/impl/JBFStrategyImpl.java 2006-04-21 16:04:43 UTC (rev 3888) @@ -0,0 +1,173 @@ +/* +* JBoss, Home of Professional Open Source +* Copyright 2005, JBoss Inc., and individual contributors as indicated +* by the @authors tag. See the copyright.txt in the distribution for a +* full listing of individual contributors. +* +* This is free software; you can redistribute it and/or 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 software 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 software; if not, write to the Free +* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +* 02110-1301 USA, or see the FSF site: http://www.fsf.org. +*/ +package org.jboss.portal.theme.impl.strategy; + +import org.apache.log4j.Logger; +import org.jboss.portal.WindowState; +import org.jboss.portal.common.MediaType; +import org.jboss.portal.theme.ThemeException; +import org.jboss.portal.theme.page.PortletContext; +import org.jboss.portal.theme.strategy.AbstractLayoutStrategy; +import org.jboss.portal.theme.strategy.StrategyContext; +import org.jboss.portal.theme.strategy.StrategyException; +import org.jboss.portal.theme.strategy.StrategyResponse; + +import java.util.ArrayList; +import java.util.Iterator; + +/* + * + * @author <a href="mailto:mho...@no...">Martin Holzner</a> + * @version $Revision: 1.2.4.1 $ +*/ +public class JBFStrategyImpl extends AbstractLayoutStrategy +{ + private static Logger log = Logger.getLogger(JBFStrategyImpl.class); + + public JBFStrategyImpl() + { + setMediaType(MediaType.HTML); + } + + /** + * Evaluate the strategy and return a strategy response, containing the desired changes. + * + * @param context a context containing the portal's current information about portlets, states and the layout + * @return a strategy response with the desired changes + * @throws org.jboss.portal.theme.strategy.StrategyException + * if the strategy is missconfigured, or can't deal with the provided information + */ + public StrategyResponse evaluate(StrategyContext context) throws StrategyException + { + if (context == null) + { + throw new NullPointerException("strategy context is null"); + } + + if (context.getLayout() == null) + { + throw new IllegalArgumentException("Strategy can only be evaluated with a valid layout provided."); + } + + log.debug("evaluating strategy for: " + context.getLayout().getName()); + + StrategyResponse response = context.createResponse(); + + ArrayList maximizedPortlets = new ArrayList(); + + // get the list of portlets and their window state, and check if one of the + // portlets is maximized + for (Iterator i = context.getPortletContexts().iterator(); i.hasNext();) + { + PortletContext portlet = (PortletContext)i.next(); + log.debug("evaluating portlet: " + portlet.getWindowID()); + try + { + if (WindowState.MAXIMIZED.equals(portlet.getWindowState())) + { + log.debug("found maximized portlet: " + portlet); + maximizedPortlets.add(portlet); + } + else + { + // exclude all, but the maximized portlet, from the render process +// response.addNoRender(portlet); + // exclude all but the maximized portlet, and those in the left/right regions + if ((!"left".equalsIgnoreCase(portlet.getRegionName())) && +(!"right".equalsIgnoreCase(portlet.getRegionName())) && +(!"innerleft".equalsIgnoreCase(portlet.getRegionName())) && +(!"innerright".equalsIgnoreCase(portlet.getRegionName()))) + { + response.addNoRender(portlet); + } + } + } + catch (ThemeException e) + { + // window state not known + log.warn(e); + response.addNoRender(portlet); + } + } + // if there is at least one portlet with maximized window state, then + // switch the layout to the maximized layout, and + // flag all portlets that are not part of the header region (except the maximized one) as 'do-not-render' + // Note: it's better to flag them as do not render than to set their window states to minimized, since that + // could be interpreted differently on the layout / theme + // if one of the portlets is in maximized mode, then use the maximized layout + if (maximizedPortlets.size() > 0) + { + PortletContext targetPortlet = context.getTargetPortlet(); + // there can only be one maximized portlet! when in doubt, the targeted portlet wins + if (targetPortlet != null && maximizedPortlets.size() > 1) + { + try + { + if (maximizedPortlets.contains(targetPortlet) && + WindowState.MAXIMIZED.equals(targetPortlet.getWindowState())) + { + for (Iterator i = maximizedPortlets.iterator(); i.hasNext();) + { + PortletContext portlet = (PortletContext)i.next(); + if (!portlet.equals(targetPortlet)) + { + log.debug("resetting maximized portlet to normal (there can only be one): " + portlet + " " + + targetPortlet + " will be maximized"); + // change the window state back to normal, and make sure the + // portlet is not rendered + response.addWindowStateChange(portlet, WindowState.NORMAL); + response.addNoRender(portlet); + } + else + { + // move the maximized portlet to the maximized region + portlet.setRegionName(WindowState.MAXIMIZED.toString()); + } + } + } + } + catch (ThemeException e) + { + // the target portlet's state isn't known (portlet was deregistered?) , so exclude it + response.addNoRender(targetPortlet); + } + } + else + { + // move the maximized portlet to the maximized region + //PortletContext portlet = (PortletContext)maximizedPortlets.get(0); + //portlet.setRegionName(WindowState.MAXIMIZED.toString()); + } + + // set the layout state so that the interceptor can check if there is another uri specified in the layout for this state + response.setLayoutState(WindowState.MAXIMIZED.toString()); + maximizedPortlets.clear(); + } + else + { + // if there is no maximized portlet, then clean up (forget about the norender list) + response.reset(); + } + + return response; + } +} Modified: labs/jbosslabs/trunk/portal-extensions/portal-default/src/web/WEB-INF/default-object.xml =================================================================== --- labs/jbosslabs/trunk/portal-extensions/portal-default/src/web/WEB-INF/default-object.xml 2006-04-21 15:01:45 UTC (rev 3887) +++ labs/jbosslabs/trunk/portal-extensions/portal-default/src/web/WEB-INF/default-object.xml 2006-04-21 16:04:43 UTC (rev 3888) @@ -24,7 +24,7 @@ <!-- Set the default strategy name (used by the strategy interceptor), see also portal-strategies.xml --> <property> <name>layout.strategyId</name> - <value>maximizedRegion</value> + <value>jbfStrategy</value> </property> <!-- The default page name, if the property is not explicited then the default page name is "default" --> <property> |
From: <jbo...@li...> - 2006-04-21 15:01:58
|
Author: tirelli Date: 2006-04-21 11:01:45 -0400 (Fri, 21 Apr 2006) New Revision: 3887 Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsNot.drl Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java Log: JBRULES-233: * Adding another integration test on LogicalAssertions Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java 2006-04-21 14:47:25 UTC (rev 3886) +++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java 2006-04-21 15:01:45 UTC (rev 3887) @@ -1570,6 +1570,45 @@ assertEquals("Exactly six events", 6, events.size()); } + public void xxxtestLogicalAssertionsNot() throws Exception { + PackageBuilder builder = new PackageBuilder(); + builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_LogicalAssertionsNot.drl" ) ) ); + Package pkg = builder.getPackage(); + + RuleBase ruleBase = getRuleBase(); + ruleBase.addPackage( pkg ); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + + List list; + + String a = new String("a"); + Integer i = new Integer(1); + workingMemory.setGlobal( "i", i ); + + workingMemory.fireAllRules(); + list = workingMemory.getObjects(); + assertEquals("i was not asserted by not a => i.", 1, list.size()); + assertEquals("i was not asserted by not a => i.", i, list.get(0)); + + FactHandle h = workingMemory.assertObject(a); + //no need to fire rules, assertion alone removes justification for i, so it should be retracted. + //workingMemory.fireAllRules(); + list = workingMemory.getObjects(); + assertEquals("a was not asserted or i not retracted.", 1, list.size()); + assertEquals("a was asserted.", a, list.get(0)); + assertFalse("i was not rectracted.", list.contains(i)); + + //no rules should fire, but nevertheless... + //workingMemory.fireAllRules(); + assertEquals("agenda should be empty.", 0, workingMemory.getAgenda().agendaSize()); + + workingMemory.retractObject(h); + workingMemory.fireAllRules(); + list = workingMemory.getObjects(); + assertEquals("i was not asserted by not a => i.", 1, list.size()); + assertEquals("i was not asserted by not a => i.", i, list.get(0)); + } + private Object serializeIn(byte[] bytes) throws IOException, ClassNotFoundException { ObjectInput in = new ObjectInputStream( new ByteArrayInputStream( bytes ) ); Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsNot.drl =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsNot.drl 2006-04-21 14:47:25 UTC (rev 3886) +++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsNot.drl 2006-04-21 15:01:45 UTC (rev 3887) @@ -0,0 +1,13 @@ +package org.drools.test; + +import java.lang.String; +import java.lang.Integer; + +global java.lang.Integer i; + +rule "r" + when + not String() + then + assertLogical(i); +end \ No newline at end of file Property changes on: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsNot.drl ___________________________________________________________________ Name: svn:executable + * Name: svn:eol-style + native |
From: <jbo...@li...> - 2006-04-21 14:48:08
|
Author: tirelli Date: 2006-04-21 10:47:25 -0400 (Fri, 21 Apr 2006) New Revision: 3886 Added: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/Alarm.java labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/EmergencyTeam.java labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/Sensor.java labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertions2.drl labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsBacking.drl labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsLoop.drl labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsNoLoop.drl labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsSelfreferencing.drl Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/Person.java labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertions.drl labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/WorkingMemoryImpl.java labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java Log: JBRULES-233: * Fixing problems described in the ticket, related to logical assertions * Adding unit tests and integration tests Added: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/Alarm.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/Alarm.java 2006-04-21 12:19:44 UTC (rev 3885) +++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/Alarm.java 2006-04-21 14:47:25 UTC (rev 3886) @@ -0,0 +1,38 @@ +package org.drools; + +public class Alarm { + private String message; + + public Alarm(String message) { + this.message = message; + } + + public String toString() { + return this.message; + } + + /** + * @inheritDoc + */ + public int hashCode() { + final int PRIME = 31; + int result = 1; + result = PRIME * result + ((message == null) ? 0 : message.hashCode()); + return result; + } + + /** + * @inheritDoc + */ + public boolean equals(Object obj) { + if ( this == obj ) return true; + if ( obj == null ) return false; + if ( getClass() != obj.getClass() ) return false; + final Alarm other = (Alarm) obj; + if ( message == null ) { + if ( other.message != null ) return false; + } else if ( !message.equals( other.message ) ) return false; + return true; + } + +} Property changes on: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/Alarm.java ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + id author date revision Name: svn:eol-style + native Added: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/EmergencyTeam.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/EmergencyTeam.java 2006-04-21 12:19:44 UTC (rev 3885) +++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/EmergencyTeam.java 2006-04-21 14:47:25 UTC (rev 3886) @@ -0,0 +1,5 @@ +package org.drools; + +public class EmergencyTeam { + +} Property changes on: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/EmergencyTeam.java ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + id author date revision Name: svn:eol-style + native Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/Person.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/Person.java 2006-04-21 12:19:44 UTC (rev 3885) +++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/Person.java 2006-04-21 14:47:25 UTC (rev 3886) @@ -84,4 +84,36 @@ public String toString() { return "[Person name='" + this.name + "']"; } + + + /** + * @inheritDoc + */ + public int hashCode() { + final int PRIME = 31; + int result = 1; + result = PRIME * result + age; + result = PRIME * result + (alive ? 1231 : 1237); + result = PRIME * result + ((name == null) ? 0 : name.hashCode()); + result = PRIME * result + sex; + return result; + } + + + /** + * @inheritDoc + */ + public boolean equals(Object obj) { + if ( this == obj ) return true; + if ( obj == null ) return false; + if ( getClass() != obj.getClass() ) return false; + final Person other = (Person) obj; + if ( age != other.age ) return false; + if ( alive != other.alive ) return false; + if ( name == null ) { + if ( other.name != null ) return false; + } else if ( !name.equals( other.name ) ) return false; + if ( sex != other.sex ) return false; + return true; + } } \ No newline at end of file Added: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/Sensor.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/Sensor.java 2006-04-21 12:19:44 UTC (rev 3885) +++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/Sensor.java 2006-04-21 14:47:25 UTC (rev 3886) @@ -0,0 +1,44 @@ +package org.drools; + +public class Sensor { + private int temperature; + private int pressure; + + public Sensor(int temp, int press) { + this.temperature = temp; + this.pressure = press; + } + + /** + * @return the pressure + */ + public int getPressure() { + return pressure; + } + + /** + * @param pressure the pressure to set + */ + public void setPressure(int pressure) { + this.pressure = pressure; + } + + /** + * @return the temperature + */ + public int getTemperature() { + return temperature; + } + + /** + * @param temperature the temperature to set + */ + public void setTemperature(int temperature) { + this.temperature = temperature; + } + + public String toString() { + return "Sensor [ temperature = "+this.temperature+", pressure = "+this.pressure+" ]"; + } + +} Property changes on: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/Sensor.java ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + id author date revision Name: svn:eol-style + native Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java 2006-04-21 12:19:44 UTC (rev 3885) +++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java 2006-04-21 14:47:25 UTC (rev 3886) @@ -38,7 +38,9 @@ import org.drools.Person; import org.drools.QueryResults; import org.drools.RuleBase; +import org.drools.Sensor; import org.drools.WorkingMemory; +import org.drools.audit.WorkingMemoryFileLogger; import org.drools.compiler.DrlParser; import org.drools.compiler.DroolsError; import org.drools.compiler.PackageBuilder; @@ -1005,37 +1007,6 @@ list.get( 7 ) ); } - public void testLogicalAssertions() throws Exception { - PackageBuilder builder = new PackageBuilder(); - builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_LogicalAssertions.drl" ) ) ); - Package pkg = builder.getPackage(); - - RuleBase ruleBase = getRuleBase(); - ruleBase.addPackage( pkg ); - WorkingMemory workingMemory = ruleBase.newWorkingMemory(); - - List list = new ArrayList(); - workingMemory.setGlobal( "list", - list ); - - Cheese brie = new Cheese( "brie", - 12 ); - FactHandle brieHandle = workingMemory.assertObject( brie ); - - workingMemory.fireAllRules(); - - assertEquals( 2, - list.size() ); - - assertEquals( 2, - workingMemory.getObjects().size() ); - - workingMemory.retractObject( brieHandle ); - - assertEquals( 0, - workingMemory.getObjects().size() ); - } - public void testDuration() throws Exception { PackageBuilder builder = new PackageBuilder(); builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_Duration.drl" ) ) ); @@ -1405,6 +1376,200 @@ assertEquals( "match Person 3", rules[2].getName() ); } + public void testLogicalAssertions() throws Exception { + PackageBuilder builder = new PackageBuilder(); + builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_LogicalAssertions.drl" ) ) ); + Package pkg = builder.getPackage(); + + RuleBase ruleBase = getRuleBase(); + ruleBase.addPackage( pkg ); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + + List list = new ArrayList(); + workingMemory.setGlobal( "list", + list ); + + Cheese brie = new Cheese( "brie", + 12 ); + FactHandle brieHandle = workingMemory.assertObject( brie ); + + Cheese provolone = new Cheese( "provolone", + 12 ); + FactHandle provoloneHandle = workingMemory.assertObject( provolone ); + + workingMemory.fireAllRules(); + + assertEquals( 3, + list.size() ); + + assertEquals( 3, + workingMemory.getObjects().size() ); + + workingMemory.retractObject( brieHandle ); + + assertEquals( 2, + workingMemory.getObjects().size() ); + + workingMemory.retractObject( provoloneHandle ); + + assertEquals( 0, + workingMemory.getObjects().size() ); + } + + public void xxxtestLogicalAssertionsBacking() throws Exception { + PackageBuilder builder = new PackageBuilder(); + builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_LogicalAssertionsBacking.drl" ) ) ); + Package pkg = builder.getPackage(); + + RuleBase ruleBase = getRuleBase(); + ruleBase.addPackage( pkg ); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + + Cheese cheese1 = new Cheese("c", 1); + Cheese cheese2 = new Cheese(cheese1.getType(), 1); + List list; + + FactHandle h1 = workingMemory.assertObject( cheese1 ); + workingMemory.fireAllRules(); + list = workingMemory.getObjects(cheese1.getType().getClass()); + assertEquals(1, list.size()); + //probably dangerous, as contains works with equals, not identity + assertEquals(cheese1.getType(), list.get(0)); + //FactHandle ht = workingMemory.getFactHandle(c1.getType()); + + FactHandle h2 = workingMemory.assertObject( cheese2 ); + workingMemory.fireAllRules(); + list = workingMemory.getObjects(cheese1.getType().getClass()); + assertEquals(1, list.size()); + assertEquals(cheese1.getType(), list.get(0)); + + workingMemory.retractObject(h1); + workingMemory.fireAllRules(); + list = workingMemory.getObjects(cheese1.getType().getClass()); + assertEquals("cheese-type " + cheese1.getType() + " was retracted, but should not. Backed by cheese2 => type.", 1, list.size()); + assertEquals("cheese-type " + cheese1.getType() + " was retracted, but should not. Backed by cheese2 => type.", cheese1.getType(), list.get(0)); + + workingMemory.retractObject(h2); + workingMemory.fireAllRules(); + list = workingMemory.getObjects(cheese1.getType().getClass()); + assertEquals("cheese-type " + cheese1.getType() + " was not retracted, but should have. Neither cheese1 => type nor cheese2 => type is true.", 0, list.size()); + } + + public void xxxtestLogicalAssertionsSelfreferencing() throws Exception { + PackageBuilder builder = new PackageBuilder(); + builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_LogicalAssertionsSelfreferencing.drl" ) ) ); + Package pkg = builder.getPackage(); + + RuleBase ruleBase = getRuleBase(); + ruleBase.addPackage( pkg ); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + + List list; + + String b = new String("b"); + String a = new String("a"); + + workingMemory.setGlobal( "b", b ); + + FactHandle h1 = workingMemory.assertObject( a ); + workingMemory.fireAllRules(); + list = workingMemory.getObjects(a.getClass()); + assertEquals(2, list.size()); + assertTrue(list.contains(a)); + assertTrue(list.contains(b)); + + workingMemory.retractObject(h1); + workingMemory.fireAllRules(); + list = workingMemory.getObjects(a.getClass()); + assertEquals("b was retracted, but it should not have. Is backed by b => b being true.", 1, list.size()); + assertEquals("b was retracted, but it should not have. Is backed by b => b being true.", b, list.get(0)); + + h1 = workingMemory.getFactHandle(b); + workingMemory.retractObject(h1); + workingMemory.fireAllRules(); + list = workingMemory.getObjects(a.getClass()); + assertEquals(0, list.size()); + } + + public void xxxtestLogicalAssertionsLoop() throws Exception { + PackageBuilder builder = new PackageBuilder(); + builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_LogicalAssertionsLoop.drl" ) ) ); + Package pkg = builder.getPackage(); + + RuleBase ruleBase = getRuleBase(); + ruleBase.addPackage( pkg ); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + + List list; + + List l = new ArrayList(); + String a = new String("a"); + workingMemory.setGlobal( "a", a ); + workingMemory.setGlobal( "l", l ); + + workingMemory.fireAllRules(); + list = workingMemory.getObjects(a.getClass()); + assertEquals("a still asserted.", 0, list.size()); + assertEquals("Rule has not fired (looped) expected number of times", 10, l.size()); + } + + public void xxxtestLogicalAssertionsNoLoop() throws Exception { + PackageBuilder builder = new PackageBuilder(); + builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_LogicalAssertionsNoLoop.drl" ) ) ); + Package pkg = builder.getPackage(); + + RuleBase ruleBase = getRuleBase(); + ruleBase.addPackage( pkg ); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + + List list; + + List l = new ArrayList(); + String a = new String("a"); + workingMemory.setGlobal( "a", a ); + workingMemory.setGlobal( "l", l ); + + workingMemory.fireAllRules(); + list = workingMemory.getObjects(a.getClass()); + assertEquals("a not asserted.", 1, list.size()); + assertEquals("a not asserted", a, list.get(0)); + assertEquals("Rule should not loop", 1, l.size()); + } + + public void xxxtestLogicalAssertions2() throws Exception { + PackageBuilder builder = new PackageBuilder(); + builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_LogicalAssertions2.drl" ) ) ); + Package pkg = builder.getPackage(); + + RuleBase ruleBase = getRuleBase(); + ruleBase.addPackage( pkg ); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + + List events = new ArrayList(); + + workingMemory.setGlobal( "events", events ); + + Sensor sensor = new Sensor(80, 80); + FactHandle handle = workingMemory.assertObject( sensor ); + + // everything should be normal + workingMemory.fireAllRules(); + + List list = workingMemory.getObjects(); + + assertEquals("Only sensor is there", 1, list.size()); + assertEquals("Only one event", 1, events.size()); + + // problems should be detected + sensor.setPressure( 200 ); + sensor.setTemperature( 200 ); + workingMemory.modifyObject( handle, sensor ); + + workingMemory.fireAllRules(); + assertEquals("Only sensor is there", 1, list.size()); + assertEquals("Exactly six events", 6, events.size()); + } + private Object serializeIn(byte[] bytes) throws IOException, ClassNotFoundException { ObjectInput in = new ObjectInputStream( new ByteArrayInputStream( bytes ) ); Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertions.drl =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertions.drl 2006-04-21 12:19:44 UTC (rev 3885) +++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertions.drl 2006-04-21 14:47:25 UTC (rev 3886) @@ -5,14 +5,22 @@ global java.util.List list; -rule justifier +rule justifier1 when - cheese : Cheese( ) + cheese : Cheese( type == "brie" ) then assertLogical( new Person( "jane" ) ); list.add( cheese ); end +rule justifier2 + when + cheese : Cheese( type == "provolone" ) + then + assertLogical( new Person( "jane" ) ); + list.add( cheese ); +end + rule justified when person : Person( ) Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertions2.drl =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertions2.drl 2006-04-21 12:19:44 UTC (rev 3885) +++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertions2.drl 2006-04-21 14:47:25 UTC (rev 3886) @@ -0,0 +1,50 @@ +package org.drools.test; + +import org.drools.Alarm; +import org.drools.EmergencyTeam; +import org.drools.Sensor; + +global java.util.List events; + +rule "Everything is Normal" + when + not Alarm( ) + then + events.add("Everything is Normal"); +end + +rule "Problem detected" salience 10 + when + sensor : Sensor( temperature > 100 ) or Sensor( pressure > 150 ) + then + events.add( "Problem detected: "+sensor.toString() ); + assertLogical( new Alarm( "Call emergency team" ) ); +end + +rule "Call Emergency Team" + when + Alarm ( ) + then + events.add( "Calling Emergency Team" ); + assertLogical( new EmergencyTeam() ); +end + +rule "Emergency Team solves temperature" salience 20 + when + EmergencyTeam() + sensor : Sensor( temperature > 100 ) + then + events.add( "Solving temperature problem" ); + sensor.setTemperature(80); + modify(sensor); +end + +rule "Emergency Team solves pressure" salience 20 + when + EmergencyTeam() + sensor : Sensor( pressure > 150 ) + then + events.add( "Solving pressure problem" ); + sensor.setPressure(80); + modify(sensor); +end Property changes on: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertions2.drl ___________________________________________________________________ Name: svn:executable + * Name: svn:eol-style + native Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsBacking.drl =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsBacking.drl 2006-04-21 12:19:44 UTC (rev 3885) +++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsBacking.drl 2006-04-21 14:47:25 UTC (rev 3886) @@ -0,0 +1,10 @@ +package org.drools.test; + +import org.drools.Cheese; + +rule "Cheese => type" + when + Cheese( type : type ) + then + assertLogical( type ); +end \ No newline at end of file Property changes on: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsBacking.drl ___________________________________________________________________ Name: svn:executable + * Name: svn:eol-style + native Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsLoop.drl =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsLoop.drl 2006-04-21 12:19:44 UTC (rev 3885) +++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsLoop.drl 2006-04-21 14:47:25 UTC (rev 3886) @@ -0,0 +1,18 @@ +package org.drools.test; + +import java.lang.String; +import java.util.List; + +global java.lang.String a; +global java.util.List l; + +rule "r" + when + not String() + then + if (l.size() < 10) + { + l.add(new Integer(0)); + assertLogical( a ); + } +end \ No newline at end of file Property changes on: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsLoop.drl ___________________________________________________________________ Name: svn:executable + * Name: svn:eol-style + native Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsNoLoop.drl =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsNoLoop.drl 2006-04-21 12:19:44 UTC (rev 3885) +++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsNoLoop.drl 2006-04-21 14:47:25 UTC (rev 3886) @@ -0,0 +1,20 @@ +package org.drools.test; + +import java.lang.String; +import java.util.List; + +global java.lang.String a; +global java.util.List l; + +rule "r" + no-loop true + when + not String() + then + l.add(new Integer(0)); + if (l.size() > 2) + { + throw new Exception( "this should not loop" ); + } + assertLogical( a ); +end \ No newline at end of file Property changes on: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsNoLoop.drl ___________________________________________________________________ Name: svn:executable + * Name: svn:eol-style + native Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsSelfreferencing.drl =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsSelfreferencing.drl 2006-04-21 12:19:44 UTC (rev 3885) +++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsSelfreferencing.drl 2006-04-21 14:47:25 UTC (rev 3886) @@ -0,0 +1,11 @@ +package org.drools.test; + +global java.lang.String b; +import java.lang.String; + +rule "String => b" + when + s : String() + then + assertLogical( b ); +end Property changes on: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsSelfreferencing.drl ___________________________________________________________________ Name: svn:executable + * Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/WorkingMemoryImpl.java =================================================================== --- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/WorkingMemoryImpl.java 2006-04-21 12:19:44 UTC (rev 3885) +++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/WorkingMemoryImpl.java 2006-04-21 14:47:25 UTC (rev 3886) @@ -103,7 +103,11 @@ private Map queryResults = Collections.EMPTY_MAP; + /** Support for logical assertions */ private static final String STATED = "STATED"; + private static final String JUSTIFIED = "JUSTIFIED"; + private static final String NEW = "NEW"; + private static final FactStatus STATUS_NEW = new FactStatus(NEW, 0); /** The eventSupport */ private final WorkingMemoryEventSupport workingMemoryEventSupport = new WorkingMemoryEventSupport( this ); @@ -425,27 +429,40 @@ boolean logical, Rule rule, Activation activation) throws FactException { + // check if the object already exists in the WM FactHandleImpl handle = (FactHandleImpl) this.identityMap.get( object ); - // return if the handle exists and this is a logical assertion - if ( (handle != null) && (logical) ) { - return handle; + // lets see if the object is already logical asserted + FactStatus logicalState = (FactStatus) this.equalsMap.get( object ); + if(logicalState == null) { + logicalState = STATUS_NEW; } - // lets see if the object is already logical asserted - Object logicalState = this.equalsMap.get( object ); + // This object is already STATED, we cannot make it justifieable + if ( (logical) && (logicalState.getStatus() == WorkingMemoryImpl.STATED) ) { + return null; + } + // return if there is already a logical handle + if ( (logical) && (logicalState.getStatus() == WorkingMemoryImpl.JUSTIFIED) ) { + addLogicalDependency( logicalState.getHandle(), + activation, + activation.getPropagationContext(), + rule ); + return logicalState.getHandle(); + } + // if we have a handle and this STATED fact was previously STATED - if ( (handle != null) && (!logical) && logicalState == WorkingMemoryImpl.STATED ) { + if ( (handle != null) && (!logical) && ( logicalState.getStatus() == WorkingMemoryImpl.STATED ) ) { return handle; } if ( !logical ) { // If this stated assertion already has justifications then we need // to cancel them - if ( logicalState instanceof FactHandleImpl ) { - handle = (FactHandleImpl) logicalState; + if ( logicalState.getStatus() == WorkingMemoryImpl.JUSTIFIED ) { + handle = logicalState.getHandle(); removeLogicalDependencies( handle ); } else { handle = (FactHandleImpl) newFactHandle(); @@ -454,19 +471,21 @@ putObject( handle, object ); - this.equalsMap.put( object, - WorkingMemoryImpl.STATED ); + if( logicalState != WorkingMemoryImpl.STATUS_NEW) { + // make sure status is stated + logicalState.setStatus( WorkingMemoryImpl.STATED ); + logicalState.incCounter(); + } else { + this.equalsMap.put( object, + new FactStatus(WorkingMemoryImpl.STATED, 1) ); + } if ( dynamic ) { addPropertyChangeListener( object ); } } else { - // This object is already STATED, we cannot make it justifieable - if ( logicalState == WorkingMemoryImpl.STATED ) { - return null; - } - handle = (FactHandleImpl) logicalState; + handle = logicalState.getHandle(); // we create a lookup handle for the first asserted equals object // all future equals objects will use that handle if ( handle == null ) { @@ -476,8 +495,8 @@ object ); this.equalsMap.put( object, - handle ); - } + new FactStatus(WorkingMemoryImpl.JUSTIFIED, handle) ); + } addLogicalDependency( handle, activation, activation.getPropagationContext(), @@ -614,11 +633,17 @@ /* check to see if this was a logical asserted object */ if ( removeLogical ) { removeLogicalDependencies( handle ); - this.equalsMap.remove( oldObject ); + //this.equalsMap.remove( oldObject ); } - if ( updateEqualsMap ) { - this.equalsMap.remove( oldObject ); + if ( removeLogical || updateEqualsMap ) { + FactStatus status = (FactStatus) this.equalsMap.get( oldObject ); + if(status != null) { + status.decCounter(); + if(status.getCounter() <= 0) { + this.equalsMap.remove( oldObject ); + } + } } this.factHandlePool.push( ((FactHandleImpl) handle).getId() ); @@ -661,7 +686,7 @@ if ( this.justified.get( handleImpl.getId() ) != null ) { this.equalsMap.remove( originalObject ); this.equalsMap.put( object, - handle ); + new FactStatus(WorkingMemoryImpl.JUSTIFIED, handleImpl) ); } PropagationContext propagationContext = new PropagationContextImpl( this.propagationIdCounter++, @@ -812,4 +837,78 @@ public void dispose() { this.ruleBase.disposeWorkingMemory( this ); } + + private static class FactStatus { + private int counter; + private String status; + private FactHandleImpl handle; + + public FactStatus() { + this(WorkingMemoryImpl.STATED, 1); + } + + public FactStatus(String status) { + this(status, 1); + } + + public FactStatus(String status, FactHandleImpl handle) { + this.status = status; + this.handle = handle; + } + + public FactStatus(String status, int counter) { + this.status = status; + this.counter = counter; + } + + /** + * @return the counter + */ + public int getCounter() { + return counter; + } + /** + * @param counter the counter to set + */ + public void setCounter(int counter) { + this.counter = counter; + } + + public int incCounter() { + return ++counter; + } + + public int decCounter() { + return --counter; + } + /** + * @return the handle + */ + public FactHandleImpl getHandle() { + return handle; + } + /** + * @param handle the handle to set + */ + public void setHandle(FactHandleImpl handle) { + this.handle = handle; + } + /** + * @return the status + */ + public String getStatus() { + return status; + } + /** + * @param status the status to set + */ + public void setStatus(String status) { + this.status = status; + } + + public String toString() { + return "FactStatus( "+this.status+", handle="+this.handle+", counter="+this.counter+")"; + } + + } } Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java =================================================================== --- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java 2006-04-21 12:19:44 UTC (rev 3885) +++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java 2006-04-21 14:47:25 UTC (rev 3886) @@ -285,7 +285,7 @@ // Alreyad identify same so return previously assigned handle logicalHandle1 = workingMemory.assertObject( logicalString2, false, - true, + false, rule1, tuple1.getActivation() ); // return the matched handle @@ -507,5 +507,96 @@ assertLength( 0, workingMemory.getJustified().values() ); } + + /** + * This tests that when multiple not identical, but equals facts, are asserted + * into WM, only when all are removed, a logical assert will succeed + * + * @throws Exception + */ + public void testMultipleAssert() throws Exception { + // create a RuleBase with a single ObjectTypeNode we attach a + // MockObjectSink so we can detect assertions and retractions + final Rule rule1 = new Rule( "test-rule1" ); + Rete rete = new Rete(); + ObjectTypeNode objectTypeNode = new ObjectTypeNode( 0, + new ClassObjectType( String.class ), + rete ); + objectTypeNode.attach(); + MockObjectSink sink = new MockObjectSink(); + objectTypeNode.addObjectSink( sink ); + final TerminalNode node = new TerminalNode( 2, + new MockTupleSource( 2 ), + rule1 ); + RuleBase ruleBase = new RuleBaseImpl(); + WorkingMemoryImpl workingMemory = (WorkingMemoryImpl) ruleBase.newWorkingMemory(); + final Agenda agenda = workingMemory.getAgenda(); + + Consequence consequence = new Consequence() { + public void evaluate(KnowledgeHelper knowledgeHelper, + WorkingMemory workingMemory) { + // do nothing + } + }; + rule1.setConsequence( consequence ); + + FactHandleImpl handle1 = new FactHandleImpl( 1 ); + ReteTuple tuple1 = new ReteTuple( handle1 ); + + final PropagationContext context1 = new PropagationContextImpl( 0, + PropagationContext.ASSERTION, + null, + null ); + + // Assert multiple stated objects + node.assertTuple( tuple1, + context1, + workingMemory ); + + String statedString1 = new String( "logical" ); + FactHandle statedHandle1 = workingMemory.assertObject( statedString1 ); + + String statedString2 = new String( "logical" ); + FactHandle statedHandle2 = workingMemory.assertObject( statedString2 ); + + // This assertion is logical should fail as there is previous stated objects + String logicalString3 = new String( "logical" ); + FactHandle logicalHandle3 = workingMemory.assertObject( logicalString3, + false, + true, + rule1, + tuple1.getActivation() ); + + // Checks that previous LogicalAssert failed + assertNull( logicalHandle3 ); + + workingMemory.retractObject( statedHandle2 ); + + logicalHandle3 = workingMemory.assertObject( logicalString3, + false, + true, + rule1, + tuple1.getActivation() ); + + // Checks that previous LogicalAssert failed as there is still one + // stated string in the working memory + assertNull( logicalHandle3 ); + + workingMemory.retractObject( statedHandle1 ); + + logicalHandle3 = workingMemory.assertObject( logicalString3, + false, + true, + rule1, + tuple1.getActivation() ); + + // Checks that previous LogicalAssert succeeded as there are no more + // stated strings in the working memory + assertNotNull( logicalHandle3 ); + + } + + + } \ No newline at end of file |
From: <jbo...@li...> - 2006-04-21 12:19:52
|
Author: KrisVerlaenen Date: 2006-04-21 08:19:44 -0400 (Fri, 21 Apr 2006) New Revision: 3885 Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/ReteViewer.java Log: fixed an error when trying to run AWT in SWT in Mac Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/ReteViewer.java =================================================================== --- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/ReteViewer.java 2006-04-21 12:04:04 UTC (rev 3884) +++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/ReteViewer.java 2006-04-21 12:19:44 UTC (rev 3885) @@ -18,6 +18,7 @@ import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; import org.eclipse.swt.SWT; +import org.eclipse.swt.SWTError; import org.eclipse.swt.awt.SWT_AWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; @@ -65,10 +66,16 @@ } }); - Composite frameParent = new Composite(parent, SWT.EMBEDDED); - frameParent.setLayoutData(new GridData(GridData.FILL_BOTH)); - frame = SWT_AWT.new_Frame(frameParent); - frame.setLayout(new BorderLayout()); + try { + Composite frameParent = new Composite(parent, SWT.EMBEDDED); + frameParent.setLayoutData(new GridData(GridData.FILL_BOTH)); + frame = SWT_AWT.new_Frame(frameParent); + frame.setLayout(new BorderLayout()); + } catch (SWTError exc) { + // it is possible that this exception is thrown if + // SWT is not supported, e.g. in Mac + DroolsIDEPlugin.log(exc); + } } private RuleBase getRuleBase() { @@ -127,7 +134,9 @@ } public void clear() { - frame.removeAll(); + if (frame != null) { // possible if frame creation failed + frame.removeAll(); + } } public boolean isDirty() { @@ -145,21 +154,23 @@ } private void generateReteView() { - clear(); - try { - RuleBase ruleBase = getRuleBase(); - if (ruleBase == null) { - // TODO signal user that rule cannot be parsed - } else { - ReteooJungViewerPanel viewer = new ReteooJungViewerPanel( - ruleBase); - frame.add(viewer); - frame.validate(); - parent.layout(); + if (frame != null) { // possible if frame creation failed + clear(); + try { + RuleBase ruleBase = getRuleBase(); + if (ruleBase == null) { + // TODO signal user that rule cannot be parsed + } else { + ReteooJungViewerPanel viewer = new ReteooJungViewerPanel( + ruleBase); + frame.add(viewer); + frame.validate(); + parent.layout(); + } + } catch (Throwable t) { + t.printStackTrace(); + DroolsIDEPlugin.log(t); } - } catch (Throwable t) { - t.printStackTrace(); - DroolsIDEPlugin.log(t); } } } |
From: <jbo...@li...> - 2006-04-21 12:04:09
|
Author: woolfel Date: 2006-04-21 08:04:04 -0400 (Fri, 21 Apr 2006) New Revision: 3884 Modified: labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/GenerateRuleSet.java labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformanceTest.java Log: updated the rule generator and performance test so I can run tests with 2k rules and 1 to 3 conditions per rule. peter Modified: labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/GenerateRuleSet.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/GenerateRuleSet.java 2006-04-21 11:47:56 UTC (rev 3883) +++ labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/GenerateRuleSet.java 2006-04-21 12:04:04 UTC (rev 3884) @@ -4,13 +4,91 @@ public class GenerateRuleSet { - /** + String linebreak = System.getProperty("line.separator"); + String tab = " "; + + /** * */ public GenerateRuleSet() { super(); } + public void generate3Condition(String outputFile, int count) { + try { + FileWriter writer = new FileWriter(outputFile); + StringBuffer buf = new StringBuffer(); + // delcare the package + buf.append("package org.drools.samples" + linebreak); + buf.append("import com.sample.benchmark.models.Account;" + linebreak + linebreak); + // now loop + for (int idx=0; idx < count; idx++) { + buf.append("rule rule" + idx + "" + linebreak); + buf.append(" when" + linebreak); + buf.append(" $acc : Account(status == \"standard\", title == \"mr\", accountId == \"acc" + idx + + "\")" + linebreak); + buf.append(" then" + linebreak); + buf.append(" System.out.println(\"rule" + idx + " fired\");" + linebreak); + buf.append("end" + linebreak + linebreak); + } + writer.write(buf.toString()); + writer.close(); + System.out.println("Generated " + count + " rules to " + outputFile); + } catch (Exception e) { + + } + } + + public void generate2Condition(String outputFile, int count) { + try { + FileWriter writer = new FileWriter(outputFile); + StringBuffer buf = new StringBuffer(); + // delcare the package + buf.append("package org.drools.samples" + linebreak); + buf.append("import com.sample.benchmark.models.Account;" + linebreak + linebreak); + // now loop + for (int idx=0; idx < count; idx++) { + buf.append("rule rule" + idx + "" + linebreak); + buf.append(" when" + linebreak); + buf.append(" $acc : Account(status == \"standard\", accountId == \"acc" + idx + + "\")" + linebreak); + buf.append(" then" + linebreak); + buf.append(" System.out.println(\"rule" + idx + " fired\");" + linebreak); + buf.append("end" + linebreak + linebreak); + } + writer.write(buf.toString()); + writer.close(); + System.out.println("Generated " + count + " rules to " + outputFile); + } catch (Exception e) { + + } + } + + public void generateOneCondition(String outputFile, int count) { + try { + FileWriter writer = new FileWriter(outputFile); + StringBuffer buf = new StringBuffer(); + // delcare the package + buf.append("package org.drools.samples" + linebreak); + buf.append("import com.sample.benchmark.models.Account;" + linebreak + linebreak); + // now loop + for (int idx=0; idx < count; idx++) { + buf.append("rule rule" + idx + "" + linebreak); + buf.append(" when" + linebreak); + buf.append(" $acc : Account(accountId == \"acc" + idx + + "\")" + linebreak); + buf.append(" then" + linebreak); + buf.append(" System.out.println(\"rule" + idx + " fired\");" + linebreak); + buf.append("end" + linebreak + linebreak); + } + writer.write(buf.toString()); + writer.close(); + System.out.println("Generated " + count + " rules to " + outputFile); + } catch (Exception e) { + + } + } + public static void main(String[] args) { // the number of rules int count = 100; @@ -19,38 +97,26 @@ if (args == null || args.length < 1) { // print out a message of the options System.out.println("No parameters were set. Please provide a rule count"); - System.out.println("and filename."); + System.out.println("filename, ruleType: 1, 2 or 3."); System.out.println(""); - System.out.println("example: GenerateRuleSet 1000 1000rules.drl"); + System.out.println("example: GenerateRuleSet 1000 1000rules.drl 1"); } else { if (args[0] != null) { count = Integer.parseInt(args[0]); outputFile = args[1]; } - String linebreak = System.getProperty("line.separator"); - String tab = " "; - try { - FileWriter writer = new FileWriter(outputFile); - StringBuffer buf = new StringBuffer(); - // delcare the package - buf.append("package org.drools.samples" + linebreak); - buf.append("import com.sample.benchmark.models.Account;" + linebreak + linebreak); - // now loop - for (int idx=0; idx < count; idx++) { - buf.append("rule rule" + idx + "" + linebreak); - buf.append(" when" + linebreak); - buf.append(" $acc : Account(status == \"standard\", title == \"mr\", accountId == \"acc" + idx + - "\")" + linebreak); - buf.append(" then" + linebreak); - buf.append(" System.out.println(\"rule" + idx + " fired\");" + linebreak); - buf.append("end" + linebreak + linebreak); - } - writer.write(buf.toString()); - writer.close(); - System.out.println("Generated " + count + " rules to " + outputFile); - } catch (Exception e) { - + int type = 1; + if (args[2] != null) { + type = Integer.parseInt(args[2]); } + GenerateRuleSet grs = new GenerateRuleSet(); + if (type == 3) { + grs.generate3Condition(outputFile,count); + } else if (type == 2) { + grs.generate2Condition(outputFile, count); + } else { + grs.generateOneCondition(outputFile,count); + } } } Modified: labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformanceTest.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformanceTest.java 2006-04-21 11:47:56 UTC (rev 3883) +++ labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformanceTest.java 2006-04-21 12:04:04 UTC (rev 3884) @@ -234,4 +234,173 @@ e.printStackTrace(); } } + + /** + * + * + */ + public void test2KRuleFire() { + try { + int factCount = 50000; + String file = "2000_rules_1condition.drl"; + int loop = 5; + long totalload = 0; + long totalassert = 0; + long totalfire = 0; + for (int c=0; c < loop; c++) { + long loadStart = System.currentTimeMillis(); + RuleBase ruleBase = readRule(file); + long loadEnd = System.currentTimeMillis(); + long loadet = loadEnd - loadStart; + totalload += loadet; + System.out.println("time to load " + file + + " " + loadet + "ms"); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + ArrayList objects = new ArrayList(); + // create the objects + for (int idx=0; idx < factCount; idx++) { + Account acc = new Account(); + acc.setAccountId("acc"+idx); + acc.setTitle("mr"); + acc.setStatus("standard"); + objects.add(acc); + } + Iterator itr = objects.iterator(); + long assertStart = System.currentTimeMillis(); + while( itr.hasNext() ) { + workingMemory.assertObject(itr.next()); + } + long assertEnd = System.currentTimeMillis(); + long assertet = assertEnd - assertStart; + totalassert += assertet; + System.out.println("time to assert " + assertet + + " ms"); + long fireStart = System.currentTimeMillis(); + workingMemory.fireAllRules(); + long fireEnd = System.currentTimeMillis(); + long fireet = fireEnd - fireStart; + totalfire += fireet; + System.out.println("time to fireAllRules " + fireet + + " ms"); + workingMemory.dispose(); + } + System.out.println(file); + System.out.println("number of objects asserted " + factCount); + System.out.println("average load " + (totalload/loop) + " ms"); + System.out.println("average assert " + (totalassert/loop) + " ms"); + System.out.println("average fire " + (totalfire/loop) + " ms"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void test2KRuleFire2Conditions() { + try { + int factCount = 50000; + String file = "2000_rules_2condition.drl"; + int loop = 5; + long totalload = 0; + long totalassert = 0; + long totalfire = 0; + for (int c=0; c < loop; c++) { + long loadStart = System.currentTimeMillis(); + RuleBase ruleBase = readRule(file); + long loadEnd = System.currentTimeMillis(); + long loadet = loadEnd - loadStart; + totalload += loadet; + System.out.println("time to load " + file + + " " + loadet + "ms"); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + ArrayList objects = new ArrayList(); + // create the objects + for (int idx=0; idx < factCount; idx++) { + Account acc = new Account(); + acc.setAccountId("acc"+idx); + acc.setTitle("mr"); + acc.setStatus("standard"); + objects.add(acc); + } + Iterator itr = objects.iterator(); + long assertStart = System.currentTimeMillis(); + while( itr.hasNext() ) { + workingMemory.assertObject(itr.next()); + } + long assertEnd = System.currentTimeMillis(); + long assertet = assertEnd - assertStart; + totalassert += assertet; + System.out.println("time to assert " + assertet + + " ms"); + long fireStart = System.currentTimeMillis(); + workingMemory.fireAllRules(); + long fireEnd = System.currentTimeMillis(); + long fireet = fireEnd - fireStart; + totalfire += fireet; + System.out.println("time to fireAllRules " + fireet + + " ms"); + workingMemory.dispose(); + } + System.out.println(file); + System.out.println("number of objects asserted " + factCount); + System.out.println("average load " + (totalload/loop) + " ms"); + System.out.println("average assert " + (totalassert/loop) + " ms"); + System.out.println("average fire " + (totalfire/loop) + " ms"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void test2KRuleFire3Conditions() { + try { + int factCount = 50000; + String file = "2000_rules_3condition.drl"; + int loop = 5; + long totalload = 0; + long totalassert = 0; + long totalfire = 0; + for (int c=0; c < loop; c++) { + long loadStart = System.currentTimeMillis(); + RuleBase ruleBase = readRule(file); + long loadEnd = System.currentTimeMillis(); + long loadet = loadEnd - loadStart; + totalload += loadet; + System.out.println("time to load " + file + + " " + loadet + "ms"); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + ArrayList objects = new ArrayList(); + // create the objects + for (int idx=0; idx < factCount; idx++) { + Account acc = new Account(); + acc.setAccountId("acc"+idx); + acc.setTitle("mr"); + acc.setStatus("standard"); + objects.add(acc); + } + Iterator itr = objects.iterator(); + long assertStart = System.currentTimeMillis(); + while( itr.hasNext() ) { + workingMemory.assertObject(itr.next()); + } + long assertEnd = System.currentTimeMillis(); + long assertet = assertEnd - assertStart; + totalassert += assertet; + System.out.println("time to assert " + assertet + + " ms"); + long fireStart = System.currentTimeMillis(); + workingMemory.fireAllRules(); + long fireEnd = System.currentTimeMillis(); + long fireet = fireEnd - fireStart; + totalfire += fireet; + System.out.println("time to fireAllRules " + fireet + + " ms"); + workingMemory.dispose(); + } + System.out.println(file); + System.out.println("number of objects asserted " + factCount); + System.out.println("average load " + (totalload/loop) + " ms"); + System.out.println("average assert " + (totalassert/loop) + " ms"); + System.out.println("average fire " + (totalfire/loop) + " ms"); + } catch (Exception e) { + e.printStackTrace(); + } + } } |
From: <jbo...@li...> - 2006-04-21 11:48:11
|
Author: mar...@jb... Date: 2006-04-21 07:47:56 -0400 (Fri, 21 Apr 2006) New Revision: 3883 Modified: labs/jbossrules/trunk/documentation/manual/en/Chapter-Install/Section-Setup.xml labs/jbossrules/trunk/documentation/manual/en/master.xml Log: -Added leaps docs from Alex Modified: labs/jbossrules/trunk/documentation/manual/en/Chapter-Install/Section-Setup.xml =================================================================== --- labs/jbossrules/trunk/documentation/manual/en/Chapter-Install/Section-Setup.xml 2006-04-21 10:55:37 UTC (rev 3882) +++ labs/jbossrules/trunk/documentation/manual/en/Chapter-Install/Section-Setup.xml 2006-04-21 11:47:56 UTC (rev 3883) @@ -5,7 +5,7 @@ <para>As Drools is an open source project, instructions for building from source are part of the manual ! Building from source means you can stay on top with the latest features. Whilst aspects of Drools are quite - complicated, many users have found ways to become contributors. </para> + complicated, many users have found ways to become contributors.</para> <para>Drools works with JDK1.4 and above. you will need also need to have the following tools installed. Minimum requirement version numbers @@ -15,7 +15,7 @@ <listitem> <para><indexterm> <primary>eclipse</primary> - </indexterm>Eclipse 3.2</para> + </indexterm>Eclipse 3.2 RC1</para> <para>http://www.eclipse.org/</para> </listitem> @@ -44,7 +44,7 @@ <listitem> <para><indexterm> <primary>Maven</primary> - </indexterm>Maven 2</para> + </indexterm>Maven 2.0.4</para> <para>http://maven.apache.org</para> </listitem> @@ -55,13 +55,13 @@ </indexterm>path. The examples given illustrative and are for a win32 system:</para> - <literallayout>Path=D:\java\j2sdk1.4.2_10\bin;C:\bin;D:\java\maven-2.0.3\bin;D:\java\apache-ant-1.6.5\bin;</literallayout> + <literallayout>Path=D:\java\j2sdk1.4.2_10\bin;C:\bin;D:\java\maven-2.0.4\bin;D:\java\apache-ant-1.6.5\bin;</literallayout> <para>Following environment variables will also need to be set. The examples given illustrative and are for a win32 system::</para> <literallayout>JAVA_HOME=D:\java\j2sdk1.4.2_10 -M2_HOME=D:\java\maven-2.0.1 +M2_HOME=D:\java\maven-2.0.4 M2_REPO=<your home directory>\.m2\repository ANT_HOME=D:\java\apache-ant-1.6.5 </literallayout> Modified: labs/jbossrules/trunk/documentation/manual/en/master.xml =================================================================== --- labs/jbossrules/trunk/documentation/manual/en/master.xml 2006-04-21 10:55:37 UTC (rev 3882) +++ labs/jbossrules/trunk/documentation/manual/en/master.xml 2006-04-21 11:47:56 UTC (rev 3883) @@ -72,7 +72,9 @@ <xi:include href="Chapter-Rule_Engine/Section-Why_use_a_Rule_Engine.xml" /> - <xi:include href="Chapter-Rule_Engine/Section-Rete_Algorithm.xml" /> + <xi:include href="Chapter-Rule_Engine/Section-Rete_Algorithm.xml" /> + + <xi:include href="Chapter-Rule_Engine/Section-Leaps_Algorithm.xml" /> <xi:include href="Chapter-Rule_Engine/Section-Rule_Base.xml" /> |
From: <jbo...@li...> - 2006-04-21 10:55:46
|
Author: mar...@jb... Date: 2006-04-21 06:55:37 -0400 (Fri, 21 Apr 2006) New Revision: 3882 Added: labs/jbossrules/updates/ Log: -added updates directory |
From: <jbo...@li...> - 2006-04-21 10:21:47
|
Author: mic...@jb... Date: 2006-04-21 06:21:39 -0400 (Fri, 21 Apr 2006) New Revision: 3881 Modified: labs/jbossrules/trunk/documentation/manual/en/master.xml Log: more documentation goodness Modified: labs/jbossrules/trunk/documentation/manual/en/master.xml =================================================================== --- labs/jbossrules/trunk/documentation/manual/en/master.xml 2006-04-21 10:19:58 UTC (rev 3880) +++ labs/jbossrules/trunk/documentation/manual/en/master.xml 2006-04-21 10:21:39 UTC (rev 3881) @@ -98,6 +98,8 @@ <xi:include href="Chapter-Rule_Language/Section-Query.xml" /> + <xi:include href="Chapter-Rule_Language/Section-DSL.xml" /> + <!--xi:include href="Chapter-Rule_Language/Section-Column.xml" /> <xi:include href="Chapter-Rule_Language/Section-Field_Constraints.xml" /> |