Friday, December 30, 2016

REST - Integration - Part 3

In Pega, One good part is, most of the services and connectors, they had used in pega implementation itself. So we no need to search outside or in other sites to identify how to implement it in Pega.

Same in the case of Rest Connector also.

Every one of us had seen the pega developer studio, in right hand side we have seen list of updates from pega, which is provided from PDN site and its consumed through REST Connection and displayed to us.

URL Used:http://pdn.pega.com/rss/designerstudio

Connect REST:pyRSSConnectService


DataPage : D_PDNFeed

Clipboard structure of Data which we are getting after parsing from the REST and then its mapped to the Data Page are below.

Once data is mapped correctly into the Data page, In UI the data will be displayed as below:


Saturday, December 17, 2016

Some Other PRPC - Pega URLs

Some other Blogs and URLs which are giving more details about Pega PRPC are given below:

Blogspot:
http://prpcpega.blogspot.in/

http://malathigujju.blogspot.in/

http://prpcdeveloper.blogspot.in/ -- This have most Details and informations

http://usnarayana-siva.blogspot.in/

http://pegacommander.blogspot.in/

http://pisupativenkatasesha.blogspot.in/2008_12_01_archive.html

http://balakrishnathati.blogspot.in/

http://mypega.blogspot.in/

http://codepega.blogspot.in/p/pega-csa-questions.html

http://pegaguide.blogspot.in/

http://singhvikash.blogspot.in/2013/08/pega-tutorial-what-is-dco-in-pega-prpc.html

http://kbolyand.blogspot.in/2015/03/format-date-datetime-in-pega-prpc.html?view=mosaic

http://prpcgroup.blogspot.in/

https://krishnapega.blogspot.in/ - Implementation Examples had been given in this URL, Creating ZIP file, Direct Web access and so on.

http://pegaiq.blogspot.in/2014/06/how-to-call-activity-from-java-java.html - Pega simple examples and sample Interview Questions

Word Press:
https://pegalive.wordpress.com/category/pega-topics/page/2/

https://techbpm.wordpress.com/2013/12/24/pega-technical-architecture/

http://www.wordpresswiki.org/introduction-to-pega/

http://www.wptutes.org/introduction-to-pega/

http://www.slideshare.net/DeclanChellar/bpmn-in-pegasystemsprpc-flow-rules

http://pega.iexpertify.com/

https://pegaworld.wordpress.com/ - similar to above sites this also has lot of examples


Other sites:
https://www.pegaxchange.com/

http://mindmajix.com/pega-interview-questions - Pega Interview Questions with answers had been given here.

Inbound Email Configuration - Part 1

In this Post we will see how to configure the inbound email i.e. Service Email in Pega PRPC.

For Configuring that we need to create Email Listener, Service Email and Service Package.

Service Package is needed for mention Access group, to know which applivctions need to pick for rulesets and version. And Pooling and then authentication.

Service Email - that is needed to parse the Email which we got. To get informations like To, From, Subject and Message and need to process based on the data we received.

Email Listener to watch the Folder, say for example - INBOX. and other configurations like What is the email sizre it can process and how much interval it should be there.

Email Account: This it to read the email for which folder need to watch, this will be mentioned in the Email Listener.

After configuring email Listener, we need to Start the Email Listener from SMA.

Screen Shot are given below:







For Starting the Email Listener from SMA:

For Testing Simple Mail.
when mail is sent received in that Email ID, email listener will read tht email so in clipboard we can see below
After getting the values we can do modifications or updations in our applications.


Thursday, December 1, 2016

REST Wizard - Part 2

Continuation of REST wizard:
For example :

Keep our url as:


and in the same domain, other services also we need to access. Their URLs like


In that case,
While running wizard, in the Define Parameters Screen

U will get option to mark it as parameter as below.


If we want to make that as parameter and it can be passed from the activity/some other place from where we are calling this REST connector.
So that single REST connector Rule can be used for multiple purpose.

Wednesday, November 30, 2016

REST Example

Continuation of the the Previous Post.

REST data transfer will mostly will happen through JSON.
We can get the JSON as JSON object directly and parse it in the connector itself or we can get that JSON as string and map to string property, then in activity we can parse the JSON object to any desired class.

In the implementation which we implemented last time will return the response as String.
we can map that string to clipboard Property as below:

After running the data page “D_LocationsV1Adminareas”, it will give the result as below.
Data page will have source of REST Connector.

"For REST we will get the JSON string, In Connector directly we can set to Clipboard property or we can assign as JSON in response tab so that it will form the clipboard structure once it receives."

"If JSON is starting as Array without the starting element, then we cannot use Directly set as JSON. we need to set to clipboard property and parse using java function and use it.
If Starting is having single page, then directly we can use JSON in the Response Tab."

Connector Rule which is created is:


in this case JSON string we are getting and we are mapping to Clipboard and
from that JSON we need to parse to get the desired result.


After executing the data page, 


After this u can parse this JSON string to create a page list property.
And it will form a structure below. And can be used for any purpose.

how to convert JSON String to Clipboard structure:

Step 1: call the data page in step 1 with the corresponding parameters.
and get the Json string in Local Variable.
D_LocationsV1Adminareas[CountryCode:"IN",apikey:"QzV2D2TGt9AyQHvzKRqbMXXXXX"]

Step 2: Using java need to parse the JSON to XML structure.
try
{
  myStepPage.adoptJSONObject(GetResponse);
  //myStepPage.adoptJSONObject(GetResponse, "GetStateList");
  
}catch(InvalidStreamError e)
  {
  oLog.infoForced("Got Error While Parsing");
}
so that it will be easy for Other Process in Pega.

Where Reponse Output is mapped to JSON.



sample data of JSON which we will get as below:
"{"success":true,"terms":"https:\/\/currencylayer.com\/terms","privacy":"https:\/\/currencylayer.com\/privacy","historical":true,"date":"2016-10-01","timestamp":1475366399,"source":"USD","quotes":{"USDAED":3.672904,"USDAFN":65.550003,"USDALL":122.239998}} 
"

Tuesday, November 29, 2016

About Rest Wizard

For Learning REST Wizard:

REST is light weight connector. Data transfers for REST happens through HTTP protocol. And Authentication also uses same as HTTP authentication.

From Designer Studio àIntegrationàConnectorsàConnect REST integration

End Point URL used in this demo is 
http://dataservice.accuweather.com/locations

Rules will get created thru this wizard are as below:
Int-Classes, and REST rule will get created in Int-Class
And Data Classes and Data transform to set the values which we got from Int Class.
and DataPage will get created.













Thursday, November 17, 2016

Javascripts used in Pega - I

Some Javascripts are given below which are used in pega:

Javascripts use to open in new window:
<script>
function ExportExcel(){
var windowProps = 'toolbar=no,location=no,menubar=no,status=yes,scrollbars=yes,resizable=yes,width=750,height=600';
var URL = new SafeURL("ClassName.ActivityName"); //Replace ClassName with name of the Applies To class and ActivityName with name of your export activity
url = URL.toURL();
window.open(url,"_self", windowProps);
}
</script>


To Call Activity from Java Script:
For calling activity from Javascript, there is already a thread ..You have to use 'SafeUrl' and httpRequestAsync function in script.

<script>
function openActivity()
{
var oSafeURL = new SafeURL("Ecorp-Report.TestActivity");
openUrlInWindow(oSafeURL, 'popup', 'width=850,height=350,left=100,scrollbars=yes,resizable=yes,status=no,toolbar=no,menubar=no');
}
</script>

(or)

<script>
function openActivity()
{
var oSafeURL = new SafeURL("Link-Attachment.Test");
openUrlInWindow(oSafeURL.toURL(), 'popup', 'width=850,height=350,left=100,scrollbars=yes,resizable=yes,status=no,toolbar=no,menubar=no');
}
</script>

(or)

To call an activity using java script : 

1) var bSafeURL= new SafeURL("A-B-C.ActivityName");
    bSafeURL.put("param1",value1);
    bSafeURL.put("param1",value2);
    pega.util.Connect.asyncRequest('GET', bSafeURL.toURL(),'');

2) var oSafeURL = new SafeURL("@baseclass.testActivity");
oSafeURL.put("ClassName", insName);
var strRuleXml = httpRequestAsynch( oSafeURL.toURL(), null, 50, 100);

apart from there there lot other ways to do it. 

Some ways that we can achive a  call to activity and open popup window / model window:

1) 
var pxReqURI = pxRequestor.pxReqURI;
openUrlInWindow(pxReqURI + "?pyActivity=A-B-C.ActivityName&Param1=" + value1, "InteractionData", "status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,left=192,top=51.2,height=500,width=800");

2)
activityURL = "<pega:reference name="pxRequestor.pxReqURI" mode="normal"/>?pyActivity=Work-myActivity&myParameterName=" + valueToPass;
windowOptions = "width:500;height:600;resizable: yes; scroll: yes; help: no";
openUrlInWindow(activityURL,"WINDOWNAME",windowOptions,false);

3) var strWindowName = "Popup window title";

 var objSafeUrl = new SafeURL("A-B-C.Activity Name");
 var contentWin = showModalDialog(objSafeUrl.toURL(), strWindowName , "width:500;height:600;resizable: yes; scroll: yes; help: no;");

4)   var objSafeUrl = new SafeURL("A-B-C.Activity Name");
windowOptions = "width:500;height:600;resizable: yes; scroll: yes; help: no";
openUrlInWindow(objSafeUrl .toURL(),"WINDOWNAME",windowOptions,false);


Sunday, November 13, 2016

Send Email with Attachments

Sample Code for Sending Email with Attachments:

Screen shot in sample activity implementation:


Sample java code for reading the Attachment:
ClipboardPage page_Attachment = null,
              page_EmbedAttachment = null,
              page_AttachmentPage = tools.findPage("AttachmentPage");
ClipboardProperty prop_pyAttachment = null;
      prop_pyAttachment = page_AttachmentPage.getProperty(".pyAttachments(<append>)");
      page_EmbedAttachment = prop_pyAttachment.getPageValue();

java.io.DataInputStream dis = null;

String strFileName = "C://EmployeeDetails1.xls";
String strTheFileName="";
java.util.HashMap hmFileInfo = new java.util.HashMap();
java.io.File objFile = new java.io.File(strFileName);
byte buffer [] = null;
java.lang.StringBuilder strFileData = null;

try {


String sCurrentLine;

dis = new java.io.DataInputStream(new java.io.FileInputStream(objFile));
            int bufferSize = 2048001;
            int fileSize = dis.available();
System.out.println("fileSize"+fileSize);
            strFileData = new StringBuilder((int) (fileSize * 1.4));
            int noOfIterations = fileSize / bufferSize;
            for (int j = 0; j < noOfIterations; j++) {
                            buffer= new byte[bufferSize];                                                  
                            dis.read(buffer, 0, bufferSize);
                            //bytes.toString()
                            System.out.println("Buffer Size "+buffer);
                            strFileData.append(Base64Util.encodeToString(buffer)); //to encode to Base64
               //strFileData.append(buffer);
            }
            int remaining = fileSize % bufferSize;
            buffer = new byte[remaining];                                                  
            dis.read(buffer, 0, remaining);
            strFileData.append(Base64Util.encodeToString(buffer));
          //strFileData.append(buffer);
          //strFileData.append(Base64Util.encodeToString(strFileData));
            dis.close();

if (strFileData == null)

{
            //throw new PRRuntimeException("Can't continue with file upload. Couldn't encode the file to Base64 so that we can store it on the database");                                           
}
 strTheFileName = objFile.getName();
String strFileExtension = "";
int nIdx = strTheFileName.lastIndexOf(".");
if (nIdx > -1){
            strFileExtension = strTheFileName.substring(nIdx + 1);
}
String decodedFileName = StringUtils.decodeCrossOSString(strTheFileName);

System.out.println("Extension "+strFileExtension+","+strTheFileName+",file date"+strFileData);


page_EmbedAttachment.putString(".pyReference", "");

page_EmbedAttachment.putString(".pyData", strFileData.toString());
page_EmbedAttachment.putString(".pyName",decodedFileName);
page_EmbedAttachment.putString(".pyDecode","true"); 
          
          oLog.infoForced("string"+strFileData.toString());

System.out.println(strFileData);

} catch (java.io.IOException e) {
e.printStackTrace();
} finally {
try {
if (dis != null)dis.close();
} catch (java.io.IOException ex) {
ex.printStackTrace();
}
}

Saturday, November 5, 2016

To Get Absolute Path of Pega Temp Directory

To get the Absolute path in Pega of the Temp Directory:

Whatever the file we uploaded, initially it will be stored in temp directory.
And then it will be saved to database.

to get the Absolute path of the Temp Directory, we can use below code:

String   explicitTmpDir  = tools.getSystemSettings().getFSSetting("initialization/explicittempdir", "" , true, false);

In Windows - sample structure will be like C:\Pega72\PRPCPersonalEdition\temp

In Linux - Sample Structure will be like /apps/pbm/pega712/weblogic/prcache

please find the below URL to get from the PDN Link
https://pdn.pega.com/community/pega-product-support/question/finding-absolute-file-path

Activity Name where u can find sys details: SysWebInfo

Sunday, October 30, 2016

Create Excel Sheet - PRPC OOTB

Write Excel - PRPC OOTB:

In PRPC there is default Activity is there for creating excel based on the Template. Those steps are given below.

Implementation Steps:

1.Template need to be uploaded in which format data need to be exported. in path --> Technical-->Binary File.



2.In Activity - Need to call "MSOGenerateExcel".

a. Step Page for that activity is Page, where the list of values are present.


3. This activity need to be called in the section, as in the screen shot.


Demo is given below.
On click of Download Employee Details link, in the popup excel will get downloaded and screen shot is given below.


Saturday, October 29, 2016

Parse Excel Using java - POI jar - for xls

Parsing Excel can be achieved as like similar to OOTB Functionality:

This Functionality can be used in Agent or some other place where to read the excel where its stored in server. This implementation can be used as alternative for File Listener where reading the Excel file.

Using poi jar its implemented:Poi Jar

Screen shot and implementation is given:
1.First Seperate One Template Excel file which contains, for which property it should set.










2. Data sheet should be in the same format as Template excel.


3.Create a Page "TempEmployeeDetails" of class "Code-Pega-List".

4.Inside the java step for which class of pxResults need to set. "Data-" (this should be of the class name for which data should set).








Sample code is given below:

ClipboardPage Page = tools.findPage("TempEmployeeDetails");
ClipboardProperty PageListProperty = Page.getProperty(".pxResults");
try {
int TemplateColSize = 0;
int CurrentColCount=0;
java.io.FileInputStream file = new java.io.FileInputStream(new java.io.File("C:\\EmployeeDetailsData1.xls"));
java.io.FileInputStream Templatefile = new java.io.FileInputStream(new java.io.File("C:\\EmployeeDetails1.xls"));
java.util.List<String> TemplateColString = new java.util.ArrayList<String>();
//Reading Property Name from the Template File
org.apache.poi.hssf.usermodel.HSSFWorkbook Templateworkbook = new org.apache.poi.hssf.usermodel.HSSFWorkbook(Templatefile);
org.apache.poi.hssf.usermodel.HSSFSheet Templatesheet = Templateworkbook.getSheetAt(0);
//Iterate through each rows from first sheet
java.util.Iterator rowIterator = Templatesheet.iterator();
while(rowIterator.hasNext()) {
org.apache.poi.ss.usermodel.Row row = (org.apache.poi.ss.usermodel.Row) rowIterator.next();
System.out.println(row.getRowNum());
if(row.getRowNum()==1){
//For each row, iterate through each columns
java.util.Iterator cellIterator = row.cellIterator();
while(cellIterator.hasNext()) {
org.apache.poi.ss.usermodel.Cell cell = (org.apache.poi.ss.usermodel.Cell) cellIterator.next();
switch(cell.getCellType()) {
case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_STRING:
TemplateColString.add(cell.getStringCellValue());
//System.out.print(cell.getBooleanCellValue() + "\t\t");
break;
}
}
}
System.out.println("");
}
Templatefile.close();
System.out.println(TemplateColString);
TemplateColSize = TemplateColString.size();
//Iterator TemplateColStringItr = TemplateColString.iterator();
System.out.println("Size of Template Excel-->"+TemplateColString.size() +TemplateColString.get(0));
//********* Reading Template File Ends Here************//

int IntColValue=0;
String StringColValue="";
boolean BooleanColValue=false;
// Reading Data from the file
org.apache.poi.hssf.usermodel.HSSFWorkbook workbook = new org.apache.poi.hssf.usermodel.HSSFWorkbook(file);
org.apache.poi.hssf.usermodel.HSSFSheet sheet = workbook.getSheetAt(0);
//Iterate through each rows from first sheet
java.util.Iterator rowIterator1 = sheet.iterator();
while(rowIterator1.hasNext()) {
org.apache.poi.ss.usermodel.Row row = (org.apache.poi.ss.usermodel.Row) rowIterator1.next();
CurrentColCount=0;
//Create a New Page
if(row.getRowNum()>0){
//Replace Data- with Class name for which pxResults Should Form
                  ClipboardPage PageListProp= tools.createPage("Data-", "EmployeeDetail" );
//For each row, iterate through each columns
Iterator cellIterator = row.cellIterator();
while(cellIterator.hasNext()) {
if(CurrentColCount<TemplateColSize){
org.apache.poi.ss.usermodel.Cell cell = (org.apache.poi.ss.usermodel.Cell) cellIterator.next();
String NameSet=TemplateColString.get(CurrentColCount);
switch(cell.getCellType()) {
case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BOOLEAN:
//System.out.print("NameSet "+NameSet+" "+cell.getBooleanCellValue() + "\t\t");
                      BooleanColValue = cell.getBooleanCellValue();
StringColValue = Boolean.toString(BooleanColValue);
PageListProp.putString(NameSet, StringColValue);
break;
case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC:
//System.out.print("NameSet "+NameSet+" "+cell.getNumericCellValue() + "\t\t");
                      IntColValue = (int) cell.getNumericCellValue();
StringColValue = Integer.toString(IntColValue);
PageListProp.putString(NameSet, StringColValue);
break;
case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_STRING:
//System.out.print("NameSet "+NameSet+" "+cell.getStringCellValue() + "\t\t");
StringColValue = cell.getStringCellValue();
PageListProp.putString(NameSet, StringColValue);
break;
}
//System.out.print(NameSet+cell.getStringCellValue());
CurrentColCount++;
}
}
                  PageListProperty.add(PageListProp);
}
//Add  the Newly Added Page to some Page List
System.out.println("");
}
file.close();
java.io.FileOutputStream out = 
new java.io.FileOutputStream(new java.io.File("C:\\test.xls"));
workbook.write(out);
out.close(); 

} catch (java.io.FileNotFoundException e) {
e.printStackTrace();
} catch (java.io.IOException e) {
e.printStackTrace();
}

Friday, October 28, 2016

Parse Excel Using PRPC - OOTB

Parsing Excel sheet in Pega:

We are having default pega activities for parsing the excel. We will see how we need to implement it.

Steps for parsing the Excel Data:
1. Create a data class for which Data you wanted to store.
here in example wanted to Upload Employee Data, so Create a Class of EmployeeDetails and its properties.
2. Excel in which format you will be uploading the data, Template Excel need to Upload.
Sample excel format is given below.
Template need to uploaded in the path Technical-->Binary File.
Screen shot:


3. For Uploading the file, OOTB pega section is "pxFileUpload"  we can use. In any flow action we can call this flow action to get upload button.
"FilePath" is the Control Used.
Screen shot:

4. In the activity you need to call "MSOParseExcelFile" - activity which will parse the uploaded excel.
as paramter give the details as in the screen shot.
FSFileName: all file which are uplloaded by default it will store in this page"pxRequestor.pyFileUpload"
TemplateRFB: Template Name which u uploaded in the step - 2

5. Call this activity in the Post Activity of the Flow action.
Screen shot:




Then in  the Clipboard u will get as below page.



Now it will store the data as Julian Date.
If Date is there then we can mention the data in the YYYYMMDD format. (ex. 20160202)
And that property also can be mentioned as Text in the Pega, so it will parse in the same format, then in Pega Activity we can change to any format we needed.