[rules-users] Drools Pattern Matching

hanumesh.m hanumesh.m at gmail.com
Wed Apr 2 02:22:24 EDT 2008


Hi,

  I am writing a rule which checks for the presence of substring in a
string. Hard coding rule works fine but if I am using variables which may
have dynamic values giving problems. How to write code equivalent of
hardcoding version.

HardCode verson :
-------------------
rule "Process 834"
	no-loop 
	when
		m: Message( fileName matches "^.*ABC-834.*$")
	then
		System.out.println( "Reading Rule for 834 ..." ); 
		m.setFromQ("ABC.834.EDI");
		m.setToQ("ABC.834.XML");
		m.setProcess("834");
		update( m );
end

Dynamic Version:
 //fileName has data 'ABC-834-test-100.edi'
// p.FILEMASK has data  'ABC-834'


----------------

rule "Process ALL" 
       no-loop                              
       when
	p: TransactionVO()
	m: Message( fileName matches p.FILEMASK)  // I can't say as (matches
"^.*"+p.FILEMASK+".*$")
             //the above st should be like if fileName has FILEMASK in it 
       then
 	System.out.println( "Reading Rule for ..." + p.NAME ); 
 	m.setFromQ(p.FROM_Q);
 	m.setToQ(p.TO_Q);
 	m.setProcess(p.TRANS_TYPE);
 	update( m );
end


-- 
View this message in context: http://www.nabble.com/Drools-Pattern-Matching-tp16442998p16442998.html
Sent from the drools - user mailing list archive at Nabble.com.




More information about the rules-users mailing list