[rules-users] Order of object creation in stateful session

Dean Whisnant dean at basys.com
Thu Jan 16 12:06:54 EST 2014


Hi,



This may be a very basic question, but I'm using drools 5.1.1 and when I invoke a stateful session and that session ends I receive back all of the facts that were created during that session and I translate those into an EDI transaction.  As an example I might have a few objects of types "2700*LX,2750* N1,2750* REF, and 2750*DTP".  I know my rules fired create objects like:



LX*1

N1*75*CMSEC

REF*17*A

DTP*007*D8*20140114

LX*2

N1*75*STATUS

REF*17*AFTNM

DTP*007*D8*20140114



Each of these lines is an object of the type I mentioned above.



My task is to make sure that the different object types "stick" together when I put them in the .x12 file so that they are formatted above.



What I do internally is I keep track that I have two of each of these objects, but I don't know if there is some type of timestamp that is on them that I could keep the first LX, N1, REF, DTP together or not.



In one example I have a rule that inserts them in the order you see, yes, it literally inserts 8 objects/facts into memory. And I need to know the order they were inserted so that I can properly form a file out of them on the backend.



Here's how I grab the objects and factHandle list.  Is there a method that might help me know what object was created by what rule and how I might keep facts created in a rule together?



                                // Get handle to all objects coming from drools

                                Collection<FactHandle> handleList = null;

                                try

                                {

                                                handleList = ksession.getFactHandles();

                                }

                                catch (Exception e)

                                {

                                                _log.error("kSession get Fact Handles. Error=" + e.getMessage());

                                }

// Build the List with the results from drools - objectOutList

                                Object anObject;

                                TranslatedObjectImpl aTranslatedObject;

                                FactHandle fH;



                                for (Iterator<FactHandle> it = handleList.iterator(); it.hasNext();)

                                {

                                                fH = (FactHandle) it.next();

                                                anObject = (Object) ksession.getObject(fH);

                                                if (anObject instanceof String)

                                                {

                                                                // prt("Ignoring back from drool the String object " + anObject.getClass().getCustomerLogName());

                                                }

                                                else if (anObject instanceof TranslatedObjectImpl)

                                                {

                                                                aTranslatedObject = (TranslatedObjectImpl) ksession.getObject(fH);

                                                                objectOutList.add(aTranslatedObject);

                                                                if (_log.isTraceEnabled()) _log.trace("Back from drools, translated object " + anObject.getClass().getSimpleName());

                                                }

                                                else

                                                {

                                                                objectOutList.add(ksession.getObject(fH));

                                                                if (_log.isTraceEnabled()) _log.trace("Back from drools, found      object " + anObject.getClass().getSimpleName());

                                                }

                                }

                                if (_log.isDebugEnabled()) _log.debug("Done with Transformer. Total number of Drools object = " + objectOutList.size());

                                ksession.dispose();



Any thoughts?



Thanks,



Dean

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20140116/527a803d/attachment-0001.html 


More information about the rules-users mailing list