XSD Property generation in Pega

This Post will shows how to generate the Property , classes and XML mapping rules in pega with Provided XSD 

Check the provided XSD and see if the format is correct 
 -> you can open the xsd in internet browser 

Now create a ruleset and ruleset version for the rules to be created 

For example Org-Int-policy and 01-01-01

 Now import the XSD to Pega using wizard

Provide the details as screenshot and go to next screen



Import the XSD Here 



Select the element name and select the rule to be created , in my case it all





Now check the list of rules to be created and finish for the rules to be created 



After finish , the rules are created and you will have a option to clean up at the last to delete everything

Pega QUIZ


Pega Certified System Architect Quiz 1

Pega Certified System Architect Quiz 2

Pega Certified System Architect Quiz 3

Pega Certified System Architect Quiz 4

Pega Certified System Architect Quiz 5

Pega Certified System Architect Quiz 6

One Time Processing

For an Application which is already in Production, we come across multiple scenario, where we have to run business logic to already existing work object and cases so that they can work with new updates.

Instead of running multiple OTA's  (one time activity) every time for every release. We are gonna generalize few rules and let Pega take care of running the OTA's /

We need data table to store the instance and OTA Processing Activity  to run the business logic,

Production Deployment Query

This post will help me to identify the missing rules and rulesets in Production after the deployment / Migration.

Run the Query and Put the results One below another in Excel sheet and mark duplicates.

The row which are not highlighted are the culprits!!

Use case Ruleset and count of rules
Query
  select concat(pyruleset, pyrulesetversion), count(pzinskey) 
from pegrule.pr4_rule_vw
where pyRuleSet like 'ORG%'
group by pyruleset, pyrulesetversion;
Use case Rulename,pzinskey With Op Name to compare the rules migrated
Query
select concat(pyruleset, pyrulesetversion,pyRuleName),
pzInsKey,pxUpdateOpName
from pegrule.pr4_rule_vw
where pyRuleSet like 'ORG%' and pxUpdateDateTime>'20230101'
AND pxUpdateOpName='John Doe';

Java syntax in Activity

Though Pega suggest us not to use java , certain times we are forced to use java for the complex solutions.
For a guy like me , who did not do java as curriculum always depends on google for the java code.
This post is going to help me to identify the syntax of certain java code which I have used

Click the button to copy the syntax and paste in the Java beautifier for alignment
https://codebeautify.org/javaviewer

Use case Add Log message
Syntax
  oLog.infoForced("Log message Here");
Use case Add try and catch block
Syntax
  try {
   oLog.infoForced("try block executed");
   } catch (Exception ex) {
    oLog.error("catch block executed", ex.toString());
} 
Use case To get current Date and Time
Syntax
  Date date1 = java.util.Calendar.getInstance().getTime();
      oLog.infoForced("Current Date Time"+ date1);
Use case To get current Date and Time
Syntax
  Date date1 = java.util.Calendar.getInstance().getTime();
      oLog.infoForced("Current Date Time"+ date1);
Use case Convert Bigdecimal(input) to date format
Syntax
  DateFormat df = new SimpleDateFormat("dd/MMM/YYYY");
      String date = df.format(input);
      oLog.infoForced("Converted Date format"+ date);
Use case To create a Clipboard page object from step page/ Page/ datapage
Syntax
ClipboardPage sp1 = myStepPage;
ClipboardPage sp2 = tools.getStepPage();
ClipboardPage cp  tools.findPage("PageName");
ClipboardPage dp  tools.findPage("D_PageName");
Use case To create a Clipboard property object from step page/ Page/ datapage
Syntax
ClipboardPage cp  tools.findPage("PageName");
String ABC = cp.getProperty("pyLabel").toString();
Use case To Loop over PageList / datapage - (D_PageName.pxResults(1).PNAME)
Syntax
String DatapageName = "D_PageName";
ClipboardPage dpage tools.findPage(DatapageName);
if (dpage != null) {
    ClipboardProperty Results = dpage.getIfPresent("pxResults");
    Iterator it = Results.iterator();
    while (it.hasNext()) {
        ClipboardProperty next = (ClipboardProperty) it.next();
        ClipboardPage nextPage = next.getPageValue();
        ClipbaordProperty propertyname = nextPage.getIfPresent("PNAME");
    	oLog.infoForced("Print Property"+ propertyname);
    }
}
Use case For Loop Logic
Syntax
int size = 10000;
    int size = sp.getProperty("PropertyName").size();
    for (int i=1 ; i <= size ; i++)
    {
    oLog.infoForced("For logic"+ i);
    }

Java to check the files in server

This post shows me how to check the files and folders in the server where pega is installed.

Since I don't have access to Pega production server directly , I have used Java here to display the list of files and folders in Pega logs.

