Thursday, April 17, 2014

Questions ILOG JRules Interview IBM WODM Questions

Issue in running Debug mode in Rules Studio I wrote a technical rule and would like to test this rule in debug mode. I am using JUnit test case for unit testing. i have deployed the ruleset in JUnit test project. I have set break points in technical rule. but while running in debug mode, the control is not stopping at the break points. I checked the "enable debug" option in archive.xml of the RuleApp project. Please let me know what are the things i need to take care for testing a ruleset in debug mode. Thanks in Advance. Hari == Ans you can run the rules in debug mode yes but you cannot have break points in the conditions only in actions. Before using JUnit make sure you can run the ruleset in debug mode using a simple java project for rules. A workaround to test the conditions is to create some print (log/sysout) functions returning true and just print the condition, one by one. Hope ti helps === Calling Ilog Jrule Rules Execution server from java client I am trying to execute a rule in IBM Jrule Rules execution server , using a java client. I am having Websphere community Edition V2.1 server, I am able call and execute the rules using JSF deployed in the samae server. I want to call and execute the rules using a java client. I didn't find any way to do this, In EJB. we can call EJB from web as well as from java client , by setting Initial Context envionment property. Is there any way similar to this is there, to call Rule Execution server rules, using java client, web part is already working. import ilog.rules.res.session.IlrPOJOSessionFactory; import ilog.rules.res.session.IlrStatelessSession; import ilog.rules.res.session.IlrSessionFactory; import ilog.rules.res.session.IlrStatefulSession; import ilog.rules.res.session.IlrSessionRequest; import ilog.rules.res.session.IlrJ2SESessionFactory; import ilog.rules.res.session.IlrSessionResponse; import ilog.rules.res.model.IlrPath; import ilog.rules.res.session.extension.IlrExtendedJ2SESessionFactory; import miniloan.Borrower; import miniloan.Loan; public class POJOEx { public static void main(String... arg) { // create rule session factory //IlrSessionFactory sessionFactory = new IlrPOJOSessionFactory(); //IlrExtendedJ2SESessionFactory sessionFactory = new IlrExtendedJ2SESessionFactory(); // j2se factory IlrSessionFactory sessionFactory = new IlrJ2SESessionFactory(); try { // use stateless session for invocation IlrStatelessSession statelessSession = sessionFactory.createStatelessSession(); //input parameter Borrower borrower = new miniloan.Borrower("Joe", 600, 80000); // in out parameter Loan loan = new miniloan.Loan(500000, 240, 0.05); IlrSessionRequest request = sessionFactory.createRequest(); //rule path request.setRulesetPath(IlrPath.parsePath("/miniloanruleapp/2.0/miniloanrules/1.0")); request.setUserDat("miniloanruleapp.MiniloanrulesclientRunnerImpl.executeminiloanrules"); request.setInputParameter("borrower", borrower); request.setInputParameter("loan", loan); //executing IlrSessionResponse response = statelessSession.execute(request); System.out.println("userdata = " + response.getOutputParameters().get("loan")); System.out.println("outputString = " + (String) response.getUserData()); System.out.println("executionId = " + response.getExecutionId()); } catch (Exception ex) { ex.printStackTrace(); } } } I am getting below error. ilog.rules.res.xu.ruleset.impl.archive.IlrRulesetArchiveInformationNotFoundException: Cannot get the information about the ruleset /miniloanruleapp/2.0/miniloanrules/1.0 can anybody suggest where to specify Rules execution server url, username and password. like we specify InitialContext values in EJB. === Ans Let me clarify what is RES because it seems there is a misunderstanding here, it may be me. RES is used in Ilog terminology to describe multiple things: - The web interface that allows you to manage your ruleapp. - The actual application that you deploy on your WebSphere CE (or else) in order to execute the rules. - The .jar files that allows you to execute the ruleapp locally. You, AFAIK, cannot connect RES using a local JAVA application. What you have coded is calling the rule engine contained in the RES*.jar files in order to execute your ruleapp locally. There is no way you can use your JAVA application like you are using your EJB application. You have to use a webservice or else which is feasible if you put the ruleapp name as a parameter of the web service for instance. You are using miniloan so you probably know the example using the web interface where you can tell which version of the ruleset to use. It will be the same if you want to programmatically manage your ruleapp deployed on RES (real application on your application server) you will need to use MDB. Nothing else. It is disapointing, I know because I went through that, but there is no way I know (at least) to do that. This is not the behaviour you have to follow. To make it work then put your ruleapp in the classpath (or root of your JAVA application in eclipse) and run it... Then you will execute your rules. RES doesn't provide the same tools than RTS where you can access RTS from any JAVA application in order to manipulate your rule project. You are 100% correct there is no way to tell the J2SE connection what is the server URL and hence no way to run your rules from the server. Hope it helps. ======== How to check the length of a number in JRules I am new to JRules coding.It may looks like a simple question. I would like to check the length of an number in JRules code. How to write the code for that. "the length of" phrase is expecting a string. I tried to use toString() to convert the number to String. But this is not working. Please give some idea. ======== Ans You can do that in multiple different ways, quite like going to Rome. :) 1/ In your Java: public static int getIntLength(final int myLovelyNumber) { return (new Integer(myLovelyNumber)).toString().length(); } Then, you add this lovely function to your BOM, and you verbalise it. Personally, I would create a separate library for such Helpers. An update will do the trick. 2/ In your BOM: I will assume that you start from scratch a/ Create a 'virtual' object in your BOM (personally, I would create a separate BOM for 'virtual' objects) and set the "execution name" (or something like that) to java.lang.object b/ create a 'virtual' static method in the the 'virtual' object with one parameter: Integer returning a: int c/ in the B2X of your new 'virtual' method add: return param.toString().length(); d/ verbalise the method Of course it is up to you to check for null value in Java or B2X. These are the main ways of doing it. One could find more tricky ways, but for a beginner (or not), it is a good approach. Hope it helps. PS: If you are happy with that then mark the answer as correct :) === What about negatives?, your solution will count the '-' as a significant value. So part (1) should be... public static int getIntLength(final int myLovelyNumber) { return (Integer.valueOf(Math.abs(myLovelyNumber))).toString().length(); } Also an 'int' can't be null. When you come to test it it'll be zero. =====

No comments: