[rules-users] Newbie on drools and servlets

Swindells, Thomas TSwindells at nds.com
Thu Apr 22 04:38:17 EDT 2010


As ever the answer is it depends on how you want to do it and where you want to put the logic.  I'm not convinced that necessarily need to use flow, instead just use a stateful knowledge session (one per client session).

Your servlet populate it with your constraints and whatever, runs a query on it to get the number of results and then the servlet code decides whether to return the results or request some refinement.  When the user submits the refinement form you fetch the session again, add the new constraint objects to the existing session and repeat (or just create a whole new session from scratch depending how you want to balance memory and performance).

As a refinement if you don't want to hardcode the logic then you could get your rules to populate a 'next page' status object and all the servlet code does is query the knowledge session to find out how it should respond.

If that logic starts to get complicated you could probably go down the flow approach, either refining the logic above (the flow always terminates each time and you start a new process, perhaps reusing the session) or you could look at using a custom work handler to send a response back to the request and then send in an event when you want processing to continue but this is probably more complicated than you need.

Thomas

> -----Original Message-----
> From: rules-users-bounces at lists.jboss.org [mailto:rules-users-
> bounces at lists.jboss.org] On Behalf Of kuena
> Sent: 22 April 2010 08:36
> To: rules-users at lists.jboss.org
> Subject: [rules-users] Newbie on drools and servlets
>
>
> Hi,
> I know a question has been asked before about drools and servlets, so I
> apologise in advance. May someone please advice me on the best way of making
> Drools and servlets friends in my application ;-) I want to use drools to
> re-implement the servlet shown below.  I have also attached the flow.
>
> In brief my scenario works as follows:
> User submits  a form to request info; result map is returned; if size >3
> refine else return  results.  Refine will require a page to be generated
> asking user how to refine. The user answer will then be used to generate
> result.
>
> I have a feeling I might just need to add another node (e.g. event wait or
> human task) between the refine action and the rule flow group node. Would
> want to avoid that but not sure how will resume flow after refine. I would
> be grateful for any pointers.
>
> http://n3.nabble.com/forum/FileDownload.jtp?type=n&id=742273&name=flow.png
>
> public class GeneratorServlet extends HttpServlet {
>     //declarations
>
>     protected void processRequest(HttpServletRequest request,
> HttpServletResponse response)
>     throws ServletException, IOException {
>         //declarations
>
>         if(request.getAttribute("resultsMap") != null){
>                map = (Map) request.getAttribute("resultsMap");
>                 //Render results i.e. present results to user if list is
> short
>                if(map.size() <= maxOutput){
>                 htmlPage.render(map, out, templatePath);
>                 }
>                 //list is long, ask  how to shorten the list
>                 else if (map.size() > maxOutput){
>                  dialogSession.setAttribute("storedResultsMap", map);
>                  htmlPage.refine(map, out, templatePath);
>                 }
>         }
>        else{ // resultsMap is null
>               if(dialogSession.getAttribute("storedResultsMap")!= null){
>                   map = (Map)
> dialogSession.getAttribute("storedResultsMap");
>                   String criteriaSelection =
> request.getParameter("refineChoice");
>
>                     if(criteriaSelection.equalsIgnoreCase("choice1")){
>                      htmlPage.render(choice1Map, out, templatePath);
>                     }
>                     else if(criteriaSelection.equalsIgnoreCase("choice2")){
>                      htmlPage.render(choice2Map, out, templatePath);
>                    }
>                    else {
>                       htmlPage.render(map, out, templatePath);
>                     }
>             }
>        }
>     }
>
> --
> View this message in context: http://drools-java-rules-
> engine.46999.n3.nabble.com/Newbie-on-drools-and-servlets-tp742273p742273.html
> Sent from the Drools - User mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users


**************************************************************************************
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmaster at nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary.

NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00
**************************************************************************************

This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmaster at nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes.
To protect the environment please do not print this e-mail unless necessary.

An NDS Group Limited company. www.nds.com




More information about the rules-users mailing list