This will help me to confirm if the file listener files are present in path or not.


try { oLog.infoForced("[FilesInDirectory] try block started "); java.io.File fileContents[] = new java.io.File(Path).listFiles(); if (fileContents != null) { for (int i = 0; i < fileContents.length; i++) { if (fileContents[i].isDirectory()) { oLog.infoForced("[FilesInDirectory] Folder: " + fileContents[i]); } else { oLog.infoForced("[FilesInDirectory] File: " + fileContents[i]); } } } oLog.infoForced("[FilesInDirectory] try block Ended "); } catch (Exception ex) { oLog.error("[FilesInDirectory] catch block expected", ex); }

try {
   oLog.infoForced("[FilesInDirectory] try block started ");
    java.io.File fileContents[] = new java.io.File(Path).listFiles();
    if (fileContents != null) {
    for (int i = 0; i < fileContents.length; i++) {
       if (fileContents[i].isDirectory()) {
    oLog.infoForced("[FilesInDirectory] Folder: " + fileContents[i]); 
} else {
                oLog.infoForced("[FilesInDirectory] File: " + fileContents[i]);
            }
        }
    }
    oLog.infoForced("[FilesInDirectory] try block Ended ");

} catch (Exception ex) {
    oLog.error("[FilesInDirectory] catch block expected", ex);
} 

Create a New Activity in Pega with parameter "Path" to pass to java step and Paste the above Java Code.

This activity contains only two steps .
1) First to set the Param.Path to Local.Path
2) Run the Java

Since I am running on my Local machine (windows) , I am passing the path as D:\InstallationApps\PRPCPersonalEdition\tomcat . If Its Linux ,we can just pass /opt

Now check the logs for the list of files and folders.

Connect Rest with Clash of clans Part 2

In the Previous Post Part 1, we saw how to get the API key from clash of clans and use it in postman to get the response.

In this Post , we will use the details from postman and create a integration in Pega.

Integration was always a difficult topic for me , there is so many topics around it (authorization, authentication, data model , integration layer ,connection time out, certificate failure) which makes it look like a nightmare. All the terms which developers use for while working integration like Parsing , converting Json/XML , Request DT , Response DT , Mapping makes it more complicated to understand the topic.

 I am going to learn one at a time and write a post about it for my future reference here. This Post will help me to understand the basic of integration and how Pega helps in creating the most of the rules required for integration.

 

Why do we need integration ?

For example : Consider two web applications which is already built in Java and Python. Now if you need data from One application to another which does not understand each other, then Integration is the way to connect to these two systems.

 

There are two types of rules in Pega which helps in integrating two applications. (another confusing terminology)

 

Connector - When you need some data , you create a connector to get the data. (Get Data - connector)

 

Service - when you need to give data , you create a service to give the data.(Give Data - Service)


Which API are gonna be used?

From the list of operations , I have selected two simple operations.

  1.  To get information about all the locations
  2.  To get the information about the player rankings for a specific location (For you to try)

 

Requirement in Pega :

Create two dropdown , one to fetch the list of location . After selecting location , pass the location to get the list of Player ranking

 

First lets create the integration rules then create a section to display to location and player list.

 

Open designer studio and Navigate to Create Rest Integration




There are 4 screens which needs to be completed.

First screen:

Provide the name : COC  ("Clash of clans") and End point URL : https://api.clashofclans.com/v1/locations
Since we are using token as authentication type , we don’t need a separate authentication profile instead we can pass the token as header (reference postman).





Second screen: Provide Resource name and select the method you want to use for this integration. (For eg Get Method , Reference from postman)


Third screen: One of the important screen, where our Data model for our integration is determined. Also we can check if our integration works too.

Two options to add the data model :1) Either you can add the REST response from postman 2) Trigger the integration and get the response .

 

I am going with option 2 , Add a REST response . In the header , Authorization field provide the token copied from postman and click run.

 




Forth Screen : Another important screen , whether the class structure is defined.

Make sure for Integration layer , Int class is selected as Parent class and  the context as Integration ruleset.

Make sure for Data layer , Data class is selected as Parent class and the context as Application ruleset.



If required Preview records and Click create . Please find the list of rules Pega has created below

 

  1. Datapage
  2. Connect Rest
  3. Class required for Integration
  4. Property required for integration
  5. Response Data transform
  6. Request Data transform

Now Provide the dropdown source as Datapage and check if results are populated.





Food for thought : Similarly , Now you can try to create the next integration ( To get the information about the player rankings for a specific location) to pass the location and get the list of players ranking.





Connect Rest with Clash of clans Part 1

 In this Post , We are gonna use API from Clash of Clans and Use Postman to check if API works.

What is clash of clans (COC) ?

