Creating custom rules in PRPC – Introduction

Pega Rules Process Commander is such a wonderful product. It is built so elegantly with layer upon layer of abstraction so that a normal business user can easily change the runtime behavior in order to adjust to the changing business conditions without going through a typical development cycle. At the same time it is a mixture of J2EE technologies, bunch of browser based thin client technologies and more importantly a wonderful design that has the unique feature of "ability to be extended in multiple layers", where a person could not distinguish whether a feature is out of the box or custom made. All these are possible due to the initial wonderful design of PRPC.

One of the best things that the designers of PRPC have done is, even though there are multiple layers of abstraction, they have given us, the end developers a chance to extend the core product through custom rule creation.

Before creating custom rules first let's get a clear understanding to the question "What is a rule?". If you can remember the Fast Track training that you have attended, you may remember the phrase "Everything is a rule" and how you left the Fast Track training with that in mind. but is it correct?, frankly not, technically a rule is an instance of a concrete class which is inheriting from Rule- Class. So while Decision Table / Decision Tree are rules, Operator ID / Access group are not, they are just data objects which does not have the "Ruleness" within them. So naturally the next question should be What is "Ruleness" ?

It turns out to be, when you inherit a class from Rule- class and make it concrete, all the instances of that class will get some magical powers as opposed to instances of a normal class. Exactly 4 magical spells which as a unit can be called as Rule Resolution options.

Rule Resolution options

More importantly you as the developer can adjust the "Ruleness" according to your requirements. You get to choose the Rule Resolution options for your custom rule. You get to choose how your custom rule should behave at runtime. 

So far we have understood the concepts of Rule and "Ruleness", now let's see the big question "What is a custom rule" 

Custom rule is a rule which describes a process / execution pattern which does not available as out of the box rule in PRPC.

One of the unique features of a custom rule is that after the initial creation,  it can be used by other developers as if it were out of the box rule.

Basically there are two flavors when comes to creating and executing rules in PRPC

1. Using an Activity to interpret an instant of a rule type. (e.g. Rule-Connect-SOAP)

2. Using the “First Use Assembly” process turning the rule instance in to a java class file and then let the PRPC engine to execute (e.g. Rule-Declare-DecisionTable)

In the next post I will explain the method one, by creating a rule that connects to an excel file to read and write data (Let's call the new rule Connect-Excel ). Here is a sneak preview of how the rule looks like.

Connect Excel - write data

Comments

  1. Hi Indrajith,

    The above article was very useful,one question i have is though you create a new rule..it seems your using Apache poi to read the excel sheet.If this much of customization needs to be done why don't we convert the excel into a csv file and parse it,correct me if I am wrong.

    ReplyDelete
  2. Hi

    You have asked a good question, in essence your question is why go for a harder way when you can do the same thing with readily available PRPC out of the box rules (According to this File listeners and parse rules.)

    One of the first and important questions that a team should ask when they are planning to create a custom rule is can we do the same thing with existing rules. (There are some more points to consider - I will write those points in the next post).

    Normally in practice most of the time custom rules are created if you are building products for redistribution (Look at most of the Pega Frameworks you will find some custom rules.)

    So in a normal project with common requirements, as you said creating a custom rule to integrate with Excel can be overkill.

    But if the organization is having a BPM Center of Excellence (COE) and planning to have lots of projects or currently having bunch of projects creating a new rule wouldn't be a bad idea, because as you can see after the initial creation the next developer can use the rule as if it were out of the box rule and furthermore you have your business knowledge in a clean manner.

    In addition this rule is able to read and write data with most of the format / layout that was thrown in to it.

    Last but not least creating a custom rule is more about understanding PRPC and its beautiful design; So it necessarily doesn’t have to be a project requirement :).

    Thanks for reading the post and for your comment.

    ReplyDelete
  3. Thanks Indrajith for the detailed explanation,all your articles are really worth reading and many things can be learnt from them.
    Of all I really liked the PRPC developer tool bar...Kudos!!!!:)

    Thanks once again

    ReplyDelete
  4. Hi Indrajith,

    It would be really helpful if you can upload the RAP containing this rule and its depedency rulesets.

    Thanks in Advance

    ReplyDelete
  5. Hey Indrajith,
    Many thanks for your work and waiting for your next post

    Thanks in Advance

    ReplyDelete
  6. Hi,
    I am eagerly waiting for the continuation of the connect-EXCEL rule. Thanks for your contribution for the developer community.

    ReplyDelete
  7. Hiee Indrajith

    Thanks a ton.
    Great that you have that willingness to share your knowledge. Hats off.
    Great work and very very useful information on your blog. Keep sharing..

    ***********Eagerly waiting for your next post on creating a rule that connects to an excel file to read and write data...**************

    ReplyDelete
  8. Hi Indrajit..i have a doubt regarding execution of the custom rule...I am using Rule instruction to call my rule class evaluateRule activity...Presently i am using a parameter called 'rulename' for identifying the name of rule in evaluateRule activity. Is there any other method that can be used so that instead of passing rule name as a parameter i want to pass parameters to my rule type...

    ReplyDelete
  9. Hi Indrajith,
    I am facing one issue in support project.
    Dotnet calling PRPC Soap service.
    The issue is SOAP Service is executing two times in some cases.
    The second execution is in same node or two different nodes in SMA (we have two nodes in SMA)

    Please let me the reason why SOAP service executing second time?
    Service is Synchronous service.
    In service package context tab STATELESS.

    I observed that, If service fails to give response with in Minute, Second request raiseing.

    ReplyDelete
  10. Hi

    When you have a how to question for a specific requirement, the best place is the PDN forum where you will find a great PRPC community waiting to help you.

    https://pdn.pega.com/community/forums

    Regards
    Indrajith

    ReplyDelete

Post a Comment

Popular posts from this blog

Creating custom rules in PRPC

CSSA PDN Links Compilation