rule "Hello World"
dialect "mvel"
when
m : Message( status == Message.HELLO, message : message )
then
System.out.println( message );
// modify ( m ) { setMessage( "Goodbyte cruel world" ),
// setStatus( Message.GOODBYE ) };
modify ( m ) { message = "Goodbye cruel world",
status = Message.GOODBYE };
end
rule "Good Bye"
dialect "java"
when
Message( status == Message.GOODBYE, message : message )
then
System.out.println( message );
end
@Service
@Transactional
public class RuleService {
private final Logger log = LoggerFactory.getLogger(RuleService.class);
@Autowired
private KieContainer kieContainer;
RuleService() {
}
public String ruleTest() {
log.debug("in ruleTest()");
KieSession ksession = this.kieContainer.newKieSession("PriceRulesKS");
ksession.setGlobal("list", new ArrayList<Object>());
final Message message = new Message();
message.setMessage("Hello World");
message.setStatus(Message.HELLO);
ksession.insert(message);
// and fire the rules
int ruleFiredCount = ksession.fireAllRules();
System.out.println("Rules checked: " + ruleFiredCount);
log.debug("Rules checked: " + ruleFiredCount);
ksession.dispose();
return message.getMessage();
}
}
=========================================================
And I have the following config
=========================================================
@Configuration
public class RuleConfiguration {
@Bean
public KieContainer kieContainer() throws IOException {
KieServices ks = KieServices.Factory.get();
return ks.getKieClasspathContainer();
}
}
=========================================================
For the following test environment, I was able to have 2 rules fired.
==========================================================
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SmartPriceApp.class)
@Transactional
public class RuleServiceIntTest {
@Autowired
private RuleService ruleService;
@Test
public void testRuleService() {
String msg = ruleService.ruleTest(); //Two rules are fired!
System.out.println(msg);
}
}
==========================================================
However, if I am using the spring rest controller, No rules were fired. I need your help.
==========================================================
@RestController
@RequestMapping("/api")
public class PriceResource {
private final RuleService ruleService;
public PriceResource(RuleService ruleService) {
this.ruleService = ruleService;
}
@PostMapping(path="/priceres")
public PriceResult priceres(@RequestBody RequestWrapper requestWrapper) {
System.out.println(requestWrapper.product);
System.out.println(requestWrapper.customer);
String msg = this.ruleService.ruleTest(); //No rules are fired!
return new PriceResult(234.7, msg);
}
}
==========================================================
--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/f5cd7be0-05c6-4677-95e4-b00b60886543%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.