Clash of Clans is an online strategy game for mobile. Well if you have no idea how this game is played, in brief, a Clasher has a village and an army. Clashers attack each other’s villages in multiplayer battles, form clans together, participate in wars against other clans, and lead their clans to victory.




How to access the clash of clans API ?

 

Registration an developer account with Clash of clans



Create an API token to access the Clash of clans API

  • Login to clash of clans
  • Navigate to Account name and Select My account
  • Under my account , Create New Key
  • Provide Name , Description and for allowed IP Address check the IP address from https://whatismyipaddress.com
  • click create key and copy the token to a notepad.





To check the list of API provided by clash of clans

From the list of operations , I have selected two simple operations.

  1.  To get information about all the locations
  2.  To get the information about the player rankings for a specific location



Using Postman To check if API works

Create new request and give the End point URL: https://api.clashofclans.com/v1/locations



In the Authorization tab, select the type as Bearer token and provide the token from notepad.


Click send to check if status is 200 (connected successfully) and the response is returned in JSON format.



Food for thought : In the same way, you can use the other API's from clash of clans and use postman to check if API response is received or not.


In the below post , we will see how pega can use the clash of Clans API and display the results.

https://welearnpega.blogspot.com/2021/01/connect-rest-with-clash-of-clans-part-2.html

OAuth Explanation in simplest way

This post helps me in understanding the concept of OAuth in a simplest way.

As I am from a non-computer background, It was really very hard to understand the concept of OAuth . All material online / YouTube which I referred appear to be Greek and Latin to understand the concept .

Finally ,I asked the same to one of my senior who explained me with a very simple concept .I am going to share the same conversation here translated in English.


Junior : Bro , You Do know about this OAuth ? I read online bro but did not understand it completely ?

Senior : Its Easy bro.

Junior : I need to understand from scratch and basics. Can you help?

Senior : Sure bro .

 There are important terminology (client , Resource , token, Resource owner) . Once client get the token, client can access the resource of resource owner.

 See this is the Definition of OAuth

 OAuth is an open standard for access delegation, commonly used as a way for Internet users to grant websites or applications access to their information on other websites but without giving them the passwords

 Junior : No no no no no !! Did not understand a word bro!!

 Senior : Cool , Let's Consider a scenario here . Have you booked an hotel online . how did you book and access your room in the hotel ?

 Junior : I booked the room using andriod app and went to receptionist to show my ID and got the room key.

 Senior : Now think of your Scenario

    We have a room = Resource

    We have a hotel which is owned by Hotel owner = Resource owner

    We have a key which is used to access the hotel room = token

    You are the one who is using the key= client

 So In order to use the room , you need a key , In order to get the key you need to show your ID. Once you got the key , you can go out and come in any time without showing the ID again. Right ? Let me put this in computer terms.

Scenario terms

Computer terms

If you need to use the room of the Hotel , you need a Key.

 

Once you get the key , you can  access the room any no of times.

If client need  to use the resource  of the resource owner ,client need a Token.

 

Once client get the token , client can access the resource any no of times.


Junior
:Interesting bro!! Continue

Senior : Now the same is happening  between services/two different applications.

Junior : What! between services.

Senior : Have you seen when you try to log in on some applications or website. They have the option to either SignUp or you can log in using your Google or Facebook account. You see options like “Sign in with Google” or “Sign in with Facebook

Junior : Yes I have seen this a lot of times


Senior : They all work using concept of OAuth .Let’s understand with an example.

We have online photo editing application ( For eg. Lunapic) and we have file storage application (For eg. Google photos).

Now they are serveral ways you can upload the file to Lunapic.

https://www12.lunapic.com/editor/?action=moreupload

 

Method 1.  Download the file from google drive and Store in File system (Computer) and upload from your file sytem(computer) to Lunapic


Method 2.You can give username and password to lunapic team to take the photos and edit it

Junior : First method looks more secure, Because what if lunapic team takes all my photos.

Senior : Exactly bro. But First method is overkill . Now, what if lunapic ask you permission to access the photo and you only give access to fetch only one photo. 

Junior : How does that happen bro ?

Senior : This happens using OAuth which involves below 4 steps :

 Step 1: The Lunapic application will identify the account and will ask google photos to get access to your photos

 Note the URL :

 https://accounts.google.com/o/oauth2/v2/auth/identifier?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fphotoslibrary&access_type=online&include_granted_scopes=true&state=state_parameter_passthrough_value&redirect_uri=https%3A%2F%2Fwww.lunapic.com%2Feditor%2Fgo.php&response_type=code&client_id=6125777372369-jple8fe1j605jubiddv9ea8cc4i1tiuf.apps.googleusercontent.com&flowName=GeneralOAuthFlow

 





Step 2: The google photos service will ask you whether to allow Lunapic application to access your photos.

(It will show you the permissions this application will have once you allow)

(assuming you say Yes)

 

Note the URL :

https://accounts.google.com/signin/oauth/consent?authuser=0&part=AJ2345i8hAPchG5LEmTYx6_QG-Ra-l06g2MbSi77rBgWw-LkAMujDHvNMRu64PE1Cqz123zt9Jv7zQvFsZz7agWnG9rK4Uzd34bS4uqQlB_0diL3453YOt8FLazstkZl9SCyHtcB2MI5BWOUmCUBbRH2IixcGNct3dQ5D1_v2ROsWmGjA7KBO123123zFJx4-v08YWWtbFiq-dil6dqdPwKOxt1AMdpe9BJn2or1rkhTIvBFmc1ketlD16S4dzFFoM9GCuzf2pHKo2xtC_Od_FYjwZRZn7knhRkGDN3Ia-rTlIBA27eAaNW12313eyVE-9oJONK2tx41awY2zGeJ5VpHuyGcR7P40pmnMqdCZIu8i8CDpZogPikJyqDHYeSCTSn1-VCPBLc8A12316irdnCkBCoyi33paFoz3jdUSWliPFPpvalUKZo-JXyDiNcVSizWhjfoDLI9cdy39AfN96PIff9-NrLTBZJ6dO-&as=S-335394665%3A15123139818031231230020050&rapt=AEjHL4NCGYreG-A032b8Pc2uS5IHeYLLQNv4QBL4WLj_PcJqlFIv5TJpBPQQaFag_h4t7yVEjsOzkalkIgasJuP0WRQvOKWW1A#

 


Step 3: The google photos service now hands over a key to the Lunapic called authorization token (Remember using the key to your hotel room)

  Note the URL: (It changes in a fraction of second) and the bold highlighted text  in URL is token here.

 

https://www.lunapic.com/editor/go.php?state=state_parameter_passthrough_value&code=4/3Q3SP6D6DhscJXtNeK1s4nTiTOc1az1Q2L_qUmHKPJDkidPlCfiYc0UOV4aVXn_Ewae6Z7ZA_1NbPlpGnNK7y-f-g&scope=https://www.googleapis.com/auth/photoslibrary

 

Step 4: Now the Lunapic can get access to your photos using the access key or token

 

Junior : So whenever I see the login with facebook and login with google , it's all OAuth concept

Senior : Yes bro! Now tell me terminology involved in this scenario

Junior :      

Resource Photos in Google photos
Resouce owner Google photos
Client Lunapic
Key  Authorization token

 

Senior :Correct!! Last but not the least. Why the token is called Authorization token ?

 

OAuth doesn't act as authentication data between client and service providers – but instead acts as an authorization 

 

Now read the definition

 

OAuth is an open standard for access delegation, commonly used as a way for Internet users to grant websites or applications access to their information on other websites but without giving them the passwords

 

Junior : Thanks Bro!! Now I know the basics , Let me check some use case with Pega.


PS: Credits to the senior : Arvind Ranganath. R

Tracer Viewer

Why I used tracer viewer ?

Last week , we had a production defect which was not reproducible in other environments. 

We checked logs and PDC too, but could not find anything suspicious. 
So Only Option left was to trace the scenario in production in run time. 

Production environment was accessible only through VDI and we tried remote tracing.

We all know the pain in working with VDI. It responds really slow and will test your patience.

Luckily found the tracer viewer tool which is provided by pega ,by which you can easily download the tracer as xml file and load the tracer locally.

What are the system requirements to run the Tracer tool ?

Pega-TracerViewer is a Java Swing based tool to view Pega Tracer xml files.

So you need latest java(jre+jdk) to be installed with file path.

Most easiest way to check if java is installed or not .

Open command prompt and type java -version.


How to Download the Tracer Tool and where is it available ?

Tracer viewer tool is available in the below link

The tool can be downloaded as zip file.


How to run Pega tracer viewer ?

Simply Extract 'pega-tracerviewer.zip' to a folder.
Run 'pega-tracerviewer.cmd' to launch the tool.


How to save the tracer and open with tool ?

Open the tracer , run the scenario and simply click on save , you will get the xml file. (I got it mailed from onshore)

Open tracer tool and go to file -> Load Pega tracer file and select the xml file.

What are the other things I can do ?

By using TracerViewer, you can do the following actions:

  • View the Tracer data offline after the test is complete.
  • Organize the data in a table or in tree views.
  • Sort the data, for example, by slowest call.
  • Search the Tracer tool output data.
  • View Performance tool statistics for each interaction (for 6.2 and later).
  • View alerts and SQL statements in the context of where and when they occurred (for 6.2 and later).
  • Group traced events by a key, such as a unique SQL statement (for 6.2 and later), stream, activity, or method.

Where can i find more details ?